Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
field
for field, definition in schema.items()
if isinstance(definition, dict)
and (
definition.get("type") == "media"
or (
definition.get("type") == "list"
and definition.get("schema", {}).get("type") == "media"
)
)
]
else:
settings["_media"] = []
if settings["_media"] and not self.media:
raise ConfigException(
"A media storage class of type "
" eve.io.media.MediaStorage must be defined "
def validate_domain_struct(self):
""" Validates that Eve configuration settings conform to the
requirements.
"""
try:
domain = self.config["DOMAIN"]
except:
raise ConfigException("DOMAIN dictionary missing or wrong.")
if not isinstance(domain, dict):
raise ConfigException("DOMAIN must be a dict.")
def validate_methods(self, allowed, proposed, item):
""" Compares allowed and proposed methods, raising a `ConfigException`
when they don't match.
:param allowed: a list of supported (allowed) methods.
:param proposed: a list of proposed methods.
:param item: name of the item to which the methods would be applied.
Used when raising the exception.
"""
diff = set(proposed) - set(allowed)
if diff:
raise ConfigException(
"Unallowed %s method(s): %s. "
"Supported: %s" % (item, ", ".join(diff), ", ".join(allowed))
)
"[%s] resource " % resource,
)
self.validate_methods(
self.supported_item_methods,
settings["item_methods"],
"[%s] item " % resource,
)
# while a resource schema is optional for read-only access,
# it is mandatory for write-access to resource/items.
if (
"POST" in settings["resource_methods"]
or "PATCH" in settings["item_methods"]
):
if not settings["schema"]:
raise ConfigException(
"A resource schema must be provided "
"when POST or PATCH methods are allowed "
"for a resource [%s]." % resource
)
self.validate_roles("allowed_roles", settings, resource)
self.validate_roles("allowed_read_roles", settings, resource)
self.validate_roles("allowed_write_roles", settings, resource)
self.validate_roles("allowed_item_roles", settings, resource)
self.validate_roles("allowed_item_read_roles", settings, resource)
self.validate_roles("allowed_item_write_roles", settings, resource)
if settings["auth_field"] == settings["id_field"]:
raise ConfigException(
'"%s": auth_field cannot be set to id_field '
"(%s)" % (resource, settings["id_field"])
def _get_resource(self):
try:
return self._related_resource_configs[(self._model, self._name)]
except LookupError:
try:
arg = self._relationship.argument
if isinstance(arg, DeclarativeMeta):
return self._related_resource_configs[arg]
elif callable(arg):
return self._related_resource_configs[arg()]
else:
return self._related_resource_configs[arg.class_]
except LookupError:
raise ConfigException(
'Cannot determine related resource for {model}.{field}. '
'Please specify `related_resources` manually.'
.format(model=self._model.__name__, field=self._name))