From 3d60652cf198bb80b5c094cc19c1ff614034a67c Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sat, 2 Dec 2023 17:18:52 +0100 Subject: [PATCH 01/29] [Functionality] Request Consumer / Producer - request to get the data for consumer and producer data --- pkgs/ui/src/app/client-1/page.tsx | 100 +++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 31 deletions(-) diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index 5abb913..07b79de 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -2,39 +2,77 @@ import SummaryDetails from "@/components/summary_card"; import { - Client1SummaryDetails, - Client1ConsumerData, - Client1ConsumerTableConfig, - Client1ProducerTableConfig, - Client1ProducerData, + Client1SummaryDetails, + Client1ConsumerData, + Client1ConsumerTableConfig, + Client1ProducerTableConfig, + Client1ProducerData, } from "@/mock/client_1"; import CustomTable from "@/components/table"; +import {useEffect, useState} from "react"; export default function Client1() { - return ( -
- -
-

Consumer View

- -
-
-

Producer View

- -
-
- ); + const [consumerData, setConsumerData] = useState(null); + const [producerData, setProducerData] = useState(null); + + useEffect(() => { + fetch('http://localhost:2979/api/v1/get_consumers', { + method: 'GET', + // credentials: 'include', + }) + .then(resp => resp.json().then(jsonData => { + console.log(jsonData); + if (jsonData.length > 0) { + setConsumerData(jsonData); + } else { + setConsumerData(Client1ConsumerData); + } + } + )) + .then(data => null) + .catch(err => null) + + fetch('http://localhost:2979/api/v1/get_producers', { + method: 'GET', + // credentials: 'include', + }) + .then(resp => resp.json().then(jsonData => { + console.log(jsonData); + if (jsonData.length > 0) { + setProducerData(jsonData); + } else { + setProducerData(Client1ProducerData); + } + } + )) + .then(data => null) + .catch(err => null) + }, []); + + return ( +
+ +
+

Consumer View

+ +
+
+

Producer View

+ +
+
+ ); } From b89d2df31b115ec381dcace013860eeaf1ae8611 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sat, 2 Dec 2023 17:30:28 +0100 Subject: [PATCH 02/29] [Functionality] Request Consumer / Producer - fixed the hook data --- pkgs/ui/src/app/client-1/page.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index 07b79de..a676334 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -12,8 +12,8 @@ import CustomTable from "@/components/table"; import {useEffect, useState} from "react"; export default function Client1() { - const [consumerData, setConsumerData] = useState(null); - const [producerData, setProducerData] = useState(null); + const [consumerData, setConsumerData] = useState([]); + const [producerData, setProducerData] = useState([]); useEffect(() => { fetch('http://localhost:2979/api/v1/get_consumers', { @@ -29,8 +29,8 @@ export default function Client1() { } } )) - .then(data => null) - .catch(err => null) + .then() + .catch() fetch('http://localhost:2979/api/v1/get_producers', { method: 'GET', @@ -45,8 +45,8 @@ export default function Client1() { } } )) - .then(data => null) - .catch(err => null) + .then() + .catch() }, []); return ( From cd0d3937c466aeb21f31db4cf5798511a3225c72 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 2 Dec 2023 17:30:39 +0100 Subject: [PATCH 03/29] [Functionality] Request Service Repository - request backend endpoint and fill data if available --- pkgs/ui/src/app/access-point/page.tsx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 177073c..25bac10 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -9,9 +9,31 @@ import { APServiceRepositoryDummyData, APServiceRepositoryTableConfig, } from "@/mock/access_point"; +import {useEffect, useState} from "react"; export default function AccessPoint() { - return ( + const [repositoryData, setRepositoryData] = useState([]); + + useEffect(() => { + fetch('http://localhost:2979/api/v1/get_repositories', { + method: 'GET', + // credentials: 'include', + }) + .then(resp => resp.json().then(jsonData => { + console.log(jsonData); + if (jsonData.length > 0) { + setRepositoryData(jsonData); + } else { + setRepositoryData(APServiceRepositoryDummyData); + } + } + )) + .then() + .catch() + }, []); + + + return (

Service Repository View

From d95c6ba98148f3bfc0777f4006efc98283225f51 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 2 Dec 2023 18:48:08 +0100 Subject: [PATCH 04/29] fix formating --- pkgs/ui/src/app/access-point/page.tsx | 42 ++++---- pkgs/ui/src/app/client-1/page.tsx | 134 +++++++++++++------------- 2 files changed, 89 insertions(+), 87 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 25bac10..997f915 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -9,31 +9,31 @@ import { APServiceRepositoryDummyData, APServiceRepositoryTableConfig, } from "@/mock/access_point"; -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; export default function AccessPoint() { - const [repositoryData, setRepositoryData] = useState([]); + const [repositoryData, setRepositoryData] = useState([]); - useEffect(() => { - fetch('http://localhost:2979/api/v1/get_repositories', { - method: 'GET', - // credentials: 'include', - }) - .then(resp => resp.json().then(jsonData => { - console.log(jsonData); - if (jsonData.length > 0) { - setRepositoryData(jsonData); - } else { - setRepositoryData(APServiceRepositoryDummyData); - } - } - )) - .then() - .catch() - }, []); + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_repositories", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + if (jsonData.length > 0) { + setRepositoryData(jsonData); + } else { + setRepositoryData(APServiceRepositoryDummyData); + } + }), + ) + .then() + .catch(); + }, []); - - return ( + return (
{ - fetch('http://localhost:2979/api/v1/get_consumers', { - method: 'GET', - // credentials: 'include', - }) - .then(resp => resp.json().then(jsonData => { - console.log(jsonData); - if (jsonData.length > 0) { - setConsumerData(jsonData); - } else { - setConsumerData(Client1ConsumerData); - } - } - )) - .then() - .catch() + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_consumers", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + if (jsonData.length > 0) { + setConsumerData(jsonData); + } else { + setConsumerData(Client1ConsumerData); + } + }), + ) + .then() + .catch(); - fetch('http://localhost:2979/api/v1/get_producers', { - method: 'GET', - // credentials: 'include', - }) - .then(resp => resp.json().then(jsonData => { - console.log(jsonData); - if (jsonData.length > 0) { - setProducerData(jsonData); - } else { - setProducerData(Client1ProducerData); - } - } - )) - .then() - .catch() - }, []); + fetch("http://localhost:2979/api/v1/get_producers", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + if (jsonData.length > 0) { + setProducerData(jsonData); + } else { + setProducerData(Client1ProducerData); + } + }), + ) + .then() + .catch(); + }, []); - return ( -
- -
-

Consumer View

- -
-
-

Producer View

- -
-
- ); + return ( +
+ +
+

Consumer View

+ +
+
+

Producer View

+ +
+
+ ); } From 2c098f4ba02e38240536ef5eba49fb153e798786 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sat, 2 Dec 2023 21:12:04 +0100 Subject: [PATCH 05/29] [Functionality] Request Consumer / Producer - request consumer, producer data for client-2 - refactored statements --- pkgs/ui/src/app/access-point/page.tsx | 6 +---- pkgs/ui/src/app/client-1/page.tsx | 20 +++++---------- pkgs/ui/src/app/client-2/page.tsx | 36 +++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 997f915..277d5c0 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -22,11 +22,7 @@ export default function AccessPoint() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - if (jsonData.length > 0) { - setRepositoryData(jsonData); - } else { - setRepositoryData(APServiceRepositoryDummyData); - } + jsonData.length > 0 ? setRepositoryData(jsonData) : setRepositoryData(APServiceRepositoryDummyData); }), ) .then() diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index 90437e6..bf47d67 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -23,11 +23,7 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - if (jsonData.length > 0) { - setConsumerData(jsonData); - } else { - setConsumerData(Client1ConsumerData); - } + jsonData.length > 0 ? setConsumerData(jsonData) : setConsumerData(Client1ConsumerData); }), ) .then() @@ -37,15 +33,11 @@ export default function Client1() { method: "GET", // credentials: 'include', }) - .then((resp) => - resp.json().then((jsonData) => { - console.log(jsonData); - if (jsonData.length > 0) { - setProducerData(jsonData); - } else { - setProducerData(Client1ProducerData); - } - }), + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 ? setProducerData(jsonData) : setProducerData(Client1ProducerData); + }), ) .then() .catch(); diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client-2/page.tsx index 80be865..b833d89 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client-2/page.tsx @@ -9,8 +9,40 @@ import { Client2SummaryDetails, } from "@/mock/client_2"; import CustomTable from "@/components/table"; +import {useEffect, useState} from "react"; export default function Client1() { + const [consumerData, setConsumerData] = useState([]); + const [producerData, setProducerData] = useState([]); + + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_consumers", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 ? setConsumerData(jsonData) : setConsumerData(Client2ConsumerData); + }), + ) + .then() + .catch(); + + fetch("http://localhost:2979/api/v1/get_producers", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 ? setProducerData(jsonData) : setProducerData(Client2ProducerData); + }), + ) + .then() + .catch(); + }, []); + return (

Consumer View

Producer View

From 9b4301d783c2136bf3ba3cf842ac7ab7f22c60c8 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sun, 3 Dec 2023 18:37:45 +0100 Subject: [PATCH 06/29] [Functionality] Request Consumer / Producer - adjusted some header names --- pkgs/ui/src/mock/access_point/index.ts | 32 +++++++++---------- pkgs/ui/src/mock/client_1/index.ts | 44 +++++++++++++------------- pkgs/ui/src/mock/client_2/index.ts | 44 +++++++++++++------------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/pkgs/ui/src/mock/access_point/index.ts b/pkgs/ui/src/mock/access_point/index.ts index 07ae286..1895a9b 100644 --- a/pkgs/ui/src/mock/access_point/index.ts +++ b/pkgs/ui/src/mock/access_point/index.ts @@ -20,25 +20,25 @@ export const APSummaryDetails = [ export const APAttachmentsDummyData = [ { entity_name: "C1", - entity_DID: "did:sov:test:1234", + entity_did: "did:sov:test:1234", network: "Carlo's Home Network", ip_address: "127.0.0.1", }, { entity_name: "C2", - entity_DID: "did:sov:test:4567", + entity_did: "did:sov:test:4567", network: "Steve's Home Network", ip_address: "127.0.0.1", }, { entity_name: "C1-TEST", - entity_DID: "did:sov:test:0001", + entity_did: "did:sov:test:0001", network: "Test Network A", ip_address: "127.0.0.1", }, { entity_name: "C2-TEST", - entity_DID: "did:sov:test:0002", + entity_did: "did:sov:test:0002", network: "Test Network B", ip_address: "127.0.0.1", }, @@ -49,7 +49,7 @@ export const APAttachmentsTableConfig = [ label: "Entity name", }, { - key: "entity_DID", + key: "entity_did", label: "Entity DID", }, { @@ -67,17 +67,17 @@ export const APServiceRepositoryDummyData = [ { service_name: "Carlo's Printing", service_type: "3D Printing", - end_point: "URL", - producer: "C1", - producer_DID: "did:sov:test:1234", + endpoint_url: "URL", + entity: "C1", + entity_did: "did:sov:test:1234", network: "Carlo's Home Network", }, { service_name: "Jeff's Printing", service_type: "3D Printing", - end_point: "URL", - producer: "C2", - producer_DID: "did:sov:test:5678", + endpoint_url: "URL", + entity: "C2", + entity_did: "did:sov:test:5678", network: "Jeff's Home Network", }, ]; @@ -91,16 +91,16 @@ export const APServiceRepositoryTableConfig = [ label: "Service type", }, { - key: "end_point", + key: "endpoint_url", label: "End point", }, { - key: "producer", - label: "Producer", + key: "entity", + label: "Entity", }, { - key: "producer_DID", - label: "Producer DID", + key: "entity_did", + label: "Entity DID", }, { key: "network", diff --git a/pkgs/ui/src/mock/client_1/index.ts b/pkgs/ui/src/mock/client_1/index.ts index 658b51e..2946c9b 100644 --- a/pkgs/ui/src/mock/client_1/index.ts +++ b/pkgs/ui/src/mock/client_1/index.ts @@ -19,33 +19,33 @@ export const Client1ConsumerData = [ { service_name: "Carlo's Printing", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:1223", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:1223", network: "Carlo's Home Network", }, { service_name: "Steve's Printing", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:1234", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:1234", network: "Steve's Home Network", }, { service_name: "Test A", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:4567", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:4567", network: "Test Network A", }, { service_name: "Test B", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:0062", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:0062", network: "Test Network B", }, ]; @@ -60,16 +60,16 @@ export const Client1ConsumerTableConfig = [ label: "Service Type", }, { - key: "end_point", + key: "endpoint_url", label: "End Point", }, { - key: "producer", - label: "Producer", + key: "entity", + label: "Entity", }, { - key: "producer_did", - label: "Producer DID", + key: "entity_did", + label: "Entity DID", }, { key: "network", @@ -81,7 +81,7 @@ export const Client1ProducerData = [ { service_name: "Carlo's Printing", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT, REGISTERED", action: "Register, Deregister, Delete", @@ -89,7 +89,7 @@ export const Client1ProducerData = [ { service_name: "Steve's Printing", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "REGISTERED", action: "Create", @@ -97,7 +97,7 @@ export const Client1ProducerData = [ { service_name: "Test Printing A", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT", action: "Register, Deregister", @@ -105,7 +105,7 @@ export const Client1ProducerData = [ { service_name: "Test Printing B", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT, REGISTERED", action: "Delete, Create", @@ -122,7 +122,7 @@ export const Client1ProducerTableConfig = [ label: "Service Type", }, { - key: "end_point", + key: "endpoint_url", label: "End Point", }, { diff --git a/pkgs/ui/src/mock/client_2/index.ts b/pkgs/ui/src/mock/client_2/index.ts index b0105fd..1f40fcd 100644 --- a/pkgs/ui/src/mock/client_2/index.ts +++ b/pkgs/ui/src/mock/client_2/index.ts @@ -19,33 +19,33 @@ export const Client2ConsumerData = [ { service_name: "Carlo's Printing", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:1223", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:1223", network: "Carlo's Home Network", }, { service_name: "Steve's Printing", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:1234", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:1234", network: "Steve's Home Network", }, { service_name: "Test A", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:4567", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:4567", network: "Test Network A", }, { service_name: "Test B", service_type: "3D Printing", - end_point: "Consume", - producer: "C2", - producer_did: "did:sov:test:0062", + endpoint_url: "Consume", + entity: "C2", + entity_did: "did:sov:test:0062", network: "Test Network B", }, ]; @@ -60,16 +60,16 @@ export const Client2ConsumerTableConfig = [ label: "Service Type", }, { - key: "end_point", + key: "endpoint_url", label: "End Point", }, { - key: "producer", - label: "Producer", + key: "entity", + label: "Entity", }, { - key: "producer_did", - label: "Producer DID", + key: "entity_did", + label: "Entity DID", }, { key: "network", @@ -81,7 +81,7 @@ export const Client2ProducerData = [ { service_name: "Carlo's Printing", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT, REGISTERED", action: "Register, Deregister, Delete", @@ -89,7 +89,7 @@ export const Client2ProducerData = [ { service_name: "Steve's Printing", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "REGISTERED", action: "Create", @@ -97,7 +97,7 @@ export const Client2ProducerData = [ { service_name: "Test Printing A", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT", action: "Register, Deregister", @@ -105,7 +105,7 @@ export const Client2ProducerData = [ { service_name: "Test Printing B", service_type: "3D Printing", - end_point: "URL", + endpoint_url: "URL", usage: "C1(3), C3(4)", status: "DRAFT, REGISTERED", action: "Delete, Create", @@ -122,7 +122,7 @@ export const Client2ProducerTableConfig = [ label: "Service Type", }, { - key: "end_point", + key: "endpoint_url", label: "End Point", }, { From f7cf1ff2b28e165de7c0c68124cbb786b0524677 Mon Sep 17 00:00:00 2001 From: Georg-Stahn Date: Mon, 4 Dec 2023 22:45:33 +0100 Subject: [PATCH 07/29] georgs6 (#34) Reviewed-on: https://gitea.gchq.icu/IoSL/service-aware-frontend/pulls/34 --- pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py index 5a9f338..9a5c8b1 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py @@ -178,7 +178,7 @@ def get_attached_entities( return entities -@router.get("/api/v1/detach") +@router.post("/api/v1/detach") async def detach( background_tasks: BackgroundTasks, entity_did: str = "did:sov:test:1234", @@ -192,7 +192,7 @@ async def detach( return {"message": "Detaching in the background"} -@router.get("/api/v1/attach") +@router.post("/api/v1/attach") async def attach( background_tasks: BackgroundTasks, entity_did: str = "did:sov:test:1234", From c25ac3025c23e51658d9d1485a9ac427e662af95 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Mon, 4 Dec 2023 23:02:54 +0100 Subject: [PATCH 08/29] [Entities] AP Service Repository View Table - adjusted repository data keys --- pkgs/ui/src/mock/access_point/index.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkgs/ui/src/mock/access_point/index.ts b/pkgs/ui/src/mock/access_point/index.ts index 1895a9b..8af005c 100644 --- a/pkgs/ui/src/mock/access_point/index.ts +++ b/pkgs/ui/src/mock/access_point/index.ts @@ -94,16 +94,20 @@ export const APServiceRepositoryTableConfig = [ key: "endpoint_url", label: "End point", }, - { - key: "entity", - label: "Entity", - }, + // { + // key: "entity", + // label: "Entity", + // }, { key: "entity_did", label: "Entity DID", }, + // { + // key: "network", + // label: "Network", + // }, { - key: "network", - label: "Network", + key: "status", + label: "Status", }, ]; From 7d4d6f59c290bf67a34c5a2be54ec9d8749dc2ed Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 3 Dec 2023 14:22:46 +0100 Subject: [PATCH 09/29] Better README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2c5987..ceaff48 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,8 @@ Let's set up your Git workflow to collaborate effectively: 2. **Git Workflow**: 1. Add your changes to Git using `git add `. - 2. Run `nix fmt` to lint your files. - 3. Commit your changes with a descriptive message: `git commit -a -m "My descriptive commit message"`. + 2. Run `nix fmt` to lint your files. This will format your files and make changes! + 3. Commit your changes and those of nix fmt with a descriptive message: `git commit -a -m "My descriptive commit message"`. 4. Make sure your branch has the latest changes from upstream by executing: ```bash git fetch && git rebase origin/main --autostash From 20e6e551d4194b0d426ee55cc8e0ccbf0744a3bc Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 3 Dec 2023 18:38:58 +0100 Subject: [PATCH 10/29] Improved README --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ceaff48..3523700 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,11 @@ Let's get your development environment up and running: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install ``` +On Windows Subsystem for Linux (WSL) the installer will fail and tell you what to do. Execute the command from the error message and then afterwards execute: +```bash +sudo echo "experimental-features = nix-command flakes" > '/etc/nix/nix.conf' +``` + 2. **Install direnv**: - Download the direnv package from [here](https://direnv.net/docs/installation.html) or run the following command: @@ -95,12 +100,12 @@ Let's set up your Git workflow to collaborate effectively: ```bash tea login add ``` + - Go to https://gitea.gchq.icu/user/settings/applications and create token with all privileges - Fill out the prompt as follows: - URL of Gitea instance: `https://gitea.gchq.icu` - Name of new Login [gitea.gchq.icu]: `gitea.gchq.icu:7171` - - Do you have an access token? No - - Username: YourUsername - - Password: YourPassword + - Do you have an access token? Yes + - Token: ********* - Set Optional settings: No 2. **Git Workflow**: From 80269832e6928cf140cca64f5b58c9eb982030ea Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 3 Dec 2023 18:39:19 +0100 Subject: [PATCH 11/29] Improved README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3523700..85d2b42 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Let's get your development environment up and running: ``` On Windows Subsystem for Linux (WSL) the installer will fail and tell you what to do. Execute the command from the error message and then afterwards execute: + ```bash sudo echo "experimental-features = nix-command flakes" > '/etc/nix/nix.conf' ``` @@ -105,13 +106,13 @@ Let's set up your Git workflow to collaborate effectively: - URL of Gitea instance: `https://gitea.gchq.icu` - Name of new Login [gitea.gchq.icu]: `gitea.gchq.icu:7171` - Do you have an access token? Yes - - Token: ********* + - Token: ****\***** - Set Optional settings: No 2. **Git Workflow**: 1. Add your changes to Git using `git add `. - 2. Run `nix fmt` to lint your files. This will format your files and make changes! + 2. Run `nix fmt` to lint your files. This will format your files and make changes! 3. Commit your changes and those of nix fmt with a descriptive message: `git commit -a -m "My descriptive commit message"`. 4. Make sure your branch has the latest changes from upstream by executing: ```bash From 10d9b995cb304f9097c72914e37dec07c0980dc0 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Wed, 6 Dec 2023 19:01:00 +0100 Subject: [PATCH 12/29] [Functionality] Request Consumer / Producer - adjusted some header names --- pkgs/ui/src/mock/client_1/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/ui/src/mock/client_1/index.ts b/pkgs/ui/src/mock/client_1/index.ts index 2946c9b..9139156 100644 --- a/pkgs/ui/src/mock/client_1/index.ts +++ b/pkgs/ui/src/mock/client_1/index.ts @@ -125,16 +125,16 @@ export const Client1ProducerTableConfig = [ key: "endpoint_url", label: "End Point", }, - { - key: "usage", - label: "Usage", - }, + // { + // key: "usage", + // label: "Usage", + // }, { key: "status", label: "Status", }, - { - key: "action", - label: "Action", - }, + // { + // key: "action", + // label: "Action", + // }, ]; From 647fc33acd7ddbfc5d45ec5596efb3adb826b317 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Wed, 6 Dec 2023 19:25:08 +0100 Subject: [PATCH 13/29] [Functionality] Request Home Table - request entities for home view table --- pkgs/ui/src/app/home/page.tsx | 24 +++++++++++++++++++++--- pkgs/ui/src/mock/home/index.ts | 26 +++++++++++++------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index 37e51de..4e14f4f 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -1,11 +1,29 @@ "use client"; -import { NoDataOverlay } from "@/components/noDataOverlay"; +import {NoDataOverlay} from "@/components/noDataOverlay"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; -import { HomeDummyData, HomeTableConfig } from "@/mock/home"; +import {HomeDummyData, HomeTableConfig} from "@/mock/home"; +import {useEffect, useState} from "react"; export default function Home() { + const [homeData, setHomeData] = useState([]); + + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_entities", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 ? setHomeData(jsonData) : setHomeData(HomeDummyData); + }), + ) + .then() + .catch(); + }, []); + return (

Home View Table

- +
diff --git a/pkgs/ui/src/mock/home/index.ts b/pkgs/ui/src/mock/home/index.ts index ccff693..b6c2d4f 100644 --- a/pkgs/ui/src/mock/home/index.ts +++ b/pkgs/ui/src/mock/home/index.ts @@ -21,27 +21,27 @@ export const HomeDummyData = [ export const HomeTableConfig = [ { - key: "entity_name", + key: "name", label: "Entity name", }, { - key: "entity_DID", + key: "did", label: "Entity DID", }, + // { + // key: "network", + // label: "Network", + // }, { - key: "network", - label: "Network", - }, - { - key: "ip_address", + key: "ip", label: "IP address", }, + // { + // key: "roles", + // label: "Roles", + // }, { - key: "roles", - label: "Roles", - }, - { - key: "visible", - label: "Visible", + key: "attached", + label: "Attached", }, ]; From 01ce85bb156c5c43d396858b3a8e51b5c9f41362 Mon Sep 17 00:00:00 2001 From: erdemarslan Date: Sat, 9 Dec 2023 18:36:24 +0100 Subject: [PATCH 14/29] fix formatting --- pkgs/ui/src/app/access-point/page.tsx | 4 ++- pkgs/ui/src/app/client-1/page.tsx | 16 ++++++----- pkgs/ui/src/app/client-2/page.tsx | 18 ++++++++----- pkgs/ui/src/app/home/page.tsx | 38 ++++++++++++++------------- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 277d5c0..0ea7a72 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -22,7 +22,9 @@ export default function AccessPoint() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 ? setRepositoryData(jsonData) : setRepositoryData(APServiceRepositoryDummyData); + jsonData.length > 0 + ? setRepositoryData(jsonData) + : setRepositoryData(APServiceRepositoryDummyData); }), ) .then() diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index bf47d67..3eb97c7 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -23,7 +23,9 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 ? setConsumerData(jsonData) : setConsumerData(Client1ConsumerData); + jsonData.length > 0 + ? setConsumerData(jsonData) + : setConsumerData(Client1ConsumerData); }), ) .then() @@ -33,11 +35,13 @@ export default function Client1() { method: "GET", // credentials: 'include', }) - .then((resp) => - resp.json().then((jsonData) => { - console.log(jsonData); - jsonData.length > 0 ? setProducerData(jsonData) : setProducerData(Client1ProducerData); - }), + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 + ? setProducerData(jsonData) + : setProducerData(Client1ProducerData); + }), ) .then() .catch(); diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client-2/page.tsx index b833d89..43da43d 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client-2/page.tsx @@ -9,7 +9,7 @@ import { Client2SummaryDetails, } from "@/mock/client_2"; import CustomTable from "@/components/table"; -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; export default function Client1() { const [consumerData, setConsumerData] = useState([]); @@ -23,7 +23,9 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 ? setConsumerData(jsonData) : setConsumerData(Client2ConsumerData); + jsonData.length > 0 + ? setConsumerData(jsonData) + : setConsumerData(Client2ConsumerData); }), ) .then() @@ -33,11 +35,13 @@ export default function Client1() { method: "GET", // credentials: 'include', }) - .then((resp) => - resp.json().then((jsonData) => { - console.log(jsonData); - jsonData.length > 0 ? setProducerData(jsonData) : setProducerData(Client2ProducerData); - }), + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 + ? setProducerData(jsonData) + : setProducerData(Client2ProducerData); + }), ) .then() .catch(); diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index 4e14f4f..08e702e 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -1,28 +1,30 @@ "use client"; -import {NoDataOverlay} from "@/components/noDataOverlay"; +import { NoDataOverlay } from "@/components/noDataOverlay"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; -import {HomeDummyData, HomeTableConfig} from "@/mock/home"; -import {useEffect, useState} from "react"; +import { HomeDummyData, HomeTableConfig } from "@/mock/home"; +import { useEffect, useState } from "react"; export default function Home() { - const [homeData, setHomeData] = useState([]); + const [homeData, setHomeData] = useState([]); - useEffect(() => { - fetch("http://localhost:2979/api/v1/get_entities", { - method: "GET", - // credentials: 'include', - }) - .then((resp) => - resp.json().then((jsonData) => { - console.log(jsonData); - jsonData.length > 0 ? setHomeData(jsonData) : setHomeData(HomeDummyData); - }), - ) - .then() - .catch(); - }, []); + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_entities", { + method: "GET", + // credentials: 'include', + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + jsonData.length > 0 + ? setHomeData(jsonData) + : setHomeData(HomeDummyData); + }), + ) + .then() + .catch(); + }, []); return (
From 084288232028355d9d28c7ad372ac46b86c9f848 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 9 Dec 2023 18:55:19 +0100 Subject: [PATCH 15/29] try creating type RepositoryData to fix pipeline --- pkgs/ui/src/app/access-point/page.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 0ea7a72..19196a4 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -11,8 +11,15 @@ import { } from "@/mock/access_point"; import { useEffect, useState } from "react"; +interface RepositoryData { + entity_name: string; + entity_did: string; + network: string; + ip_address: string; +} + export default function AccessPoint() { - const [repositoryData, setRepositoryData] = useState([]); + const [repositoryData, setRepositoryData] = useState([]); useEffect(() => { fetch("http://localhost:2979/api/v1/get_repositories", { From a93e6019c5c395d031045482011d45cb3315dad0 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sat, 9 Dec 2023 18:57:20 +0100 Subject: [PATCH 16/29] clan_cli: Added automated database population. Fixed incorrect error handling in backend --- pkgs/clan-cli/clan_cli/webui/__init__.py | 6 ++ pkgs/clan-cli/clan_cli/webui/app.py | 5 +- .../clan-cli/clan_cli/webui/error_handlers.py | 2 +- .../clan_cli/webui/routers/sql_connect.py | 55 +++++++++---------- pkgs/clan-cli/clan_cli/webui/schemas.py | 8 ++- pkgs/clan-cli/clan_cli/webui/server.py | 21 +++++++ pkgs/clan-cli/clan_cli/webui/sql_crud.py | 26 ++++----- pkgs/clan-cli/clan_cli/webui/sql_models.py | 1 + pkgs/clan-cli/tests/test_db_api.py | 32 ++++++++--- 9 files changed, 102 insertions(+), 54 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/webui/__init__.py b/pkgs/clan-cli/clan_cli/webui/__init__.py index de2f5ae..4fc79ad 100644 --- a/pkgs/clan-cli/clan_cli/webui/__init__.py +++ b/pkgs/clan-cli/clan_cli/webui/__init__.py @@ -22,6 +22,12 @@ def register_parser(parser: argparse.ArgumentParser) -> None: parser.add_argument( "--host", type=str, default="localhost", help="Host to listen on" ) + parser.add_argument( + "--no-populate", + action="store_true", + help="Don't populate the database with dummy data", + default=False, + ) parser.add_argument( "--no-open", action="store_true", help="Don't open the browser", default=False ) diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index b5cb9b1..173cef8 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -35,10 +35,11 @@ def setup_app() -> FastAPI: # bind sql engine # TODO comment aut and add flag to run with pupulated data rm *.sql run pytest with marked then start clan webui # https://docs.pytest.org/en/7.1.x/example/markers.html - sql_models.Base.metadata.drop_all(engine) + # sql_models.Base.metadata.drop_all(engine) + sql_models.Base.metadata.create_all(bind=engine) - app = FastAPI(lifespan=lifespan) + app = FastAPI(lifespan=lifespan, swagger_ui_parameters={"tryItOutEnabled": True}) app.add_middleware( CORSMiddleware, allow_origins=origins, diff --git a/pkgs/clan-cli/clan_cli/webui/error_handlers.py b/pkgs/clan-cli/clan_cli/webui/error_handlers.py index 341bb2e..9948cc5 100644 --- a/pkgs/clan-cli/clan_cli/webui/error_handlers.py +++ b/pkgs/clan-cli/clan_cli/webui/error_handlers.py @@ -25,7 +25,7 @@ def sql_error_handler(request: Request, exc: SQLAlchemyError) -> JSONResponse: def clan_error_handler(request: Request, exc: ClanError) -> JSONResponse: - log.error("ClanError: %s", exc) + log.exception(exc) detail = [ { "loc": [], diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py index 9a5c8b1..9fe73f7 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py @@ -1,3 +1,4 @@ +import logging import time from typing import List, Optional @@ -5,6 +6,7 @@ import httpx from fastapi import APIRouter, BackgroundTasks, Depends from sqlalchemy.orm import Session +from ...errors import ClanError from .. import sql_crud, sql_db, sql_models from ..schemas import ( Consumer, @@ -20,6 +22,8 @@ from ..tags import Tags router = APIRouter() +log = logging.getLogger(__name__) + ######################### # # @@ -141,11 +145,7 @@ def get_repository( @router.post("/api/v1/create_entity", response_model=Entity, tags=[Tags.entities]) def create_entity( entity: EntityCreate, db: Session = Depends(sql_db.get_db) -) -> EntityCreate | str: - # todo checken ob schon da ... - if sql_crud.get_entity_by_did(db, did=entity.did): - print("did already exsists") - return "Error did already exsists in db" +) -> EntityCreate: return sql_crud.create_entity(db, entity) @@ -178,7 +178,7 @@ def get_attached_entities( return entities -@router.post("/api/v1/detach") +@router.post("/api/v1/detach", response_model=Entity, tags=[Tags.entities]) async def detach( background_tasks: BackgroundTasks, entity_did: str = "did:sov:test:1234", @@ -186,13 +186,11 @@ async def detach( limit: int = 100, db: Session = Depends(sql_db.get_db), ) -> dict[str, str]: - background_tasks.add_task( - sql_crud.set_attached_by_entity_did, db, entity_did, False - ) - return {"message": "Detaching in the background"} + entity = sql_crud.set_attached_by_entity_did(db, entity_did, False) + return entity -@router.post("/api/v1/attach") +@router.post("/api/v1/attach", tags=[Tags.entities]) async def attach( background_tasks: BackgroundTasks, entity_did: str = "did:sov:test:1234", @@ -200,27 +198,28 @@ async def attach( limit: int = 100, db: Session = Depends(sql_db.get_db), ) -> dict[str, str]: + if sql_crud.get_entity_by_did(db, entity_did) is None: + raise ClanError(f"Entity with did '{entity_did}' not found") + background_tasks.add_task(attach_entity, db, entity_did) return {"message": "Attaching in the background"} -# TODO def attach_entity(db: Session, entity_did: str) -> None: db_entity = sql_crud.set_attached_by_entity_did(db, entity_did, True) try: - if db_entity is not None: - while db_entity.attached: - # query status endpoint - # https://www.python-httpx.org/ - response = httpx.get(f"http://{db_entity.ip}", timeout=2) - print(response) - # test with: - # while true ; do printf 'HTTP/1.1 200 OK\r\n\r\ncool, thanks' | nc -l -N localhost 5555 ; done - # client test (apt install python3-httpx): - # httpx http://localhost:5555 - # except not reached set false - time.sleep(1) - except Exception as e: - print(e) - if db_entity is not None: - db_entity = sql_crud.set_attached_by_entity_did(db, entity_did, False) + while db_entity.attached: + # query status endpoint + # https://www.python-httpx.org/ + response = httpx.get(f"http://{db_entity.ip}", timeout=2) + print(response) + # test with: + # while true ; do printf 'HTTP/1.1 200 OK\r\n\r\ncool, thanks' | nc -l -N localhost 5555 ; done + # client test (apt install python3-httpx): + # httpx http://localhost:5555 + # except not reached set false + time.sleep(1) + except Exception: + log.warning(f"Entity {entity_did} not reachable. Setting attached to false") + + db_entity = sql_crud.set_attached_by_entity_did(db, entity_did, False) diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index 96987f9..ccfb548 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -27,7 +27,7 @@ class ProducerBase(BaseModel): service_type: str = "3D Printing" endpoint_url: str = "http://127.0.0.1:8000" status: str = "unknown" - other: dict = {"test": "test"} + other: dict = {"action": ["register", "deregister", "delete", "create"]} class ProducerCreate(ProducerBase): @@ -91,7 +91,11 @@ class EntityBase(BaseModel): name: str = "C1" ip: str = "127.0.0.1" attached: bool = False - other: dict = {"test": "test"} + visible: bool = True + other: dict = { + "network": "Carlo's Home Network", + "roles": ["service repository", "service prosumer"], + } class EntityCreate(EntityBase): diff --git a/pkgs/clan-cli/clan_cli/webui/server.py b/pkgs/clan-cli/clan_cli/webui/server.py index 66b0f39..8975166 100644 --- a/pkgs/clan-cli/clan_cli/webui/server.py +++ b/pkgs/clan-cli/clan_cli/webui/server.py @@ -105,6 +105,27 @@ def start_server(args: argparse.Namespace) -> None: if not args.no_open: Thread(target=open_browser, args=(base_url, args.sub_url)).start() + # DELETE all data from the database + from . import sql_models + from .sql_db import engine + + sql_models.Base.metadata.drop_all(engine) + + if args.no_populate is False: + test_dir = Path(__file__).parent.parent.parent / "tests" + + if not test_dir.is_dir(): + raise ClanError(f"Could not find test dir: {test_dir}") + + test_db_api = test_dir / "test_db_api.py" + if not test_db_api.is_file(): + raise ClanError(f"Could not find test db api: {test_db_api}") + + import subprocess + + cmd = ["pytest", "-s", "-n0", str(test_db_api)] + subprocess.run(cmd, check=True) + uvicorn.run( "clan_cli.webui.app:app", host=args.host, diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index d6119c9..fcc8c15 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -3,6 +3,7 @@ from typing import List, Optional from sqlalchemy.orm import Session from sqlalchemy.sql.expression import true +from ..errors import ClanError from . import schemas, sql_models ######################### @@ -153,21 +154,18 @@ def get_attached_entities( ) -# set attached -# None if did not found # Returns same entity if setting didnt changed something def set_attached_by_entity_did( db: Session, entity_did: str, value: bool -) -> Optional[sql_models.Entity]: - # ste attached to true +) -> sql_models.Entity: db_entity = get_entity_by_did(db, entity_did) - if db_entity is not None: - # db_entity.attached = Column(True) - setattr(db_entity, "attached", value) - # save changes in db - db.add(db_entity) - db.commit() - db.refresh(db_entity) - return db_entity - else: - return db_entity + if db_entity is None: + raise ClanError(f"Entity with did '{entity_did}' not found") + + setattr(db_entity, "attached", value) + + # save changes in db + db.add(db_entity) + db.commit() + db.refresh(db_entity) + return db_entity diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index 88231ca..68ab103 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -26,6 +26,7 @@ class Entity(Base): name = Column(String, index=True) ip = Column(String, index=True) attached = Column(Boolean, index=True) + visible = Column(Boolean, index=True) ## Non queryable body ## # In here we deposit: Network, Roles, Visible, etc. diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 5f6d16e..9e24e4d 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -77,7 +77,9 @@ def test_producer(api: TestClient) -> None: "service_type": "3D Printing", "endpoint_url": "http://127.0.0.1:8000", "status": "unknown", - "other": {"test": "test"}, + "other": { + "action": ["register", "deregister", "delete", "create"] + }, "entity_did": default_entity_did, } paramter = "producer" @@ -92,7 +94,9 @@ def test_producer2(api: TestClient) -> None: "service_type": "Fax", "endpoint_url": "http://127.0.0.1:8001", "status": "unknown", - "other": {"faxen": "dicke"}, + "other": { + "action": ["register", "deregister", "delete", "create"] + }, "entity_did": default_entity_did2, } paramter = "producer" @@ -107,7 +111,9 @@ def test_producer3(api: TestClient) -> None: "service_type": "VR-Stream", "endpoint_url": "http://127.0.0.1:8002", "status": "unknown", - "other": {"oculos": "rift"}, + "other": { + "action": ["register", "deregister", "delete", "create"] + }, "entity_did": default_entity_did3, } paramter = "producer" @@ -122,7 +128,9 @@ def test_producer4(api: TestClient) -> None: "service_type": "gallary", "endpoint_url": "http://127.0.0.1:8003", "status": "unknown", - "other": {"nice": "pics"}, + "other": { + "action": ["register", "deregister", "delete", "create"] + }, "entity_did": default_entity_did4, } paramter = "producer" @@ -137,7 +145,9 @@ def test_producer5(api: TestClient) -> None: "service_type": "Game-Shop", "endpoint_url": "http://127.0.0.1:8004", "status": "unknown", - "other": {"war": "games"}, + "other": { + "action": ["register", "deregister", "delete", "create"] + }, "entity_did": default_entity_did5, } paramter = "producer" @@ -263,7 +273,11 @@ def test_entity(api: TestClient) -> None: "name": "C1", "ip": "127.0.0.1", "attached": False, - "other": {"test": "test"}, + "visible": True, + "other": { + "network": "Carlo1's Home Network", + "roles": ["service repository", "service consumer"], + }, } paramter = "entity" # get_request = "entity_did=did%3Asov%3Atest%3A1234" @@ -276,7 +290,11 @@ def test_entity2(api: TestClient) -> None: "name": "C2", "ip": "127.0.0.2", "attached": False, - "other": {"test": "test"}, + "visible": True, + "other": { + "network": "Carlo2's Home Network", + "roles": ["service repository", "service prosumer"], + }, } paramter = "entity" get_request = "entity_did=" + url.quote(default_entity_did2) From 4e0346d0a0e73c7efbf41100c40ca5590c7e7dfb Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sat, 9 Dec 2023 18:57:55 +0100 Subject: [PATCH 17/29] nix fmt --- README.md | 2 +- pkgs/clan-cli/tests/test_db_api.py | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 85d2b42..ef9cb23 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Let's set up your Git workflow to collaborate effectively: - URL of Gitea instance: `https://gitea.gchq.icu` - Name of new Login [gitea.gchq.icu]: `gitea.gchq.icu:7171` - Do you have an access token? Yes - - Token: ****\***** + - Token: \***\*\*\*\*** - Set Optional settings: No 2. **Git Workflow**: diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 9e24e4d..b26a65e 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -77,9 +77,7 @@ def test_producer(api: TestClient) -> None: "service_type": "3D Printing", "endpoint_url": "http://127.0.0.1:8000", "status": "unknown", - "other": { - "action": ["register", "deregister", "delete", "create"] - }, + "other": {"action": ["register", "deregister", "delete", "create"]}, "entity_did": default_entity_did, } paramter = "producer" @@ -94,9 +92,7 @@ def test_producer2(api: TestClient) -> None: "service_type": "Fax", "endpoint_url": "http://127.0.0.1:8001", "status": "unknown", - "other": { - "action": ["register", "deregister", "delete", "create"] - }, + "other": {"action": ["register", "deregister", "delete", "create"]}, "entity_did": default_entity_did2, } paramter = "producer" @@ -111,9 +107,7 @@ def test_producer3(api: TestClient) -> None: "service_type": "VR-Stream", "endpoint_url": "http://127.0.0.1:8002", "status": "unknown", - "other": { - "action": ["register", "deregister", "delete", "create"] - }, + "other": {"action": ["register", "deregister", "delete", "create"]}, "entity_did": default_entity_did3, } paramter = "producer" @@ -128,9 +122,7 @@ def test_producer4(api: TestClient) -> None: "service_type": "gallary", "endpoint_url": "http://127.0.0.1:8003", "status": "unknown", - "other": { - "action": ["register", "deregister", "delete", "create"] - }, + "other": {"action": ["register", "deregister", "delete", "create"]}, "entity_did": default_entity_did4, } paramter = "producer" @@ -145,9 +137,7 @@ def test_producer5(api: TestClient) -> None: "service_type": "Game-Shop", "endpoint_url": "http://127.0.0.1:8004", "status": "unknown", - "other": { - "action": ["register", "deregister", "delete", "create"] - }, + "other": {"action": ["register", "deregister", "delete", "create"]}, "entity_did": default_entity_did5, } paramter = "producer" From 129e25e52e834417a6731274d76546f1940b097d Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 9 Dec 2023 18:58:59 +0100 Subject: [PATCH 18/29] fix linting --- pkgs/ui/src/app/access-point/page.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 19196a4..0e22a84 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -12,14 +12,14 @@ import { import { useEffect, useState } from "react"; interface RepositoryData { - entity_name: string; - entity_did: string; - network: string; - ip_address: string; + entity_name: string; + entity_did: string; + network: string; + ip_address: string; } export default function AccessPoint() { - const [repositoryData, setRepositoryData] = useState([]); + const [repositoryData, setRepositoryData] = useState([]); useEffect(() => { fetch("http://localhost:2979/api/v1/get_repositories", { From 0c08cde34c3a5295c178260af09e70cb7824e85d Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sat, 9 Dec 2023 19:10:11 +0100 Subject: [PATCH 19/29] Fixed testing issue. Improved README --- README.md | 10 ++++++---- pkgs/clan-cli/clan_cli/webui/__init__.py | 4 ++-- pkgs/clan-cli/clan_cli/webui/server.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ef9cb23..5d285c8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# 1Service Aware Network Project Repo +# Service Aware Network Project Repo -Welcome to our website repository! This repo is designed to help you and your team build high-quality websites efficiently. We've carefully chosen the technologies to make development smooth and enjoyable. Here's what you can expect from this template: +Welcome to our website repository! This repo is designed to build high-quality websites efficiently. We've carefully chosen the technologies to make development smooth and enjoyable. **Frontend**: Our frontend is powered by [React NextJS](https://nextjs.org/), a popular and versatile framework for building web applications. @@ -51,6 +51,7 @@ sudo echo "experimental-features = nix-command flakes" > '/etc/nix/nix.conf' 4. **Clone the Repository and Navigate**: - Clone this repository and navigate to it. + - If you are under Windows Subystem For Linux (WSL) please clone the repository to the home folder of your Linux. Do NOT clone it onto your Windows machine! 5. **Allow .envrc**: @@ -72,9 +73,10 @@ sudo echo "experimental-features = nix-command flakes" > '/etc/nix/nix.conf' - To start the backend server, execute: ```bash - clan webui --reload --no-open --log-level debug + clan webui --reload --no-open --log-level debug --populate ``` - The server will automatically restart if any Python files change. + - The `--populate` flag will automatically populate the database with dummy data 8. **Build the Frontend**: @@ -194,8 +196,8 @@ If you need to inspect the Nix sandbox while running tests, follow these steps: 2. Use `cntr` and `psgrep` to attach to the Nix sandbox. This allows you to interactively debug your code while it's paused. For example: ```bash - cntr exec -w your_sandbox_name psgrep -a -x your_python_process_name + cntr attach ``` These debugging and testing methods will help you identify and fix issues in your backend code efficiently, ensuring the reliability and robustness of your application. diff --git a/pkgs/clan-cli/clan_cli/webui/__init__.py b/pkgs/clan-cli/clan_cli/webui/__init__.py index 4fc79ad..1305e78 100644 --- a/pkgs/clan-cli/clan_cli/webui/__init__.py +++ b/pkgs/clan-cli/clan_cli/webui/__init__.py @@ -23,9 +23,9 @@ def register_parser(parser: argparse.ArgumentParser) -> None: "--host", type=str, default="localhost", help="Host to listen on" ) parser.add_argument( - "--no-populate", + "--populate", action="store_true", - help="Don't populate the database with dummy data", + help="Populate the database with dummy data", default=False, ) parser.add_argument( diff --git a/pkgs/clan-cli/clan_cli/webui/server.py b/pkgs/clan-cli/clan_cli/webui/server.py index 8975166..762ccb2 100644 --- a/pkgs/clan-cli/clan_cli/webui/server.py +++ b/pkgs/clan-cli/clan_cli/webui/server.py @@ -111,7 +111,7 @@ def start_server(args: argparse.Namespace) -> None: sql_models.Base.metadata.drop_all(engine) - if args.no_populate is False: + if args.populate: test_dir = Path(__file__).parent.parent.parent / "tests" if not test_dir.is_dir(): From 1cfb5f9fa83a8e0e460081ed17d0f575df20fffe Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 9 Dec 2023 19:11:30 +0100 Subject: [PATCH 20/29] transform data received from endpoint --- pkgs/ui/src/app/access-point/page.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 0e22a84..05feee3 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -29,8 +29,16 @@ export default function AccessPoint() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); + + const transformedData = jsonData.map((item) => ({ + entity_name: item.service_name, + entity_did: item.entity_did, + network: item.network, + ip_address: "", // You might need to set an appropriate default value + })); + jsonData.length > 0 - ? setRepositoryData(jsonData) + ? setRepositoryData(transformedData) : setRepositoryData(APServiceRepositoryDummyData); }), ) From 37d34d4f36b2201b0f01a46ac0de8965fa4ea73d Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sat, 9 Dec 2023 19:29:42 +0100 Subject: [PATCH 21/29] fixed the issues for merge --- pkgs/ui/src/app/access-point/page.tsx | 9 +++------ pkgs/ui/src/app/client-1/page.tsx | 10 ++-------- pkgs/ui/src/app/client-2/page.tsx | 10 ++-------- pkgs/ui/src/app/home/page.tsx | 6 ++---- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 05feee3..ba05481 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -6,7 +6,6 @@ import { APSummaryDetails, APAttachmentsDummyData, APAttachmentsTableConfig, - APServiceRepositoryDummyData, APServiceRepositoryTableConfig, } from "@/mock/access_point"; import { useEffect, useState } from "react"; @@ -30,16 +29,14 @@ export default function AccessPoint() { resp.json().then((jsonData) => { console.log(jsonData); - const transformedData = jsonData.map((item) => ({ + const transformedData = jsonData.map((item: { service_name: any; entity_did: any; network: any; }) => ({ entity_name: item.service_name, entity_did: item.entity_did, network: item.network, - ip_address: "", // You might need to set an appropriate default value + ip_address: "", })); - jsonData.length > 0 - ? setRepositoryData(transformedData) - : setRepositoryData(APServiceRepositoryDummyData); + setRepositoryData(transformedData); }), ) .then() diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index 3eb97c7..a2f6b0e 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -3,10 +3,8 @@ import SummaryDetails from "@/components/summary_card"; import { Client1SummaryDetails, - Client1ConsumerData, Client1ConsumerTableConfig, Client1ProducerTableConfig, - Client1ProducerData, } from "@/mock/client_1"; import CustomTable from "@/components/table"; import { useEffect, useState } from "react"; @@ -23,9 +21,7 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 - ? setConsumerData(jsonData) - : setConsumerData(Client1ConsumerData); + setConsumerData(jsonData); }), ) .then() @@ -38,9 +34,7 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 - ? setProducerData(jsonData) - : setProducerData(Client1ProducerData); + setProducerData(jsonData); }), ) .then() diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client-2/page.tsx index 43da43d..8b9a8d0 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client-2/page.tsx @@ -2,9 +2,7 @@ import SummaryDetails from "@/components/summary_card"; import { - Client2ConsumerData, Client2ConsumerTableConfig, - Client2ProducerData, Client2ProducerTableConfig, Client2SummaryDetails, } from "@/mock/client_2"; @@ -23,9 +21,7 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 - ? setConsumerData(jsonData) - : setConsumerData(Client2ConsumerData); + setConsumerData(jsonData); }), ) .then() @@ -38,9 +34,7 @@ export default function Client1() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 - ? setProducerData(jsonData) - : setProducerData(Client2ProducerData); + setProducerData(jsonData); }), ) .then() diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index 08e702e..16b0984 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -3,7 +3,7 @@ import { NoDataOverlay } from "@/components/noDataOverlay"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; -import { HomeDummyData, HomeTableConfig } from "@/mock/home"; +import { HomeTableConfig } from "@/mock/home"; import { useEffect, useState } from "react"; export default function Home() { @@ -17,9 +17,7 @@ export default function Home() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - jsonData.length > 0 - ? setHomeData(jsonData) - : setHomeData(HomeDummyData); + setHomeData(jsonData); }), ) .then() From 556b3867876bf4f8e02b76a1f7a4e0aade7328b7 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sat, 9 Dec 2023 19:39:42 +0100 Subject: [PATCH 22/29] fix formatting --- pkgs/ui/src/app/access-point/page.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index ba05481..230ee98 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -29,12 +29,14 @@ export default function AccessPoint() { resp.json().then((jsonData) => { console.log(jsonData); - const transformedData = jsonData.map((item: { service_name: any; entity_did: any; network: any; }) => ({ - entity_name: item.service_name, - entity_did: item.entity_did, - network: item.network, - ip_address: "", - })); + const transformedData = jsonData.map( + (item: { service_name: any; entity_did: any; network: any }) => ({ + entity_name: item.service_name, + entity_did: item.entity_did, + network: item.network, + ip_address: "", + }), + ); setRepositoryData(transformedData); }), From f296c01abc24a4c4db02e7929fad3d389df17c81 Mon Sep 17 00:00:00 2001 From: ui-asset-bot Date: Sat, 9 Dec 2023 18:45:38 +0000 Subject: [PATCH 23/29] update ui-assets.nix --- pkgs/ui/nix/ui-assets.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/ui/nix/ui-assets.nix b/pkgs/ui/nix/ui-assets.nix index 9e81835..8d7ce17 100644 --- a/pkgs/ui/nix/ui-assets.nix +++ b/pkgs/ui/nix/ui-assets.nix @@ -1,5 +1,5 @@ { fetchzip }: fetchzip { - url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/16glc9nkcqsalf5jwcwcsv1nx65cqwrqr95n1ghmb365nxi57bb4/assets.tar.gz"; - sha256 = "16glc9nkcqsalf5jwcwcsv1nx65cqwrqr95n1ghmb365nxi57bb4"; + url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/07dai984ffhflf6i6bs5dg1dybgq6s4vrkwi1fr05sxppg7bz1wq/assets.tar.gz"; + sha256 = "07dai984ffhflf6i6bs5dg1dybgq6s4vrkwi1fr05sxppg7bz1wq"; } From b12201c559baa97c531e52a561779b3f68e99afa Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sat, 9 Dec 2023 20:57:05 +0100 Subject: [PATCH 24/29] Added resolution endpoint. Added delete endpoints. Added tests for new endpoints --- .../clan_cli/webui/routers/sql_connect.py | 91 ++++++++++++++++++- pkgs/clan-cli/clan_cli/webui/schemas.py | 26 ++++++ pkgs/clan-cli/clan_cli/webui/sql_crud.py | 75 ++++++++++++++- pkgs/clan-cli/clan_cli/webui/sql_models.py | 3 +- pkgs/clan-cli/clan_cli/webui/tags.py | 5 + pkgs/clan-cli/tests/test_db_api.py | 46 ++++++++++ 6 files changed, 242 insertions(+), 4 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py index 9fe73f7..05da969 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py @@ -17,6 +17,8 @@ from ..schemas import ( ProducerCreate, Repository, RepositoryCreate, + Resolution, + ResolutionCreate, ) from ..tags import Tags @@ -61,6 +63,15 @@ def get_producer( return producer +@router.delete("/api/v1/delete_producer", tags=[Tags.producers]) +def delete_producer( + entity_did: str = "did:sov:test:1234", + db: Session = Depends(sql_db.get_db), +) -> dict[str, str]: + sql_crud.delete_producer_by_entity_did(db, entity_did) + return {"message": "Producer deleted"} + + ######################### # # # Consumer # @@ -97,6 +108,15 @@ def get_consumer( return consumer +@router.delete("/api/v1/delete_consumer", tags=[Tags.consumers]) +def delete_consumer( + entity_did: str = "did:sov:test:1234", + db: Session = Depends(sql_db.get_db), +) -> dict[str, str]: + sql_crud.delete_consumer_by_entity_did(db, entity_did) + return {"message": "Consumer deleted"} + + ######################### # # # REPOSITORY # @@ -133,10 +153,19 @@ def get_repository( limit: int = 100, db: Session = Depends(sql_db.get_db), ) -> List[sql_models.Repository]: - repository = sql_crud.get_repository_by_did(db, did=entity_did) + repository = sql_crud.get_repository_by_entity_did(db, did=entity_did) return repository +@router.delete("/api/v1/delete_repository", tags=[Tags.repositories]) +def delete_repository( + entity_did: str = "did:sov:test:1234", + db: Session = Depends(sql_db.get_db), +) -> dict[str, str]: + sql_crud.delete_repository_by_entity_did(db, did=entity_did) + return {"message": "Repository deleted"} + + ######################### # # # Entity # @@ -185,7 +214,7 @@ async def detach( skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db), -) -> dict[str, str]: +) -> sql_models.Entity: entity = sql_crud.set_attached_by_entity_did(db, entity_did, False) return entity @@ -223,3 +252,61 @@ def attach_entity(db: Session, entity_did: str) -> None: log.warning(f"Entity {entity_did} not reachable. Setting attached to false") db_entity = sql_crud.set_attached_by_entity_did(db, entity_did, False) + + +@router.delete("/api/v1/delete_entity_recursive", tags=[Tags.entities]) +def delete_entity( + entity_did: str = "did:sov:test:1234", + db: Session = Depends(sql_db.get_db), +) -> dict[str, str]: + sql_crud.delete_entity_by_did_recursive(db, did=entity_did) + return {"message": "Entity deleted and all relations to that entity"} + + +######################### +# # +# Resolution # +# # +######################### +@router.post( + "/api/v1/create_resolution", response_model=Resolution, tags=[Tags.resolutions] +) +def create_resolution( + resolution: ResolutionCreate, + db: Session = Depends(sql_db.get_db), +) -> sql_models.Resolution: + return sql_crud.create_resolution(db, resolution) + + +@router.get( + "/api/v1/get_resolutions", response_model=List[Resolution], tags=[Tags.resolutions] +) +def get_resolutions( + skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db) +) -> List[sql_models.Resolution]: + resolutions = sql_crud.get_resolutions(db, skip=skip, limit=limit) + return resolutions + + +@router.get( + "/api/v1/get_resolution", response_model=List[Resolution], tags=[Tags.resolutions] +) +def get_resolution( + requester_did: str = "did:sov:test:1122", + skip: int = 0, + limit: int = 100, + db: Session = Depends(sql_db.get_db), +) -> List[sql_models.Resolution]: + resolution = sql_crud.get_resolution_by_requester_did( + db, requester_did=requester_did + ) + return resolution + + +@router.delete("/api/v1/delete_resolution", tags=[Tags.resolutions]) +def delete_resolution( + requester_did: str = "did:sov:test:1122", + db: Session = Depends(sql_db.get_db), +) -> dict[str, str]: + sql_crud.delete_resolution_by_requester_did(db, requester_did=requester_did) + return {"message": "Resolution deleted"} diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index ccfb548..303e0f7 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -109,3 +109,29 @@ class Entity(EntityCreate): class Config: orm_mode = True + + +######################### +# # +# Resolution # +# # +######################### + + +class ResolutionBase(BaseModel): + requester_name: str = "C1" + requester_did: str = "did:sov:test:1122" + resolved_did: str = "did:sov:test:1234" + other: dict = {"test": "test"} + + +class ResolutionCreate(ResolutionBase): + pass + + +class Resolution(ResolutionCreate): + timestamp: datetime + id: int + + class Config: + orm_mode = True diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index fcc8c15..cf03c41 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -41,6 +41,13 @@ def get_producers_by_entity_did( ) +def delete_producer_by_entity_did(db: Session, entity_did: str) -> None: + db.query(sql_models.Producer).filter( + sql_models.Producer.entity_did == entity_did + ).delete() + db.commit() + + ######################### # # # Consumer # @@ -76,6 +83,13 @@ def get_consumers_by_entity_did( ) +def delete_consumer_by_entity_did(db: Session, entity_did: str) -> None: + db.query(sql_models.Consumer).filter( + sql_models.Consumer.entity_did == entity_did + ).delete() + db.commit() + + ######################### # # # REPOSITORY # @@ -105,7 +119,7 @@ def get_repository_by_uuid(db: Session, uuid: str) -> Optional[sql_models.Reposi ) -def get_repository_by_did( +def get_repository_by_entity_did( db: Session, did: str, skip: int = 0, limit: int = 100 ) -> List[sql_models.Repository]: return ( @@ -117,6 +131,13 @@ def get_repository_by_did( ) +def delete_repository_by_entity_did(db: Session, did: str) -> None: + db.query(sql_models.Repository).filter( + sql_models.Repository.entity_did == did + ).delete() + db.commit() + + ######################### # # # Entity # @@ -169,3 +190,55 @@ def set_attached_by_entity_did( db.commit() db.refresh(db_entity) return db_entity + + +def delete_entity_by_did(db: Session, did: str) -> None: + db.query(sql_models.Entity).filter(sql_models.Entity.did == did).delete() + db.commit() + + +def delete_entity_by_did_recursive(db: Session, did: str) -> None: + delete_producer_by_entity_did(db, did) + delete_consumer_by_entity_did(db, did) + delete_repository_by_entity_did(db, did) + delete_entity_by_did(db, did) + + +######################### +# # +# Resolution # +# # +######################### +def create_resolution( + db: Session, resolution: schemas.ResolutionCreate +) -> sql_models.Resolution: + db_resolution = sql_models.Resolution(**resolution.dict()) + db.add(db_resolution) + db.commit() + db.refresh(db_resolution) + return db_resolution + + +def get_resolutions( + db: Session, skip: int = 0, limit: int = 100 +) -> List[sql_models.Resolution]: + return db.query(sql_models.Resolution).offset(skip).limit(limit).all() + + +def get_resolution_by_requester_did( + db: Session, requester_did: str, skip: int = 0, limit: int = 100 +) -> List[sql_models.Resolution]: + return ( + db.query(sql_models.Resolution) + .filter(sql_models.Resolution.requester_did == requester_did) + .offset(skip) + .limit(limit) + .all() + ) + + +def delete_resolution_by_requester_did(db: Session, requester_did: str) -> None: + db.query(sql_models.Resolution).filter( + sql_models.Resolution.requester_did == requester_did + ).delete() + db.commit() diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index 68ab103..c606b9f 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -107,4 +107,5 @@ class Resolution(Base): requester_name = Column(String, index=True) requester_did = Column(String, index=True) resolved_did = Column(String, index=True) - timestamp = Column(DateTime, index=True) + other = Column(JSON) + timestamp = Column(DateTime(timezone=True), server_default=func.now()) diff --git a/pkgs/clan-cli/clan_cli/webui/tags.py b/pkgs/clan-cli/clan_cli/webui/tags.py index 78f7968..7f11e48 100644 --- a/pkgs/clan-cli/clan_cli/webui/tags.py +++ b/pkgs/clan-cli/clan_cli/webui/tags.py @@ -7,6 +7,7 @@ class Tags(Enum): consumers = "consumers" entities = "entities" repositories = "repositories" + resolutions = "resolution" def __str__(self) -> str: return self.value @@ -29,4 +30,8 @@ tags_metadata: List[Dict[str, Any]] = [ "name": str(Tags.repositories), "description": "Operations on a repository.", }, + { + "name": str(Tags.resolutions), + "description": "Operations on a resolution.", + }, ] diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index b26a65e..2595a86 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -38,8 +38,11 @@ def make_test_post_and_get( headers={"Content-Type": "application/json"}, ) assert response.status_code == 200 + if paramter == "repository": assert_extra_info(["time_created"], request_body, response.json()) + elif paramter == "resolution": + assert_extra_info(["timestamp", "id"], request_body, response.json()) elif paramter == "consumer": assert_extra_info(["id"], request_body, response.json()) elif paramter == "entity": @@ -55,6 +58,8 @@ def make_test_post_and_get( assert response.status_code == 200 if paramter == "repository": assert_extra_info(["time_created"], request_body, response.json()[0]) + elif paramter == "resolution": + assert_extra_info(["timestamp", "id"], request_body, response.json()[0]) elif paramter == "consumer": assert_extra_info(["id"], request_body, response.json()[0]) elif paramter == "entity": @@ -289,3 +294,44 @@ def test_entity2(api: TestClient) -> None: paramter = "entity" get_request = "entity_did=" + url.quote(default_entity_did2) make_test_post_and_get(api, request_body, paramter, get_request) + + +######################### +# # +# Resolution # +# # +######################### +def test_resolution(api: TestClient) -> None: + request_body = { + "requester_did": default_entity_did2, + "requester_name": "C2", + "resolved_did": default_entity_did, + "other": {"test": "test"}, + } + paramter = "resolution" + get_request = "requester_did=" + url.quote(default_entity_did2) + make_test_post_and_get(api, request_body, paramter, get_request) + + +def test_resolution2(api: TestClient) -> None: + request_body = { + "requester_did": default_entity_did3, + "requester_name": "C3", + "resolved_did": default_entity_did, + "other": {"test": "test"}, + } + paramter = "resolution" + get_request = "requester_did=" + url.quote(default_entity_did3) + make_test_post_and_get(api, request_body, paramter, get_request) + + +def test_resolution3(api: TestClient) -> None: + request_body = { + "requester_did": default_entity_did4, + "requester_name": "C4", + "resolved_did": default_entity_did, + "other": {"test": "test"}, + } + paramter = "resolution" + get_request = "requester_did=" + url.quote(default_entity_did4) + make_test_post_and_get(api, request_body, paramter, get_request) From 5262d83da08d5b0468be0bb85fa6e623bd1d5595 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sun, 10 Dec 2023 00:15:34 +0100 Subject: [PATCH 25/29] [Functionality] Request DID Resolution - fetch resolution data - adjustments --- pkgs/ui/src/app/access-point/page.tsx | 12 +---------- pkgs/ui/src/app/client-1/page.tsx | 2 -- pkgs/ui/src/app/client-2/page.tsx | 1 - .../app/distributed-ledger-gateway/page.tsx | 20 +++++++++++++++++-- pkgs/ui/src/app/home/page.tsx | 1 - pkgs/ui/src/mock/dlg/index.ts | 14 ++++++------- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 230ee98..6f07177 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -28,17 +28,7 @@ export default function AccessPoint() { .then((resp) => resp.json().then((jsonData) => { console.log(jsonData); - - const transformedData = jsonData.map( - (item: { service_name: any; entity_did: any; network: any }) => ({ - entity_name: item.service_name, - entity_did: item.entity_did, - network: item.network, - ip_address: "", - }), - ); - - setRepositoryData(transformedData); + setRepositoryData(jsonData); }), ) .then() diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx index a2f6b0e..763702a 100644 --- a/pkgs/ui/src/app/client-1/page.tsx +++ b/pkgs/ui/src/app/client-1/page.tsx @@ -16,7 +16,6 @@ export default function Client1() { useEffect(() => { fetch("http://localhost:2979/api/v1/get_consumers", { method: "GET", - // credentials: 'include', }) .then((resp) => resp.json().then((jsonData) => { @@ -29,7 +28,6 @@ export default function Client1() { fetch("http://localhost:2979/api/v1/get_producers", { method: "GET", - // credentials: 'include', }) .then((resp) => resp.json().then((jsonData) => { diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client-2/page.tsx index 8b9a8d0..b3a7b75 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client-2/page.tsx @@ -16,7 +16,6 @@ export default function Client1() { useEffect(() => { fetch("http://localhost:2979/api/v1/get_consumers", { method: "GET", - // credentials: 'include', }) .then((resp) => resp.json().then((jsonData) => { diff --git a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx index cc1c15e..41e83fa 100644 --- a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx +++ b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx @@ -1,14 +1,30 @@ "use client"; import { - DLGResolutionDummyData, DLGResolutionTableConfig, DLGSummaryDetails, } from "@/mock/dlg"; import CustomTable from "@/components/table"; import SummaryDetails from "@/components/summary_card"; +import {useEffect, useState} from "react"; export default function DLG() { + const [resolutionData, setResolutionData] = useState([]); + + useEffect(() => { + fetch("http://localhost:2979/api/v1/get_resolutions", { + method: "GET", + }) + .then((resp) => + resp.json().then((jsonData) => { + console.log(jsonData); + setResolutionData(jsonData); + }), + ) + .then() + .catch(); + }, []); + return (

DID Resolution View

diff --git a/pkgs/ui/src/app/home/page.tsx b/pkgs/ui/src/app/home/page.tsx index 16b0984..d6c3566 100644 --- a/pkgs/ui/src/app/home/page.tsx +++ b/pkgs/ui/src/app/home/page.tsx @@ -12,7 +12,6 @@ export default function Home() { useEffect(() => { fetch("http://localhost:2979/api/v1/get_entities", { method: "GET", - // credentials: 'include', }) .then((resp) => resp.json().then((jsonData) => { diff --git a/pkgs/ui/src/mock/dlg/index.ts b/pkgs/ui/src/mock/dlg/index.ts index 0163634..2e33f79 100644 --- a/pkgs/ui/src/mock/dlg/index.ts +++ b/pkgs/ui/src/mock/dlg/index.ts @@ -16,14 +16,14 @@ export const DLGSummaryDetails = [ export const DLGResolutionDummyData = [ { requester_name: "C1", - requester_DID: "did:sov:test:1234", - DID_resolved: "did:sov:test:1234", + requester_did: "did:sov:test:1234", + resolved_did: "did:sov:test:1234", timestamp: "2023.11.01 17:05:45", }, { requester_name: "C2", - requester_DID: "did:sov:test:5678", - DID_resolved: "did:sov:test:5678", + requester_did: "did:sov:test:5678", + resolved_did: "did:sov:test:5678", timestamp: "2023.12.01 15:05:50", }, ]; @@ -34,12 +34,12 @@ export const DLGResolutionTableConfig = [ label: "Requester name", }, { - key: "requester_DID", + key: "requester_did", label: "Requester DID", }, { - key: "DID_resolved", - label: "DID resolved", + key: "resolved_did", + label: "Resolved DID", }, { key: "timestamp", From 61261d7ac3c61c27558ec53ae07c5f88ef7510d4 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Sun, 10 Dec 2023 00:30:30 +0100 Subject: [PATCH 26/29] [Functionality] Request DID Resolution - fixes --- pkgs/ui/src/app/access-point/page.tsx | 1 - pkgs/ui/src/app/distributed-ledger-gateway/page.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 6f07177..6a18acf 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -23,7 +23,6 @@ export default function AccessPoint() { useEffect(() => { fetch("http://localhost:2979/api/v1/get_repositories", { method: "GET", - // credentials: 'include', }) .then((resp) => resp.json().then((jsonData) => { diff --git a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx index 41e83fa..731737a 100644 --- a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx +++ b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx @@ -6,7 +6,7 @@ import { } from "@/mock/dlg"; import CustomTable from "@/components/table"; import SummaryDetails from "@/components/summary_card"; -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; export default function DLG() { const [resolutionData, setResolutionData] = useState([]); From 88578fe0077711fd59c1d728b212b5d9f5a23d37 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Sun, 10 Dec 2023 00:45:52 +0100 Subject: [PATCH 27/29] fix formatting --- pkgs/clan-cli/bin/clan | 0 pkgs/clan-cli/bin/clan-config | 0 pkgs/clan-cli/bin/gen-openapi | 0 pkgs/node-packages/generate.sh | 0 pkgs/ui/nix/update-ui-assets.sh | 0 pkgs/ui/src/app/distributed-ledger-gateway/page.tsx | 5 +---- 6 files changed, 1 insertion(+), 4 deletions(-) mode change 100755 => 100644 pkgs/clan-cli/bin/clan mode change 100755 => 100644 pkgs/clan-cli/bin/clan-config mode change 100755 => 100644 pkgs/clan-cli/bin/gen-openapi mode change 100755 => 100644 pkgs/node-packages/generate.sh mode change 100755 => 100644 pkgs/ui/nix/update-ui-assets.sh diff --git a/pkgs/clan-cli/bin/clan b/pkgs/clan-cli/bin/clan old mode 100755 new mode 100644 diff --git a/pkgs/clan-cli/bin/clan-config b/pkgs/clan-cli/bin/clan-config old mode 100755 new mode 100644 diff --git a/pkgs/clan-cli/bin/gen-openapi b/pkgs/clan-cli/bin/gen-openapi old mode 100755 new mode 100644 diff --git a/pkgs/node-packages/generate.sh b/pkgs/node-packages/generate.sh old mode 100755 new mode 100644 diff --git a/pkgs/ui/nix/update-ui-assets.sh b/pkgs/ui/nix/update-ui-assets.sh old mode 100755 new mode 100644 diff --git a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx index 731737a..73312b2 100644 --- a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx +++ b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx @@ -1,9 +1,6 @@ "use client"; -import { - DLGResolutionTableConfig, - DLGSummaryDetails, -} from "@/mock/dlg"; +import { DLGResolutionTableConfig, DLGSummaryDetails } from "@/mock/dlg"; import CustomTable from "@/components/table"; import SummaryDetails from "@/components/summary_card"; import { useEffect, useState } from "react"; From 5c0696b1bf959e5ebd1a800f9e4fa228c1989f6d Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Sun, 10 Dec 2023 18:16:59 +0100 Subject: [PATCH 28/29] Fixing asset pipeline --- .gitea/workflows/ui_assets.yaml | 2 +- pkgs/ui/nix/update-ui-assets.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/ui_assets.yaml b/.gitea/workflows/ui_assets.yaml index 3c7f527..d4e1088 100644 --- a/.gitea/workflows/ui_assets.yaml +++ b/.gitea/workflows/ui_assets.yaml @@ -25,7 +25,7 @@ jobs: || echo "$MODIFIED_FILES" | grep -q ".gitea/workflows/ui_assets.yaml"; then echo "UI files have changed" - ./pkgs/ui/nix/update-ui-assets.sh + bash ./pkgs/ui/nix/update-ui-assets.sh # git push if we have a diff diff --git a/pkgs/ui/nix/update-ui-assets.sh b/pkgs/ui/nix/update-ui-assets.sh index 0bfc6b1..d3ab7d9 100644 --- a/pkgs/ui/nix/update-ui-assets.sh +++ b/pkgs/ui/nix/update-ui-assets.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # shellcheck shell=bash set -xeuo pipefail From 85d62aac8997068c8545cbcf10084b8731a1aa86 Mon Sep 17 00:00:00 2001 From: ui-asset-bot Date: Sun, 10 Dec 2023 17:30:51 +0000 Subject: [PATCH 29/29] update ui-assets.nix --- pkgs/ui/nix/ui-assets.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/ui/nix/ui-assets.nix b/pkgs/ui/nix/ui-assets.nix index 8d7ce17..848c912 100644 --- a/pkgs/ui/nix/ui-assets.nix +++ b/pkgs/ui/nix/ui-assets.nix @@ -1,5 +1,5 @@ { fetchzip }: fetchzip { - url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/07dai984ffhflf6i6bs5dg1dybgq6s4vrkwi1fr05sxppg7bz1wq/assets.tar.gz"; - sha256 = "07dai984ffhflf6i6bs5dg1dybgq6s4vrkwi1fr05sxppg7bz1wq"; + url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/042x4cdb35zzwjx3fc7v0qxil1fbam5xrgg42v816yih9kl5dqrz/assets.tar.gz"; + sha256 = "042x4cdb35zzwjx3fc7v0qxil1fbam5xrgg42v816yih9kl5dqrz"; }