Skip to main content

Aserto API client

Project description

Aserto API client

High-level client interface to Aserto's APIs.

At the moment this only supports interacting with Aserto's Authorizer service.

Installation

Using Pip

pip install aserto

Using Poetry

poetry add aserto

Usage

from aserto.client import AuthorizerOptions, Identity
from aserto.client.api.authorizer import AuthorizerClient


client = AuthorizerClient(
    identity=Identity(type="NONE"),
    options=AuthorizerOptions(
        api_key=ASERTO_API_KEY,
        tenant_id=ASERTO_TENANT_ID,
        service_type="gRPC",
    ),
)

result = await client.decision_tree(
    decisions=["visible", "enabled", "allowed"],
    policy_instance_name=ASERTO_POLICY_INSTANCE_NAME,
    policy_instance_label=ASERTO_POLICY_INSTANCE_LABEL,
    policy_path_root=ASERTO_POLICY_PATH_ROOT,
    policy_path_separator="DOT",
)

assert result == {
    "GET.your.policy.path": {
        "visible": True,
        "enabled": True,
        "allowed": False,
    },
}

Directory

The Directory APIs can be used to get or set object instances and relation instances. They can also be used to check whether a user has a permission or relation on an object instance.

Directory Client

You can initialize a directory client as follows:

from aserto.client.directory import Directory

ds = Directory.connect(api_key="my_api_key", tenant_id="1234", address="localhost:9292")
  • address: hostname:port of directory service (required)
  • api_key: API key for directory service (required if using hosted directory)
  • tenant_id: Aserto tenant ID (required if using hosted directory)
  • cert: Path to the grpc service certificate when connecting to local topaz instance.

'get_object' function

Get a directory object instance with the type and the key.

user = ds.get_object(type="user", key="euang@acmecorp.com")

'get_objects' function

Get object instances with an object type type and page size.

from aserto.client.directory import PaginationRequest

users = ds.get_objects(object_type="user", page=PaginationRequest(size=10))

'set_object' function

Create an object instance with the specified fields. For example:

from google.protobuf.json_format import ParseDict
from google.protobuf.struct_pb2 import Struct

properties = ParseDict({"displayName": "test object"}, Struct())

user = ds.set_object(object={
    "type": "user",
    "key": "test-object",
    "properties": properties,
})

'delete_object' function

Delete an object instance using its type and key:

ds.delete_object(type="user", key="test-object")

License

This project is licensed under the MIT license. See the LICENSE file for more info.

Project details


Download files

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

Source Distribution

aserto-0.21.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

aserto-0.21.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file aserto-0.21.0.tar.gz.

File metadata

  • Download URL: aserto-0.21.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Darwin/22.5.0

File hashes

Hashes for aserto-0.21.0.tar.gz
Algorithm Hash digest
SHA256 121b663105c5d1139d21e88d12d239652edb5fcba8561ad255953462311ec5e6
MD5 674978d45522c73b5c20b13f1bbc53ab
BLAKE2b-256 8726681251d74c5de220d0a3d34bd6706a1ed2a4dc7f890deda3609b6aacb3de

See more details on using hashes here.

File details

Details for the file aserto-0.21.0-py3-none-any.whl.

File metadata

  • Download URL: aserto-0.21.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Darwin/22.5.0

File hashes

Hashes for aserto-0.21.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1339531079eedb68b403064affce674f8e2256f288f38b9896ec81c3984a71f2
MD5 d5758ce702202e6151b8adb6ffab9edb
BLAKE2b-256 8dcbeaba3939a58754b279830ef2567010d0ee0fc788e0e668ade076edded6e9

See more details on using hashes here.

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