diff options
Diffstat (limited to 'docker/api/buildkit/auth/auth.py')
-rw-r--r-- | docker/api/buildkit/auth/auth.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docker/api/buildkit/auth/auth.py b/docker/api/buildkit/auth/auth.py new file mode 100644 index 0000000..df096a7 --- /dev/null +++ b/docker/api/buildkit/auth/auth.py @@ -0,0 +1,26 @@ +from .auth_pb2 import CredentialsResponse +from .auth_grpc import AuthBase +from ..grpc import Attachable +from docker.auth import resolve_authconfig + + +class Auth(AuthBase, Attachable): + def __init__(self, authconfig, credstore_env, *args, **kwargs): + self.authconfig = authconfig + self.credstore_env = credstore_env + super(Auth, self).__init__(*args, **kwargs) + + async def Credentials(self, stream): + request = await stream.recv_message() + host = request.Host + auth_data = resolve_authconfig( + self.authconfig, host, self.credstore_env + ) + response = None + if auth_data is None: + response = CredentialsResponse(Username=None, Secret=None) + else: + response = CredentialsResponse( + Username=auth_data['Username'], Secret=auth_data['Password'] + ) + await stream.send_message(response) |