@@ -2156,14 +2156,22 @@ def validate_github_token(token, github_user):
2156
2156
* see if it conforms expectations (only [a-f]+[0-9] characters, length of 40)
2157
2157
* see if it can be used for authenticated access
2158
2158
"""
2159
- sha_regex = re .compile ('^[0-9a-f]{40}' )
2159
+ # cfr. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
2160
+ token_regex = re .compile ('^ghp_[a-zA-Z0-9]{36}$' )
2161
+ token_regex_old_format = re .compile ('^[0-9a-f]{40}$' )
2160
2162
2161
2163
# token should be 40 characters long, and only contain characters in [0-9a-f]
2162
- sanity_check = bool (sha_regex .match (token ))
2164
+ sanity_check = bool (token_regex .match (token ))
2163
2165
if sanity_check :
2164
2166
_log .info ("Sanity check on token passed" )
2165
2167
else :
2166
- _log .warning ("Sanity check on token failed; token doesn't match pattern '%s'" , sha_regex .pattern )
2168
+ _log .warning ("Sanity check on token failed; token doesn't match pattern '%s'" , token_regex .pattern )
2169
+ sanity_check = bool (token_regex_old_format .match (token ))
2170
+ if sanity_check :
2171
+ _log .info ("Sanity check on token (old format) passed" )
2172
+ else :
2173
+ _log .warning ("Sanity check on token failed; token doesn't match pattern '%s'" ,
2174
+ token_regex_old_format .pattern )
2167
2175
2168
2176
# try and determine sha of latest commit in easybuilders/easybuild-easyconfigs repo through authenticated access
2169
2177
sha = None
@@ -2173,6 +2181,7 @@ def validate_github_token(token, github_user):
2173
2181
except Exception as err :
2174
2182
_log .warning ("An exception occurred when trying to use token for authenticated GitHub access: %s" , err )
2175
2183
2184
+ sha_regex = re .compile ('^[0-9a-f]{40}$' )
2176
2185
token_test = bool (sha_regex .match (sha or '' ))
2177
2186
if token_test :
2178
2187
_log .info ("GitHub token can be used for authenticated GitHub access, validation passed" )
0 commit comments