Skip to content

Commit cb1a2b7

Browse files
author
Jongmin Kim
committed
2 parents ed0a843 + 0cedd67 commit cb1a2b7

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/spaceone/core/service/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import copy
12
import functools
23
import logging
3-
import copy
4+
import time
45
from typing import Generator, Union, Literal
56

67
from opentelemetry import trace
@@ -181,6 +182,8 @@ def _pipeline(
181182

182183
try:
183184
with _TRACER.start_as_current_span("PreProcessing"):
185+
start_time = time.time()
186+
184187
# 1. Event - Start
185188
if event_handler_state:
186189
for handler in get_event_handlers():
@@ -239,7 +242,9 @@ def _pipeline(
239242

240243
# 9. Print Response Info Log
241244
if print_info_log:
242-
_LOGGER.info(f"(RESPONSE) => SUCCESS")
245+
246+
process_time = time.time() - start_time
247+
_LOGGER.info(f"(RESPONSE) => SUCCESS (Time = {process_time:.2f}s)")
243248

244249
return response_or_iterator
245250

src/spaceone/core/service/utils.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"change_timestamp_value",
2323
"change_date_value",
2424
"change_timestamp_filter",
25+
"check_query_filter",
2526
]
2627

2728

@@ -420,3 +421,49 @@ def _convert_date_from_string(date_str, key, date_format) -> date:
420421
return datetime.strptime(date_str, date_format).date()
421422
except Exception as e:
422423
raise ERROR_INVALID_PARAMETER_TYPE(key=key, type=date_format)
424+
425+
426+
def check_query_filter(keywords=None) -> callable:
427+
if keywords is None:
428+
keywords = []
429+
430+
def wrapper(func):
431+
@functools.wraps(func)
432+
def wrapped_func(cls, params):
433+
query = params.get("query", {})
434+
if "filter" in query:
435+
for filters in query["filter"]:
436+
key = filters.get("key", filters.get("k"))
437+
if key in keywords:
438+
raise ERROR_INVALID_PARAMETER(
439+
key=key, reason="Include secure parameter"
440+
)
441+
442+
if "group_by" in query:
443+
for group_bys in query["group_by"]:
444+
key = group_bys.get("key", group_bys.get("k"))
445+
if key in keywords:
446+
raise ERROR_INVALID_PARAMETER(
447+
key=key, reason="Include secure parameter"
448+
)
449+
450+
if "fields" in query:
451+
value = query["fields"].get("value", query["fields"].get("v"))
452+
key = value.get("key", value.get("k"))
453+
if key in keywords:
454+
raise ERROR_INVALID_PARAMETER(
455+
key=key, reason="Include secure parameter"
456+
)
457+
458+
if "distinct" in query:
459+
key = query["distinct"]
460+
if key in keywords:
461+
raise ERROR_INVALID_PARAMETER(
462+
key=key, reason="Include secure parameter"
463+
)
464+
465+
return func(cls, params)
466+
467+
return wrapped_func
468+
469+
return wrapper

0 commit comments

Comments
 (0)