Skip to content

Commit

Permalink
Merge pull request #2 from FiniteStateInc/v0.0.4-dev
Browse files Browse the repository at this point in the history
v0.0.4 RC
  • Loading branch information
nickvido authored Jul 21, 2023
2 parents 6df3f72 + fa3fb1c commit 2041109
Show file tree
Hide file tree
Showing 14 changed files with 4,450 additions and 4,036 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import finite_state_sdk

## Generating the docs

```
$ pip3 install pdoc
$ pdoc -o docs -d markdown finite_state_sdk
```bash
pip3 install pdoc
export VERSION=0.0.4
pdoc -o docs -d google --logo "https://camo.githubusercontent.com/ea2191106c0aa7006f669bef130bf089bb3fedc0463bcecebeabbefd6b4362ad/68747470733a2f2f66696e69746573746174652e696f2f68732d66732f68756266732f46532d4c6f676f2d46696e616c2d30312e706e67" -t ./docs-template ./finite_state_sdk
```

# Finite State API
Expand Down
3 changes: 3 additions & 0 deletions docs-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pdoc docs-template

Custom documentation template for use with `pdoc` documenation generator.
Empty file added docs-template/custom.css
Empty file.
19 changes: 19 additions & 0 deletions docs-template/module.html.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
We want to extend the default template instead of defining everything ourselves.
#}
{% extends "default/module.html.jinja2" %}

{#
We can redefine individual blocks.
For example, if the `--favicon` option does not do what you want, you can specify a replacement like this.
#}
{% block favicon %}
<link rel="shortcut icon" href="https://finitestate.io/hubfs/cropped-fs-favicon-01-1-32x32.png"/>
{% endblock %}

{#
We can access system environment variables in the template, for example to pass version information.
#}
{% block nav_footer %}
<footer>finite-state-sdk-python v{{ env["VERSION"] }}</footer>
{% endblock %}
6,378 changes: 3,291 additions & 3,087 deletions docs/finite_state_sdk.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/finite_state_sdk/queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="pdoc 14.0.0"/>
<title>finite_state_sdk.queries API documentation</title>
<link rel="shortcut icon" href="https://finitestate.io/hubfs/cropped-fs-favicon-01-1-32x32.png"/>

<style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>
<style>/*! syntax-highlighting.css */pre{line-height:125%;}span.linenos{color:inherit; background-color:transparent; padding-left:5px; padding-right:20px;}.pdoc-code .hll{background-color:#ffffcc}.pdoc-code{background:#f8f8f8;}.pdoc-code .c{color:#3D7B7B; font-style:italic}.pdoc-code .err{border:1px solid #FF0000}.pdoc-code .k{color:#008000; font-weight:bold}.pdoc-code .o{color:#666666}.pdoc-code .ch{color:#3D7B7B; font-style:italic}.pdoc-code .cm{color:#3D7B7B; font-style:italic}.pdoc-code .cp{color:#9C6500}.pdoc-code .cpf{color:#3D7B7B; font-style:italic}.pdoc-code .c1{color:#3D7B7B; font-style:italic}.pdoc-code .cs{color:#3D7B7B; font-style:italic}.pdoc-code .gd{color:#A00000}.pdoc-code .ge{font-style:italic}.pdoc-code .gr{color:#E40000}.pdoc-code .gh{color:#000080; font-weight:bold}.pdoc-code .gi{color:#008400}.pdoc-code .go{color:#717171}.pdoc-code .gp{color:#000080; font-weight:bold}.pdoc-code .gs{font-weight:bold}.pdoc-code .gu{color:#800080; font-weight:bold}.pdoc-code .gt{color:#0044DD}.pdoc-code .kc{color:#008000; font-weight:bold}.pdoc-code .kd{color:#008000; font-weight:bold}.pdoc-code .kn{color:#008000; font-weight:bold}.pdoc-code .kp{color:#008000}.pdoc-code .kr{color:#008000; font-weight:bold}.pdoc-code .kt{color:#B00040}.pdoc-code .m{color:#666666}.pdoc-code .s{color:#BA2121}.pdoc-code .na{color:#687822}.pdoc-code .nb{color:#008000}.pdoc-code .nc{color:#0000FF; font-weight:bold}.pdoc-code .no{color:#880000}.pdoc-code .nd{color:#AA22FF}.pdoc-code .ni{color:#717171; font-weight:bold}.pdoc-code .ne{color:#CB3F38; font-weight:bold}.pdoc-code .nf{color:#0000FF}.pdoc-code .nl{color:#767600}.pdoc-code .nn{color:#0000FF; font-weight:bold}.pdoc-code .nt{color:#008000; font-weight:bold}.pdoc-code .nv{color:#19177C}.pdoc-code .ow{color:#AA22FF; font-weight:bold}.pdoc-code .w{color:#bbbbbb}.pdoc-code .mb{color:#666666}.pdoc-code .mf{color:#666666}.pdoc-code .mh{color:#666666}.pdoc-code .mi{color:#666666}.pdoc-code .mo{color:#666666}.pdoc-code .sa{color:#BA2121}.pdoc-code .sb{color:#BA2121}.pdoc-code .sc{color:#BA2121}.pdoc-code .dl{color:#BA2121}.pdoc-code .sd{color:#BA2121; font-style:italic}.pdoc-code .s2{color:#BA2121}.pdoc-code .se{color:#AA5D1F; font-weight:bold}.pdoc-code .sh{color:#BA2121}.pdoc-code .si{color:#A45A77; font-weight:bold}.pdoc-code .sx{color:#008000}.pdoc-code .sr{color:#A45A77}.pdoc-code .s1{color:#BA2121}.pdoc-code .ss{color:#19177C}.pdoc-code .bp{color:#008000}.pdoc-code .fm{color:#0000FF}.pdoc-code .vc{color:#19177C}.pdoc-code .vg{color:#19177C}.pdoc-code .vi{color:#19177C}.pdoc-code .vm{color:#19177C}.pdoc-code .il{color:#666666}</style>
Expand All @@ -22,6 +23,7 @@
<path fill-rule="evenodd" d="M4.146 8.354a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H14.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3z"/>
</svg> &nbsp;finite_state_sdk</a>

<img src="https://camo.githubusercontent.com/ea2191106c0aa7006f669bef130bf089bb3fedc0463bcecebeabbefd6b4362ad/68747470733a2f2f66696e69746573746174652e696f2f68732d66732f68756266732f46532d4c6f676f2d46696e616c2d30312e706e67" class="logo" alt="project logo"/>

<input type="search" placeholder="Search..." role="searchbox" aria-label="search"
pattern=".+" required>
Expand Down Expand Up @@ -54,6 +56,7 @@ <h2>API Documentation</h2>
</ul>


<footer>finite-state-sdk-python v0.0.4</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.

110 changes: 110 additions & 0 deletions examples/upload_test_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import finite_state_sdk
import json
import os

"""
This is an example of uploading test results from a third party scanner such as an SCA or SAST tool.
NOTE, the create_new_asset_version_and_upload_test_results function is a convenience function that
can be used as the basis for integration with your CI/CD pipeline.
Uploading Test Results to Finite State
To upload test results, you will need:
* Business Unit ID (get this from the API or app, see this example)
* Created By User ID (get this from the API or app)
* An Asset ID (get this from the API or app, see this example)
* A version name (you make this up, or it comes from your build system, e.g. 1.0, 1.2, etc.)
* A File Path (this is the path to the file on your local machine)
* Test Result file type - in this case we are uploading a CycloneDX SBOM file
In this example:
* We assume that you have already created an Asset, and are creating a new AssetVersion for that Asset. This corresponds to analyzing a new version of your source code, for example.
Note: An Asset and AssetVersion may or may not be related to a Product. In this example, it is not.
To install the SDK, use pip:
pip install finite-state-sdk
"""

"""
You can store your secrets in a file called .env in the same directory as this script
that looks like:
export CLIENT_ID="your client id"
export CLIENT_SECRET="your client secret"
export ORGANIZATION_CONTEXT="your organization context"
Before running the script, run the following command in the terminal:
source .env
DO NOT COMMIT THIS FILE TO YOUR SOURCE CODE REPOSITORY!!!
"""

# get CLIENT_ID and CLIENT_SECRET from env
CLIENT_ID = os.environ.get("CLIENT_ID")
CLIENT_SECRET = os.environ.get("CLIENT_SECRET")
ORGANIZATION_CONTEXT = os.environ.get("ORGANIZATION_CONTEXT")


# Get an auth token - this is a bearer token that you will use for all subsequent requests
# The token is valid for 24 hours
token = finite_state_sdk.get_auth_token(CLIENT_ID, CLIENT_SECRET)

# get all business units to get the business_unit_id
business_units = finite_state_sdk.get_all_business_units(token, ORGANIZATION_CONTEXT)
# print(json.dumps(business_units, indent=4))

"""
Example Response:
[
{
"_cursor": "{\"id\":\"xxxxxxxx28\"}",
"id": "xxxxxxxx28",
"name": "Finite State Products"
}
]
"""

# You can also get this from the app by clicking Account and navigating to the Business Unit
business_unit_id = "" # CHANGEME: Get the business unit ID of the BU that owns the product

# get all users to get the user id
users = finite_state_sdk.get_all_users(token, ORGANIZATION_CONTEXT)
print(json.dumps(users, indent=4))

"""
Example Response:
[
{
"_cursor": "{\"id\":\"xxxxxxx73\"}",
"id": "xxxxxxx73",
"email": "[email protected]"
}
]
"""

# You can also get this from the app by clicking Account and navigating to the User
created_by_user_id = "" # CHANGEME: Get the user ID to associate with the creation of the product

# You can also get this from the app by navigating to the Asset, this ID is the number in the URL
# https://platform.finitestate.io/artifacts/<YOUR_ASSET_ID>
asset_id = "" # CHANGEME: Get the asset ID to associate with the binary

file_path = "" # CHANGEME: Path to the file you want to upload
version_name = "" # CHANGEME: Name of the version you are uploading (e.g. 1.0, 1.1, or the commit hash of your source code repository, etc.)

# upload the test results
# NOTE: you must specify the test result file type
# In this case we are uploading a CycloneDX SBOM, so we use the value "cyclonedx"
response = finite_state_sdk.create_new_asset_version_and_upload_test_results(token, ORGANIZATION_CONTEXT, business_unit_id=business_unit_id, created_by_user_id=created_by_user_id, asset_id=asset_id, version=version_name, file_path=file_path, product_id=None, artifact_description="Source Code Repository", test_type="cyclonedx")
print("Uploaded the test results:")
print(json.dumps(response, indent=4))

"""
Example Response:
{
"completeTestResultUpload": {
"key": "test_results/org=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/asset_version=xxxxxxxx69/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx3bb"
}
}
"""
Loading

0 comments on commit 2041109

Please sign in to comment.