{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Managing Access Requests" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "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:\n", "\n", "* Creating a new access request on Bailo.\n", "* Retrieving an existing access request from the service.\n", "* Making changes to an access request.\n", "* Deleting an access request.\n", "\n", "Prerequisites:\n", "\n", "* Python 3.9 or higher (including a notebook environment for this demo).\n", "* A local or remote Bailo service (see https://github.com/gchq/Bailo)." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The Bailo python client is split into two sub-packages: **core** and **helper**.\n", "\n", "* **Core:** For direct interactions with the service endpoints.\n", "* **Helper:** For more intuitive interactions with the service, using classes (e.g. Model) to handle operations.\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Necessary import statements\n", "\n", "from bailo import AccessRequest, Model, Client\n", "\n", "# Instantiating the PkiAgent(), if using.\n", "# agent = PkiAgent(cert='', key='', auth='')\n", "\n", "# Instantiating the Bailo client\n", "\n", "client = Client(\"http://127.0.0.1:8080\") # <- INSERT BAILO URL (if not hosting locally)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Creating a new access request" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this section, we will 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 will also need to create a new model on the service, which our access request will be for." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = Model.create(client=client, name=\"YOLOv5\", description=\"YOLOv5 model for object detection.\")\n", "model_id = model.model_id\n", "\n", "metadata = {\"overview\": {\"entities\": [\"user\"], \"name\": \"test\", \"endDate\": \"1970-01-01\"}}\n", "access_request = AccessRequest.create(client=client, model_id=model_id, schema_id=\"minimal-access-request-general-v10\", metadata=metadata)\n", "\n", "access_request_id = access_request.access_request_id" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Retrieving an access request" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Using the .from_id() method" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this section, we will 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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "access_request = AccessRequest.from_id(client=client, model_id=model_id, access_request_id=access_request_id)\n", "\n", "access_request.metadata" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Making changes to an access request" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "new_metadata = access_request.metadata\n", "new_metadata[\"overview\"][\"name\"] = \"newname\"\n", "\n", "access_request.metadata = new_metadata\n", "access_request.update()\n", "\n", "access_request.metadata" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Deleting an access request" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "You can also delete access requests by simply calling the `.delete()` method, as demonstrated below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "access_request.delete()" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }