예제 #1
0
 def validate_put(self):
     parser = RequestParser()
     parser.add_argument('status',
                         type=str,
                         required=True,
                         help='The status for the API.')
     return parser.parse_args()
예제 #2
0
 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
예제 #3
0
 def validate_post(self):
     parser = RequestParser()
     parser.add_argument('roleId',
                         type=str,
                         required=True,
                         help='The id of the role to add to the system.')
     return parser.parse_args()
예제 #4
0
 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
예제 #5
0
 def validate_post(self):
     parser = RequestParser()
     parser.add_argument(
         'accountId',
         type=str,
         required=True,
         help='The id of the service account to add to the role.')
     return parser.parse_args()
예제 #6
0
 def request_parser(cls):
     """Return a flask RequestParser object that can be used in post/put processing."""
     parser = RequestParser()
     for name, source, attr, typ, help, default in cls.PARAMS:
         if source == 'derived':
             continue
         required = source == 'required'
         parser.add_argument(name, type=typ, required=required, help=help, default=default)
     return parser
예제 #7
0
 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
예제 #8
0
 def request_parser(cls):
     """Return a flask RequestParser object that can be used in post/put processing."""
     parser = RequestParser()
     for name, source, attr, typ, help, default in cls.PARAMS:
         if source == 'derived':
             continue
         required = source == 'required'
         if Config.get('web', 'case') == 'camel':
             param_name = under_to_camel(name)
         else:
             param_name = name
         parser.add_argument(param_name, type=typ, required=required, help=help, default=default)
     return parser
예제 #9
0
 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
예제 #10
0
 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.")
     args = parser.parse_args()
     for k,v in args.items():
         try:
             int(v)
         except ValueError:
             raise ResourceError(message="Argument {} must be an integer.".format(k))
     return args
예제 #11
0
 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))
     args = parser.parse_args()
     if not args['level'] in PERMISSION_LEVELS:
         raise ResourceError("Invalid permission level: {}. \
         The valid values are {}".format(args['level'], PERMISSION_LEVELS))
     return args
예제 #12
0
 def validate_post(self):
     parser = RequestParser()
     parser.add_argument('accountId',
                         type=str,
                         required=True,
                         help='The id for the service account.')
     parser.add_argument('password',
                         type=str,
                         required=True,
                         help='The password for the service account.')
     return parser.parse_args()
예제 #13
0
    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
예제 #14
0
 def validate_post(self):
     parser = RequestParser()
     parser.add_argument('num', type=int, help="Number of workers to start (default is 1).")
     args = parser.parse_args()
     return args
예제 #15
0
 def validate_post(self):
     parser = RequestParser()
     parser.add_argument('state', type=str, required=True, help="Set the state for this actor.")
     args = parser.parse_args()
     return args