@ -200,11 +200,11 @@ def ShouldUseSSO(host: str) -> bool:
return False
class Authenticator( object ) :
class _ Authenticator( object ) :
""" Base authenticator class for authenticator implementations to subclass. """
# Cached Authenticator subclass instance, resolved via get().
_resolved : Optional [ Authenticator] = None
# Cached _ Authenticator subclass instance, resolved via get().
_resolved : Optional [ _ Authenticator] = None
_resolved_lock = threading . Lock ( )
def authenticate ( self , conn : HttpConn ) :
@ -212,7 +212,7 @@ class Authenticator(object):
raise NotImplementedError ( )
def debug_summary_state ( self ) - > str :
""" If this Authenticator has any debugging information about its state,
""" If this _ Authenticator has any debugging information about its state,
_WriteGitPushTraces will call this to include in the git push traces .
Return value is any relevant debugging information with all PII / secrets
@ -241,12 +241,12 @@ class Authenticator(object):
@classmethod
def get ( cls ) :
""" Returns: ( Authenticator) The identified Authenticator to use.
""" Returns: ( _ Authenticator) The identified _ Authenticator to use.
Probes the local system and its environment and identifies the
Authenticator instance to use .
_ Authenticator instance to use .
The resolved Authenticator instance is cached as a class variable .
The resolved _ Authenticator instance is cached as a class variable .
"""
with cls . _resolved_lock :
if ret := cls . _resolved :
@ -258,14 +258,14 @@ class Authenticator(object):
skip_sso = newauth . SkipSSO ( )
if use_new_auth :
LOGGER . debug ( ' Authenticator.get: using new auth stack' )
LOGGER . debug ( ' _ Authenticator.get: using new auth stack' )
if LuciContextAuthenticator . is_applicable ( ) :
LOGGER . debug (
' Authenticator.get: using LUCI context authenticator' )
' _ Authenticator.get: using LUCI context authenticator' )
ret = LuciContextAuthenticator ( )
else :
LOGGER . debug (
' Authenticator.get: using chained authenticator' )
' _ Authenticator.get: using chained authenticator' )
a = [
SSOAuthenticator ( ) ,
# GCE detection can't distinguish cloud workstations.
@ -287,7 +287,7 @@ class Authenticator(object):
for candidate in authenticators :
if candidate . is_applicable ( ) :
LOGGER . debug ( ' Authenticator.get: Selected %s . ' ,
LOGGER . debug ( ' _ Authenticator.get: Selected %s . ' ,
candidate . __name__ )
ret = candidate ( )
cls . _resolved = ret
@ -299,7 +299,23 @@ class Authenticator(object):
)
class SSOAuthenticator ( Authenticator ) :
def debug_auth ( ) - > Tuple [ str , str ] :
""" Returns the name of the chosen auth scheme and any additional debugging
information for that authentication scheme . """
authn = _Authenticator . get ( )
return authn . __class__ . __name__ , authn . debug_summary_state ( )
def ensure_authenticated ( gerrit_host : str , git_host : str ) - > Tuple [ bool , str ] :
""" Returns (bypassable, error message).
If the error message is empty , there is no error to report . If bypassable is
true , the caller will allow the user to continue past the error .
"""
return _Authenticator . get ( ) . ensure_authenticated ( gerrit_host , git_host )
class SSOAuthenticator ( _Authenticator ) :
""" SSOAuthenticator implements a Google-internal authentication scheme.
TEMPORARY configuration for Googlers ( one ` url ` block for each Gerrit host ) :
@ -515,8 +531,8 @@ class SSOAuthenticator(Authenticator):
return ' '
class CookiesAuthenticator ( Authenticator) :
""" Authenticator implementation that uses " .gitcookies " for token.
class CookiesAuthenticator ( _ Authenticator) :
""" _ Authenticator implementation that uses " .gitcookies " for token.
Expected case for developer workstations .
"""
@ -525,7 +541,7 @@ class CookiesAuthenticator(Authenticator):
def __init__ ( self ) :
# Credentials will be loaded lazily on first use. This ensures
# Authenticator get() can always construct an authenticator, even if
# _ Authenticator get() can always construct an authenticator, even if
# something is broken. This allows 'creds-check' to proceed to actually
# checking creds later, rigorously (instead of blowing up with a cryptic
# error if they are wrong).
@ -677,8 +693,8 @@ class CookiesAuthenticator(Authenticator):
return ' %s @ %s ' % ( username , domain )
class GceAuthenticator ( Authenticator) :
""" Authenticator implementation that uses GCE metadata service for token.
class GceAuthenticator ( _ Authenticator) :
""" _ Authenticator implementation that uses GCE metadata service for token.
"""
_INFO_URL = ' http://metadata.google.internal '
@ -757,8 +773,8 @@ class GceAuthenticator(Authenticator):
return ' '
class LuciContextAuthenticator ( Authenticator) :
""" Authenticator implementation that uses LUCI_CONTEXT ambient local auth.
class LuciContextAuthenticator ( _ Authenticator) :
""" _ Authenticator implementation that uses LUCI_CONTEXT ambient local auth.
"""
@staticmethod
def is_applicable ( * , conn : Optional [ HttpConn ] = None ) :
@ -778,7 +794,7 @@ class LuciContextAuthenticator(Authenticator):
class LuciAuthAuthenticator ( LuciContextAuthenticator ) :
""" Authenticator implementation that uses `luci-auth` credentials.
""" _ Authenticator implementation that uses `luci-auth` credentials.
This is the same as LuciContextAuthenticator , except that it is for local
non - google . com developer credentials .
@ -789,13 +805,13 @@ class LuciAuthAuthenticator(LuciContextAuthenticator):
return True
class ChainedAuthenticator ( Authenticator) :
""" Authenticator that delegates to others in sequence.
class ChainedAuthenticator ( _ Authenticator) :
""" _ Authenticator that delegates to others in sequence.
Authenticators should implement the method ` is_applicable_for ` .
"""
def __init__ ( self , authenticators : List [ Authenticator] ) :
def __init__ ( self , authenticators : List [ _ Authenticator] ) :
self . authenticators = list ( authenticators )
def is_applicable ( self , * , conn : Optional [ HttpConn ] = None ) - > bool :
@ -889,7 +905,7 @@ def CreateHttpConn(host,
body : Optional [ Dict ] = None ,
timeout = 300 ,
* ,
authenticator : Optional [ Authenticator] = None ) - > HttpConn :
authenticator : Optional [ _ Authenticator] = None ) - > HttpConn :
""" Opens an HTTPS connection to a Gerrit service, and sends a request. """
headers = headers or { }
bare_host = host . partition ( ' : ' ) [ 0 ]
@ -914,7 +930,7 @@ def CreateHttpConn(host,
req_body = rendered_body )
if authenticator is None :
authenticator = Authenticator. get ( )
authenticator = _ Authenticator. get ( )
# TODO(crbug.com/1059384): Automatically detect when running on cloudtop.
if isinstance ( authenticator , GceAuthenticator ) :
print ( ' If you \' re on a cloudtop instance, export '
@ -1728,7 +1744,7 @@ class EmailRecord(TypedDict):
def GetAccountEmails ( host ,
account_id = ' self ' ,
* ,
authenticator : Optional [ Authenticator] = None
authenticator : Optional [ _ Authenticator] = None
) - > Optional [ List [ EmailRecord ] ] :
""" Returns all emails for this account, and an indication of which of these
is preferred .