Esempio n. 1
0
 def test__single_parameter_search_returns_empty_list_if_no_match(self):
     fake_boto3_session, paginate = self.get_mock_boto3_session()
     with Replacer() as r:
         r.replace('deployfish.aws.systems_manager.get_boto3_session',
                   fake_boto3_session)
         parameters = UnboundParameterFactory.new('foo.bar.BAZ')
         compare(parameters, [])
Esempio n. 2
0
def parameters_update(ctx, name, new_kms_key, value, force_multiple, dry_run):
    """
    Update the parameter that matches NAME with either a new KMS Key ID, a new value, or both.

    If NAME ends with a '*', and you use the --new-kms-key parameter, update the KMS Key ID on on all parameters that
    begin with the prefix.

    If NAME ends with a '*', and you use the --value parameter, don't update the value for all parameters that begin
    with the prefix unless you also specify --force-multiple.
    """
    parms = UnboundParameterFactory.new(name)
    if not parms:
        print('No parameters found that match "{}"'.format(name))
    else:
        parms.sort()
        print("\nBEFORE:")
        print("-----------------------------------------------------------------------")
        for parm in parms:
            print(parm)
        print("\nAFTER:")
        print("-----------------------------------------------------------------------")
        for parm in parms:
            if new_kms_key:
                parm.kms_key_id = new_kms_key
            if len(parms) == 1 or force_multiple:
                if value:
                    parm.value = value
            if not dry_run:
                parm.save(overwrite=True)
            print(parm)
Esempio n. 3
0
 def test__wildcard_parameter_search_deals_with_multiple_lists_from_iterator(
         self):
     fake_boto3_session, paginate = self.get_mock_boto3_session(
         data=[[{
             'Type': 'String',
             'Name': 'foo.bar.BAZ'
         }, {
             'Type': 'String',
             'Name': 'foo.bar.BLU'
         }], [
             {
                 'Type': 'String',
                 'Name': 'foo.bar.FLA'
             },
         ]])
     with Replacer() as r:
         r.replace('deployfish.aws.systems_manager.get_boto3_session',
                   fake_boto3_session)
         r.replace(
             'deployfish.aws.systems_manager.UnboundParameter._from_aws',
             Mock())
         parameters = UnboundParameterFactory.new('foo.bar.*')
         self.assertEqual(len(parameters), 3)
         self.assertEqual(parameters[0].name, 'foo.bar.BAZ')
         self.assertEqual(parameters[1].name, 'foo.bar.BLU')
         self.assertEqual(parameters[2].name, 'foo.bar.FLA')
Esempio n. 4
0
 def test__single_parameter_search_uses_Equals_filter(self):
     fake_boto3_session, paginate = self.get_mock_boto3_session()
     with Replacer() as r:
         r.replace('deployfish.aws.systems_manager.get_boto3_session',
                   fake_boto3_session)
         UnboundParameterFactory.new('foo.bar.BAZ')
         paginate.assert_called_once()
         compare(
             paginate.call_args,
             call(PaginationConfig={
                 'MaxItems': 100,
                 'PageSize': 50
             },
                  ParameterFilters=[{
                      'Key': 'Name',
                      'Option': 'Equals',
                      'Values': ['foo.bar.BAZ']
                  }]))
Esempio n. 5
0
def show(ctx, name):
    """
    Print out all parameters that match NAME.   If NAME ends with a '*', do a wildcard search on all parameters that
    begin with the prefix.
    """
    parms = UnboundParameterFactory.new(name)
    parms.sort()
    if not parms:
        print('No parameters found that match "{}"'.format(name))
    else:
        for parm in parms:
            print(parm)
Esempio n. 6
0
 def test__single_parameter_search_returns_parameter_if_match(self):
     fake_boto3_session, paginate = self.get_mock_boto3_session(
         data={
             'Type': 'String',
             'Name': 'foo.bar.BAZ'
         })
     with Replacer() as r:
         r.replace('deployfish.aws.systems_manager.get_boto3_session',
                   fake_boto3_session)
         r.replace(
             'deployfish.aws.systems_manager.UnboundParameter._from_aws',
             Mock())
         parameters = UnboundParameterFactory.new('foo.bar.BAZ')
         self.assertEqual(len(parameters), 1)
         self.assertEqual(parameters[0].name, 'foo.bar.BAZ')
Esempio n. 7
0
 def test__single_parameter_search_sets_kms_key_id_on_parameter_if_key(
         self):
     fake_boto3_session, paginate = self.get_mock_boto3_session(
         data={
             'Type': 'SecureString',
             'Name': 'foo.bar.BAZ',
             'KeyId': 'my_key_id'
         })
     with Replacer() as r:
         r.replace('deployfish.aws.systems_manager.get_boto3_session',
                   fake_boto3_session)
         r.replace(
             'deployfish.aws.systems_manager.UnboundParameter._from_aws',
             Mock())
         parameters = UnboundParameterFactory.new('foo.bar.BAZ')
         self.assertEqual(len(parameters), 1)
         self.assertEqual(parameters[0].kms_key_id, 'my_key_id')
Esempio n. 8
0
def parameters_copy(ctx, from_name, to_name, new_kms_key, overwrite, dry_run):
    """
    If FROM_NAME does not end with a "*", copy a parameter named FROM_NAME to another named TO_NAME.

    If FROM_NAME does end with a '*', do a wildcard search on all parameters that begin with the FROM_NAME, and copy
    those parameters to new ones with the FROM_NAME as prefix replaced with TO_NAME as prefix.
    """
    parms = UnboundParameterFactory.new(from_name)
    if not parms:
        print('No parameters found that match "{}"'.format(from_name))
    else:
        parms.sort()
        print("\FROM:")
        print(
            "-----------------------------------------------------------------------"
        )
        for parm in parms:
            print(parm)
        m = WILDCARD_RE.search(from_name)
        if m:
            if not to_name.endswith('.'):
                to_name += "."
            for parm in parms:
                parm.prefix = to_name
                if new_kms_key:
                    parm.kms_key_id = new_kms_key
        else:
            for parm in parms:
                parm.name = to_name
        print("\nTO:")
        print(
            "-----------------------------------------------------------------------"
        )
        for parm in parms:
            if not dry_run:
                try:
                    parm.save(overwrite=overwrite)
                except ValueError:
                    pass
                else:
                    print(parm)