Coverage for src/main/python/services/enrollment.py: 100%

1 from typing import Any, cast

2

3 import requests

4

5

6 def generate_server_enrollment_token(

7 team_name: str,

8 project_name: str,

9 org_name: str,

10 bearer_token: str,

11 resource_group_id: str,

12 project_id: str,

13 description: str = "Generated by script",

14) -> dict[str, Any]:

15 """

16 Generate an enrollment token from Okta API.

17

18 Args:

19 team_name: The team name

20 project_name: The project name

21 org_name: The organization name

22 bearer_token: The bearer token for authentication

23 key_secret: The API key secret

24

25 Returns:

26 dict: The API response data

27 """

28 url = (

29 f"https://{org_name}.pam.okta.com/v1/teams/{team_name}/resource_groups/"

30 f"{resource_group_id}/projects/{project_id}/server_enrollment_tokens"

31 )

32 # POST endpoint for creating server enrollment tokens

33

34 payload = {"description": description}

35

36 headers = {

37 "Content-Type": "application/json",

38 "Authorization": f"Bearer {bearer_token}",

39 }

40

41 response = requests.post(url, json=payload, headers=headers)

42 response.raise_for_status() # Raise an exception for bad status codes

43

44 return cast(dict[str, Any], response.json())