示例#1
0
 def _filter_userdata(self, processed_ud):
     filters = [
         launch_index.Filter(util.safe_int(self.launch_index)),
     ]
     new_ud = processed_ud
     for f in filters:
         new_ud = f.apply(new_ud)
     return new_ud
 def _select(self, message):
     msg_idx = message.get("Launch-Index", None)
     if self.allow_none and msg_idx is None:
         return True
     msg_idx = util.safe_int(msg_idx)
     if msg_idx != self.wanted_idx:
         return False
     return True
示例#3
0
 def assertCounts(self, message, expected_counts):
     orig_message = copy.deepcopy(message)
     for (index, count) in expected_counts.items():
         index = util.safe_int(index)
         filtered_message = launch_index.Filter(index).apply(message)
         self.assertEqual(count_messages(filtered_message), count)
     # Ensure original message still ok/not modified
     self.assertTrue(self.equivalentMessage(message, orig_message))
示例#4
0
 def _filter_xdata(self, processed_ud):
     filters = [
         launch_index.Filter(util.safe_int(self.launch_index)),
     ]
     new_ud = processed_ud
     for f in filters:
         new_ud = f.apply(new_ud)
     return new_ud
 def assertCounts(self, message, expected_counts):
     orig_message = copy.deepcopy(message)
     for (index, count) in expected_counts.items():
         index = util.safe_int(index)
         filtered_message = launch_index.Filter(index).apply(message)
         self.assertEquals(count_messages(filtered_message), count)
     # Ensure original message still ok/not modified
     self.assertTrue(self.equivalentMessage(message, orig_message))
示例#6
0
 def _select(self, message):
     msg_idx = message.get('Launch-Index', None)
     if self.allow_none and msg_idx is None:
         return True
     msg_idx = util.safe_int(msg_idx)
     if msg_idx != self.wanted_idx:
         return False
     return True
示例#7
0
    def _parse(self, blob):
        leaves = {}
        children = []
        blob = util.decode_binary(blob)

        if not blob:
            return (leaves, children)

        def has_children(item):
            if item.endswith("/"):
                return True
            else:
                return False

        def get_name(item):
            if item.endswith("/"):
                return item.rstrip("/")
            return item

        for field in blob.splitlines():
            field = field.strip()
            field_name = get_name(field)
            if not field or not field_name:
                continue
            # Don't materialize credentials
            if field_name == 'security-credentials':
                continue
            if has_children(field):
                if field_name not in children:
                    children.append(field_name)
            else:
                contents = field.split("=", 1)
                resource = field_name
                if len(contents) > 1:
                    # What a PITA...
                    (ident, sub_contents) = contents
                    ident = util.safe_int(ident)
                    if ident is not None:
                        resource = "%s/openssh-key" % (ident)
                        field_name = sub_contents
                leaves[field_name] = resource
        return (leaves, children)
示例#8
0
    def _parse(self, blob):
        leaves = {}
        children = []
        blob = util.decode_binary(blob)

        if not blob:
            return (leaves, children)

        def has_children(item):
            if item.endswith("/"):
                return True
            else:
                return False

        def get_name(item):
            if item.endswith("/"):
                return item.rstrip("/")
            return item

        for field in blob.splitlines():
            field = field.strip()
            field_name = get_name(field)
            if not field or not field_name:
                continue
            # Don't materialize credentials
            if field_name == 'security-credentials':
                continue
            if has_children(field):
                if field_name not in children:
                    children.append(field_name)
            else:
                contents = field.split("=", 1)
                resource = field_name
                if len(contents) > 1:
                    # What a PITA...
                    (ident, sub_contents) = contents
                    ident = util.safe_int(ident)
                    if ident is not None:
                        resource = "%s/openssh-key" % (ident)
                        field_name = sub_contents
                leaves[field_name] = resource
        return (leaves, children)