# Path: harpoon/amazon.py
# def assume_role(arn):
#     if boto3 is None:
#         raise FoundNoBoto()
# 
#     log.info("Assuming role as %s", arn)
# 
#     session = boto3.session.Session()
#     session_name = "harpoon-{0}-".format(VERSION)
# 
#     # Clear out empty values
#     for name in [
#         "AWS_ACCESS_KEY_ID",
#         "AWS_SECRET_ACCESS_KEY",
#         "AWS_SECURITY_TOKEN",
#         "AWS_SESSION_TOKEN",
#     ]:
#         if name in os.environ and not os.environ[name]:
#             del os.environ[name]
# 
#     sts = session.client("sts")
#     with catch_no_credentials("Couldn't assume role", arn=arn):
#         with catch_boto_400("Couldn't assume role", arn=arn):
#             creds = sts.assume_role(RoleArn=arn, RoleSessionName=session_name)["Credentials"]
# 
#     return boto3.session.Session(
#         aws_access_key_id=creds["AccessKeyId"],
#         aws_secret_access_key=creds["SecretAccessKey"],
#         aws_session_token=creds["SessionToken"],
#     )
# 
# def decrypt_kms(session, ciphertext, region):
#     return session.client("kms", region).decrypt(CiphertextBlob=base64.b64decode(ciphertext))[
#         "Plaintext"
#     ]
# 
# def get_s3_slip(session, location):
#     parsed = urlparse(location)
#     log.info("Getting slip from s3://{0}{1}".format(parsed.netloc, parsed.path))
#     return (
#         session.resource("s3").Object(parsed.netloc, parsed.path[1:]).get()["Body"].read().strip()
#     )


from harpoon.amazon import assume_role, decrypt_kms, get_s3_slip
from delfick_project.norms import sb, dictobj
from urllib.parse import urlparse
import subprocess
import logging
import time
import os
                process = subprocess.Popen(["docker", "login", "--help"], stdout=subprocess.PIPE)
                out, _ = process.communicate()
                if isinstance(out, bytes):
                    out = out.decode()

                if "-e, --email" in out:
                    cmd = "docker login -u {0} -p {1} -e emailnotneeded@goawaydocker.com {2}".format(
                        username, password, registry
                    )
                else:
                    cmd = "docker login -u {0} -p {1} {2}".format(username, password, registry)
                os.system(cmd)
                docker_api.reload_config()
            else:
                docker_api.login(username, password, registry=registry, reauth=True)


class PlainAuthentication(dictobj):
    fields = ["username", "password"]

    @property
    def creds(self):
        return self.username, self.password


class KmsAuthentication(dictobj):
    fields = ["username", "password", "role", "region"]

    @property
    def creds(self):

# Path: harpoon/amazon.py
# def assume_role(arn):
#     if boto3 is None:
#         raise FoundNoBoto()
# 
#     log.info("Assuming role as %s", arn)
# 
#     session = boto3.session.Session()
#     session_name = "harpoon-{0}-".format(VERSION)
# 
#     # Clear out empty values
#     for name in [
#         "AWS_ACCESS_KEY_ID",
#         "AWS_SECRET_ACCESS_KEY",
#         "AWS_SECURITY_TOKEN",
#         "AWS_SESSION_TOKEN",
#     ]:
#         if name in os.environ and not os.environ[name]:
#             del os.environ[name]
# 
#     sts = session.client("sts")
#     with catch_no_credentials("Couldn't assume role", arn=arn):
#         with catch_boto_400("Couldn't assume role", arn=arn):
#             creds = sts.assume_role(RoleArn=arn, RoleSessionName=session_name)["Credentials"]
# 
#     return boto3.session.Session(
#         aws_access_key_id=creds["AccessKeyId"],
#         aws_secret_access_key=creds["SecretAccessKey"],
#         aws_session_token=creds["SessionToken"],
#     )
# 
# def decrypt_kms(session, ciphertext, region):
#     return session.client("kms", region).decrypt(CiphertextBlob=base64.b64decode(ciphertext))[
#         "Plaintext"
#     ]
# 
# def get_s3_slip(session, location):
#     parsed = urlparse(location)
#     log.info("Getting slip from s3://{0}{1}".format(parsed.netloc, parsed.path))
#     return (
#         session.resource("s3").Object(parsed.netloc, parsed.path[1:]).get()["Body"].read().strip()
#     )


# Path: harpoon/option_spec/authentication_objs.py
from harpoon.amazon import assume_role, decrypt_kms, get_s3_slip
from delfick_project.norms import sb, dictobj
from urllib.parse import urlparse
import subprocess
import logging
import time
import os

                process = subprocess.Popen(["docker", "login", "--help"], stdout=subprocess.PIPE)
                out, _ = process.communicate()
                if isinstance(out, bytes):
                    out = out.decode()

                if "-e, --email" in out:
                    cmd = "docker login -u {0} -p {1} -e emailnotneeded@goawaydocker.com {2}".format(
                        username, password, registry
                    )
                else:
                    cmd = "docker login -u {0} -p {1} {2}".format(username, password, registry)
                os.system(cmd)
                docker_api.reload_config()
            else:
                docker_api.login(username, password, registry=registry, reauth=True)


class PlainAuthentication(dictobj):
    fields = ["username", "password"]

    @property
    def creds(self):
        return self.username, self.password


class KmsAuthentication(dictobj):
    fields = ["username", "password", "role", "region"]

    @property
    def creds(self):

        session = assume_role(self.role)