Skip to main content

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:

  1. Login to the Machina Console
  2. Go to the Data Policies tab
  3. Filter the data policies, if necessary
  4. Click Export on the top right
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

management_api_tools-1.0.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page