def add_cloud_formation_cli_arguments(parser, include_boto_arguments=True, include_bucket_arguments=True):
    """
    Utility function for adding CloudFormation specific CLI arguments.
    """
    if include_boto_arguments:
        # GOTCHA: Since many modules use krux_boto, the krux_boto's CLI arguments can be included twice,
        # causing an error. This creates a way to circumvent that.

        # Add all the boto arguments
        add_boto_cli_arguments(parser)

    add_s3_cli_arguments(parser, False)

    # Add those specific to the application
    group = get_group(parser, NAME)

    if include_bucket_arguments:
        # If you want to fix the S3 bucket used to upload templates, do not use these arguments
        group.add_argument(
            '--bucket-name',
            type=str,
            default=CloudFormation.DEFAULT_S3_BUCKET,
            help='Name of the bucket to upload cloud formation template to (Default: %(default)s)'
        )

        group.add_argument(
            '--bucket-region',
            type=str,
            default=CloudFormation.DEFAULT_S3_REGION,
            help='Region of the bucket to upload cloud formation template to (Default: %(default)s)'
        )
예제 #2
0
def add_s3_cli_arguments(parser, include_boto_arguments=True, *args, **kwargs):
    """
    Utility function for adding S3 specific CLI arguments.
    """
    if include_boto_arguments:
        # GOTCHA: Since EC2 and S3 both uses Boto, the Boto's CLI arguments can be included twice,
        # causing an error. This creates a way to circumvent that.

        # Add all the boto arguments
        add_boto_cli_arguments(parser, *args, **kwargs)
예제 #3
0
    def test_cli_arguments_check(self):
        """
        Boto warns users correctly when CLI arguments and passed in credentials don't match.
        """
        credential_map = {
            ACCESS_KEY: {
                'CLI': 'ZYXWVUTSR',
                'ENV': 'ABCDEFGHI',
                'msg': 'boto-access-key',
            },
            SECRET_KEY: {
                'CLI': '0Z9Y8X7W6V5U4T3S2R1',
                'ENV': '1A2B3C4D5E6F7G8H9I0',
                'msg': 'boto-secret-key',
            },
        }

        # Mocking the parser to trigger the warning
        parser = krux.cli.get_parser()
        add_boto_cli_arguments(parser)
        namespace = parser.parse_args([
            '--boto-access-key', credential_map[ACCESS_KEY]['CLI'],
            '--boto-secret-key', credential_map[SECRET_KEY]['CLI'],
        ])
        mock_parser = MagicMock(
            return_value=MagicMock(
                spec=ArgumentParser,
                autospec=True,
                _action_groups=[],
                parse_known_args=MagicMock(return_value=namespace)
            )
        )

        # Mocking the logger to check for calls later
        mock_logger = MagicMock(spec=Logger, autospec=True)

        mock_env = {
            ACCESS_KEY: credential_map[ACCESS_KEY]['ENV'],
            SECRET_KEY: credential_map[SECRET_KEY]['ENV'],
        }

        with patch.dict('krux_boto.boto.os.environ', mock_env, clear=True):
            with patch('krux_boto.boto.get_parser', mock_parser):
                self.boto = Boto(
                    logger=mock_logger
                )

        for key, value in credential_map.iteritems():
            msg = 'You set %s as {0} in CLI, but passed %s to the library. ' \
                'To avoid this error, consider using get_boto() function. ' \
                'For more information, please check README.' \
                .format(value['msg'])
            cli_key = value['CLI'][0:3] + '[...]' + value['CLI'][-3:]
            env_key = value['ENV'][0:3] + '[...]' + value['ENV'][-3:]
            mock_logger.warn.assert_any_call(msg, cli_key, env_key)
예제 #4
0
def add_sqs_cli_arguments(parser, include_boto_arguments=True):
    """
    Utility function for adding SQS specific CLI arguments.
    """
    if include_boto_arguments:
        # GOTCHA: Since many modules use krux_boto, the krux_boto's CLI arguments can be included twice,
        # causing an error. This creates a way to circumvent that.

        # Add all the boto arguments
        add_boto_cli_arguments(parser)

    # Add those specific to the application
    group = get_group(parser, NAME)
예제 #5
0
    def add_cli_arguments(self, parser):
        super(Application, self).add_cli_arguments(parser)

        # add the arguments for boto
        add_boto_cli_arguments(parser)
예제 #6
0
    def add_cli_arguments(self, parser):
        super(Application, self).add_cli_arguments(parser)

        # add the arguments for boto
        add_boto_cli_arguments(parser)