Esempio n. 1
0
def _ProcessRetryParametersNode(node, cron):
    """Converts <retry-parameters> in node to cron.retry_parameters."""

    retry_parameters_node = xml_parser_utils.GetChild(node, 'retry-parameters')
    if retry_parameters_node is None:
        cron.retry_parameters = None
        return

    retry_parameters = _RetryParameters()
    cron.retry_parameters = retry_parameters
    for tag in _RETRY_PARAMETER_TAGS:
        if xml_parser_utils.GetChild(retry_parameters_node, tag) is not None:
            setattr(
                retry_parameters, tag.replace('-', '_'),
                xml_parser_utils.GetChildNodeText(retry_parameters_node, tag))
Esempio n. 2
0
    def ProcessSecurityConstraintNode(self, node):
        """Pulls data from the security constraint node and adds to WebXml object.

    Args:
      node: An ElementTree Xml node that looks something like the following:

        <security-constraint>
          <web-resource-collection>
            <url-pattern>/profile/*</url-pattern>
          </web-resource-collection>
          <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
          </user-data-constraint>
        </security-constraint>
    """
        security_constraint = SecurityConstraint()
        resources_node = xml_parser_utils.GetChild(node,
                                                   'web-resource-collection')
        security_constraint.patterns = [
            xml_parser_utils.GetNodeText(sub_node) for sub_node in
            xml_parser_utils.GetNodes(resources_node, 'url-pattern')
        ]
        constraint = xml_parser_utils.GetChild(node, 'auth-constraint')
        if constraint is not None:
            role_name = xml_parser_utils.GetChildNodeText(
                constraint, 'role-name').lower()
            if role_name:
                if role_name not in ('none', '*', 'admin'):
                    self.errors.append(
                        'Bad value for <role-name> (%s), must be none, '
                        '*, or admin' % role_name)
                security_constraint.required_role = role_name

        user_constraint = xml_parser_utils.GetChild(node,
                                                    'user-data-constraint')
        if user_constraint is not None:
            guarantee = xml_parser_utils.GetChildNodeText(
                user_constraint, 'transport-guarantee').lower()
            if guarantee not in ('none', 'integral', 'confidential'):
                self.errors.append(
                    'Bad value for <transport-guarantee> (%s), must be'
                    ' none, integral, or confidential' % guarantee)
            security_constraint.transport_guarantee = guarantee

        self.web_xml.security_constraints.append(security_constraint)
Esempio n. 3
0
 def _ProcessPushQueueNode(self, node, queue):
     if xml_parser_utils.GetChild(node, 'acl') is not None:
         self.errors.append('The element <acl> is not defined for push '
                            "queues; bad <queue> entry with name '%s'" %
                            queue.name)
     for tag in PUSH_QUEUE_TAGS:
         field_name = tag.replace('-', '_')
         setattr(queue, field_name,
                 xml_parser_utils.GetChildNodeText(node, tag))
     self._ProcessRetryParametersNode(node, queue)
Esempio n. 4
0
    def ProcessBackendNode(self, node):
        """Processes XML nodes labeled 'backend' into a Backends object."""
        tag = xml_parser_utils.GetTag(node)
        if tag != 'backend':
            self.errors.append('Unrecognized node: <%s>' % tag)
            return

        backend = Backend()
        name = xml_parser_utils.GetAttribute(node, 'name')
        if not name:
            self.errors.append('All backends must have names')
            backend.name = '-'
        else:
            backend.name = name
        instance_class = xml_parser_utils.GetChildNodeText(node, 'class')
        if instance_class:
            backend.instance_class = instance_class
        instances = xml_parser_utils.GetChildNodeText(node, 'instances')
        if instances:
            try:
                backend.instances = int(instances)
            except ValueError:
                self.errors.append(
                    '<instances> must be an integer (bad value %s) in backend %s'
                    % (instances, backend.name))
        max_concurrent_requests = xml_parser_utils.GetChildNodeText(
            node, 'max-concurrent-requests')
        if max_concurrent_requests:
            try:
                backend.max_concurrent_requests = int(max_concurrent_requests)
            except ValueError:
                self.errors.append(
                    '<max-concurrent-requests> must be an integer '
                    '(bad value %s) in backend %s' %
                    (max_concurrent_requests, backend.name))

        options_node = xml_parser_utils.GetChild(node, 'options')
        if options_node is not None:
            for sub_node in options_node.getchildren():
                tag = xml_parser_utils.GetTag(sub_node)
                if tag not in ('fail-fast', 'dynamic', 'public'):
                    self.errors.append(
                        '<options> only supports values fail-fast, '
                        'dynamic, and public (bad value %s) in backend %s' %
                        (tag, backend.name))
                    continue
                tag = tag.replace('-', '')
                if xml_parser_utils.BooleanValue(sub_node.text):
                    backend.options.add(tag)
                else:
                    if tag in backend.options:
                        backend.options.remove(tag)

        self.backends.append(backend)
Esempio n. 5
0
    def _ProcessPullQueueNode(self, node, queue):
        """Populates PullQueue-specific fields from parsed XML."""
        for tag in PUSH_QUEUE_TAGS:
            if xml_parser_utils.GetChild(node, tag) is not None:
                self.errors.append(PULL_QUEUE_ERROR_MESSAGE %
                                   (tag, queue.name))

        acl_node = xml_parser_utils.GetChild(node, 'acl')

        if acl_node is not None:
            queue.acl = Acl()
            queue.acl.user_emails = [
                sub_node.text for sub_node in xml_parser_utils.GetNodes(
                    acl_node, 'user-email')
            ]
            queue.acl.writer_emails = [
                sub_node.text for sub_node in xml_parser_utils.GetNodes(
                    acl_node, 'writer-email')
            ]
        else:
            queue.acl = None

        self._ProcessRetryParametersNode(node, queue)
Esempio n. 6
0
    def _ProcessRetryParametersNode(self, node, queue):
        """Pulls information out of <retry-parameters> node."""
        retry_parameters_node = xml_parser_utils.GetChild(
            node, 'retry-parameters')
        if retry_parameters_node is None:
            queue.retry_parameters = None
            return
        retry_parameters = RetryParameters()
        queue.retry_parameters = retry_parameters
        retry_parameters.task_retry_limit = xml_parser_utils.GetChildNodeText(
            retry_parameters_node, 'task-retry-limit')

        for tag in PUSH_QUEUE_RETRY_PARAMS:

            if xml_parser_utils.GetChild(retry_parameters_node,
                                         tag) is not None:
                if isinstance(queue, PullQueue):
                    self.errors.append(RETRY_PARAM_ERROR_MESSAGE %
                                       (tag, queue.name))
                else:
                    setattr(
                        retry_parameters, tag.replace('-', '_'),
                        xml_parser_utils.GetChildNodeText(
                            retry_parameters_node, tag))
Esempio n. 7
0
    def _ProcessUrlMappingNode(self, node):
        """Parses out URL and possible ID for filter-mapping and servlet-mapping.

    Pulls url-pattern text out of node and adds to WebXml object. If url-pattern
    has an id attribute, adds that as well. This is done for <servlet-mapping>
    and <filter-mapping> nodes.

    Args:
      node: An ElementTreeNode which looks something like the following:

        <servlet-mapping>
          <servlet-name>redteam</servlet-name>
          <url-pattern>/red/*</url-pattern>
        </servlet-mapping>
    """
        url_pattern_node = xml_parser_utils.GetChild(node, 'url-pattern')
        if url_pattern_node is not None:
            self.web_xml.patterns.append(url_pattern_node.text)
            id_attr = xml_parser_utils.GetAttribute(url_pattern_node, 'id')
            if id_attr:
                self.web_xml.pattern_to_id[url_pattern_node.text] = id_attr