Add schema validation of namespaces and sources methods
This commit is contained in:
parent
57528aa2bc
commit
e025d8c2b2
5 changed files with 96 additions and 9 deletions
|
@ -6,6 +6,79 @@ from endpoints.building import PreparedBuild
|
|||
from data import model
|
||||
from buildtrigger.triggerutil import get_trigger_config, InvalidServiceException
|
||||
|
||||
NAMESPACES_SCHEMA = {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'personal': {
|
||||
'type': 'boolean',
|
||||
'description': 'True if the namespace is the user\'s personal namespace',
|
||||
},
|
||||
'score': {
|
||||
'type': 'number',
|
||||
'description': 'Score of the relevance of the namespace',
|
||||
},
|
||||
'avatar_url': {
|
||||
'type': 'string',
|
||||
'description': 'URL of the avatar for this namespace',
|
||||
},
|
||||
'url': {
|
||||
'type': 'string',
|
||||
'description': 'URL of the website to view the namespace',
|
||||
},
|
||||
'id': {
|
||||
'type': 'string',
|
||||
'description': 'Trigger-internal ID of the namespace',
|
||||
},
|
||||
'title': {
|
||||
'type': 'string',
|
||||
'description': 'Human-readable title of the namespace',
|
||||
},
|
||||
},
|
||||
'required': ['personal', 'score', 'avatar_url', 'url', 'id', 'title'],
|
||||
},
|
||||
}
|
||||
|
||||
BUILD_SOURCES_SCHEMA = {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'name': {
|
||||
'type': 'string',
|
||||
'description': 'The name of the repository, without its namespace',
|
||||
},
|
||||
'full_name': {
|
||||
'type': 'string',
|
||||
'description': 'The name of the repository, with its namespace',
|
||||
},
|
||||
'description': {
|
||||
'type': 'string',
|
||||
'description': 'The description of the repository. May be an empty string',
|
||||
},
|
||||
'last_updated': {
|
||||
'type': 'number',
|
||||
'description': 'The date/time when the repository was last updated, since epoch in UTC',
|
||||
},
|
||||
'url': {
|
||||
'type': 'string',
|
||||
'description': 'The URL at which to view the repository in the browser',
|
||||
},
|
||||
'has_admin_permissions': {
|
||||
'type': 'boolean',
|
||||
'description': 'True if the current user has admin permissions on the repository',
|
||||
},
|
||||
'private': {
|
||||
'type': 'boolean',
|
||||
'description': 'True if the repository is private',
|
||||
},
|
||||
},
|
||||
'required': ['name', 'full_name', 'description', 'last_updated', 'url',
|
||||
'has_admin_permissions', 'private'],
|
||||
},
|
||||
}
|
||||
|
||||
METADATA_SCHEMA = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
|
@ -242,3 +315,14 @@ class BuildTriggerHandler(object):
|
|||
prepared.tags = [commit_sha[:7]]
|
||||
|
||||
return prepared
|
||||
|
||||
@classmethod
|
||||
def build_sources_response(cls, sources):
|
||||
validate(sources, BUILD_SOURCES_SCHEMA)
|
||||
return sources
|
||||
|
||||
@classmethod
|
||||
def build_namespaces_response(cls, namespaces_dict):
|
||||
namespaces = list(namespaces_dict.values())
|
||||
validate(namespaces, NAMESPACES_SCHEMA)
|
||||
return namespaces
|
||||
|
|
Reference in a new issue