Skip to content

Commit

Permalink
add parameter functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaBlooms committed Nov 21, 2024
1 parent fe01144 commit a828218
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,12 @@
r = j1.get_integration_instance_details(instance_id="<GUID>")
print("get_integration_instance_details()")
print(json.dumps(r, indent=1))

r = j1.get_parameter_details(name="ParameterName")
print(json.dumps(r, indent=1))

r = j1.list_account_parameters()
print(json.dumps(r, indent=1))

r = j1.create_update_parameter(name="ParameterName", value="stored_value", secret=False)
print(json.dumps(r, indent=1))
63 changes: 63 additions & 0 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import requests
from requests.adapters import HTTPAdapter, Retry
from retrying import retry
from typing import Union, List

from jupiterone.errors import (
JupiterOneClientError,
Expand Down Expand Up @@ -53,6 +54,9 @@
INTEGRATION_INSTANCES,
INTEGRATION_INSTANCE,
UPDATE_INTEGRATION_INSTANCE,
PARAMETER,
PARAMETER_LIST,
UPSERT_PARAMETER,
)


Expand Down Expand Up @@ -1199,4 +1203,63 @@ def get_compliance_framework_item_details(self, item_id: str = None):
}

response = self._execute_query(COMPLIANCE_FRAMEWORK_ITEM, variables=variables)
return response

def get_parameter_details(self, name: str = None):
"""Fetch Details of a configured Parameter in J1 account
"""
variables = {
"name": name
}

response = self._execute_query(PARAMETER, variables=variables)
return response

def list_account_parameters(self):
"""Fetch List of all configured Account Parameters in J1 account
"""
results = []

data = {
"query": PARAMETER_LIST,
"flags": {
"variableResultSize": True
}
}

r = requests.post(url=self.graphql_url, headers=self.headers, json=data, verify=True).json()
results.extend(r['data']['parameterList']['items'])

while r['data']['parameterList']['pageInfo']['hasNextPage'] == True:
cursor = r['data']['parameterList']['pageInfo']['endCursor']

# cursor query until last page fetched
data = {
"query": PARAMETER_LIST,
"variables": {
"cursor": cursor
},
"flags": {
"variableResultSize": True
}
}

r = requests.post(url=self.graphql_url, headers=self.headers, json=data, verify=True).json()
results.extend(r['data']['parameterList']['items'])

return results

def create_update_parameter(self, name: str = None, value: Union[str, int, bool, list] = None, secret: bool = False):
"""Create or Update Account Parameter in J1 account
"""
variables = {
"name": name,
"value": value,
"secret": secret
}

response = self._execute_query(UPSERT_PARAMETER, variables=variables)
return response
36 changes: 36 additions & 0 deletions jupiterone/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,3 +1194,39 @@
__typename
}
"""

# PARAMETERS
PARAMETER = """
query Query($name: String!) {
parameter(name: $name) {
name
value
secret
lastUpdatedOn
}
}
"""
PARAMETER_LIST = """
query Query($limit: Int, $cursor: String) {
parameterList(limit: $limit, cursor: $cursor) {
items {
name
value
secret
lastUpdatedOn
}
pageInfo {
endCursor
hasNextPage
}
}
}
"""
UPSERT_PARAMETER = """
mutation UpsertParameter($name: String!, $value: ParameterValue!, $secret: Boolean) {
setParameter(name: $name, value: $value, secret: $secret) {
success
__typename
}
}
"""

0 comments on commit a828218

Please sign in to comment.