Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,093 changes: 1,090 additions & 1,003 deletions docs/finite_state_sdk.html

Large diffs are not rendered by default.

1,109 changes: 571 additions & 538 deletions docs/finite_state_sdk/queries.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/finite_state_sdk/token_cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2>API Documentation</h2>
</ul>


<footer>finite-state-sdk-python v0.0.6</footer>
<footer>finite-state-sdk-python v0.0.7</footer>

<a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev" target="_blank">
built with <span class="visually-hidden">pdoc</span><img
Expand Down
2 changes: 1 addition & 1 deletion docs/search.js

Large diffs are not rendered by default.

39 changes: 31 additions & 8 deletions finite_state_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def create_new_asset_version_artifact_and_test_for_upload(token, organization_co
business_unit_id (str, optional):
Business Unit ID to create the asset version for. If not provided, the default Business Unit will be used.
created_by_user_id (str, optional):
User ID to create the asset version for. If not provided, the default user will be used.
User ID that will be the creator of the asset version. If not specified, the creator of the related Asset will be used.
asset_id (str, required):
Asset ID to create the asset version for. If not provided, the default asset will be used.
version (str, required):
Expand All @@ -276,6 +276,11 @@ def create_new_asset_version_artifact_and_test_for_upload(token, organization_co
Returns:
str: The Test ID of the newly created test that is used for uploading the file.
"""
if not asset_id:
raise ValueError("Asset ID is required")
if not version:
raise ValueError("Version is required")

assets = get_all_assets(token, organization_context, asset_id=asset_id)
asset = assets[0]

Expand All @@ -292,20 +297,15 @@ def create_new_asset_version_artifact_and_test_for_upload(token, organization_co
# if business_unit_id or created_by_user_id are not provided, get the existing asset
if not business_unit_id or not created_by_user_id:
if not business_unit_id:
business_unit_id = asset['businessUnit']['id']
business_unit_id = asset['group']['id']
if not created_by_user_id:
created_by_user_id = asset['createdByUser']['id']
created_by_user_id = asset['createdBy']['id']

if not business_unit_id:
raise ValueError("Business Unit ID is required and could not be retrieved from the existing asset")
if not created_by_user_id:
raise ValueError("Created By User ID is required and could not be retrieved from the existing asset")

if not asset_id:
raise ValueError("Asset ID is required")
if not version:
raise ValueError("Version is required")

# create the asset version
response = create_asset_version(token, organization_context, business_unit_id=business_unit_id, created_by_user_id=created_by_user_id, asset_id=asset_id, asset_version_name=version)
# get the asset version ID
Expand Down Expand Up @@ -1013,6 +1013,29 @@ def get_artifact_context(token, organization_context, artifact_id):
return artifact[0]['ctx']


def get_assets(token, organization_context, asset_id=None, business_unit_id=None):
"""
Gets assets in the organization. Uses pagination to get all results.

Args:
token (str):
Auth token. This is the token returned by get_auth_token(). Just the token, do not include "Bearer" in this string, that is handled inside the method.
organization_context (str):
Organization context. This is provided by the Finite State API management. It looks like "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
asset_id (str, optional):
Asset ID to get, by default None. If None specified, will get all Assets. If specified, will get only the Asset with that ID.
business_unit_id (str, optional):
Business Unit ID to filter by, by default None. If None specified, will get all Assets. If specified, will get only the Assets in the specified Business Unit.

Raises:
Exception: Raised if the query fails.

Returns:
list: List of Asset Objects
"""
return get_all_paginated_results(token, organization_context, queries.ALL_ASSETS['query'], queries.ALL_ASSETS['variables'](asset_id, business_unit_id), 'allAssets')


def get_auth_token(client_id, client_secret, token_url=TOKEN_URL, audience=AUDIENCE):
"""
Get an auth token for use with the API using CLIENT_ID and CLIENT_SECRET
Expand Down
33 changes: 33 additions & 0 deletions finite_state_sdk/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
_cursor
id
name
__typename
}
}
""",
Expand All @@ -37,6 +38,7 @@
_cursor
id
email
__typename
}
}
""",
Expand All @@ -59,6 +61,7 @@
_cursor
id
name
__typename
}
}
""",
Expand All @@ -81,10 +84,13 @@
_cursor
id
name
testStatuses
relativeRiskScore
asset {
id
name
}
__typename
}
}
""",
Expand Down Expand Up @@ -129,11 +135,28 @@ def asset_variables(asset_id=None, business_unit_id=None):
id
name
createdAt
createdBy {
id
email
__typename
}
group {
id
name
}
ctx {
asset
businessUnits
products
}
versions {
id
name
relativeRiskScore
testStatuses
__typename
}
__typename
}
}
""",
Expand Down Expand Up @@ -180,6 +203,7 @@ def artifact_variables(artifact_id=None, business_unit_id=None):
businessUnits
products
}
__typename
}
}
""",
Expand All @@ -202,6 +226,7 @@ def artifact_variables(artifact_id=None, business_unit_id=None):
id
name
createdAt
__typename
}
}
""",
Expand Down Expand Up @@ -237,6 +262,7 @@ def artifact_variables(artifact_id=None, business_unit_id=None):
name
}
}
__typename
}
}""",
"variables": lambda product_id: {
Expand Down Expand Up @@ -371,6 +397,7 @@ def _create_GET_FINDINGS_VARIABLES(asset_version_id=None, category=None):
}
__typename
}
__typename
}
}""",
"variables": lambda asset_version_id=None, category=None: _create_GET_FINDINGS_VARIABLES(asset_version_id=asset_version_id, category=category)
Expand Down Expand Up @@ -487,6 +514,12 @@ def _create_GET_SOFTWARE_COMPONENTS_VARIABLES(asset_version_id=None, type=None):
id
name
createdAt
createdBy {
id
email
__typename
}
__typename
}
}
""",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "finite-state-sdk"
version = "0.0.6"
version = "0.0.7"
authors = [
"Finite State, Inc. <developer-tools@finitestate.io>"
]
Expand Down
Loading