openfga¶
Interface Library for OpenFGA.
This library wraps relation endpoints using the openfga interface
and provides a Python API for requesting OpenFGA authorization model
stores to be created.
Getting Started¶
To get started using the library, you just need to fetch the library using charmcraft:
cd some-charm
charmcraft fetch-lib charms.openfga_k8s.v1.openfga
In the metadata.yaml of the charm, add the following:
requires:
openfga:
interface: openfga
Then, to initialise the library:
from charms.openfga_k8s.v1.openfga import (
OpenFGARequires,
OpenFGAStoreCreateEvent,
)
class SomeCharm(CharmBase):
def __init__(self, *args):
# ...
self.openfga = OpenFGARequires(self, "test-openfga-store")
self.framework.observe(
self.openfga.on.openfga_store_created,
self._on_openfga_store_created,
)
def _on_openfga_store_created(self, event: OpenFGAStoreCreateEvent):
if not event.store_id:
return
info = self.openfga.get_store_info()
if not info:
return
logger.info("store id {}".format(info.store_id))
logger.info("token {}".format(info.token))
logger.info("grpc_api_url {}".format(info.grpc_api_url))
logger.info("http_api_url {}".format(info.http_api_url))
- class OpenFGAProvider(
- charm: CharmBase,
- relation_name: str = 'openfga',
- http_port: str | None = '8080',
- grpc_port: str | None = '8081',
- scheme: str | None = 'http',
Bases:
ObjectRequirer side of the openfga relation.
- on¶
Custom charm events.
- update_relation_app_data(
- data: OpenfgaProviderAppData,
- relation_id: int,
- update_relations_app_data(
- data: OpenfgaProviderBaseData,
- class OpenFGARequires( )¶
Bases:
ObjectThis class defines the functionality for the ‘requires’ side of the ‘openfga’ relation.
- Hook events observed:
relation-created
relation-changed
relation-departed
- on¶
Custom charm events.
- get_store_info() OpenfgaProviderAppData | None¶
Get the OpenFGA store and server info.
- class OpenFGAStoreCreateEvent(handle: Handle, store_id: str)¶
Bases:
HookEventEvent emitted when a new OpenFGA store is created.
- class OpenFGAStoreRemovedEvent(handle: Handle)¶
Bases:
HookEventEvent emitted when a new OpenFGA store is removed.
- class OpenFGAStoreRequestEvent( )¶
Bases:
RelationEventEvent emitted when a new OpenFGA store is requested.
- class OpenfgaProviderAppData(
- *,
- grpc_api_url: str,
- http_api_url: str,
- store_id: str | None = None,
- token: str | None = None,
- token_secret_id: str | None = None,
Bases:
OpenfgaProviderBaseDataOpenfga requirer application databag model.