Skip to content

Commit

Permalink
feat: modify check group by logic
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Jun 21, 2024
1 parent b2c01fb commit 3ad49d9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/spaceone/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,30 @@ def _get_data_source_id_from_filter(query: dict) -> str:
@staticmethod
def _check_group_by(query: dict) -> None:
group_by = query.get("group_by", [])
for group_by_field in group_by:
if group_by_field.split(".")[0] == "data":
for grop_by_option in group_by:
key = None

if isinstance(grop_by_option, dict):
key = grop_by_option.get("key")
name = grop_by_option.get("name")
if not (key and name):
raise ERROR_INVALID_PARAMETER(
key="group_by",
reason="group_by option requires a key and name.",
)
elif isinstance(grop_by_option, str):
key = grop_by_option

if key is None or not isinstance(key, str):
raise ERROR_INVALID_PARAMETER(
key="group_by", reason="Group by key is not exist or invalid type."
)
elif key.split(".")[0] == "data":
raise ERROR_INVALID_PARAMETER(
key=group_by_field, reason=f"Data field is not allowed to group by."
key=key, reason="Data field is not allowed to group by."
)
elif group_by_field in ["cost", "usage_quantity"]:
elif key in ["cost", "usage_quantity"]:
raise ERROR_INVALID_PARAMETER(
key=group_by_field,
reason=f"{group_by_field} are not allowed to group by.",
key=key,
reason=f"{key} are not allowed to group by.",
)

0 comments on commit 3ad49d9

Please sign in to comment.