This script demonstrates generating custom CSV output from the /api/v1/hosts
and /api/v1/containers
endpoints. It is "throwaway" code and does not include
test cases, is not optimized or elegant, and is not intended to be reused for other purposes.
git clone https://github.com/cfarquhar/cwp_custom_csv
Exact steps will vary depending on what you use to manage python versions and
virtual environments. This works for pyenv
and poetry
:
cd cwp_custom_csv
pyenv install 3.10.0
pyenv local 3.10.0
poetry install
poetry shell
If you are not using poetry
, install the dependencies as shown below after
activating your virtualenv:
cd cwp_custom_csv
pip install -r requirements.txt
- Log in to SaaS console
- Navigate to Compute > System > Utilities
- In the "Path to Console" section, copy the value
- Create
TWISTLOCK_ADDRESS
environment variable with this value:
# export TWISTLOCK_ADDRESS=<CONSOLE_PATH>
If you already have access keys created, configure them in the environment variables as shown below.
- Log in to SaaS console
- Navigate to Settings > Access Control > Access Keys
- Click Add > Access Key in the top right
- Enter a name and expiration time (if desired)
- Click "Save"
- Copy the "Access Key ID" and "Secret Key" values
- Create
TWISTLOCK_USER
andTWISTLOCK_PASSWORD
environment variables with these values:
# export TWISTLOCK_USER=<ACCESS_KEY_ID>
# export TWISTLOCK_PASSWORD=<SECRET_KEY>
$ python ./generate.py
Summary:
--------
Output file: hosts.csv
Records retrieved from API: 127
Rows written to CSV: 127
Output file: containers.csv
Records retrieved from API: 405
Rows written to CSV: 405
Output file: container_compliance.csv
Records retrieved from API: 406
Rows written to CSV: 1272
$ ls -1 *csv
container_compliance.csv
containers.csv
hosts.csv