-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints_api_key.py
120 lines (87 loc) · 3.46 KB
/
endpoints_api_key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
Module to requests via API Key Authentication
Uses "cognigy_open_api.py" to handle authentication and pagination for OpenAPI requests.
This doesn't cover all possible request of Cognigy but it's fairly easy to add new ones.
"""
import warnings
warnings.filterwarnings('ignore')
from tqdm import tqdm # progress bar
import openapi_client # Import helper function for Cognitive OpenAPI requests
def get_audit_events(base_url, api_key, params=None):
"""
get-/management/v2.0/audit/events
Retrieves a list of all audit events.
Args:
base_url (str): The base URL of the API.
api_key (str): The API key for authentication.
params (dict, optional): A dictionary containing parameters to add to the query.
Defaults to None.
Returns:
list: A list of dictionaries containing details of all audit events.
Each dictionary represents an audit event's details.
"""
# Define the endpoint for retrieving the list of audit events
audit_events_endpoint = "auditevents"
if params is None:
params = {}
# Make a query to get the list of audit events
audit_events = openapi_client.get_requests_api_key(
base_url=base_url,
endpoint=audit_events_endpoint,
api_key=api_key,
params=params
)
# Return the list of details for all audit events
return audit_events
def post_deprecate_password(base_url, api_key, user_id):
"""
post-/management/v2.0/users/-userId-/deprecatePassword
Deprecates the password of a user.
Args:
base_url (str): The base URL of the API.
api_key (str): The API key for authentication.
user_id (str): The ID of the user whose password should be deprecated.
Returns:
dict: A dictionary containing details of the user whose password was deprecated.
The dictionary represents the user's details.
"""
# Define the endpoint for deprecating the password of a user
deprecate_password_endpoint = f"users/deprecatepassword"
# Make a query to deprecate the password of a user
password_deprecated_bool = openapi_client.post_requests_api_key(
base_url=base_url,
endpoint=deprecate_password_endpoint,
api_key=api_key,
params={"userId": user_id}
)
# Return if password was deprecated
return password_deprecated_bool
def get_user_by_id(base_url, api_key, user_id):
response = openapi_client.get_requests_api_key(
base_url,
f"users/{user_id}",
api_key, {}
)
return response
def delete_project_by_id(base_url, api_key, project_id):
"""
Deletes a project by its project ID.
Args:
base_url (str): The base URL of the API.
api_key (str): The API key for authentication.
project_id (str): The ID of the project to be deleted.
Returns:
bool: True if the project was successfully deleted, False otherwise.
Raises:
Exception: If the deletion fails or the API returns an error.
"""
# Define the endpoint for deleting a project by ID
delete_project_endpoint = f"projects/{project_id}"
# Make a DELETE request to delete the project
project_deleted_bool = openapi_client.delete_requests_api_key(
base_url=base_url,
endpoint=delete_project_endpoint,
api_key=api_key
)
# Return if the project was successfully deleted
return project_deleted_bool