def validate_put(self, actor): # inherit derived attributes from the original actor, including id and db_id: parser = Actor.request_parser() # remove since name is only required for POST, not PUT parser.remove_argument('name') parser.add_argument('force', type=bool, required=False, help="Whether to force an update of the actor image", default=False) # if camel case, need to remove fields snake case versions of fields that can be updated if Config.get('web', 'case') == 'camel': actor.pop('use_container_uid') actor.pop('default_environment') # this update overrides all required and optional attributes try: new_fields = parser.parse_args() logger.debug("new fields from actor PUT: {}".format(new_fields)) except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') else: msg = '{}: {}'.format(msg, e) raise DAOError("Invalid actor description: {}".format(msg)) if not actor.stateless and new_fields.get('stateless'): raise DAOError("Invalid actor description: an actor that was not stateless cannot be update to be stateless.") actor.update(new_fields) return actor
def validate_max_uses(self, max_uses): try: m = int(max_uses) except Exception: raise DAOError("The max uses parameter must be an integer.") if m ==0 or m < -1: raise DAOError("The max uses parameter must be a positive integer or -1 " "(to denote unlimited uses).")
def validate_post(self): parser = RequestParser() parser.add_argument('message', type=str, required=False, help="The message to send to the actor.") args = parser.parse_args() # if a special 'message' object isn't passed, use entire POST payload as message if not args.get('message'): json_data = request.get_json() if json_data: args['message'] = json_data args['_abaco_Content-Type'] = 'application/json' else: # try to get data for mime types not recognized by flask. flask creates a python string for these try: args['message'] = json.loads(request.data) except TypeError: raise DAOError( 'message POST body could not be serialized. Pass JSON data or use the message attribute.' ) args['_abaco_Content-Type'] = 'str' else: # the special message object is a string args['_abaco_Content-Type'] = 'str' return args
def validate_post(self): logger.debug("validating message payload.") parser = RequestParser() parser.add_argument('message', type=str, required=False, help="The message to send to the actor.") args = parser.parse_args() # if a special 'message' object isn't passed, use entire POST payload as message if not args.get('message'): logger.debug("POST body did not have a message field.") json_data = request.get_json() if json_data: logger.debug("message was JSON data.") args['message'] = json_data args['_abaco_Content-Type'] = 'application/json' else: logger.debug("message was NOT JSON data.") # try to get data for mime types not recognized by flask. flask creates a python string for these try: args['message'] = json.loads(request.data) except TypeError: logger.debug("message POST body could not be serialized. args: {}".format(args)) raise DAOError('message POST body could not be serialized. Pass JSON data or use the message attribute.') args['_abaco_Content-Type'] = 'str' else: # the special message object is a string logger.debug("POST body has a message field. Setting _abaco_Content-type to 'str'.") args['_abaco_Content-Type'] = 'str' return args
def validate_post(self): logger.debug("validating message payload.") parser = RequestParser() parser.add_argument('message', type=str, required=False, help="The message to send to the actor.") args = parser.parse_args() # if a special 'message' object isn't passed, use entire POST payload as message if not args.get('message'): logger.debug("POST body did not have a message field.") # first check for binary data: if request.headers.get( 'Content-Type') == 'application/octet-stream': # ensure not sending too much data length = request.headers.get('Content-Length') if not length: raise ResourceError( "Content Length required for application/octet-stream." ) try: int(length) except Exception: raise ResourceError("Content Length must be an integer.") if int(length) > int(Config.get('web', 'max_content_length')): raise ResourceError( "Message exceeds max content length of: {}".format( Config.get('web', 'max_content_length'))) logger.debug( "using get_data, setting content type to application/octet-stream." ) args['message'] = request.get_data() args['_abaco_Content_Type'] = 'application/octet-stream' return args json_data = request.get_json() if json_data: logger.debug("message was JSON data.") args['message'] = json_data args['_abaco_Content_Type'] = 'application/json' else: logger.debug("message was NOT JSON data.") # try to get data for mime types not recognized by flask. flask creates a python string for these try: args['message'] = json.loads(request.data) except TypeError: logger.debug( "message POST body could not be serialized. args: {}". format(args)) raise DAOError( 'message POST body could not be serialized. Pass JSON data or use the message attribute.' ) args['_abaco_Content_Type'] = 'str' else: # the special message object is a string logger.debug( "POST body has a message field. Setting _abaco_Content_type to 'str'." ) args['_abaco_Content_Type'] = 'str' return args
def validate_post(self): parser = Actor.request_parser() try: return parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid actor description: {}".format(msg))
def validate_post(self): parser = RequestParser() parser.add_argument('num', type=int, help="Number of workers to start (default is 1).") try: args = parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid POST: {}".format(msg)) return args
def validate_post(self): parser = Nonce.request_parser() try: args = parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid nonce description: {}".format(msg)) # additional checks if 'level' in args: if not args['level'] in PERMISSION_LEVELS: raise DAOError("Invalid nonce description. " "The level attribute must be one of: {}".format(PERMISSION_LEVELS)) if Config.get('web', 'case') == 'snake': if 'max_uses' in args: self.validate_max_uses(args['max_uses']) else: if 'maxUses' in args: self.validate_max_uses(args['maxUses']) return args
def validate_post(self): parser = RequestParser() parser.add_argument('state', type=str, required=True, help="Set the state for this actor.") try: args = parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid actor state description: {}".format(msg)) return args
def validate_post(self): parser = RequestParser() parser.add_argument('user', type=str, required=True, help="User owning the permission.") parser.add_argument('level', type=str, required=True, help="Level of the permission: {}".format(PERMISSION_LEVELS)) try: args = parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid permissions description: {}".format(msg)) if not args['level'] in PERMISSION_LEVELS: raise ResourceError("Invalid permission level: {}. \ The valid values are {}".format(args['level'], PERMISSION_LEVELS)) return args
def validate_put(self, actor): # inherit derived attributes from the original actor, including id and db_id: parser = Actor.request_parser() # remove since name is only required for POST, not PUT parser.remove_argument('name') parser.add_argument( 'force', type=bool, required=False, help="Whether to force an update of the actor image", default=False) # this update overrides all required and optional attributes try: actor.update(parser.parse_args()) except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid actor description: {}".format(msg)) return actor
def validate_post(self): parser = RequestParser() parser.add_argument('runtime', type=str, required=True, help="Runtime, in milliseconds, of the execution.") parser.add_argument('cpu', type=str, required=True, help="CPU usage, in user jiffies, of the execution.") parser.add_argument('io', type=str, required=True, help="Block I/O usage, in number of 512-byte sectors read from and written to, by the execution.") # Accounting for memory is quite hard -- probably easier to cap all containers at a fixed amount or perhaps have # a graduated list of cap sized (e.g. small, medium and large). # parser.add_argument('mem', type=str, required=True, help="Memory usage, , of the execution.") try: args = parser.parse_args() except BadRequest as e: msg = 'Unable to process the JSON description.' if hasattr(e, 'data'): msg = e.data.get('message') raise DAOError("Invalid actor execution description: {}".format(msg)) for k,v in args.items(): try: int(v) except ValueError: raise ResourceError(message="Argument {} must be an integer.".format(k)) return args
def validate_post(self): json_data = request.get_json() if not json_data: raise DAOError("Invalid actor state description: state must be JSON serializable.") return json_data