Skip to content

Commit

Permalink
Merge pull request #847 from gchq/feature/BAI-957/access-requests-client
Browse files Browse the repository at this point in the history
Add access request endpoints to the client
  • Loading branch information
GB27247 authored Nov 3, 2023
2 parents f0207a9 + 5583da7 commit 0ef684d
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 2 deletions.
90 changes: 90 additions & 0 deletions lib/python-beta/src/bailo/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,93 @@ def patch_team(
f"{self.url}/v2/team/{team_id}",
json=filtered_json,
).json()

def get_access_request(
self,
model_id: str,
access_request_id: str
):
"""
Retrieves a specific access request given its unique ID.
:param model_id: Unique model ID
:param access_request_id: Unique access request ID
:return: JSON response object
"""
return self.agent.get(
f"{self.url}/v2/model/{model_id}/access-request/{access_request_id}",
)

def get_access_requests(
self,
model_id: str,
):
"""
Retrieves all access requests given a specific model.
:param model_id: Unique model ID
:param access_request_id: Unique access request ID
:return: JSON response object
"""
return self.agent.get(
f"{self.url}/v2/model/{model_id}/access-requests",
)

def post_access_request(
self,
model_id: str,
metadata: Any,
schema_id: str
):
"""
Creates an access request given a model ID
:param model_id: Unique model ID
:param metadata: Metadata object, defined by access request schema
:param schema_id: Unique schema ID
:return: JSON response object
"""
return self.agent.post(
f"{self.url}/v2/model/{model_id}/access-requests",
json={
"schemaId": schema_id,
"metadata": metadata
}
)

def delete_access_request(
self,
model_id: str,
access_request_id: str
):
"""
Deletes a specific access request associated with a model.
:param model_id: Unique model ID
:param access_request_id: Unique access request ID
:return: JSON response object
"""
return self.agent.delete(
f"{self.url}/v2/model/{model_id}/access-request/{access_request_id}",
)

def patch_access_request(
self,
model_id: str,
access_request_id: str,
metadata: Any,
schema_id: str | None = None
):
"""
Updates an access request given its unique ID
:param model_id: Unique model ID
:param access_request_id: Unique access request ID
:metadata: Metadata object, defined by access request schemas
:return: JSON response object
"""
filtered_json = filter_none({"schemaId": schema_id, "metadata": metadata})
return self.agent.patch(
f"{self.url}/v2/model/{model_id}/access-request/{access_request_id}",
json=filtered_json
)
69 changes: 67 additions & 2 deletions lib/python-beta/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

import json

from bailo import Client, ModelVisibility, SchemaKind
Expand Down Expand Up @@ -94,8 +95,8 @@ def test_post_release(requests_mock):

client = Client("https://example.com")
result = client.post_release(
model_id="test_id",
model_card_version=1,
model_id="test_id",
model_card_version=1,
release_version='v1',
notes='Test Note',
files=[],
Expand Down Expand Up @@ -291,3 +292,67 @@ def test_patch_team(requests_mock):
)

assert result == {"success": True}

def test_get_access_request(requests_mock):
requests_mock.get("https://example.com/api/v2/model/test_id/access-request/test_id", json={"success": True})

client = Client("https://example.com")
result = client.get_access_request(
model_id="test_id",
access_request_id="test_id"
)

assert result == {"success": True}

def test_get_access_requests(requests_mock):
requests_mock.get("https://example.com/api/v2/model/test_id/access-requests", json={"success": True})

client = Client("https://example.com")
result = client.get_access_requests(
model_id="test_id"
)

assert result == {"success": True}

def test_post_access_request(requests_mock):
requests_mock.post("https://example.com/api/v2/model/test_id/access-requests", json={"success": True})

x = {"overview":{"entities":["user"],"name":"test"}}
y = json.dumps(x)

client = Client("https://example.com")
result = client.post_access_request(
model_id="test_id",
metadata=y,
schema_id="test_id"
)

assert result == {"success": True}

def test_delete_access_request(requests_mock):
requests_mock.delete("https://example.com/api/v2/model/test_id/access-request/test_id", json={"success": True})

client = Client("https://example.com")
result = client.delete_access_request(
model_id="test_id",
access_request_id="test_id"
)

assert result == {"success": True}

def test_patch_access_request(requests_mock):
requests_mock.patch("https://example.com/api/v2/model/test_id/access-request/test_id", json={"success": True})

client = Client("https://example.com")

x = {"overview":{"entities":["user"],"name":"test"}}
y = json.dumps(x)

result = client.patch_access_request(
model_id="test_id",
access_request_id="test_id",
metadata=y,
schema_id="test_id"
)

assert result == {"success": True}

0 comments on commit 0ef684d

Please sign in to comment.