def create_session(): try: data = json.loads(request.data.decode('utf-8')) except ValueError as e: return (error('Base', 'MalformedJSON'), 400) if 'UserName' in data.keys() and 'Password' in data.keys(): result = g.session.create( username=data['UserName'], password=data['Password'] ) if isinstance(result, tuple): return (error(result[0], result[1]), result[2]) if result: response = make_response( render_template('sessions/Session.1.0.0.json', id=str(result['ID']), username=result['USERNAME'] ), 201, ) response.headers['Location'] = URL['SESSIONS'] + '/Sessions/' +\ str(result['ID']) response.headers['X-Auth-Token'] = result['X-AUTH'] return response else: return (error('Base', 'MalformedJSON'), 500) return (error('BluebirdServer', 'UnauthorizedLoginAttempt'), 401)
def create_session(): try: data = json.loads(request.data.decode('utf-8')) except ValueError as e: return (error('Base', 'MalformedJSON'), 400) if 'UserName' in data.keys() and 'Password' in data.keys(): result = g.session.create( username=data['UserName'], password=data['Password'] ) if isinstance(result, tuple): return (error(result[0], result[1]), result[2]) if result: response = make_response( render_template('sessions/Session.1.0.0.json', id=str(result['ID']), username=result['USERNAME'] ), 201, ) response.headers['Location'] = URL['SESSIONS'] + '/Sessions/' +\ str(result['ID']) response.headers['X-Auth-Token'] = result['X-AUTH'] return response else: return (error('Base', 'MalformedJSON'), 500) return (error('BluebirdServer', 'UnauthorizedLoginAttempt'), 401)
def create_session(): try: data = json.loads(request.data.decode('utf-8')) assert 'UserName' and 'Password' in data result = g.session.create(username=data['UserName'], password=data['Password']) response = make_response( render_template('sessions/Session.1.0.0.json', id=str(result['ID']), username=result['USERNAME']), 201, ) response.headers['Location'] = URL['SESSIONS'] + '/' + str( result['ID']) response.headers['X-Auth-Token'] = result['X-AUTH'] return response except (ValueError, TypeError, KeyError, AssertionError): return (error('Base', 'UnrecognizedRequestBody'), 400) except (NoAuthModule, NoValidSession, SessionLimitExceeded) as e: return e.response()
def check_content_type(): """Check if incoming POST request is JSON""" if request.method == 'POST': content_type = request.headers.get('Content-Type') if content_type == 'application/json': return else: return (error('Base', 'MalformedJSON'), 500)
def show_domains(domain): domain = g.libvirt.get_domain(domain) if domain: return render_template('ComputerSystem.1.0.1.json', domain=domain, server=Server()) else: return (error('Base', 'ResourceMissingAtURI'), 404)
def check_content_type(): """Check if incoming POST request is JSON""" if request.method == 'POST': content_type = request.headers.get('Content-Type') if content_type == 'application/json': return else: return (error('Base', 'MalformedJSON'), 500)
def show_domains(domain): domain = g.libvirt.get_domain(domain) if domain: return render_template('ComputerSystem.1.0.1.json', domain=domain, server=Server() ) else: return (error('Base', 'ResourceMissingAtURI'), 404)
def reset(domain): dom = g.libvirt.get_domain(domain) if not dom: return (error('Base', 'ResourceMissingAtURI'), 404) try: data = json.loads(request.data.decode('utf-8')) except ValueError as e: return (error('Base', 'MalformedJSON'), 400) if 'ResetType' in data.keys(): action = g.libvirt.valid_action(data['ResetType']) if action: credentials = (g.login['USERNAME'], g.login['PASSWORD']) execute = getattr(dom, action) credentials = (credentials) manager = LibvirtManage(credentials) return (error('Base', 'ActionNotSupported'), 500)
def check_content_type(): """Check if incoming POST request is JSON""" if request.method == 'POST': content_type = request.headers.get('Content-Type') if content_type == 'application/json': try: json.loads(request.data.decode('utf-8')) return except (ValueError, TypeError, KeyError): pass return (error('Base', 'MalformedJSON'), 400)
def reset(domain): dom = g.libvirt.get_domain(domain) if not dom: return (error('Base', 'ResourceMissingAtURI'), 404) try: data = json.loads(request.data.decode('utf-8')) except ValueError as e: return (error('Base', 'MalformedJSON'), 400) if 'ResetType' in data.keys(): username = g.login['USERNAME'] action = g.libvirt.valid_action(data['ResetType']) if action: execute = getattr(dom, action) if execute(username): ("", 200) else: return (error('BluebirdServer', 'UnauthorizedResetAction'), 401) return (error('Base', 'ActionNotSupported'), 500)
def reset(domain): if not g.libvirt.get_domain(domain): return (error('Base', 'ResourceMissingAtURI'), 404) try: data = json.loads(request.data.decode('utf-8')) manager = LibvirtManage((g.login['USERNAME'], g.login['PASSWORD'])) manager.reset(domain, data['ResetType']) return ('', 200) except Exception as e: return (str(e), 400) pass return ('', 400)
def decorated_function(*args, **kwargs): """ Return Not Implemented (501) if query parameters are given. When the resource addressed is a collection, the client can use the following paging query options to specify that a subset of the members be returned. These paging query options apply to the Members property of a collection resource. Query options: * http://collection?$skip=5 * http://collection?$top=30 """ for parameter in request.args: if parameter.startswith('$'): return (error('Base', 'QueryNotSupported'), 501) return f(*args, **kwargs)
def decorated_function(*args, **kwargs): """ Return Not Implemented (501) if query parameters are given. When the resource addressed is a collection, the client can use the following paging query options to specify that a subset of the members be returned. These paging query options apply to the Members property of a collection resource. Query options: * http://collection?$skip=5 * http://collection?$top=30 """ for parameter in request.args: if parameter.startswith('$'): return (error('Base', 'QueryNotSupported'), 501) return f(*args, **kwargs)
def decorated_function(*args, **kwargs): """X-Auth-Token and basic authentication decorator""" if xauth() or basic_authentication(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)
def response(self): return (error(self.__registry, self.__message), 403)
def decorated_function(*args, **kwargs): """Basic authentication decorator""" if basic_authentication(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)
def decorated_function(*args, **kwargs): """X-Auth-Token and basic authentication decorator""" if xauth() or basic_authentication(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)
def decorated_function(*args, **kwargs): """X-Auth-Token header decorator""" if xauth(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)
def decorated_function(*args, **kwargs): """Basic authentication decorator""" if basic_authentication(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)
def decorated_function(*args, **kwargs): """X-Auth-Token header decorator""" if xauth(): return f(*args, **kwargs) else: return (error('Base', 'NoValidSession'), 401)