Ejemplo n.º 1
0
    def test_format_string_values(self):
        obj = {
            "Key1": "Value1",
            "Key2": 42,
            "Key3": "{xx}",
            u"Key4": [True, {
                u"K": u"{yy}"
            }, "{xx}"],
        }
        fmt = utils.format_string_values(obj, **{"xx": "aa", "yy": "bb"})

        self.assertEqual(fmt["Key3"], "aa")
        self.assertEqual(fmt["Key4"][2], "aa")
        self.assertEqual(fmt["Key4"][1]["K"], "bb")

        self.assertEqual(utils.format_string_values({'k': '{1}'}),
                         {'k': '{1}'})

        self.assertEqual(
            utils.format_string_values({
                'k': '{limit}',
                'b': '{account_id}'
            },
                                       account_id=21), {
                                           'k': '{limit}',
                                           'b': '21'
                                       })
Ejemplo n.º 2
0
 def __init__(self, data=None, manager=None):
     if manager is not None:
         config_args = {
             'account_id': manager.config.account_id,
             'region': manager.config.region
         }
         self.data = utils.format_string_values(data, **config_args)
     else:
         self.data = utils.format_string_values(data)
     self.manager = manager
Ejemplo n.º 3
0
 def __init__(self, data=None, manager=None):
     if manager is not None:
         config_args = {
             'account_id': manager.config.account_id,
             'region': manager.config.region
         }
         self.data = utils.format_string_values(data, **config_args)
     else:
         self.data = utils.format_string_values(data)
     self.manager = manager
Ejemplo n.º 4
0
 def expand_variables(self, variables):
     """expand variables in the mode role and output_dir fields.
     """
     p = self.policy.data
     if 'mode' in p:
         if 'role' in p['mode']:
             p['mode']['role'] = utils.format_string_values(p['mode']['role'], **variables)
         if 'execution-options' in p['mode']:
             if 'output_dir' in p['mode']['execution-options']:
                 p['mode']['execution-options']['output_dir'] = utils.format_string_values(
                     p['mode']['execution-options']['output_dir'], **variables)
     return p
Ejemplo n.º 5
0
 def expand_variables(self, variables):
     """expand variables in the mode role and output_dir fields.
     """
     p = self.policy.data
     if 'mode' in p:
         if 'role' in p['mode']:
             p['mode']['role'] = utils.format_string_values(
                 p['mode']['role'], **variables)
         if 'execution-options' in p['mode']:
             if 'output_dir' in p['mode']['execution-options']:
                 p['mode']['execution-options'][
                     'output_dir'] = utils.format_string_values(
                         p['mode']['execution-options']['output_dir'],
                         **variables)
     return p
Ejemplo n.º 6
0
    def expand_variables(self, variables):
        """Expand variables in policy data.

        Updates the policy data in-place.
        """
        # format string values returns a copy
        updated = utils.format_string_values(self.data, **variables)

        # Several keys should only be expanded at runtime, perserve them.
        if 'member-role' in updated.get('mode', {}):
            updated['mode']['member-role'] = self.data['mode']['member-role']

        # Update ourselves in place
        self.data = updated
        # Reload filters/actions using updated data, we keep a reference
        # for some compatiblity preservation work.
        m = self.resource_manager
        self.resource_manager = self.load_resource_manager()

        # XXX: Compatiblity hack
        # Preserve notify action subject lines which support
        # embedded jinja2 as a passthrough to the mailer.
        for old_a, new_a in zip(m.actions, self.resource_manager.actions):
            if old_a.type == 'notify' and 'subject' in old_a.data:
                new_a.data['subject'] = old_a.data['subject']
Ejemplo n.º 7
0
    def expand_variables(self, variables):
        """Expand variables in policy data.

        Updates the policy data in-place.
        """
        # format string values returns a copy
        updated = utils.format_string_values(self.data, **variables)

        # Several keys should only be expanded at runtime, perserve them.
        if 'member-role' in updated.get('mode', {}):
            updated['mode']['member-role'] = self.data['mode']['member-role']

        # Update ourselves in place
        self.data = updated
        # Reload filters/actions using updated data, we keep a reference
        # for some compatiblity preservation work.
        m = self.resource_manager
        self.resource_manager = self.load_resource_manager()

        # XXX: Compatiblity hack
        # Preserve notify action subject lines which support
        # embedded jinja2 as a passthrough to the mailer.
        for old_a, new_a in zip(m.actions, self.resource_manager.actions):
            if old_a.type == 'notify' and 'subject' in old_a.data:
                new_a.data['subject'] = old_a.data['subject']
Ejemplo n.º 8
0
    def test_format_string_values(self):
        obj = {'Key1': 'Value1', 'Key2': 42, 'Key3': '{xx}', u'Key4': [True, {u'K': u'{yy}'}, '{xx}']}
        fmt = utils.format_string_values(obj, **{'xx': 'aa', 'yy': 'bb'})

        self.assertEqual(fmt['Key3'], 'aa')
        self.assertEqual(fmt['Key4'][2], 'aa')
        self.assertEqual(fmt['Key4'][1]['K'], 'bb')
Ejemplo n.º 9
0
    def test_format_string_values(self):
        obj = {'Key1': 'Value1', 'Key2': 42, 'Key3': '{xx}', u'Key4': [True, {u'K': u'{yy}'}, '{xx}']}
        fmt = utils.format_string_values(obj, **{'xx': 'aa', 'yy': 'bb'})

        self.assertEqual(fmt['Key3'], 'aa')
        self.assertEqual(fmt['Key4'][2], 'aa')
        self.assertEqual(fmt['Key4'][1]['K'], 'bb')
Ejemplo n.º 10
0
 def __init__(self, data, manager):
     config_args = {
         'account_id': manager.config.account_id,
         'region': manager.config.region
     }
     self.data = format_string_values(data, **config_args)
     self.manager = manager
     self.resolver = URIResolver(manager.session_factory, manager._cache)
Ejemplo n.º 11
0
 def __init__(self, data, manager):
     config_args = {
         'account_id': manager.config.account_id,
         'region': manager.config.region
     }
     self.data = format_string_values(data, **config_args)
     self.manager = manager
     self.resolver = URIResolver(manager.session_factory, manager._cache)
Ejemplo n.º 12
0
    def test_format_string_values(self):
        obj = {
            "Key1": "Value1",
            "Key2": 42,
            "Key3": "{xx}",
            u"Key4": [True, {u"K": u"{yy}"}, "{xx}"],
        }
        fmt = utils.format_string_values(obj, **{"xx": "aa", "yy": "bb"})

        self.assertEqual(fmt["Key3"], "aa")
        self.assertEqual(fmt["Key4"][2], "aa")
        self.assertEqual(fmt["Key4"][1]["K"], "bb")
Ejemplo n.º 13
0
    def test_format_string_values(self):
        obj = {
            "Key1": "Value1",
            "Key2": 42,
            "Key3": "{xx}",
            u"Key4": [True, {u"K": u"{yy}"}, "{xx}"],
        }
        fmt = utils.format_string_values(obj, **{"xx": "aa", "yy": "bb"})

        self.assertEqual(fmt["Key3"], "aa")
        self.assertEqual(fmt["Key4"][2], "aa")
        self.assertEqual(fmt["Key4"][1]["K"], "bb")

        self.assertEqual(
            utils.format_string_values(
                {'k': '{1}'}),
            {'k': '{1}'})

        self.assertEqual(
            utils.format_string_values(
                {'k': '{limit}',
                 'b': '{account_id}'}, account_id=21),
            {'k': '{limit}',
             'b': '21'})