|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +JupiterOne Python SDK - Account Parameter (List Value) Example |
| 4 | +
|
| 5 | +This example demonstrates how to create or update an Account Parameter where the |
| 6 | +value is a list of strings. |
| 7 | +
|
| 8 | +Prerequisites (environment variables): |
| 9 | +- JUPITERONE_ACCOUNT_ID |
| 10 | +- JUPITERONE_API_TOKEN |
| 11 | +- (optional) JUPITERONE_URL |
| 12 | +- (optional) JUPITERONE_SYNC_URL |
| 13 | +
|
| 14 | +Usage: |
| 15 | + python 07_account_parameters_list_example.py |
| 16 | +""" |
| 17 | + |
| 18 | +import os |
| 19 | +from jupiterone import JupiterOneClient |
| 20 | + |
| 21 | + |
| 22 | +def setup_client() -> JupiterOneClient: |
| 23 | + """Instantiate the JupiterOne client using environment variables.""" |
| 24 | + return JupiterOneClient( |
| 25 | + account=os.getenv("JUPITERONE_ACCOUNT_ID"), |
| 26 | + token=os.getenv("JUPITERONE_API_TOKEN"), |
| 27 | + url=os.getenv("JUPITERONE_URL", "https://graphql.us.jupiterone.io"), |
| 28 | + sync_url=os.getenv("JUPITERONE_SYNC_URL", "https://api.us.jupiterone.io"), |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +def main() -> None: |
| 33 | + print("JupiterOne - Create/Update Account Parameter (List Value)") |
| 34 | + print("=" * 70) |
| 35 | + |
| 36 | + # Configure the parameter name and value |
| 37 | + # Name can be anything meaningful to your workflows |
| 38 | + parameter_name = os.getenv("J1_LIST_PARAM_NAME", "ENTITY_TYPES_TO_INCLUDE") |
| 39 | + |
| 40 | + # Example list value requested: ["aws_account", "aws_security_group"] |
| 41 | + parameter_value = ["aws_account", "aws_security_group"] |
| 42 | + |
| 43 | + try: |
| 44 | + j1 = setup_client() |
| 45 | + |
| 46 | + print(f"Creating/Updating parameter '{parameter_name}' with value: {parameter_value}") |
| 47 | + result = j1.create_update_parameter( |
| 48 | + name=parameter_name, |
| 49 | + value=parameter_value, |
| 50 | + secret=False, |
| 51 | + ) |
| 52 | + |
| 53 | + # The mutation returns a success flag; fetch the parameter to verify |
| 54 | + if result and result.get("setParameter", {}).get("success") is True: |
| 55 | + print("✓ Parameter upsert reported success") |
| 56 | + else: |
| 57 | + print("! Parameter upsert did not report success (check details below)") |
| 58 | + print(result) |
| 59 | + |
| 60 | + # Verify by reading it back (non-secret parameters will return the value) |
| 61 | + details = j1.get_parameter_details(name=parameter_name) |
| 62 | + print("\nFetched parameter details:") |
| 63 | + print(details) |
| 64 | + |
| 65 | + print("\n✓ Completed creating/updating list-valued account parameter") |
| 66 | + |
| 67 | + except Exception as exc: |
| 68 | + print(f"✗ Error: {exc}") |
| 69 | + print("\nMake sure you have set the following environment variables:") |
| 70 | + print("- JUPITERONE_ACCOUNT_ID") |
| 71 | + print("- JUPITERONE_API_TOKEN") |
| 72 | + print("- JUPITERONE_URL (optional)") |
| 73 | + print("- JUPITERONE_SYNC_URL (optional)") |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + main() |
| 78 | + |
| 79 | + |
0 commit comments