# 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
    @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)
        password = decrypt_kms(session, self.password, self.region)
        return self.username, password


class S3SlipAuthentication(dictobj):
    fields = ["location", "role"]

    @property
    def creds(self):
        if not hasattr(self, "_store"):
            self._store = None

        if self._store is not None:
            tm, stored = self._store
            if time.time() - tm > 3000:
                self.store = None
            else:
                return stored


# 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

    @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)
        password = decrypt_kms(session, self.password, self.region)
        return self.username, password


class S3SlipAuthentication(dictobj):
    fields = ["location", "role"]

    @property
    def creds(self):
        if not hasattr(self, "_store"):
            self._store = None

        if self._store is not None:
            tm, stored = self._store
            if time.time() - tm > 3000:
                self.store = None
            else:
                return stored


        session = assume_role(self.role)