def test_get_base_input_artifact_name_build_enabled(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild'
    )
    assert action._get_base_input_artifact_name() == 'output-source'
示例#2
0
def test_get_base_output_artifact_name_build(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild',
    )
    assert action._get_base_output_artifact_name() == '{0}-build'.format(
        BASE_MAP_PARAMS['name'])
def test_get_input_artifacts_no_build_deploy(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    for category in ['Approval', 'Source']:
        action = Action(
            map_params=BASE_MAP_PARAMS,
            category=category,
            provider='Manual' if category == 'Approval' else 'CodeCommit',
        )
        assert action._get_input_artifacts() == []
示例#4
0
def test_get_base_output_artifact_name_deploy_codebuild(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Deploy',
        provider='CodeBuild',
        target={
            'name': 'targetname',
            'id': 'someid',
        },
    )
    assert action._get_base_output_artifact_name() == ''
def test_get_base_input_artifact_name_deploy_build_disabled(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    map_params = deepcopy(BASE_MAP_PARAMS)
    map_params['default_providers']['build']['enabled'] = False
    action = Action(
        map_params=map_params,
        category='Deploy',
        provider='CodeBuild',
        target={
            'name': 'targetname',
            'id': 'someid',
        },
    )
    assert action._get_base_input_artifact_name() == 'output-source'
def test_get_input_artifacts_deploy_with_cfn_param_overrides_is_cse(base_input_name_mock, action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    base_input_name_mocked_value = 'BaseInputName'
    base_input_name_mock.return_value = base_input_name_mocked_value
    override_mocked_value = 'OverrideName'
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Deploy',
        provider='CloudFormation',
        action_mode='CHANGE_SET_EXECUTE',
        target={
            'name': 'targetname',
            'id': 'someid',
            'properties': {
                'param_overrides': [
                    {
                        'param': 'SomeParam',
                        'inputs': override_mocked_value,
                        'key_name': 'SomeKeyName',
                    },
                ],
            },
        },
    )
    assert action.config['input_artifacts'] == [
        aws_codepipeline.CfnPipeline.InputArtifactProperty(
            name=base_input_name_mocked_value,
        )
    ]
示例#7
0
def test_get_base_output_artifact_name_deploy_cfn_with_outputs_csr(
        action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    override_outputs_mocked_value = 'OverrideName'
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Deploy',
        provider='CloudFormation',
        action_mode='CHANGE_SET_REPLACE',
        target={
            'name': 'targetname',
            'id': 'someid',
            'properties': {
                'outputs': override_outputs_mocked_value,
            },
        },
    )
    assert action._get_base_output_artifact_name() == ''
示例#8
0
def test_get_output_artifacts_no_base_output(base_output_name_mock,
                                             action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    base_output_name_mock.return_value = ''
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild',
    )
    assert not 'output_artifacts' in action.config
def test_generates_without_input_and_output_artifacts(input_mock, output_mock,
                                                      action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    mocked_value = None
    input_mock.return_value = mocked_value
    output_mock.return_value = mocked_value
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild',
    )
    assert not 'input_artifacts' in action.config
    assert not 'output_artifacts' in action.config
示例#10
0
 def __init__(self, scope: core.Construct, id: str, map_params: dict,
              **kwargs):  #pylint: disable=W0622
     super().__init__(scope, id, **kwargs)
     self.build = _codepipeline.CfnPipeline.StageDeclarationProperty(
         name="Build",
         actions=[
             Action(name="Build",
                    provider="Jenkins",
                    category="Build",
                    run_order=1,
                    map_params=map_params,
                    action_name="build").config
         ])
示例#11
0
def test_get_output_artifacts_with_base_output(base_output_name_mock,
                                               action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    base_output_name_mocked_value = 'BaseOutputName'
    base_output_name_mock.return_value = base_output_name_mocked_value
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild',
    )
    assert action.config['output_artifacts'] == [
        aws_codepipeline.CfnPipeline.OutputArtifactProperty(
            name=base_output_name_mocked_value, )
    ]
示例#12
0
 def __init__(self, scope: core.Construct, id: str, map_params: dict,
              **kwargs):  #pylint: disable=W0622
     super().__init__(scope, id, **kwargs)
     self.source = _codepipeline.CfnPipeline.StageDeclarationProperty(
         name="Source-S3",
         actions=[
             Action(name="source",
                    provider="S3",
                    owner="AWS",
                    category="Source",
                    run_order=1,
                    map_params=map_params,
                    action_name="source").config
         ])
def test_generates_with_input_and_output_artifacts_when_given(
        input_mock, output_mock, action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    mocked_input_value = 'InputArtifacts'
    mocked_output_value = 'OutputArtifacts'
    input_mock.return_value = mocked_input_value
    output_mock.return_value = mocked_output_value
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Build',
        provider='CodeBuild',
    )
    assert action.config['input_artifacts'] == mocked_input_value
    assert action.config['output_artifacts'] == mocked_output_value
示例#14
0
 def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
     super().__init__(scope, id, **kwargs)
     self.source = _codepipeline.CfnPipeline.StageDeclarationProperty(
         name="Source-{0}".format(map_params.get("default_providers", {}).get("source", {}).get("properties", {}).get("account_id", ADF_DEPLOYMENT_ACCOUNT_ID)),
         actions=[
             Action(
                 name="source",
                 provider="CodeCommit",
                 category="Source",
                 run_order=1,
                 map_params=map_params,
                 action_name="source"
             ).config
         ]
     )
def test_get_input_artifacts_deploy_simple(base_input_name_mock, action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    base_input_name_mocked_value = 'BaseInputName'
    base_input_name_mock.return_value = base_input_name_mocked_value
    action = Action(
        map_params=BASE_MAP_PARAMS,
        category='Deploy',
        provider='CodeBuild',
        target={
            'properties': {
                'param_overrides': [],
            },
        },
    )
    assert action.config['input_artifacts'] == [
        aws_codepipeline.CfnPipeline.InputArtifactProperty(
            name=base_input_name_mocked_value,
        )
    ]
示例#16
0
def test_get_base_output_artifact_name_source(action_decl_mock):
    action_decl_mock.side_effect = lambda **x: x
    action = Action(map_params=BASE_MAP_PARAMS,
                    category='Source',
                    provider='CodeCommit')
    assert action._get_base_output_artifact_name() == 'output-source'
示例#17
0
 def __init__(self, scope: core.Construct, id: str,
              shared_modules_bucket: str, deployment_region_kms: str,
              map_params: dict, target, **kwargs):  #pylint: disable=W0622
     super().__init__(scope, id, **kwargs)
     ADF_DEFAULT_BUILD_ROLE = 'arn:aws:iam::{0}:role/adf-codebuild-role'.format(
         ADF_DEPLOYMENT_ACCOUNT_ID)
     ADF_DEFAULT_BUILD_TIMEOUT = 20
     # if CodeBuild is being used as a deployment action we want to allow target specific values.
     if target:
         _build_role = 'arn:aws:iam::{0}:role/{1}'.format(
             ADF_DEPLOYMENT_ACCOUNT_ID,
             target.get('properties', {}).get('role')) if target.get(
                 'properties', {}).get('role') else ADF_DEFAULT_BUILD_ROLE
         _timeout = target.get(
             'properties', {}).get('timeout') or ADF_DEFAULT_BUILD_TIMEOUT
         _env = _codebuild.BuildEnvironment(
             build_image=CodeBuild.determine_build_image(
                 scope, target, map_params),
             compute_type=target.get('properties', {}).get('size')
             or getattr(
                 _codebuild.ComputeType,
                 map_params['default_providers']['build'].get(
                     'properties', {}).get('size', "SMALL").upper()),
             environment_variables=CodeBuild.generate_build_env_variables(
                 _codebuild, shared_modules_bucket, map_params, target),
             privileged=target.get('properties', {}).get(
                 'privileged', False)
             or map_params['default_providers']['build'].get(
                 'properties', {}).get('privileged', False))
         _spec_filename = (target.get('properties', {}).get('spec_filename')
                           or map_params['default_providers']['deploy'].get(
                               'properties', {}).get('spec_filename')
                           or 'deployspec.yml')
         _codebuild.PipelineProject(
             self,
             'project',
             environment=_env,
             encryption_key=_kms.Key.from_key_arn(
                 self,
                 'default_deployment_account_key',
                 key_arn=deployment_region_kms),
             description="ADF CodeBuild Project for {0}".format(id),
             project_name="adf-deploy-{0}".format(id),
             timeout=core.Duration.minutes(_timeout),
             role=_iam.Role.from_role_arn(self,
                                          'build_role',
                                          role_arn=_build_role),
             build_spec=_codebuild.BuildSpec.from_source_filename(
                 _spec_filename))
         self.deploy = Action(name="{0}".format(id),
                              provider="CodeBuild",
                              category="Build",
                              project_name="adf-deploy-{0}".format(id),
                              run_order=1,
                              target=target,
                              map_params=map_params,
                              action_name="{0}".format(id)).config
     else:
         _build_role = 'arn:aws:iam::{0}:role/{1}'.format(
             ADF_DEPLOYMENT_ACCOUNT_ID,
             map_params['default_providers']['build'].get('properties', {}).
             get('role')) if map_params['default_providers']['build'].get(
                 'properties', {}).get('role') else ADF_DEFAULT_BUILD_ROLE
         _timeout = map_params['default_providers']['build'].get(
             'properties', {}).get('timeout') or ADF_DEFAULT_BUILD_TIMEOUT
         _env = _codebuild.BuildEnvironment(
             build_image=CodeBuild.determine_build_image(
                 scope, target, map_params),
             compute_type=getattr(
                 _codebuild.ComputeType,
                 map_params['default_providers']['build'].get(
                     'properties', {}).get('size', "SMALL").upper()),
             environment_variables=CodeBuild.generate_build_env_variables(
                 _codebuild, shared_modules_bucket, map_params),
             privileged=map_params['default_providers']['build'].get(
                 'properties', {}).get('privileged', False))
         if map_params['default_providers']['build'].get('properties',
                                                         {}).get('role'):
             ADF_DEFAULT_BUILD_ROLE = 'arn:aws:iam::{0}:role/{1}'.format(
                 ADF_DEPLOYMENT_ACCOUNT_ID,
                 map_params['default_providers']['build'].get(
                     'properties', {}).get('role'))
         _build_stage_spec = map_params['default_providers']['build'].get(
             'properties', {}).get('spec_filename')
         _build_inline_spec = map_params['default_providers']['build'].get(
             'properties',
             {}).get('spec_inline',
                     '') or map_params['default_providers']['build'].get(
                         'properties', {}).get('spec_inline', '')
         if _build_stage_spec:
             _spec = _codebuild.BuildSpec.from_source_filename(
                 _build_stage_spec)
         elif _build_inline_spec:
             _spec = _codebuild.BuildSpec.from_object(_build_inline_spec)
         else:
             _spec = None
         _codebuild.PipelineProject(
             self,
             'project',
             environment=_env,
             encryption_key=_kms.Key.from_key_arn(
                 self,
                 'DefaultDeploymentAccountKey',
                 key_arn=deployment_region_kms),
             description="ADF CodeBuild Project for {0}".format(
                 map_params['name']),
             project_name="adf-build-{0}".format(map_params['name']),
             timeout=core.Duration.minutes(_timeout),
             build_spec=_spec,
             role=_iam.Role.from_role_arn(self,
                                          'default_build_role',
                                          role_arn=_build_role))
         self.build = _codepipeline.CfnPipeline.StageDeclarationProperty(
             name="Build",
             actions=[
                 Action(name="Build",
                        provider="CodeBuild",
                        category="Build",
                        run_order=1,
                        map_params=map_params,
                        action_name="build").config
             ])
    def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, deployment_region_kms: str, map_params: dict, target, **kwargs): #pylint: disable=W0622
        super().__init__(scope, id, **kwargs)
        stack = core.Stack.of(self)

        ADF_DEFAULT_BUILD_ROLE = f'arn:{stack.partition}:iam::{ADF_DEPLOYMENT_ACCOUNT_ID}:role/adf-codebuild-role'
        ADF_DEFAULT_BUILD_TIMEOUT = 20

        # if CodeBuild is being used as a deployment action we want to allow target specific values.
        if target:
            _role_name = target.get('properties', {}).get('role')
            _build_role = f'arn:{stack.partition}:iam::{ADF_DEPLOYMENT_ACCOUNT_ID}:role/{_role_name}' if _role_name else ADF_DEFAULT_BUILD_ROLE
            _timeout = target.get('properties', {}).get('timeout') or map_params['default_providers']['deploy'].get('properties', {}).get('timeout') or ADF_DEFAULT_BUILD_TIMEOUT
            _env = _codebuild.BuildEnvironment(
                build_image=CodeBuild.determine_build_image(scope, target, map_params),
                compute_type=target.get(
                    'properties', {}).get(
                        'size') or getattr(
                            _codebuild.ComputeType, map_params['default_providers']['build'].get(
                                'properties', {}).get(
                                    'size', "SMALL").upper()),
                environment_variables=CodeBuild.generate_build_env_variables(_codebuild, shared_modules_bucket, map_params, target),
                privileged=target.get('properties', {}).get('privileged', False) or map_params['default_providers']['build'].get('properties', {}).get('privileged', False)
            )
            build_spec = CodeBuild.determine_build_spec(
                id,
                map_params['default_providers']['deploy'].get('properties', {}),
                target,
            )
            _codebuild.PipelineProject(
                self,
                'project',
                environment=_env,
                encryption_key=_kms.Key.from_key_arn(self, 'default_deployment_account_key', key_arn=deployment_region_kms),
                description=f"ADF CodeBuild Project for {id}",
                project_name=f"adf-deploy-{id}",
                timeout=core.Duration.minutes(_timeout),
                role=_iam.Role.from_role_arn(self, 'build_role', role_arn=_build_role, mutable=False),
                build_spec=build_spec,
            )
            self.deploy = Action(
                name=id,
                provider="CodeBuild",
                category="Build",
                project_name=f"adf-deploy-{id}",
                run_order=1,
                target=target,
                map_params=map_params,
                action_name=id,
            ).config
        else:
            _role_name = map_params['default_providers']['build'].get(
                'properties', {}).get('role')
            _build_role = f'arn:{stack.partition}:iam::{ADF_DEPLOYMENT_ACCOUNT_ID}:role/{_role_name}' if _role_name else ADF_DEFAULT_BUILD_ROLE
            _timeout = map_params['default_providers']['build'].get('properties', {}).get('timeout') or ADF_DEFAULT_BUILD_TIMEOUT
            _env = _codebuild.BuildEnvironment(
                build_image=CodeBuild.determine_build_image(scope, target, map_params),
                compute_type=getattr(_codebuild.ComputeType, map_params['default_providers']['build'].get('properties', {}).get('size', "SMALL").upper()),
                environment_variables=CodeBuild.generate_build_env_variables(_codebuild, shared_modules_bucket, map_params),
                privileged=map_params['default_providers']['build'].get('properties', {}).get('privileged', False)
            )
            if _role_name:
                ADF_DEFAULT_BUILD_ROLE = f'arn:{stack.partition}:iam::{ADF_DEPLOYMENT_ACCOUNT_ID}:role/{_role_name}'
            build_spec = CodeBuild.determine_build_spec(
                id,
                map_params['default_providers']['build'].get('properties', {})
            )
            _codebuild.PipelineProject(
                self,
                'project',
                environment=_env,
                encryption_key=_kms.Key.from_key_arn(self, 'DefaultDeploymentAccountKey', key_arn=deployment_region_kms),
                description=f"ADF CodeBuild Project for {map_params['name']}",
                project_name=f"adf-build-{map_params['name']}",
                timeout=core.Duration.minutes(_timeout),
                build_spec=build_spec,
                role=_iam.Role.from_role_arn(self, 'default_build_role', role_arn=_build_role, mutable=False)
            )
            self.build = _codepipeline.CfnPipeline.StageDeclarationProperty(
                name="Build",
                actions=[
                    Action(
                        name="Build",
                        provider="CodeBuild",
                        category="Build",
                        run_order=1,
                        map_params=map_params,
                        action_name="build"
                    ).config
                ]
            )