Python SDK for Machina Management API's
Project description
Management API Tools
This toolkit arose from the need to ensure a consistent state of policies during the 2020 Ionic Hackathon. It has since evolved and now supports the Data Policies and Metrics Management API's.
This software is not officially supported by Ionic Security, Inc.
Features
- Authenticate to Machina using a simple interface for basic, bearer, and HMAC authentication methods.
- List, create, update, backup, and delete data policies programmatically.
- Retrieve metrics activity for various request types.
Usage
Install management_api_tools (requires Python 3.7+):
python -m pip install management_api_tools
To preserve the current configuration of data policies prior to the execution of a demo, backup_policies.py can create a backup of all data policies programmatically.
Alternatively, it is possible to export data policies manually:
- Login to the Machina Console
- Go to the Data Policies tab
- Filter the data policies, if necessary
- Click Export on the top right
- Download the file
With the exported policies saved locally, you can use management_api_tools to enforce your desired state:
from pathlib import Path
from management_api_tools import Machina
def first_policy_demo():
""" Ensure the desired state exists for the first demo. """
# Modify the path to point to the location of the JSON file.
document = Path.cwd().joinpath('data-policies.json')
policy_document = document.read_text(encoding='utf-8-sig')
api = Machina(instance_id='INSTANCE_ID')
api.hmac_authentication(identity='HMAC_IDENTITY', secret='HMAC_SECRET')
# merge='replace' will delete all other data policies that do not exist in the JSON file.
return api.create_update_multiple_policies(policy_document=policy_document, merge='replace')
def second_policy_demo():
""" Ensure the desired state exists for the second demo. """
...
desired_state = first_policy_demo()
print(desired_state.ok)
Additional examples can be found in policies_client.py.
Local Development and Testing
Development
Development and testing should be done in a virtual environment.
$ git clone https://github.com/Fauxsys/management_api_tools.git
$ cd management_api_tools
$ python -m venv venv --prompt management_api_tools
$ source venv/bin/activate
(management_api_tools) $ python -m pip install -U pip
Install management_api_tools locally.
(management_api_tools) $ python -m pip install -e ".[test]"
Testing
Review the design document to understand the test runner implementation.
You can test any changes locally with pytest.
(management_api_tools) $ python -m pytest --cov=management_api_tools
You can also test management_api_tools as an installed package.
(management_api_tools) $ python -m tox
Building a wheel
(management_api_tools) $ python -m pip install build
(management_api_tools) $ python -m build --wheel
There should now be a wheel in the dist
directory.
(management_api_tools) $ ls -1 dist
management_api_tools-1.0.0-py3-none-any.whl
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for management_api_tools-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee17bed3a23c91ed58366e02daac7e02175e35ea4cca0d33944a887b5f212e5a |
|
MD5 | 271c3bd718b57bdbc975ec07c76aede7 |
|
BLAKE2b-256 | 1c7a56eadc40db4930c397b42764cfb5d0828f181a253746eb68215021f8b096 |