Exemple #1
0
    def validate_attributes(cls, bundle, item_id, attributes):
        if attributes.get('delete', False):
            for attr in attributes.keys():
                if attr not in ['delete'] + list(
                        BUILTIN_ITEM_ATTRIBUTES.keys()):
                    raise BundleError(
                        _("{item} from bundle '{bundle}' cannot have other "
                          "attributes besides 'delete'").format(
                              item=item_id, bundle=bundle.name))

        if 'hash_method' in attributes and \
                attributes['hash_method'] not in HASH_METHODS:
            raise BundleError(
                _("Invalid hash method for {item} in bundle '{bundle}': '{method}'"
                  ).format(
                      bundle=bundle.name,
                      item=item_id,
                      method=attributes['hash_method'],
                  ))

        if 'password_hash' in attributes and ('password' in attributes
                                              or 'salt' in attributes):
            raise BundleError(
                _("{item} in bundle '{bundle}': 'password_hash' "
                  "cannot be used with 'password' or 'salt'").format(
                      bundle=bundle.name, item=item_id))

        if 'salt' in attributes and 'password' not in attributes:
            raise BundleError(
                _("{}: salt given without a password").format(item_id))
Exemple #2
0
    def validate_attributes(cls, bundle, item_id, attributes):
        if attributes.get('delete', False):
            for attr in attributes.keys():
                if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                    raise BundleError(_(
                        "{item} from bundle '{bundle}' cannot have other "
                        "attributes besides 'delete'"
                    ).format(item=item_id, bundle=bundle.name))
        if 'content' in attributes and 'source' in attributes:
            raise BundleError(_(
                "{item} from bundle '{bundle}' cannot have both 'content' and 'source'"
            ).format(item=item_id, bundle=bundle.name))

        if (
            attributes.get('content_type', None) == "any" and (
                'content' in attributes or
                'encoding' in attributes or
                'source' in attributes
            )
        ):
            raise BundleError(_(
                "{item} from bundle '{bundle}' with content_type 'any' "
                "must not define 'content', 'encoding' and/or 'source'"
            ).format(item=item_id, bundle=bundle.name))

        for key, value in attributes.items():
            ATTRIBUTE_VALIDATORS[key](item_id, value)
Exemple #3
0
    def validate_attributes(cls, bundle, item_id, attributes):
        if attributes.get('delete', False):
            for attr in attributes.keys():
                if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                    raise BundleError(_(
                        "{item} from bundle '{bundle}' cannot have other "
                        "attributes besides 'delete'"
                    ).format(item=item_id, bundle=bundle.name))

        if 'hash_method' in attributes and \
                attributes['hash_method'] not in HASH_METHODS:
            raise BundleError(
                _("Invalid hash method for {item} in bundle '{bundle}': '{method}'").format(
                    bundle=bundle.name,
                    item=item_id,
                    method=attributes['hash_method'],
                )
            )

        if 'password_hash' in attributes and (
            'password' in attributes or
            'salt' in attributes
        ):
            raise BundleError(_(
                "{item} in bundle '{bundle}': 'password_hash' "
                "cannot be used with 'password' or 'salt'"
            ).format(bundle=bundle.name, item=item_id))

        if 'salt' in attributes and 'password' not in attributes:
            raise BundleError(
                _("{}: salt given without a password").format(item_id)
            )
Exemple #4
0
 def validate_attributes(cls, bundle, item_id, attributes):
     if attributes.get('delete', False):
         for attr in attributes.keys():
             if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                 raise BundleError(_(
                     "{item} from bundle '{bundle}' cannot have other "
                     "attributes besides 'delete'"
                 ).format(item=item_id, bundle=bundle.name))
Exemple #5
0
 def validate_attributes(cls, bundle, item_id, attributes):
     if attributes.get('delete', False):
         for attr in attributes.keys():
             if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                 raise BundleError(_(
                     "{item} from bundle '{bundle}' cannot have other "
                     "attributes besides 'delete'"
                 ).format(item=item_id, bundle=bundle.name))
 def validate_attributes(cls, bundle, item_id, attributes):
     if attributes.get('delete', False):
         for attr in attributes.keys():
             if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                 raise BundleError(_(
                     "{item} from bundle '{bundle}' cannot have other "
                     "attributes besides 'delete'"
                 ).format(item=item_id, bundle=bundle.name))
     if attributes.get('manifest') and attributes.get('manifest_file'):
         raise BundleError(_(
             "{item} from bundle '{bundle}' cannot have both 'manifest' and 'manifest_file'"
         ).format(item=item_id, bundle=bundle.name))
     if attributes.get('manifest_processor') not in (None, 'jinja2', 'mako'):
         raise BundleError(_(
             "{item} from bundle '{bundle}' has invalid manifest_processor "
             "(must be 'jinja2' or 'mako')"
         ).format(item=item_id, bundle=bundle.name))
Exemple #7
0
 def validate_attributes(cls, bundle, item_id, attributes):
     if attributes.get('delete', False):
         for attr in attributes.keys():
             if attr not in ['delete'] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                 raise BundleError(_(
                     "{item} from bundle '{bundle}' cannot have other "
                     "attributes besides 'delete'"
                 ).format(item=item_id, bundle=bundle.name))
     if attributes.get('manifest') and attributes.get('manifest_file'):
         raise BundleError(_(
             "{item} from bundle '{bundle}' cannot have both 'manifest' and 'manifest_file'"
         ).format(item=item_id, bundle=bundle.name))
     if attributes.get('manifest_processor') not in (None, 'jinja2', 'mako'):
         raise BundleError(_(
             "{item} from bundle '{bundle}' has invalid manifest_processor "
             "(must be 'jinja2' or 'mako')"
         ).format(item=item_id, bundle=bundle.name))
Exemple #8
0
    def validate_attributes(cls, bundle, item_id, attributes):
        if attributes.get("delete", False):
            for attr in attributes.keys():
                if attr not in ["delete"] + list(BUILTIN_ITEM_ATTRIBUTES.keys()):
                    raise BundleError(
                        _("{item} from bundle '{bundle}' cannot have other " "attributes besides 'delete'").format(
                            item=item_id, bundle=bundle.name
                        )
                    )
        if "content" in attributes and "source" in attributes:
            raise BundleError(
                _("{item} from bundle '{bundle}' cannot have both 'content' and 'source'").format(
                    item=item_id, bundle=bundle.name
                )
            )

        if "content" in attributes and attributes.get("content_type") == "binary":
            raise BundleError(
                _(
                    "{item} from bundle '{bundle}' cannot have binary inline content "
                    "(use content_type 'base64' instead)"
                ).format(item=item_id, bundle=bundle.name)
            )

        if "encoding" in attributes and attributes.get("content_type") in ("any", "base64", "binary"):
            raise BundleError(
                _(
                    "content_type of {item} from bundle '{bundle}' cannot provide different encoding "
                    "(remove the 'encoding' attribute)"
                ).format(item=item_id, bundle=bundle.name)
            )

        if attributes.get("content_type", None) == "any" and (
            "content" in attributes or "encoding" in attributes or "source" in attributes
        ):
            raise BundleError(
                _(
                    "{item} from bundle '{bundle}' with content_type 'any' "
                    "must not define 'content', 'encoding' and/or 'source'"
                ).format(item=item_id, bundle=bundle.name)
            )

        for key, value in attributes.items():
            ATTRIBUTE_VALIDATORS[key](item_id, value)
Exemple #9
0
    def validate_attributes(cls, bundle, item_id, attributes):
        if attributes.get('delete', False):
            for attr in attributes.keys():
                if attr not in ['delete'] + list(
                        BUILTIN_ITEM_ATTRIBUTES.keys()):
                    raise BundleError(
                        _("{item} from bundle '{bundle}' cannot have other "
                          "attributes besides 'delete'").format(
                              item=item_id, bundle=bundle.name))
        if 'content' in attributes and 'source' in attributes:
            raise BundleError(
                _("{item} from bundle '{bundle}' cannot have both 'content' and 'source'"
                  ).format(item=item_id, bundle=bundle.name))

        if 'content' in attributes and attributes.get(
                'content_type') == 'binary':
            raise BundleError(
                _("{item} from bundle '{bundle}' cannot have binary inline content "
                  "(use content_type 'base64' instead)").format(
                      item=item_id, bundle=bundle.name))

        if 'encoding' in attributes and attributes.get('content_type') in (
                'any',
                'base64',
                'binary',
        ):
            raise BundleError(
                _("content_type of {item} from bundle '{bundle}' cannot provide different encoding "
                  "(remove the 'encoding' attribute)").format(
                      item=item_id, bundle=bundle.name))

        if (attributes.get('content_type', None) == "any"
                and ('content' in attributes or 'encoding' in attributes
                     or 'source' in attributes)):
            raise BundleError(
                _("{item} from bundle '{bundle}' with content_type 'any' "
                  "must not define 'content', 'encoding' and/or 'source'").
                format(item=item_id, bundle=bundle.name))

        for key, value in attributes.items():
            ATTRIBUTE_VALIDATORS[key](item_id, value)