Files
pillar/pillar/api/eve_settings.py

803 lines
20 KiB
Python
Raw Normal View History

import os
URL_PREFIX = 'api'
2015-03-10 11:38:57 +01:00
# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide
# read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
# individual items (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PUT', 'DELETE']
2015-03-10 11:38:57 +01:00
PAGINATION_LIMIT = 250
2016-05-23 14:40:16 +02:00
PAGINATION_DEFAULT = 250
2015-03-10 11:38:57 +01:00
_file_embedded_schema = {
'type': 'objectid',
'data_relation': {
'resource': 'files',
'field': '_id',
'embeddable': True
}
}
_node_embedded_schema = {
'type': 'objectid',
'data_relation': {
'resource': 'nodes',
'field': '_id',
'embeddable': True
}
}
2016-03-05 23:22:57 +01:00
_required_user_embedded_schema = {
'type': 'objectid',
'required': True,
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True
},
}
2016-03-04 18:53:59 +01:00
_activity_object_type = {
'type': 'string',
'required': True,
'allowed': [
'project',
'user',
'node'
],
}
2015-03-11 16:03:19 +01:00
users_schema = {
'full_name': {
2015-03-10 11:38:57 +01:00
'type': 'string',
'minlength': 1,
'maxlength': 128,
2015-11-05 00:23:48 +01:00
'required': True,
},
'username': {
'type': 'string',
'minlength': 3,
'maxlength': 128,
'required': True,
'unique': True,
},
'email': {
'type': 'string',
'minlength': 5,
'maxlength': 60,
2015-03-10 11:38:57 +01:00
},
'roles': {
'type': 'list',
'schema': {'type': 'string'}
},
'groups': {
'type': 'list',
'default': [],
2015-05-21 12:04:46 -03:00
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'groups',
'field': '_id',
'embeddable': True
}
}
},
'auth': {
# Storage of authentication credentials (one will be able to auth with
# multiple providers on the same account)
'type': 'list',
'required': True,
'schema': {
'type': 'dict',
'schema': {
'provider': {
'type': 'string',
2016-04-26 12:33:48 +02:00
'allowed': ["blender-id", "local"],
},
2016-04-26 12:33:48 +02:00
'user_id': {
'type': 'string'
},
2016-04-26 12:33:48 +02:00
# A token is considered a "password" in case the provider is
# "local".
'token': {
'type': 'string'
}
}
}
2015-11-12 00:34:32 +01:00
},
'settings': {
'type': 'dict',
'schema': {
'email_communications': {
'type': 'integer',
'allowed': [0, 1]
}
}
},
'service': {
'type': 'dict',
'allow_unknown': True,
'schema': {
'badger': {
'type': 'list',
'schema': {'type': 'string'}
}
}
}
2015-03-10 11:38:57 +01:00
}
organizations_schema = {
'name': {
'type': 'string',
'minlength': 1,
'maxlength': 128,
'required': True
},
2015-10-05 19:57:37 +02:00
'email': {
'type': 'string'
},
'url': {
'type': 'string',
'minlength': 1,
'maxlength': 128,
'required': True
},
'description': {
'type': 'string',
'maxlength': 256,
},
'website': {
'type': 'string',
'maxlength': 256,
},
'location': {
'type': 'string',
'maxlength': 256,
},
'picture': dict(
nullable=True,
**_file_embedded_schema),
'users': {
'type': 'list',
'default': [],
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True
}
}
},
'teams': {
'type': 'list',
'default': [],
'schema': {
'type': 'dict',
'schema': {
# Team name
'name': {
'type': 'string',
'minlength': 1,
'maxlength': 128,
'required': True
},
# List of user ids for the team
'users': {
'type': 'list',
'default': [],
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'users',
'field': '_id',
}
}
},
# List of groups assigned to the team (this will automatically
# update the groups property of each user in the team)
'groups': {
'type': 'list',
'default': [],
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'groups',
'field': '_id',
}
}
}
}
}
}
}
permissions_embedded_schema = {
'groups': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'group': {
'type': 'objectid',
'required': True,
'data_relation': {
'resource': 'groups',
'field': '_id',
'embeddable': True
}
},
'methods': {
'type': 'list',
'required': True,
'allowed': ['GET', 'PUT', 'POST', 'DELETE']
}
}
},
},
'users': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
2016-07-07 11:57:59 +02:00
'user': {
'type': 'objectid',
'required': True,
},
'methods': {
'type': 'list',
'required': True,
'allowed': ['GET', 'PUT', 'POST', 'DELETE']
}
}
}
},
'world': {
'type': 'list',
2016-07-07 11:57:59 +02:00
# 'required': True,
'allowed': ['GET', ]
},
'is_free': {
'type': 'boolean',
}
}
2015-03-10 11:38:57 +01:00
nodes_schema = {
'name': {
'type': 'string',
'minlength': 1,
'maxlength': 128,
2015-03-11 16:03:19 +01:00
'required': True,
},
'description': {
'type': 'string',
},
'picture': _file_embedded_schema,
'order': {
'type': 'integer',
'minlength': 0,
},
'revision': {
'type': 'integer',
},
'parent': _node_embedded_schema,
2015-10-28 20:34:14 +01:00
'project': {
'type': 'objectid',
2016-07-07 11:57:59 +02:00
'data_relation': {
'resource': 'projects',
'field': '_id',
'embeddable': True
2016-07-07 11:57:59 +02:00
},
2015-03-10 11:38:57 +01:00
},
'user': {
'type': 'objectid',
2015-05-01 11:32:42 -03:00
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True
},
},
'node_type': {
'type': 'string',
'required': True
2015-03-10 11:38:57 +01:00
},
'properties': {
2016-07-07 11:57:59 +02:00
'type': 'dict',
'valid_properties': True,
'required': True,
2016-07-07 11:57:59 +02:00
},
'permissions': {
'type': 'dict',
'schema': permissions_embedded_schema
},
2016-07-07 15:41:42 +02:00
'short_code': {
'type': 'string',
},
2015-03-11 16:03:19 +01:00
}
tokens_schema = {
'user': {
'type': 'objectid',
'required': True,
},
'token': {
'type': 'string',
2015-04-08 11:47:19 -03:00
'required': True,
},
'expire_time': {
'type': 'datetime',
'required': True,
},
'is_subclient_token': {
'type': 'boolean',
'required': False,
}
}
2015-04-20 08:56:22 -03:00
files_schema = {
# Name of the file after processing, possibly hashed.
2015-04-20 08:56:22 -03:00
'name': {
'type': 'string',
'required': True,
},
'description': {
'type': 'string',
},
2016-07-07 11:57:59 +02:00
'content_type': { # MIME type image/png video/mp4
'type': 'string',
'required': True,
},
# Duration in seconds, only if it's a video
'duration': {
'type': 'integer',
},
2016-07-07 11:57:59 +02:00
'size': { # xs, s, b, 720p, 2K
2015-05-08 11:28:58 -03:00
'type': 'string'
},
2016-07-07 11:57:59 +02:00
'format': { # human readable format, like mp4, HLS, webm, mov
'type': 'string'
},
2016-07-07 11:57:59 +02:00
'width': { # valid for images and video content_type
'type': 'integer'
},
'height': {
'type': 'integer'
},
2015-04-20 08:56:22 -03:00
'user': {
'type': 'objectid',
'required': True,
},
2016-07-07 11:57:59 +02:00
'length': { # Size in bytes
2015-04-20 08:56:22 -03:00
'type': 'integer',
'required': True,
},
2016-05-06 11:42:22 +02:00
'length_aggregate_in_bytes': { # Size of file + all variations
'type': 'integer',
'required': False,
# it's computed on the fly anyway, so clients don't need to provide it.
2016-05-06 11:42:22 +02:00
},
2015-04-20 08:56:22 -03:00
'md5': {
'type': 'string',
'required': True,
},
# Original filename as given by the user, cleaned-up to make it safe.
2015-04-20 08:56:22 -03:00
'filename': {
'type': 'string',
'required': True,
},
2015-04-21 17:26:41 -03:00
'backend': {
'type': 'string',
'required': True,
'allowed': ["attract-web", "pillar", "cdnsun", "gcs", "unittest"]
},
# Where the file is in the backend storage itself. In the case of GCS,
# it is relative to the /_ folder. In the other cases, it is relative
# to the root of that storage backend. required=False to allow creation
# before uploading to a storage, in case the final path is determined
# by that storage backend.
'file_path': {
2015-04-20 08:56:22 -03:00
'type': 'string',
2015-05-08 11:28:58 -03:00
},
'link': {
'type': 'string',
},
'link_expires': {
'type': 'datetime',
},
'project': {
# The project node the files belongs to (does not matter if it is
# attached to an asset or something else). We use the project id as
# top level filtering, folder or bucket name. Later on we will be able
# to join permissions from the project and verify user access.
'type': 'objectid',
'data_relation': {
'resource': 'projects',
'field': '_id',
'embeddable': True
},
},
2016-07-07 11:57:59 +02:00
'variations': { # File variations (used to be children, see above)
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
2016-07-07 11:57:59 +02:00
'is_public': { # If True, the link will not be hashed or signed
2016-02-26 16:17:38 +01:00
'type': 'boolean'
},
2016-07-07 11:57:59 +02:00
'content_type': { # MIME type image/png video/mp4
'type': 'string',
'required': True,
},
'duration': {
'type': 'integer',
},
2016-07-07 11:57:59 +02:00
'size': { # xs, s, b, 720p, 2K
'type': 'string'
},
2016-07-07 11:57:59 +02:00
'format': { # human readable format, like mp4, HLS, webm, mov
'type': 'string'
},
2016-07-07 11:57:59 +02:00
'width': { # valid for images and video content_type
'type': 'integer'
},
'height': {
'type': 'integer'
},
2016-07-07 11:57:59 +02:00
'length': { # Size in bytes
'type': 'integer',
'required': True,
},
'md5': {
'type': 'string',
'required': True,
},
'file_path': {
'type': 'string',
},
'link': {
'type': 'string',
}
}
}
},
'processing': {
'type': 'dict',
2015-05-08 11:28:58 -03:00
'schema': {
'job_id': {
2016-07-07 11:57:59 +02:00
'type': 'string' # can be int, depending on the backend
},
'backend': {
'type': 'string',
'allowed': ["zencoder", "local"]
},
'status': {
'type': 'string',
'allowed': ["pending", "waiting", "processing", "finished",
2016-07-07 11:57:59 +02:00
"failed", "cancelled"]
},
2015-05-08 11:28:58 -03:00
}
},
'status': {
'type': 'string',
'allowed': ['uploading', 'queued_for_processing', 'processing', 'complete', 'failed'],
'required': False,
'default': 'complete', # default value for backward compatibility.
},
2015-04-20 08:56:22 -03:00
}
groups_schema = {
'name': {
'type': 'string',
'required': True
2015-04-21 17:26:41 -03:00
}
}
projects_schema = {
'name': {
'type': 'string',
'minlength': 1,
'maxlength': 128,
'required': True,
},
'description': {
'type': 'string',
},
# Short summary for the project
'summary': {
'type': 'string',
'maxlength': 128
},
# Logo
'picture_square': _file_embedded_schema,
# Header
'picture_header': _file_embedded_schema,
'header_node': dict(
nullable=True,
**_node_embedded_schema
),
'user': {
'type': 'objectid',
'required': True,
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True
},
},
'category': {
'type': 'string',
'allowed': [
'training',
'film',
'assets',
'software',
'game',
'home',
],
'required': True,
},
'is_private': {
'type': 'boolean',
'default': True,
},
'url': {
'type': 'string'
},
'organization': {
'type': 'objectid',
'nullable': True,
'data_relation': {
2016-07-07 11:57:59 +02:00
'resource': 'organizations',
'field': '_id',
'embeddable': True
},
},
'status': {
'type': 'string',
'allowed': [
'published',
'pending',
],
},
# Latest nodes being edited
'nodes_latest': {
'type': 'list',
'schema': {
'type': 'objectid',
}
},
# Featured nodes, manually added
'nodes_featured': {
'type': 'list',
'schema': {
'type': 'objectid',
}
},
# Latest blog posts, manually added
'nodes_blog': {
'type': 'list',
'schema': {
'type': 'objectid',
}
},
# Where Node type schemas for every projects are defined
'node_types': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
# URL is the way we identify a node_type when calling it via
# the helper methods in the Project API.
'url': {'type': 'string'},
'name': {'type': 'string'},
'description': {'type': 'string'},
# Allowed parents for the node_type
'parent': {
'type': 'list',
'schema': {
'type': 'string'
}
},
'dyn_schema': {
'type': 'dict',
'allow_unknown': True
},
'form_schema': {
'type': 'dict',
'allow_unknown': True
},
'permissions': {
'type': 'dict',
'schema': permissions_embedded_schema
}
},
}
},
'permissions': {
'type': 'dict',
'schema': permissions_embedded_schema
},
# Properties defined by extensions. Extensions should use their name
# (see the PillarExtension.name property) as the key, and are free to
# use whatever they want as value (but we suggest a dict for future
# extendability).
'extension_props': {
'type': 'dict',
'required': False,
},
}
2016-03-04 18:53:59 +01:00
activities_subscriptions_schema = {
2016-03-05 23:22:57 +01:00
'user': _required_user_embedded_schema,
2016-03-04 18:53:59 +01:00
'context_object_type': _activity_object_type,
'context_object': {
'type': 'objectid',
'required': True
},
'notifications': {
'type': 'dict',
'schema': {
'email': {
'type': 'boolean',
},
'web': {
'type': 'boolean',
2016-03-05 23:22:57 +01:00
'default': True
2016-03-04 18:53:59 +01:00
},
}
2016-03-05 23:22:57 +01:00
},
'is_subscribed': {
'type': 'boolean',
'default': True
2016-03-04 18:53:59 +01:00
}
}
activities_schema = {
2016-03-05 23:22:57 +01:00
'actor_user': _required_user_embedded_schema,
2016-03-04 18:53:59 +01:00
'verb': {
'type': 'string',
'required': True
},
'object_type': _activity_object_type,
'object': {
'type': 'objectid',
'required': True
},
'context_object_type': _activity_object_type,
'context_object': {
'type': 'objectid',
'required': True
},
'project': {
'type': 'objectid',
'data_relation': {
'resource': 'projects',
'field': '_id',
},
'required': False,
},
2016-10-12 14:29:28 +02:00
# If the object type is 'node', the node type can be stored here.
'node_type': {
'type': 'string',
'required': False,
}
2016-03-04 18:53:59 +01:00
}
notifications_schema = {
2016-03-05 23:22:57 +01:00
'user': _required_user_embedded_schema,
2016-03-04 18:53:59 +01:00
'activity': {
'type': 'objectid',
2016-03-05 23:22:57 +01:00
'required': True,
2016-03-04 18:53:59 +01:00
},
'is_read': {
'type': 'boolean',
},
}
2015-03-10 11:38:57 +01:00
nodes = {
'schema': nodes_schema,
'public_methods': ['GET'],
'public_item_methods': ['GET'],
2016-05-02 17:06:59 +02:00
'soft_delete': True,
2015-03-11 16:03:19 +01:00
}
2015-03-10 11:38:57 +01:00
2015-03-11 16:03:19 +01:00
users = {
'item_title': 'user',
2015-03-10 11:38:57 +01:00
# We choose to override global cache-control directives for this resource.
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'item_methods': ['GET', 'PUT', 'PATCH'],
'public_item_methods': ['GET'],
# By default don't include the 'auth' field. It can still be obtained
# using projections, though, so we block that in hooks.
'datasource': {'projection': {u'auth': 0}},
2015-03-11 16:03:19 +01:00
'schema': users_schema
2015-03-10 11:38:57 +01:00
}
tokens = {
'resource_methods': ['GET', 'POST'],
# Allow 'token' to be returned with POST responses
2016-07-07 11:57:59 +02:00
# 'extra_response_fields': ['token'],
2016-07-07 11:57:59 +02:00
'schema': tokens_schema
}
2015-03-10 11:38:57 +01:00
2015-04-20 08:56:22 -03:00
files = {
'resource_methods': ['GET', 'POST'],
'item_methods': ['GET', 'PATCH'],
'public_methods': ['GET'],
'public_item_methods': ['GET'],
'schema': files_schema
2015-04-20 08:56:22 -03:00
}
groups = {
'resource_methods': ['GET', 'POST'],
'public_methods': ['GET'],
'public_item_methods': ['GET'],
'schema': groups_schema,
}
organizations = {
'schema': organizations_schema,
'public_item_methods': ['GET'],
'public_methods': ['GET']
}
projects = {
'schema': projects_schema,
'public_item_methods': ['GET'],
'public_methods': ['GET'],
'soft_delete': True,
}
2016-03-04 18:53:59 +01:00
activities = {
'schema': activities_schema,
}
activities_subscriptions = {
'schema': activities_subscriptions_schema,
}
notifications = {
2016-03-05 23:22:57 +01:00
'schema': notifications_schema,
2016-03-04 18:53:59 +01:00
}
2015-03-10 11:38:57 +01:00
DOMAIN = {
2015-03-11 16:03:19 +01:00
'users': users,
2015-04-08 11:47:19 -03:00
'nodes': nodes,
'tokens': tokens,
2015-04-20 08:56:22 -03:00
'files': files,
'groups': groups,
'organizations': organizations,
2016-03-04 18:53:59 +01:00
'projects': projects,
'activities': activities,
'activities-subscriptions': activities_subscriptions,
'notifications': notifications
2015-03-10 11:38:57 +01:00
}
MONGO_HOST = os.environ.get('PILLAR_MONGO_HOST', 'localhost')
MONGO_PORT = int(os.environ.get('PILLAR_MONGO_PORT', 27017))
MONGO_DBNAME = os.environ.get('PILLAR_MONGO_DBNAME', 'eve')
2015-10-16 17:49:15 +02:00
CACHE_EXPIRES = 60
HATEOAS = False
UPSET_ON_PUT = False # do not create new document on PUT of non-existant URL.
X_DOMAINS = '*'
X_ALLOW_CREDENTIALS = True
X_HEADERS = 'Authorization'
XML = False