Coverage for src / main / python / services / resource_groups.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-17 22:29 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-17 22:29 +0000
1import sys
2from typing import Any, cast
4import requests
7def get_resource_groups_by_team(
8 bearer_token: str, org_name: str, team_name: str
9) -> list[dict[str, Any]]:
10 """
11 Retrieve a list of resource groups for a given team using bearer token auth.
13 Args:
14 bearer_token (str): The bearer token for authentication
15 team_name (str): The name of the team to get resource groups for
17 Returns:
18 List[Dict[str, Any]]: A list of project dictionaries
19 """
20 headers = {
21 "Authorization": f"Bearer {bearer_token}",
22 "Content-Type": "application/json",
23 }
25 # Replace with actual API endpoint
26 url = f"https://{org_name}.pam.okta.com/v1/teams/{team_name}/resource_groups"
28 try:
29 # print(f"Fetching resource groups from URL: {url} with headers: {headers}")
30 response = requests.get(url, headers=headers)
31 response.raise_for_status()
32 return cast(list[dict[str, Any]], response.json()["list"])
33 except requests.exceptions.RequestException as e:
34 print(f"Error fetching resource groups: {e}")
35 return []
38def get_projects_by_resource_group(
39 bearer_token: str, org_name: str, team_name: str, resource_group_id: str
40) -> list[dict[str, Any]]:
41 """
42 Retrieve a list of projects for a resource group using bearer token auth.
44 Args:
45 bearer_token (str): The bearer token for authentication
46 team_name (str): The name of the team to get projects for
47 resource_group_id (str): The ID of the resource group to filter projects by
49 Returns:
50 List[Dict[str, Any]]: A list of project dictionaries
51 """
52 headers = {
53 "Authorization": f"Bearer {bearer_token}",
54 "Content-Type": "application/json",
55 }
57 # Replace with actual API endpoint
58 url = f"https://{org_name}.pam.okta.com/v1/teams/{team_name}/resource_groups/{resource_group_id}/projects"
60 try:
61 # print(f"Fetching resourcegroups from URL: {url} with headers: {headers}")
62 response = requests.get(url, headers=headers)
63 response.raise_for_status()
64 list = response.json()["list"]
65 # print(f"Projects in resource group {resource_group_id}: {list}")
66 return [
67 {"id": r["id"], "name": r["name"]} for r in list if r["deleted_at"] is None
68 ]
69 except requests.exceptions.RequestException as e:
70 print(f"Error fetching projects: {e}", file=sys.stderr)
71 return []