def test_require_schema_email_ok(value): schema = {"data": {"$ref": "#/definitions/email"}} schema = validators.create_data_schema(schema) function = validators.require_schema(schema)(dummy_function) mck = mock.MagicMock() mck.request_json = {"data": value} function(mck)
def test_require_schema_non_empty_string_ok(): schema = {"data": {"$ref": "#/definitions/non_empty_string"}} schema = validators.create_data_schema(schema) function = validators.require_schema(schema)(dummy_function) mck = mock.MagicMock() mck.request_json = {"data": "1"} function(mck)
def test_require_schema_uuid_ok(): schema = {"data": {"$ref": "#/definitions/uuid4"}} schema = validators.create_data_schema(schema) function = validators.require_schema(schema)(dummy_function) mck = mock.MagicMock() mck.request_json = {"data": pytest.faux.gen_uuid()} function(mck)
def test_require_schema_email_fail(value): schema = {"data": {"$ref": "#/definitions/email"}} schema = validators.create_data_schema(schema) function = validators.require_schema(schema)(dummy_function) mck = mock.MagicMock() mck.request_json = {"data": value} with pytest.raises(exceptions.InvalidJSONError): function(mck)
def test_require_schema_uuid_array_fail(wrap_into_array, value): schema = {"data": {"$ref": "#/definitions/uuid4_array"}} schema = validators.create_data_schema(schema) function = validators.require_schema(schema)(dummy_function) mck = mock.MagicMock() if wrap_into_array: value = [value] mck.request_json = {"data": value} with pytest.raises(exceptions.InvalidJSONError): function(mck)
{"$ref": "#/definitions/hostname"}, {"$ref": "#/definitions/ip"} ]}, "username": {"$ref": "#/definitions/non_empty_string"}, "id": {"$ref": "#/definitions/dmidecode_uuid"} } """Data schema for the server discovery.""" MODEL_SCHEMA = validators.create_model_schema( server.ServerModel.MODEL_NAME, DATA_SCHEMA ) MODEL_SCHEMA["properties"]["id"] = {"$ref": "#/definitions/dmidecode_uuid"} """Schema for the model with optional data fields.""" SERVER_DISCOVERY_SCHEMA = validators.create_data_schema( SERVER_DISCOVERY_DATA_SCHEMA ) """Schema for the server discovery.""" CONF = config.make_api_config() """Config.""" LOG = log.getLogger(__name__) """Logger.""" def require_create_server_authorization(func): """Special authorization decorator for server create.""" normal_decorated_func = auth.AUTH.require_authorization( "api", "create_server")
POST_SCHEMA = { "playbook_configuration": { "type": "object", "additionalProperties": False, "required": ["id", "version"], "properties": { "id": { "$ref": "#/definitions/uuid4" }, "version": { "$ref": "#/definitions/positive_integer" } } } } POST_SCHEMA = validators.create_data_schema(POST_SCHEMA, True) """Schema for creating new execution.""" LOG_CACHE_TIMEOUT = 60 * 60 * 24 * 30 # 1 month, almost immutable though """Timeout to cache execution log on client side.""" LOG = log.getLogger(__name__) """Logger.""" class ExecutionView(generic.VersionedCRUDView): """Implementation of view for /v1/execution API.""" decorators = [ auth.AUTH.require_authorization("api", "view_execution"), auth.AUTH.require_authentication
"version": {"$ref": "#/definitions/positive_integer"}, "fqdn": {"$ref": "#/definitions/non_empty_string"}, "ip": {"$ref": "#/definitions/non_empty_string"} } } } } } """Data schema for the model.""" MODEL_SCHEMA = validators.create_model_schema( cluster.ClusterModel.MODEL_NAME, DATA_SCHEMA ) """Schema for the model with optional data fields.""" POST_SCHEMA = validators.create_data_schema( {"name": {"$ref": "#/definitions/cluster_name_string"}}, True) LOG = log.getLogger(__name__) """Logger.""" class ClusterView(generic.VersionedCRUDView): """Implementation of view for /v1/cluster API.""" decorators = [ auth.AUTH.require_authorization("api", "view_cluster"), auth.AUTH.require_authentication ] NAME = "cluster" MODEL_NAME = "cluster"
from decapod_common.models import playbook_configuration from decapod_common.models import task POST_SCHEMA = { "playbook_configuration": { "type": "object", "additionalProperties": False, "required": ["id", "version"], "properties": { "id": {"$ref": "#/definitions/uuid4"}, "version": {"$ref": "#/definitions/positive_integer"} } } } POST_SCHEMA = validators.create_data_schema(POST_SCHEMA, True) """Schema for creating new execution.""" LOG_CACHE_TIMEOUT = 60 * 60 * 24 * 30 # 1 month, almost immutable though """Timeout to cache execution log on client side.""" LOG = log.getLogger(__name__) """Logger.""" class ExecutionView(generic.VersionedCRUDView): """Implementation of view for /v1/execution API.""" decorators = [ auth.AUTH.require_authorization("api", "view_execution"), auth.AUTH.require_authentication
}, "username": { "$ref": "#/definitions/non_empty_string" }, "id": { "$ref": "#/definitions/dmidecode_uuid" } } """Data schema for the server discovery.""" MODEL_SCHEMA = validators.create_model_schema(server.ServerModel.MODEL_NAME, DATA_SCHEMA) MODEL_SCHEMA["properties"]["id"] = {"$ref": "#/definitions/dmidecode_uuid"} """Schema for the model with optional data fields.""" SERVER_DISCOVERY_SCHEMA = validators.create_data_schema( SERVER_DISCOVERY_DATA_SCHEMA) """Schema for the server discovery.""" CONF = config.make_api_config() """Config.""" LOG = log.getLogger(__name__) """Logger.""" def require_create_server_authorization(func): """Special authorization decorator for server create.""" normal_decorated_func = auth.AUTH.require_authorization( "api", "create_server") normal_decorated_func = normal_decorated_func(func)
from decapod_api import auth from decapod_api import exceptions as http_exceptions from decapod_api import validators from decapod_api.views import generic from decapod_common import config from decapod_common import emailutils from decapod_common import exceptions as base_exceptions from decapod_common import log from decapod_common.models import password_reset from decapod_common.models import user NEW_PASSWORD_RESET_SCHEMA = validators.create_data_schema({ "login": {"$ref": "#/definitions/non_empty_string"} }, mandatory=True) """JSON Schema of reseting new password.""" UPDATE_PASSWORD_SCHEMA = validators.create_data_schema({ "password": {"$ref": "#/definitions/non_empty_string"} }, mandatory=True) """JSON Schema of updateing for new password.""" PASSWORD_MESSAGE = """\ Hi, We've got the request to reset your password. To reset just follow this URL, it will be avaialble for next 24 hours: {url}
"ip": { "$ref": "#/definitions/non_empty_string" } } } } } } """Data schema for the model.""" MODEL_SCHEMA = validators.create_model_schema(cluster.ClusterModel.MODEL_NAME, DATA_SCHEMA) """Schema for the model with optional data fields.""" POST_SCHEMA = validators.create_data_schema( {"name": { "$ref": "#/definitions/cluster_name_string" }}, True) LOG = log.getLogger(__name__) """Logger.""" class ClusterView(generic.VersionedCRUDView): """Implementation of view for /v1/cluster API.""" decorators = [ auth.AUTH.require_authorization("api", "view_cluster"), auth.AUTH.require_authentication ] NAME = "cluster"
"version": {"$ref": "#/definitions/positive_integer"}, "fqdn": {"$ref": "#/definitions/non_empty_string"}, "ip": {"$ref": "#/definitions/non_empty_string"} } } } } } """Data schema for the model.""" MODEL_SCHEMA = validators.create_model_schema( cluster.ClusterModel.MODEL_NAME, DATA_SCHEMA ) """Schema for the model with optional data fields.""" POST_SCHEMA = validators.create_data_schema( {"name": {"$ref": "#/definitions/non_empty_string"}}, True) LOG = log.getLogger(__name__) """Logger.""" class ClusterView(generic.VersionedCRUDView): """Implementation of view for /v1/cluster API.""" decorators = [ auth.AUTH.require_authorization("api", "view_cluster"), auth.AUTH.require_authentication ] NAME = "cluster" MODEL_NAME = "cluster"