Skip to content

Commit

Permalink
fix: remove retool mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrittner committed Aug 22, 2024
1 parent c4b274d commit b912d99
Showing 1 changed file with 66 additions and 95 deletions.
161 changes: 66 additions & 95 deletions admyral/actions/integrations/compliance/retool.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Annotated
from httpx import Client
# from collections import defaultdict
# from dateutil import parser
# from datetime import datetime, timezone, timedelta
from collections import defaultdict
from dateutil import parser
from datetime import datetime, timezone, timedelta

from admyral.action import action, ArgumentMetadata

# from admyral.context import ctx
from admyral.context import ctx
from admyral.typings import JsonValue


Expand Down Expand Up @@ -40,47 +40,30 @@ def list_retool_inactive_users(
# Returns a list of users. The API token must have the "Users > Read" scope.
# https://docs.retool.com/reference/api/#tag/Users/paths/~1users~1%7BuserId%7D/patch

# secret = ctx.get().secrets.get("RETOOL_SECRET")
# api_key = secret["api_key"]
# domain = secret["domain"]

# with get_retool_client(domain, api_key) as client:
# # TODO: handle pageination
# response = client.get("/users")
# response.raise_for_status()
# response_json = response.json()

# if not response_json["success"]:
# raise RuntimeError(
# f"Failed to list Retool users: {response_json['message']}"
# )

# utc_time_now = datetime.now(timezone.utc) - timedelta(
# days=inactivity_threshold_in_days
# )

# return [
# user
# for user in response_json["data"]
# if parser.isoparse(user["last_active"]) <= utc_time_now
# ]

# Mock data
return [
{
"id": "string",
"legacy_id": "string",
"email": "[email protected]",
"active": False,
"created_at": "2019-02-08T11:45:48.899Z",
"last_active": "2019-02-08T11:45:48.899Z",
"first_name": "Franky",
"last_name": "string",
"metadata": {},
"is_admin": True,
"user_type": "default",
}
]
secret = ctx.get().secrets.get("RETOOL_SECRET")
api_key = secret["api_key"]
domain = secret["domain"]

with get_retool_client(domain, api_key) as client:
# TODO: handle pageination
response = client.get("/users")
response.raise_for_status()
response_json = response.json()

if not response_json["success"]:
raise RuntimeError(
f"Failed to list Retool users: {response_json['message']}"
)

utc_time_now = datetime.now(timezone.utc) - timedelta(
days=inactivity_threshold_in_days
)

return [
user
for user in response_json["data"]
if parser.isoparse(user["last_active"]) <= utc_time_now
]


@action(
Expand All @@ -93,53 +76,41 @@ def list_groups_per_user() -> dict[str, JsonValue]:
# Get all permission groups for an organization or space. The API token must have the "Groups > Read" scope.
# https://docs.retool.com/reference/api/v2/#tag/Groups/paths/~1groups~1%7BgroupId%7D/put

# secret = ctx.get().secrets.get("RETOOL_SECRET")
# api_key = secret["api_key"]
# domain = secret["domain"]

# with get_retool_client(domain, api_key) as client:
# # Fetch all users to get the last active date
# response = client.get("/users")
# response.raise_for_status()
# response_json = response.json()

# if not response_json["success"]:
# raise RuntimeError(
# f"Failed to list Retool users: {response_json['message']}"
# )

# groups_per_user = {
# user["email"]: {
# "groups": defaultdict(list),
# "last_active": user["last_active"]
# }
# for user in response_json["data"]
# }

# # Fetch all groups
# response = client.get("/groups")
# response.raise_for_status()
# response_json = response.json()

# if not response_json["success"]:
# raise RuntimeError(
# f"Failed to list Retool groups: {response_json['message']}"
# )

# for group in response_json["data"]:
# for member in group["member"]:
# groups_per_user[member]["groups"].append(group["name"])

# return groups_per_user

# Mock data
return {
"[email protected]": {
"groups": ["group1", "group2"],
"last_active": "2019-02-08T11:45:48.899Z",
},
"[email protected]": {
"groups": ["group1"],
"last_active": "2019-02-08T11:45:48.899Z",
},
}
secret = ctx.get().secrets.get("RETOOL_SECRET")
api_key = secret["api_key"]
domain = secret["domain"]

with get_retool_client(domain, api_key) as client:
# Fetch all users to get the last active date
response = client.get("/users")
response.raise_for_status()
response_json = response.json()

if not response_json["success"]:
raise RuntimeError(
f"Failed to list Retool users: {response_json['message']}"
)

groups_per_user = {
user["email"]: {
"groups": defaultdict(list),
"last_active": user["last_active"],
}
for user in response_json["data"]
}

# Fetch all groups
response = client.get("/groups")
response.raise_for_status()
response_json = response.json()

if not response_json["success"]:
raise RuntimeError(
f"Failed to list Retool groups: {response_json['message']}"
)

for group in response_json["data"]:
for member in group["member"]:
groups_per_user[member]["groups"].append(group["name"])

return groups_per_user

0 comments on commit b912d99

Please sign in to comment.