forked from auth0/jupiterone-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path07_account_parameters_list_example.py
More file actions
79 lines (59 loc) · 2.52 KB
/
07_account_parameters_list_example.py
File metadata and controls
79 lines (59 loc) · 2.52 KB
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
#!/usr/bin/env python3
"""
JupiterOne Python SDK - Account Parameter (List Value) Example
This example demonstrates how to create or update an Account Parameter where the
value is a list of strings.
Prerequisites (environment variables):
- JUPITERONE_ACCOUNT_ID
- JUPITERONE_API_TOKEN
- (optional) JUPITERONE_URL
- (optional) JUPITERONE_SYNC_URL
Usage:
python 07_account_parameters_list_example.py
"""
import os
from jupiterone import JupiterOneClient
def setup_client() -> JupiterOneClient:
"""Instantiate the JupiterOne client using environment variables."""
return JupiterOneClient(
account=os.getenv("JUPITERONE_ACCOUNT_ID"),
token=os.getenv("JUPITERONE_API_TOKEN"),
url=os.getenv("JUPITERONE_URL", "https://graphql.us.jupiterone.io"),
sync_url=os.getenv("JUPITERONE_SYNC_URL", "https://api.us.jupiterone.io"),
)
def main() -> None:
print("JupiterOne - Create/Update Account Parameter (List Value)")
print("=" * 70)
# Configure the parameter name and value
# Name can be anything meaningful to your workflows
parameter_name = os.getenv("J1_LIST_PARAM_NAME", "ENTITY_TYPES_TO_INCLUDE")
# Example list value requested: ["aws_account", "aws_security_group"]
parameter_value = ["aws_account", "aws_security_group"]
try:
j1 = setup_client()
print(f"Creating/Updating parameter '{parameter_name}' with value: {parameter_value}")
result = j1.create_update_parameter(
name=parameter_name,
value=parameter_value,
secret=False,
)
# The mutation returns a success flag; fetch the parameter to verify
if result and result.get("setParameter", {}).get("success") is True:
print("✓ Parameter upsert reported success")
else:
print("! Parameter upsert did not report success (check details below)")
print(result)
# Verify by reading it back (non-secret parameters will return the value)
details = j1.get_parameter_details(name=parameter_name)
print("\nFetched parameter details:")
print(details)
print("\n✓ Completed creating/updating list-valued account parameter")
except Exception as exc:
print(f"✗ Error: {exc}")
print("\nMake sure you have set the following environment variables:")
print("- JUPITERONE_ACCOUNT_ID")
print("- JUPITERONE_API_TOKEN")
print("- JUPITERONE_URL (optional)")
print("- JUPITERONE_SYNC_URL (optional)")
if __name__ == "__main__":
main()