Managing Access Requests
The Bailo python client enables intuitive interaction with the Bailo service, from within a python environment. This example notebook will run through the following concepts:
Creating a new access request on Bailo.
Retrieving an existing access request from the service.
Making changes to an access request.
Deleting an access request.
Prerequisites:
Python 3.8.1 or higher (including a notebook environment for this demo).
A local or remote Bailo service (see https://github.com/gchq/Bailo).
Introduction
The Bailo python client is split into two sub-packages: core and helper.
Core: For direct interactions with the service endpoints.
Helper: For more intuitive interactions with the service, using classes (e.g. Model) to handle operations.
In order to create helper classes, you will first need to instantiate a Client()
object from the core. By default, this object will not support any authentication. However, Bailo also supports PKI authentication, which you can use from Python by passing a PkiAgent()
object into the Client()
object when you instantiate it.
[ ]:
# Necessary import statements
from bailo import AccessRequest, Model, Client
# Instantiating the PkiAgent(), if using.
# agent = PkiAgent(cert='', key='', auth='')
# Instantiating the Bailo client
client = Client("http://127.0.0.1:8080") # <- INSERT BAILO URL (if not hosting locally)
Creating a new access request
In this section, we’ll create a new access request using the AccessRequest.create()
classmethod. On the Bailo service, an access request must consist of at least 3 parameters upon creation. These are model_id, schema_id and metadata. Below, we use the Client()
object created before when instantiating the new AccessRequest()
object. We’ll also need to create a new model on the service, which our access request will be for.
[ ]:
model = Model.create(client=client, name="YOLOv5", description="YOLOv5 model for object detection.", team_id="uncategorised")
model_id = model.model_id
metadata = {"overview": {"entities": ["user"], "name": "test", "endDate": "1970-01-01"}}
access_request = AccessRequest.create(client=client, model_id=model_id, schema_id="minimal-access-request-general-v10", metadata=metadata)
access_request_id = access_request.access_request_id
Retrieving an access request
Using the .from_id() method
In this section, we’ll retrieve our previous access request using the AccessRequest.from_id()
classmethod. This will create your AccessRequest()
object as before, but using existing information retrieved from the service.
[ ]:
access_request = AccessRequest.from_id(client=client, model_id=model_id, access_request_id=access_request_id)
access_request.metadata
Making changes to an access request
You can make changes to an access request by editing the metadata attribute directly, and then calling the .update()
method. This is demonstrated below with a name change.
[ ]:
new_metadata = access_request.metadata
new_metadata["overview"]["name"] = "newname"
access_request.metadata = new_metadata
access_request.update()
access_request.metadata
Deleting an access request
You can also delete access requests by simply calling the .delete()
method, as demonstrated below.
[ ]:
access_request.delete()