def update_user(self, username, password=None, **kwargs): all_user = self.get_all() if password: kwargs['password'] = self.make_password(password) if username in all_user: kwargs['lut'] = strftime(datetime.now()) else: kwargs['username'] = username kwargs['created'] = strftime(datetime.now()) max_user = max(all_user.values(), key=lambda x: x['id']) if all_user else None kwargs['id'] = max_user['id'] + 1 if max_user else 1 kwargs['lut'] = strftime(datetime.now()) all_user.setdefault(username, {}) all_user[username].update(kwargs) self.save_all(all_user)
def format_message_data(self, message): context = dict( client=message.context, request=dict( headers=dict(message.request.headers), ) ) data = dict( pid=os.getpid(), message_type=message.message_type, config_name=message.config_name, hash_code=message.hash_code, data=message.data, context=context, env=message.env, client_ip=message.request.environ.get("client")[0], lut=strftime(message.lut) ) try: config_project = self.get_config_project(message.config_name) with config_project.use_env(message.env, message.context): data['server_hash_code'] = config_project.get_hash_code() except ProjectNoFoundException: data['server_hash_code'] = '--' return data
def to_dict(self, indent=0): context = self.context context.update(headers=dict(self.request.headers)) return dict( message_type=self.message_type, config_name=self.config_name, hash_code=self.hash_code, data=self.data, context=json.dumps(context, indent=indent) if indent else context, lut=strftime(self.lut))
def record_history(self, env, source_data, data): if not (data and isinstance(data, dict)): return data = list(data.values())[0] org_data = source_data[self.env].get(data['key']) or {} if to_hash(org_data) == to_hash(data): return if 'history' not in source_data: source_data['history'] = {} source_data['history'].setdefault(env, {}) source_data['history'][env].setdefault(data['key'], []) source_data['history'][env][data['key']].append( dict(before=org_data, after=data, operator=self.request.user.id if self.request else None, lut=strftime(datetime.datetime.now())))
def format_message_data(self, message): context = dict(client=message.context, request=dict(headers=dict(message.request.headers), )) data = dict( pid=os.getpid(), message_type=message.message_type, config_name=message.config_name, hash_code=message.hash_code, data=message.data, context=context, env=message.env, client_ip=message.request.environ.get("client")[0], lut=strftime(message.lut), host_name=message.context['environ'].get('HOSTNAME', 'unknown'), client_pid=message.context.get('pid', '--'), ) return data
def clear_history_message(self): date_str = strftime(datetime.datetime.now(), '%Y-%m-%d') if date_str == self._clear_date: return self.db_client[self._config_publish_scope].remove({'created': {'$lt': date_str}}) self._clear_date = date_str