py_abac.storage.mongo package

Submodules

py_abac.storage.mongo.migrations module

MongoDB migrations

class py_abac.storage.mongo.migrations.MongoMigration0To0x2x0(storage: py_abac.storage.mongo.storage.MongoStorage)[source]

Bases: py_abac.storage.migration.Migration

Migration between versions 0 and 0.2.0

down()[source]

Migrate DB schema down

up()[source]

Migrate DB schema up

property order

Number of this migration in the row of migrations

class py_abac.storage.mongo.migrations.MongoMigrationSet(storage: py_abac.storage.mongo.storage.MongoStorage, collection: str = 'py_abac_migrations')[source]

Bases: py_abac.storage.migration.MigrationSet

Migrations Collection for MongoStorage

last_applied()[source]

Number of the last migration that was applied up

migrations()[source]

Get migrations. Subclasses should defile a list of storage migrations here

save_applied_number(number: int)[source]

Save the last applied up migration number

py_abac.storage.mongo.model module

MongoDB policy storage model

class py_abac.storage.mongo.model.PolicyModel(_id: str, policy_str: str, tags: dict = None)[source]

Bases: object

Model to store policy as document on MongoDB.

Parameters
  • _id – document ID

  • policy_str – policy JSON string

  • tags – tags for target based filtering

classmethod from_doc(data)[source]

Create policy model from MongoDB document

classmethod from_policy(policy: py_abac.policy.policy.Policy)[source]

Create model instance from policy object

static get_aggregate_pipeline(subject_id: str, resource_id: str, action_id: str)[source]

Get query using target ids to retrieve policies

to_doc()[source]

Get MongoDB document

to_policy()[source]

Get policy object

py_abac.storage.mongo.storage module

MongoDB storage implementation

class py_abac.storage.mongo.storage.MongoStorage(client: pymongo.mongo_client.MongoClient, db_name: str = 'py_abac', collection: str = 'py_abac_policies')[source]

Bases: py_abac.storage.base.Storage

Stores and retrieves policies from MongoDB

Parameters
  • client – mongodb client

  • db_name – database to use for storing policies

  • collection – collection to use for storing policies

add(policy: py_abac.policy.policy.Policy)[source]

Store a policy

delete(uid: str)[source]

Delete a policy

get(uid: str) → Optional[py_abac.policy.policy.Policy][source]

Get specific policy

get_all(limit: int, offset: int) → Generator[py_abac.policy.policy.Policy, None, None][source]

Retrieve all the policies within a window

get_for_target(subject_id: str, resource_id: str, action_id: str) → Generator[py_abac.policy.policy.Policy, None, None][source]

Get all policies for given target IDs.

update(policy: py_abac.policy.policy.Policy)[source]

Update a policy

Module contents

MongoDB storage