Ejemplo n.º 1
0
def put_secret_value(arguments) -> None:
    configuration = AWSAPIConfigurationPolicy()
    configuration.configuration_file_full_path = arguments.configuration_file_full_path
    configuration.init_from_file()

    aws_api = AWSAPI(configuration)

    aws_api.put_secret_value(arguments.secret_name, arguments.secret_value)
Ejemplo n.º 2
0
def test_login():
    docker_api = DockerAPI()
    aws_api = AWSAPI()
    credentials = aws_api.get_ecr_authorization_info(region=src_aws_region)

    if len(credentials) != 1:
        raise ValueError(f"len(credentials) != 1")
    credentials = credentials[0]

    registry, username, password = credentials["proxy_host"], credentials["user_name"], credentials["decoded_token"]
    docker_api.login(registry, username, password)
Ejemplo n.º 3
0
def init_and_cache(arguments) -> None:
    configuration = AWSAPIConfigurationPolicy()
    configuration.configuration_file_full_path = arguments.configuration_file_full_path
    configuration.init_from_file()

    aws_api = AWSAPI(configuration)

    init_functions = {"interfaces": aws_api.init_network_interfaces}
    cache_files = {
        "interfaces": configuration.aws_api_ec2_network_interfaces_cache_file
    }

    objects = init_functions[arguments.target]()
    aws_api.cache_objects(objects, cache_files[arguments.target])
Ejemplo n.º 4
0
def cleanup(arguments) -> None:
    configuration = AWSAPIConfigurationPolicy()
    configuration.configuration_file_full_path = arguments.configuration_file_full_path
    configuration.init_from_file()

    aws_api = AWSAPI(configuration)

    init_functions = {"interfaces": aws_api.init_network_interfaces}
    cache_files = {
        "interfaces": configuration.aws_api_ec2_network_interfaces_cache_file
    }
    output_files = {
        "interfaces":
        configuration.aws_api_cleanups_network_interfaces_report_file
    }

    init_functions[arguments.target](from_cache=True,
                                     cache_file=cache_files[arguments.target])
    aws_api.cleanup_report_network_interfaces(output_files[arguments.target])
Ejemplo n.º 5
0
def test_provision_lambda():
    packer = Packer()
    aws_api = AWSAPI()

    files_paths = [
        os.path.join(os.path.dirname(os.path.abspath(__file__)), "build",
                     "files_list_test", file_name)
        for file_name in ["dependency_1.py", "entrypoint.py"]
    ]
    packer.add_files_to_zip(f"{ZIP_FILE_NAME}.zip", files_paths)
    aws_lambda = AWSLambda({})
    aws_lambda.region = Region.get_region("us-west-2")
    aws_lambda.name = "horey-test-lambda"
    aws_lambda.role = mock_values["lambda:execution_role"]
    aws_lambda.handler = "entrypoint.main"
    aws_lambda.runtime = "python3.8"
    aws_lambda.tags = {"lvl": "tst", "name": "horey-test"}
    aws_lambda.policy = {
        "Version":
        "2012-10-17",
        "Id":
        "default",
        "Statement": [{
            "Sid": aws_lambda.name + "_" + "sid",
            "Effect": "Allow",
            "Principal": {
                "Service": "events.amazonaws.com"
            },
            "Action": "lambda:InvokeFunction",
            "Resource": None,
            "Condition": {
                "ArnLike": {
                    "AWS:SourceArn":
                    mock_values["lambda:policy_events_rule_arn"]
                }
            }
        }]
    }

    aws_api.provision_aws_lambda(aws_lambda, force=True)

    assert aws_lambda.state == "Active"
Ejemplo n.º 6
0
def get_secret_file(arguments) -> None:
    if arguments.configuration_file_full_path != "None":
        configuration = AWSAPIConfigurationPolicy()
        configuration.configuration_file_full_path = arguments.configuration_file_full_path
        configuration.init_from_file()
        aws_api = AWSAPI(configuration)
    else:
        aws_api = AWSAPI()

    aws_api.get_secret_file(arguments.secret_name, arguments.secret_file_path)
Ejemplo n.º 7
0
    def __init__(self, configuration):
        aws_api_conf = AWSAPIConfigurationPolicy()
        aws_api_conf.configuration_file_full_path = configuration.aws_api_configuration_values_file_path
        aws_api_conf.init_from_file()
        self.aws_api = AWSAPI(configuration=aws_api_conf)

        jenkins_conf = JenkinsConfigurationPolicy()
        jenkins_conf.configuration_file_full_path = configuration.jenkins_manager_configuration_values_file_path
        jenkins_conf.init_from_file()
        self.jenkins_manager = JenkinsManager(configuration=jenkins_conf)

        self.jenkins_ec2_instance_type = configuration.jenkins_ec2_instance_type
        self.ssh_master_access_key_name = "jenkins-master-access-key"
        self.ssh_agent_access_key_name = "jenkins-agent-access-key"

        self.jenkins_mater_iam_role_name = "role-jenkins-master"
        self.jenkins_mater_iam_role_name = "policy-jenkins-master-spot-fleet-access"
        self.public_subnet_id = ""
        self.private_subnet_id = ""
        self.jenkins_master_security_group_name = ""
        self.ssh_agent_security_group_name = ""
Ejemplo n.º 8
0
def login(docker_api):
    aws_api = AWSAPI()
    credentials = aws_api.get_ecr_authorization_info(region=src_aws_region)
    credentials = credentials[0]
    registry, username, password = credentials["proxy_host"], credentials["user_name"], credentials["decoded_token"]
    docker_api.login(registry, username, password)
Ejemplo n.º 9
0
from horey.common_utils.common_utils import CommonUtils

configuration_values_file_full_path = os.path.join(
    os.path.dirname(os.path.abspath(__file__)),
    "h_logger_configuration_values.py")

logger = get_logger(
    configuration_values_file_full_path=configuration_values_file_full_path)

configuration = AWSAPIConfigurationPolicy()
configuration.configuration_file_full_path = os.path.abspath(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..",
                 "ignore", "aws_api_configuration_values.py"))
configuration.init_from_file()

aws_api = AWSAPI(configuration=configuration)

mock_values_file_path = os.path.abspath(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "ignore",
                 "mock_values.py"))
mock_values = CommonUtils.load_object_from_module(mock_values_file_path,
                                                  "main")


def test_add_managed_region():
    aws_api.add_managed_region(Region.get_region("us-west-2"))


def test_provision_certificate():
    cert = ACMCertificate({})
    cert.region = Region.get_region("us-east-1")