Skip to content

Commit

Permalink
add nested parse in operations log.parse_values
Browse files Browse the repository at this point in the history
  • Loading branch information
voidZXL committed Nov 22, 2024
1 parent 1e2b684 commit e3b4521
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/en/guide/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Like a declarative interface, `Client` a class is a declarative client. It only

## Write a `Client` class

Classes are written `Client` in the same way as [编写 API ](../api-route), except that our class needs to inherit from the `utilmeta.core.cli.Client` class.
Classes are written `Client` in the same way as [Writing API Class](../api-route), except that our class needs to inherit from the `utilmeta.core.cli.Client` class.

### Request function

Expand Down
3 changes: 2 additions & 1 deletion tests/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ServiceEnvironment(Env):
database=Database(
name=DB_OPS_PATH,
engine='sqlite3',
)
),
secret_names=[Operations.DEFAULT_SECRET_NAMES, 'token']
))
service.use(DatabaseConnections({
'default': Database(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_7_ops/test_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from tests.conftest import setup_service

setup_service(__name__, backend='django', async_param=[False])


class TestLog:
def test_parse_values(self, service):
from utilmeta.ops.log import Logger
logger = Logger()
assert (logger.parse_values([{'user': {'password': '123', 'token': 'XXX'}}]) ==
[{'user': {'password': '********', 'token': '********'}}])
assert (logger.parse_values([{'user': {'UserPassword': '123', 'Access_Token': 'XXX'}}]) ==
[{'user': {'UserPassword': '********', 'Access_Token': '********'}}])
2 changes: 1 addition & 1 deletion utilmeta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__website__ = 'https://utilmeta.com'
__homepage__ = 'https://utilmeta.com/py'
__author__ = 'Xulin Zhou (@voidZXL)'
__version__ = '2.6.3'
__version__ = '2.6.4'


def version_info() -> str:
Expand Down
1 change: 1 addition & 0 deletions utilmeta/ops/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Operations(Config):
REF: ClassVar = 'utilmeta.ops'
HOST: ClassVar = 'utilmeta.com'
ROUTER_NAME: ClassVar = '_OperationsDatabaseRouter'
DEFAULT_SECRET_NAMES: ClassVar = DEFAULT_SECRET_NAMES

Database: ClassVar = Database

Expand Down
16 changes: 7 additions & 9 deletions utilmeta/ops/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,22 +684,19 @@ def parse_values(self, data):
k: str
if isinstance(v, list):
result[k] = self.parse_values(v)
elif isinstance(v, dict):
result[k] = self.parse_values(v)
elif file_like(v):
result[k] = self.get_file_repr(data)
else:
for key in self.config.secret_names:
if key in k.lower():
v = SECRET
break
if any(key in k.lower() for key in self.config.secret_names):
v = SECRET
result[k] = v
return result
if isinstance(data, list):
result = []
for d in data:
if file_like(d):
result.append(self.get_file_repr(data))
else:
result.append(d)
result.append(self.parse_values(d))
return result
if file_like(data):
return self.get_file_repr(data)
Expand All @@ -708,7 +705,8 @@ def parse_values(self, data):
data = data.decode()
elif isinstance(data, (bytearray, memoryview)):
data = bytes(data).decode()

if isinstance(data, (bool, int, float, str)):
return data
return str(data)

@classmethod
Expand Down

0 comments on commit e3b4521

Please sign in to comment.