示例#1
0
def disable_codecommit():
    # Remove the default branch and repo if they deny so we do not depoloy to CodeCommit by default
    LOG.debug("Denied option to use CodeCommit removing default values")
    set_repo_default_for_current_environment(None)
    set_branch_default_for_current_environment(None)
    fileoperations.write_config_setting('global', 'repository', None)
    fileoperations.write_config_setting('global', 'branch', None)
    LOG.debug("Disabled CodeCommit for use with EB CLI")
示例#2
0
def disable_codecommit():
    # Remove the default branch and repo if they deny so we do not depoloy to CodeCommit by default
    LOG.debug("Denied option to use CodeCommit removing default values")
    set_repo_default_for_current_environment(None)
    set_branch_default_for_current_environment(None)
    fileoperations.write_config_setting('global', 'repository', None)
    fileoperations.write_config_setting('global', 'branch', None)
    LOG.debug("Disabled CodeCommit for use with EB CLI")
示例#3
0
    def do_command(self):
        commonops.raise_if_inside_platform_workspace()

        interactive = self.app.pargs.interactive
        region_name = self.app.pargs.region
        noverify = self.app.pargs.no_verify_ssl
        keyname = self.app.pargs.keyname
        profile = self.app.pargs.profile
        platform = self.app.pargs.platform
        source = self.app.pargs.source
        app_name = self.app.pargs.application_name
        modules = self.app.pargs.modules
        force_non_interactive = _customer_is_avoiding_interactive_flow(
            self.app.pargs)
        tags = self.app.pargs.tags

        # The user specifies directories to initialize
        if modules and len(modules) > 0:
            self.initialize_multiple_directories(
                modules,
                region_name,
                interactive,
                force_non_interactive,
                keyname,
                profile,
                noverify,
                platform
            )
            return

        fileoperations.touch_config_folder()
        region_name = commonops.set_region_for_application(interactive, region_name, force_non_interactive, platform)
        commonops.set_up_credentials(profile, region_name, interactive)
        app_name = get_app_name(app_name, interactive, force_non_interactive)
        default_env = set_default_env(interactive, force_non_interactive)
        tags = tagops.get_and_validate_tags(tags)

        platform_arn, keyname_of_existing_application = create_app_or_use_existing_one(app_name, default_env, tags)
        platform = _determine_platform(
            customer_provided_platform=platform,
            existing_app_platform=platform_arn,
            force_interactive=interactive and not force_non_interactive)

        handle_buildspec_image(platform, force_non_interactive)

        prompt_codecommit = should_prompt_customer_to_opt_into_codecommit(
            force_non_interactive,
            region_name,
            source
        )
        repository, branch = None, None
        if prompt_codecommit:
            repository, branch = configure_codecommit(source)
        initializeops.setup(app_name, region_name, platform, dir_path=None, repository=repository, branch=branch)
        configure_keyname(platform, keyname, keyname_of_existing_application, interactive, force_non_interactive)
        fileoperations.write_config_setting('global', 'include_git_submodules', True)
        if noverify:
            fileoperations.write_config_setting('global', 'no-verify-ssl', True)
示例#4
0
def setup_ignore_file():
    io.log_info('Setting up ignore file for source control')
    sc = fileoperations.get_config_setting('global', 'sc')

    if not sc:
        source_control = SourceControl.get_source_control()
        source_control.set_up_ignore_file()
        sc_name = source_control.get_name()
        fileoperations.write_config_setting('global', 'sc', sc_name)
示例#5
0
    def initialize_multiple_directories(
            self,
            modules,
            region,
            interactive,
            force_non_interactive,
            keyname,
            profile,
            noverify,
            platform
    ):
        application_created = False
        app_name = None
        cwd = os.getcwd()
        for module in modules:
            if os.path.exists(module) and os.path.isdir(module):
                os.chdir(module)
                fileoperations.touch_config_folder()

                # Region should be set once for all modules
                region = region or commonops.set_region_for_application(interactive, region, force_non_interactive)
                commonops.set_up_credentials(profile, region, interactive)

                # App name should be set once for all modules
                if not app_name:
                    # Switching back to the root dir will suggest the root dir name
                    # as the application name
                    os.chdir(cwd)
                    app_name = get_app_name(None, interactive, force_non_interactive)
                    os.chdir(module)

                if noverify:
                    fileoperations.write_config_setting('global', 'no-verify-ssl', True)

                default_env = '/ni' if force_non_interactive else None

                if not application_created:
                    platform_arn, keyname_of_existing_application = commonops.create_app(
                        app_name,
                        default_env=default_env
                    )
                    application_created = True
                else:
                    platform_arn, keyname_of_existing_application = commonops.pull_down_app_info(
                        app_name,
                        default_env=default_env
                    )
                io.echo('\n--- Configuring module: {0} ---'.format(module))
                module_platform = _determine_platform(
                    customer_provided_platform=platform,
                    existing_app_platform=platform_arn,
                    force_interactive=interactive)

                initializeops.setup(app_name, region, module_platform)
                configure_keyname(module_platform, keyname, keyname_of_existing_application, interactive, force_non_interactive)
                os.chdir(cwd)
    def test_dissociate_environment_from_branch__environment_is_not_default_env(
            self):
        fileoperations.write_config_setting(
            'branch-defaults', 'default', {'environment': 'my-environment-2'})

        terminateops.dissociate_environment_from_branch('my-environment')

        self.assertEqual({'environment': 'my-environment-2'},
                         fileoperations.get_config_setting(
                             'branch-defaults', 'default'))
示例#7
0
def write_setting_to_current_branch(keyname, value):
    source_control = SourceControl.get_source_control()

    branch_name = source_control.get_current_branch()

    fileoperations.write_config_setting(
        'branch-defaults',
        branch_name,
        {keyname: value}
    )
示例#8
0
    def initialize_multiple_directories(self, modules, region, interactive,
                                        force_non_interactive, keyname,
                                        profile, noverify, platform):
        application_created = False
        app_name = None
        cwd = os.getcwd()
        for module in modules:
            if os.path.exists(module) and os.path.isdir(module):
                os.chdir(module)
                fileoperations.touch_config_folder()

                # Region should be set once for all modules
                region = region or commonops.set_region_for_application(
                    interactive, region, force_non_interactive)
                commonops.set_up_credentials(profile, region, interactive)

                # App name should be set once for all modules
                if not app_name:
                    # Switching back to the root dir will suggest the root dir name
                    # as the application name
                    os.chdir(cwd)
                    app_name = get_app_name(None, interactive,
                                            force_non_interactive)
                    os.chdir(module)

                if noverify:
                    fileoperations.write_config_setting(
                        'global', 'no-verify-ssl', True)

                default_env = '/ni' if force_non_interactive else None

                if not application_created:
                    sstack, keyname_of_existing_application = commonops.create_app(
                        app_name, default_env=default_env)
                    application_created = True
                else:
                    sstack, keyname_of_existing_application = commonops.pull_down_app_info(
                        app_name, default_env=default_env)
                solution = get_solution_stack(platform, sstack, interactive)
                io.echo('\n--- Configuring module: {0} ---'.format(module))

                solution = solution or sstack

                if not solution and fileoperations.env_yaml_exists():
                    solution = extract_solution_stack_from_env_yaml()
                    if solution:
                        io.echo(strings['init.usingenvyamlplatform'].replace(
                            '{platform}', solution))
                solution = solution or solution_stack_ops.get_solution_stack_from_customer(
                )
                initializeops.setup(app_name, region, solution)
                configure_keyname(solution, keyname,
                                  keyname_of_existing_application, interactive,
                                  force_non_interactive)
                os.chdir(cwd)
示例#9
0
    def test_list__neutral_workspace__all_platforms_and_status_filters_are_not_applicable(self):
        self.setup_platform_workspace()
        fileoperations.write_config_setting(
            'global',
            'workspace_type',
            None
        )

        app = EB(argv=['platform', 'list', '-a', '-s', 'READY'])
        app.setup()
        app.run()
示例#10
0
    def test_list__neutral_workspace__command_is_not_applicable(self):
        self.setup_platform_workspace()
        fileoperations.write_config_setting(
            'global',
            'workspace_type',
            None
        )

        app = EBP(argv=['list'])
        app.setup()
        app.run()
示例#11
0
def configure_keyname(solution, keyname, keyname_of_existing_app, interactive,
                      force_non_interactive):
    if 'IIS' not in solution:
        keyname = get_keyname(keyname, keyname_of_existing_app, interactive,
                              force_non_interactive)

        if keyname == -1:
            keyname = None

        fileoperations.write_config_setting('global', 'default_ec2_keyname',
                                            keyname)
    def test_switch_default_environment__redundantly_switch_to_present_environment(
            self, get_environment_mock):
        fileoperations.write_config_setting('branch-defaults', 'default',
                                            {'environment': 'my-old-env'})

        get_environment_mock.return_value = mock.MagicMock('some-environment')

        useops.switch_default_environment('my-old-env')

        branch_defaults = fileoperations.get_config_setting(
            'branch-defaults', 'default')
        self.assertEqual('my-old-env', branch_defaults['environment'])
示例#13
0
    def test_write_config_setting_no_section(self):
        fileoperations.create_config_file('ebcli-test', 'us-east-1',
                                          'my-solution-stack')

        dict = fileoperations._get_yaml_dict(fileoperations.local_config_file)
        self.assertFalse('mytestsection' in dict)

        fileoperations.write_config_setting('mytestsection', 'testkey',
                                            'value')

        dict = fileoperations._get_yaml_dict(fileoperations.local_config_file)
        self.assertTrue('mytestsection' in dict)
示例#14
0
    def test_write_config_setting_no_file(self):
        if os.path.exists(fileoperations.local_config_file):
            os.remove(fileoperations.local_config_file)

        self.assertFalse(os.path.exists(fileoperations.local_config_file))

        fileoperations.write_config_setting('mytestsection', 'testkey',
                                            'value')

        self.assertTrue(os.path.exists(fileoperations.local_config_file))
        dict = fileoperations._get_yaml_dict(fileoperations.local_config_file)
        self.assertTrue('mytestsection' in dict)
    def test_dissociate_environment_from_branch(self):
        fileoperations.write_config_setting(
            'branch-defaults',
            'default',
            {
                'environment': 'my-environment'
            }
        )

        terminateops.dissociate_environment_from_branch('my-environment')

        self.assertIsNotNone(fileoperations.get_config_setting('branch-defaults', 'default'))
    def get_instance_profile(self):
        # Check to see if it was specified on the command line
        profile = self.app.pargs.instance_profile

        if profile is None:
            try:
                # Check to see if it is associated with the workspace
                profile = fileoperations.get_instance_profile()
            except NotInitializedError:
                pass

        if profile is None:
            # Check to see if the default instance profile already exists
            try:
                existing_profiles = iam.get_instance_profile_names()
                if iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE in existing_profiles:
                    profile = iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE
            except NotAuthorizedError:
                io.log_warning(strings['platformcreateiamdescribeerror.info'])

        if profile is None:
            # We will now create the default role for the customer
            try:
                profile = iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE
                try:
                    iam.create_instance_profile(profile)
                    io.log_info(strings['platformcreateiamcreated.info'])
                except AlreadyExistsError:
                    pass

                document = iam_documents.EC2_ASSUME_ROLE_PERMISSION
                try:
                    # Create a role with the same name
                    iam.create_role(profile, document)

                    # Attach required custom platform builder permissions
                    iam.put_role_policy(
                        profile,
                        iam_attributes.PLATFORM_BUILDER_INLINE_POLICY_NAME,
                        iam_documents.CUSTOM_PLATFORM_BUILDER_INLINE_POLICY)
                    # Associate instance profile with the required role
                    iam.add_role_to_profile(profile, profile)
                    io.log_info(strings['platformcreateiampolicyadded.info'])
                except AlreadyExistsError:
                    # If the role exists then we leave it as is, we do not try to add or modify its policies
                    pass

            except NotAuthorizedError:
                io.log_warning(strings['platformcreateiamcreateerror.info'])

        # Save to disk
        write_config_setting('global', 'instance_profile', profile)
def update_config(app_name, cfg_name):
    config_location = resolve_config_location(cfg_name)
    if config_location is None:
        raise NotFoundError('No local version of ' + cfg_name + ' found.')

    fileoperations.write_config_setting(
        'EnvironmentConfigurationMetadata',
        'DateModified', (('%f' % (time.time() * 1000)).split('.')[0]),
        file=config_location)

    filename = fileoperations.get_filename_without_extension(config_location)

    upload_config_file(app_name, filename, config_location)
    def test_logs__neutral_workspace__command_not_applicable(self):
        self.setup_application_workspace()
        fileoperations.write_config_setting('global', 'workspace', None)

        with self.assertRaises(
                ApplicationWorkspaceNotSupportedError) as context_manager:
            app = EB(argv=['platform', 'logs'])
            app.setup()
            app.run()

        self.assertEqual(
            'This command is not supported outside Platform workspaces.',
            str(context_manager.exception))
示例#19
0
    def do_command(self):
        platform = prompt_for_platform()

        if isinstance(platform, PlatformVersion):
            alert_platform_status(platform)
            if platform.platform_branch_name:
                platform = platform.platform_branch_name
            else:
                platform = platform.platform_name
        elif isinstance(platform, PlatformBranch):
            alert_platform_branch_status(platform)
            platform = platform.branch_name

        fileoperations.write_config_setting('global', 'default_platform', platform)
    def test_switch_default_environment__environment_not_found(
            self, get_environment_mock):
        fileoperations.write_config_setting('branch-defaults', 'default',
                                            {'environment': 'my-old-env'})

        get_environment_mock.side_effect = NotFoundError(
            'Environment "my-new-env" not Found.')

        with self.assertRaises(NotFoundError):
            useops.switch_default_environment('my-new-env')

        branch_defaults = fileoperations.get_config_setting(
            'branch-defaults', 'default')
        self.assertEqual('my-old-env', branch_defaults['environment'])
示例#21
0
    def test_write_config_setting_override(self):
        fileoperations.create_config_file('ebcli-test', 'us-east-1',
                                          'my-solution-stack')

        dict = fileoperations._get_yaml_dict(fileoperations.local_config_file)
        self.assertTrue('global' in dict)
        self.assertTrue('application_name' in dict['global'])
        self.assertTrue('application_name' in dict['global'])
        self.assertEqual(dict['global']['application_name'], 'ebcli-test')

        fileoperations.write_config_setting('global', 'application_name',
                                            'new_name')

        dict = fileoperations._get_yaml_dict(fileoperations.local_config_file)
        self.assertEqual(dict['global']['application_name'], 'new_name')
示例#22
0
    def set_up_credentials(self):
        given_profile = self.app.pargs.profile
        if given_profile:
            ## Profile already set at abstractController
            profile = given_profile
        else:
            profile = 'eb-cli'
            aws.set_profile(profile)

        profile = self.check_credentials(profile)

        if not initializeops.credentials_are_valid():
            initializeops.setup_credentials()
        else:
            fileoperations.write_config_setting('global', 'profile', profile)
示例#23
0
def update_config(app_name, cfg_name):
    config_location = resolve_config_location(cfg_name)
    if config_location is None:
        raise NotFoundError('No local version of ' + cfg_name + ' found.')

    # Update modified date
    fileoperations.write_config_setting('EnvironmentConfigurationMetadata',
                                        'DateModified',
                                        (('%f' % (time.time() * 1000)).split('.')[0]),
                                        file=config_location)

    # Get just the name of the file
    filename = fileoperations.get_filename_without_extension(config_location)

    upload_config_file(app_name, filename, config_location)
示例#24
0
def set_up_credentials(given_profile, given_region, interactive, force_non_interactive=False):
    if given_profile:
        # Profile already set at abstractController
        profile = given_profile
    elif os.environ.get('AWS_ACCESS_KEY_ID') and os.environ.get('AWS_SECRET_ACCESS_KEY'):
        profile = None
    else:
        profile = 'eb-cli'
        aws.set_profile(profile)

    profile, _ = check_credentials(profile, given_profile, given_region, interactive, force_non_interactive)

    if not credentials_are_valid():
        setup_credentials()
    else:
        fileoperations.write_config_setting('global', 'profile', profile)
示例#25
0
    def test_create_config_file_file_exists(self):
        fileoperations.write_config_setting('global', 'randomKey', 'val')
        fileoperations.write_config_setting('test', 'application_name', 'app1')

        app_name = 'ebcli-test'
        region = 'us-east-1'
        solution = 'my-solution-stack'
        fileoperations.create_config_file(app_name, region, solution)

        key = fileoperations.get_config_setting('global', 'randomKey')
        app = fileoperations.get_config_setting('global', 'application_name')
        test = fileoperations.get_config_setting('test', 'application_name')

        self.assertEqual(key, 'val')
        self.assertEqual(app, app_name)
        self.assertEqual(test, 'app1')
示例#26
0
def set_up_credentials(given_profile, given_region, interactive, force_non_interactive=False):
    if given_profile:
        # Profile already set at abstractController
        profile = given_profile
    else:
        profile = 'eb-cli'
        aws.set_profile(profile)

    profile, region = check_credentials(profile, given_profile, given_region, interactive, force_non_interactive)

    if not initializeops.credentials_are_valid():
        initializeops.setup_credentials()
    else:
        fileoperations.write_config_setting('global', 'profile', profile)

    return region
示例#27
0
def set_up_credentials(given_profile, given_region, interactive, force_non_interactive=False):
    if given_profile:
        # Profile already set at abstractController
        profile = given_profile
    else:
        profile = 'eb-cli'
        aws.set_profile(profile)

    profile, region = check_credentials(profile, given_profile, given_region, interactive, force_non_interactive)

    if not initializeops.credentials_are_valid():
        initializeops.setup_credentials()
    else:
        fileoperations.write_config_setting('global', 'profile', profile)

    return region
示例#28
0
    def get_instance_profile(self):
        profile_name = self.app.pargs.instance_profile

        if profile_name is None:
            try:
                profile_name = fileoperations.get_instance_profile()
            except NotInitializedError:
                pass

        if profile_name is None\
                or profile_name == iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE:
            profile_name = commonops.create_instance_profile(
                iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE,
                iam_attributes.DEFAULT_CUSTOM_PLATFORM_BUILDER_POLICIES)

        write_config_setting('global', 'instance_profile', profile_name)
示例#29
0
    def get_instance_profile(self):
        # Check to see if it was specified on the command line
        profile_name = self.app.pargs.instance_profile

        if profile_name is None:
            try:
                # Check to see if it is associated with the workspace
                profile_name = fileoperations.get_instance_profile()
            except NotInitializedError:
                pass

        if profile_name is None\
                or profile_name == iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE:
            profile_name = commonops.create_instance_profile(iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE,
                                              iam_attributes.DEFAULT_CUSTOM_PLATFORM_BUILDER_POLICIES)

        # Save to disk
        write_config_setting('global', 'instance_profile', profile_name)
示例#30
0
def setup_credentials(access_id=None, secret_key=None):
    io.log_info('Setting up ~/aws/ directory with config file')

    if access_id is None or secret_key is None:
        io.echo(strings['cred.prompt'])

    if access_id is None:
        access_id = io.prompt('aws-access-id',
                              default='ENTER_AWS_ACCESS_ID_HERE')
    if secret_key is None:
        secret_key = io.prompt('aws-secret-key', default='ENTER_SECRET_HERE')

    fileoperations.save_to_aws_config(access_id, secret_key)

    fileoperations.touch_config_folder()
    fileoperations.write_config_setting('global', 'profile', 'eb-cli')

    aws.set_session_creds(access_id, secret_key)
示例#31
0
文件: create.py 项目: mschmutz1/jokic
    def get_instance_profile(self):
        # Check to see if it was specified on the command line
        profile_name = self.app.pargs.instance_profile

        if profile_name is None:
            try:
                # Check to see if it is associated with the workspace
                profile_name = fileoperations.get_instance_profile()
            except NotInitializedError:
                pass

        if profile_name is None\
                or profile_name == iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE:
            profile_name = commonops.create_instance_profile(iam_attributes.DEFAULT_PLATFORM_BUILDER_ROLE,
                                              iam_attributes.DEFAULT_CUSTOM_PLATFORM_BUILDER_POLICIES)

        # Save to disk
        write_config_setting('global', 'instance_profile', profile_name)
    def test_switch_default_repo_and_branch__default_branch_environment_are_absent__writes_new(
            self, get_branch_mock):
        fileoperations.write_config_setting('branch-defaults', 'default',
                                            {'environment': 'my-old-env'})

        get_branch_mock.return_value = mock.MagicMock('new-codecommit-branch')

        useops.switch_default_repo_and_branch(
            repo_name='new-codecommit-repository',
            branch_name='new-codecommit-branch',
        )

        environment_defaults = fileoperations.get_config_setting(
            'environment-defaults', 'my-old-env')

        self.assertEqual('new-codecommit-branch',
                         environment_defaults['branch'])
        self.assertEqual('new-codecommit-repository',
                         environment_defaults['repository'])
    def test_switch_default_repo_and_branch__remote_codecommit_repository_absent__exception_is_raised__present_values_left_intact(
            self, get_branch_mock):
        get_branch_mock.side_effect = ServiceError
        fileoperations.write_config_setting('branch-defaults', 'default',
                                            {'environment': 'my-old-env'})
        gitops.write_setting_to_current_environment_or_default(
            'branch', 'old-codecommit-branch')
        gitops.write_setting_to_current_environment_or_default(
            'repository', 'old-codecommit-repository')

        with self.assertRaises(NotFoundError):
            useops.switch_default_repo_and_branch(
                repo_name='nonexistent-codecommit-repository',
                branch_name='nonexistent-codecommit-branch',
            )

        environment_defaults = fileoperations.get_config_setting(
            'environment-defaults', 'my-old-env')
        self.assertEqual('old-codecommit-branch',
                         environment_defaults['branch'])
        self.assertEqual('old-codecommit-repository',
                         environment_defaults['repository'])
示例#34
0
    def do_command(self):
        # get arguments
        self.interactive = self.app.pargs.interactive
        self.region = self.app.pargs.region
        self.noverify = self.app.pargs.no_verify_ssl
        self.force_non_interactive = False

        # Determine if the customer is avoiding interactive mode by setting the platform flag
        if self.app.pargs.platform:
            self.force_non_interactive = True

        # Code Commit integration
        self.source = self.app.pargs.source
        source_location = None
        branch = None
        repository = None
        if self.source is not None:
            source_location, repository, branch = utils.parse_source(self.source)

        # The user specifies directories to initialize
        self.modules = self.app.pargs.modules
        if self.modules and len(self.modules) > 0:
            self.initialize_multiple_directories()
            return

        default_env = self.get_old_values()
        fileoperations.touch_config_folder()

        if self.interactive:
            self.region = get_region(self.region, self.interactive, self.force_non_interactive)
        else:
            self.region = get_region_from_inputs(self.region)
        aws.set_region(self.region)

        self.region = set_up_credentials(self.app.pargs.profile, self.region, self.interactive)

        self.solution = self.get_solution_stack()
        self.app_name = self.get_app_name()
        if self.noverify:
            fileoperations.write_config_setting('global',
                                                'no-verify-ssl', True)

        if not default_env and not self.interactive:
            # try to get default env from config file if exists
            try:
                default_env = commonops.get_current_branch_environment()
            except NotInitializedError:
                default_env = None
        elif self.interactive:
            default_env = None

        if self.force_non_interactive:
            default_env = '/ni'

        # Create application
        sstack, key = commonops.pull_down_app_info(self.app_name, default_env=default_env) if elasticbeanstalk.application_exist(self.app_name) \
            else commonops.create_app(self.app_name, default_env=default_env)

        if not self.solution:
            self.solution = sstack

        platform_set = False
        if not self.solution or \
                (self.interactive and not self.app.pargs.platform):
            if fileoperations.env_yaml_exists():
                env_yaml_platform = fileoperations.get_platform_from_env_yaml()
                if env_yaml_platform:
                    platform = solutionstack.SolutionStack(env_yaml_platform).platform_shorthand
                    self.solution = platform
                    platform_set = True

            if not platform_set:
                self.solution = solution_stack_ops.get_solution_stack_from_customer().platform_shorthand

        # Select CodeBuild image if BuildSpec is present do not prompt or show if we are non-interactive
        if fileoperations.build_spec_exists() and not self.force_non_interactive:
            build_spec = fileoperations.get_build_configuration()
            if build_spec is not None and build_spec.image is None:
                LOG.debug("Buildspec file is present but image is does not exist. Attempting to fill best guess.")
                platform_image = initializeops.get_codebuild_image_from_platform(self.solution)

                # If the return is a dictionary then it must be a single image and we can use that automatically
                if type(platform_image) is dict:
                    io.echo('codebuild.latestplatform'.replace('{platform}', self.solution))
                else:
                    # Otherwise we have an array for images which we must prompt the customer to pick from
                    io.echo(prompts['codebuild.getplatform'].replace('{platform}', self.solution))
                    selected = utils.prompt_for_index_in_list(map(lambda image: image['description'], platform_image))
                    platform_image = platform_image[selected]
                    platform_image['name'] = utils.decode_bytes(platform_image['name'])

                # Finally write the CodeBuild image back to the buildspec file
                fileoperations.write_config_setting(fileoperations.buildspec_config_header,
                                                    'Image',
                                                    platform_image['name'],
                                                    file=fileoperations.buildspec_name)

        # Setup code commit integration
        # Ensure that git is setup
        source_control = SourceControl.get_source_control()
        try:
            source_control_setup = source_control.is_setup()
            if source_control_setup is None:
                source_control_setup = False
        except CommandError:
            source_control_setup = False

        default_branch_exists = False
        if gitops.git_management_enabled() and not self.interactive:
            default_branch_exists = True

        # Warn the customer if they picked a region that CodeCommit is not supported
        codecommit_region_supported = codecommit.region_supported(self.region)

        if self.source is not None and not codecommit_region_supported:
            io.log_warning(strings['codecommit.badregion'])

        # Prompt customer to opt into CodeCommit unless one of the follows holds:
        if self.force_non_interactive:
            prompt_codecommit = False
        elif not codecommit.region_supported(self.region):
            prompt_codecommit = False
        elif self.source and source_location.lower() != 'codecommit':
            # Do not prompt if customer has already specified a code source to
            # associate the EB workspace with
            prompt_codecommit = False
        elif default_branch_exists:
            # Do not prompt if customer has already configured the EB application
            # in the present working directory with Git
            prompt_codecommit = False
        else:
            prompt_codecommit = True

        # Prompt for interactive CodeCommit
        if prompt_codecommit:
            if not source_control_setup:
                io.echo(strings['codecommit.nosc'])
            else:
                io.echo(strings['codecommit.ccwarning'])
                try:
                    if not self.source:
                        io.validate_action(prompts['codecommit.usecc'], "y")

                    # Setup git config settings for code commit credentials
                    source_control.setup_codecommit_cred_config()

                    # Get user specified repository
                    remote_url = None
                    if repository is None:
                        repository = get_repository_interactive()
                    else:
                        try:
                            setup_codecommit_remote_repo(repository, source_control)
                        except ServiceError as ex:
                            if self.source:
                                create_codecommit_repository(repository)
                                setup_codecommit_remote_repo(repository, source_control)
                            else:
                                io.log_error(strings['codecommit.norepo'])
                                raise ex

                    # Get user specified branch
                    if branch is None:
                        branch = get_branch_interactive(repository)
                    else:
                        try:
                            codecommit.get_branch(repository, branch)
                        except ServiceError as ex:
                            if self.source:
                                create_codecommit_branch(source_control, branch)
                            else:
                                io.log_error(strings['codecommit.nobranch'])
                                raise ex
                        source_control.setup_existing_codecommit_branch(branch, remote_url)

                except ValidationError:
                    LOG.debug("Denied option to use CodeCommit, continuing initialization")

        # Initialize the whole setup
        initializeops.setup(self.app_name, self.region, self.solution, dir_path=None, repository=repository, branch=branch)

        if 'IIS' not in self.solution:
            self.keyname = self.get_keyname(default=key)

            if self.keyname == -1:
                self.keyname = None

            fileoperations.write_config_setting('global', 'default_ec2_keyname',
                                                self.keyname)

        # Default to including git submodules when creating zip files through `eb create`/`eb deploy`.
        fileoperations.write_config_setting('global', 'include_git_submodules', True)
示例#35
0
    def initialize_multiple_directories(self):
        application_created = False
        self.app_name = None
        cwd = os.getcwd()
        for module in self.modules:
            if os.path.exists(module) and os.path.isdir(module):
                os.chdir(module)
                fileoperations.touch_config_folder()

                # Region should be set once for all modules
                if not self.region:
                    if self.interactive:
                        self.region = get_region(self.region, self.interactive, self.force_non_interactive)
                    else:
                        self.region = get_region_from_inputs(self.app.pargs.region)
                    aws.set_region(self.region)

                self.region = set_up_credentials(self.app.pargs.profile, self.region, self.interactive)

                solution = self.get_solution_stack()

                # App name should be set once for all modules
                if not self.app_name:
                    # Switching back to the root dir will suggest the root dir name
                    # as the application name
                    os.chdir(cwd)
                    self.app_name = self.get_app_name()
                    os.chdir(module)

                if self.noverify:
                    fileoperations.write_config_setting('global',
                                                        'no-verify-ssl', True)

                default_env = None

                if self.force_non_interactive:
                    default_env = '/ni'

                if not application_created:
                    sstack, key = commonops.create_app(self.app_name,
                                                       default_env=default_env)
                    application_created = True
                else:
                    sstack, key = commonops.pull_down_app_info(self.app_name,
                                                               default_env=default_env)

                io.echo('\n--- Configuring module: {0} ---'.format(module))

                if not solution:
                    solution = sstack

                platform_set = False
                # TODO: Do not require a solution stack if one has already been set by this point
                if not solution or \
                        (self.interactive and not self.app.pargs.platform):
                    if fileoperations.env_yaml_exists():
                        env_yaml_platform = fileoperations.get_platform_from_env_yaml()
                        if env_yaml_platform:
                            platform = solutionstack.SolutionStack(env_yaml_platform).platform_shorthand
                            solution = platform
                            io.echo(strings['init.usingenvyamlplatform'].replace('{platform}', platform))
                            platform_set = True

                    if not platform_set:
                        solution = solution_stack_ops.get_solution_stack_from_customer()

                initializeops.setup(self.app_name, self.region,
                                    solution)

                if 'IIS' not in solution:
                    keyname = self.get_keyname(default=key)

                    if keyname == -1:
                        self.keyname = None

                    fileoperations.write_config_setting('global', 'default_ec2_keyname',
                                                        keyname)
                os.chdir(cwd)
示例#36
0
def set_branch_default_for_global(branch_name):
    fileoperations.write_config_setting('global', 'branch', branch_name)
示例#37
0
    def do_command(self):
        # get arguments
        self.interactive = self.app.pargs.interactive
        self.region = self.app.pargs.region
        self.noverify = self.app.pargs.no_verify_ssl
        self.force_non_interactive = False

        # Determine if the customer is avoiding interactive mode by setting the platform flag
        if self.app.pargs.platform:
            self.force_non_interactive = True

        # Code Commit integration
        self.source = self.app.pargs.source
        source_location = None
        branch = None
        repository = None
        if self.source is not None:
            source_location, repository, branch = utils.parse_source(
                self.source)

        # The user specifies directories to initialize
        self.modules = self.app.pargs.modules
        if self.modules and len(self.modules) > 0:
            self.initialize_multiple_directories()
            return

        default_env = self.get_old_values()
        fileoperations.touch_config_folder()

        if self.interactive:
            self.region = get_region(self.region, self.interactive,
                                     self.force_non_interactive)
        else:
            self.region = get_region_from_inputs(self.app.pargs.region)
        aws.set_region(self.region)

        # Warn the customer if they picked a region that CodeCommit is not supported
        codecommit_region_supported = codecommit.region_supported(self.region)
        if self.source is not None and not codecommit_region_supported:
            io.log_warning(strings['codecommit.badregion'])

        self.region = set_up_credentials(self.app.pargs.profile, self.region,
                                         self.interactive)

        self.solution = self.get_solution_stack()
        self.app_name = self.get_app_name()
        if self.noverify:
            fileoperations.write_config_setting('global', 'no-verify-ssl',
                                                True)

        if not default_env and not self.interactive:
            # try to get default env from config file if exists
            try:
                default_env = commonops.get_current_branch_environment()
            except NotInitializedError:
                default_env = None
        elif self.interactive:
            default_env = None

        if self.force_non_interactive:
            default_env = '/ni'

        # Create application
        sstack, key = commonops.pull_down_app_info(self.app_name, default_env=default_env) if elasticbeanstalk.application_exist(self.app_name) \
            else commonops.create_app(self.app_name, default_env=default_env)

        if not self.solution:
            self.solution = sstack

        platform_set = False
        if not self.solution or \
                (self.interactive and not self.app.pargs.platform):
            if fileoperations.env_yaml_exists():
                env_yaml_platform = fileoperations.get_platform_from_env_yaml()
                if env_yaml_platform:
                    platform = solutionstack.SolutionStack(
                        env_yaml_platform).version
                    self.solution = platform
                    platform_set = True

            if not platform_set:
                result = commonops.prompt_for_solution_stack()
                self.solution = result.version

        # Select CodeBuild image if BuildSpec is present do not prompt or show if we are non-interactive
        if fileoperations.build_spec_exists(
        ) and not self.force_non_interactive:
            build_spec = fileoperations.get_build_configuration()
            if build_spec is not None and build_spec.image is None:
                LOG.debug(
                    "Buildspec file is present but image is does not exist. Attempting to fill best guess."
                )
                platform_image = initializeops.get_codebuild_image_from_platform(
                    self.solution)

                # If the return is a dictionary then it must be a single image and we can use that automatically
                if type(platform_image) is dict:
                    io.echo('codebuild.latestplatform'.replace(
                        '{platform}', self.solution))
                else:
                    # Otherwise we have an array for images which we must prompt the customer to pick from
                    io.echo(prompts['codebuild.getplatform'].replace(
                        '{platform}', self.solution))
                    selected = utils.prompt_for_index_in_list(
                        map(lambda image: image['description'],
                            platform_image))
                    platform_image = platform_image[selected]
                    platform_image['name'] = utils.decode_bytes(
                        platform_image['name'])

                # Finally write the CodeBuild image back to the buildspec file
                fileoperations.write_config_setting(
                    fileoperations.buildspec_config_header,
                    'Image',
                    platform_image['name'],
                    file=fileoperations.buildspec_name)

        # Setup code commit integration
        # Ensure that git is setup
        source_control = SourceControl.get_source_control()
        try:
            source_control_setup = source_control.is_setup()
            if source_control_setup is None:
                source_control_setup = False
        except CommandError:
            source_control_setup = False

        default_branch_exists = False
        if gitops.git_management_enabled() and not self.interactive:
            default_branch_exists = True

        prompt_codecommit = True
        # Do not prompt if we are in non-interactive mode, the region is not supported for CodeCommit,
        #  the specified source is from CodeCommit OR we already have default CodeCommit values set.
        if self.force_non_interactive \
                or not codecommit.region_supported(self.region) \
                or self.source is not None \
                or default_branch_exists:
            prompt_codecommit = False

        # Prompt for interactive CodeCommit
        if prompt_codecommit:
            if not source_control_setup:
                io.echo(strings['codecommit.nosc'])
            else:
                io.echo(strings['codecommit.ccwarning'])
                try:
                    io.validate_action(prompts['codecommit.usecc'], "y")

                    # Setup git config settings for code commit credentials
                    source_control.setup_codecommit_cred_config()

                    # Get user specified repository
                    if repository is None:
                        repository = get_repository_interactive()
                    else:
                        try:
                            result = codecommit.get_repository(repository)
                            source_control.setup_codecommit_remote_repo(
                                remote_url=result['repositoryMetadata']
                                ['cloneUrlHttp'])
                        except ServiceError as ex:
                            io.log_error(strings['codecommit.norepo'])
                            raise ex

                    # Get user specified branch
                    if branch is None:
                        branch = get_branch_interactive(repository)
                    else:
                        try:
                            codecommit.get_branch(repository, branch)
                        except ServiceError as ex:
                            io.log_error(strings['codecommit.nobranch'])
                            raise ex
                        source_control.setup_existing_codecommit_branch(branch)

                except ValidationError:
                    LOG.debug(
                        "Denied option to use CodeCommit, continuing initialization"
                    )

        # Initialize the whole setup
        initializeops.setup(self.app_name,
                            self.region,
                            self.solution,
                            dir_path=None,
                            repository=repository,
                            branch=branch)

        if 'IIS' not in self.solution:
            self.keyname = self.get_keyname(default=key)

            if self.keyname == -1:
                self.keyname = None

            fileoperations.write_config_setting('global',
                                                'default_ec2_keyname',
                                                self.keyname)

        # Default to including git submodules when creating zip files through `eb create`/`eb deploy`.
        fileoperations.write_config_setting('global', 'include_git_submodules',
                                            True)
示例#38
0
def set_repo_default_for_global(repo_name):
    fileoperations.write_config_setting('global', 'repository', repo_name)
示例#39
0
 def do_command(self):
     platform = solution_stack_ops.get_solution_stack_from_customer().name
     fileoperations.write_config_setting('global', 'default_platform', platform)
示例#40
0
def write_setting_to_current_environment_or_default(keyname, value):
    env_name = commonops.get_current_branch_environment()
    if env_name is None:
        fileoperations.write_config_setting('global', keyname, value)
    else:
        fileoperations.write_config_setting('environment-defaults', env_name, {keyname: value})