示例#1
0
 def on_post(self, req, resp):
     req_data = req.media or {}
     resp_data, valid = Config_Request_Schema(
         many=is_list(req_data),
         method=HTTP_Method.POST).validate(data=req_data)
     if valid:
         req_data_wrap = wrap(req_data)
         if len(req_data_wrap) > 0:
             for config in req_data_wrap:
                 for cfg, cfg_list in config.items():
                     for data in wrap(cfg_list):
                         if cfg == 'actions':
                             output = self.__actions(data)
                             schema = Config_Action_Response_Schema
                         elif cfg == 'parameters':
                             output = self.__parameters(data)
                             schema = Config_Parameter_Response_Schema
                         elif cfg == 'resources':
                             output = self.__resources(data)
                             schema = Config_Resource_Response_Schema
                         output.update(id=data.get('id', None),
                                       timestamp=datetime_to_str())
                         resp_data, valid = schema(
                             many=False,
                             method=HTTP_Method.POST).validate(data=output)
                         if valid:
                             Content_Response(output).add(resp)
                         else:
                             resp_data.add(resp)
         else:
             msg = f'No content to apply configurations with the {{request}}'
             No_Content_Response(msg, request=req_data).apply(resp)
     else:
         resp_data.apply(resp)
示例#2
0
    def on_post(self, req, resp):
        req_data = req.media or {}
        resp_data, valid = Status_Request_Schema(method=HTTP_Method.POST)  \
            .validate(data=req_data)
        if valid:
            now = datetime_to_str()

            id = req_data.get('id')
            username = req_data.get('username', None)
            password = req_data.get('password', None)

            self.data['id'] = id
            self.data['last_heartbeat'] = now

            if username and self.auth_db.get(username, None) != hash(password):
                msg = f'Credentials from CB {req.host}:{req.port} not valid.'
                self.log.warning(msg)

            username = generate_username()
            password = generate_password()
            self.auth_db[username] = hash(password)

            self.log.notice(f'hearbeating from CB at {now}')

            data = dict(**self.data, username=username, password=password)
            resp_data, valid = Status_Response_Schema(method=HTTP_Method.POST) \
                .validate(data=data)
            if valid:
                Content_Response(data).apply(resp)
            else:
                resp_data.apply(resp)
        else:
            resp_data.apply(resp)
示例#3
0
 def __init__(self):
     """Set the data and logger."""
     self.data = {
         'id': False,
         'started': datetime_to_str(),
         'last_heartbeat': False
     }
     self.log = Log.get('status')
示例#4
0
 def __init__(self):
     """Set the data and logger."""
     cls = Status_Resource
     self.data = dict(id=None,
                      started=datetime_to_str(),
                      last_heartbeat=None)
     ttl = int(Arg_Reader.db.auth_max_ttl)
     cls.auth_db = TTL_Ordered_Dict(default_ttl=ttl)
     self.log = Log.get('status')
示例#5
0
 def on_post(self, req, resp):
     req_data = req.media or {}
     resp_data, valid = Status_Request_Schema(
         method=HTTP_Method.POST).validate(data=req_data)
     if valid:
         now = datetime_to_str()
         id = req_data.get('id')
         self.data['id'] = id
         self.data['last_heartbeat'] = now
         self.log.notice(f'Hearbeating from CB at {now}')
         resp_data, valid = Status_Response_Schema(
             method=HTTP_Method.POST).validate(data=self.data)
         if valid:
             Content_Response(self.data).apply(resp)
         else:
             resp_data.apply(resp)
     else:
         resp_data.apply(resp)