From 6bfb892233bbe90fb1b0998e3eee8057f7f0b044 Mon Sep 17 00:00:00 2001 From: Immanuel Kunz Date: Tue, 18 Jul 2023 09:30:24 +0200 Subject: [PATCH] Add public certificates route (#458) * add public certificates route * Update redirect to /cloud --------- Co-authored-by: Angelika Schneider --- src/lib/PublicCertificateCard.svelte | 35 +++++++++++++++++++++ src/lib/orchestrator.ts | 21 +++++++++++++ src/routes/public/certificates/+page.svelte | 24 ++++++++++++++ src/routes/public/certificates/+page.ts | 17 ++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/lib/PublicCertificateCard.svelte create mode 100644 src/routes/public/certificates/+page.svelte create mode 100644 src/routes/public/certificates/+page.ts diff --git a/src/lib/PublicCertificateCard.svelte b/src/lib/PublicCertificateCard.svelte new file mode 100644 index 0000000..ce1e4b8 --- /dev/null +++ b/src/lib/PublicCertificateCard.svelte @@ -0,0 +1,35 @@ + + + + "{certificate.name}" + + +

+ ID: + {certificate.id}
+ Name: + {certificate.name}
+ Service ID: + {certificate.cloudServiceId}
+ Issue Date: + {certificate.issueDate}
+ Expiration Date: + {certificate.expirationDate}
+ Schema: + {certificate.standard}
+ Assurance Level: + {certificate.assuranceLevel}
+ CAB: + {certificate.cab}
+ Description: + {certificate.description}
+

+
+
+
+
diff --git a/src/lib/orchestrator.ts b/src/lib/orchestrator.ts index 3553c80..b254afc 100644 --- a/src/lib/orchestrator.ts +++ b/src/lib/orchestrator.ts @@ -115,6 +115,10 @@ export interface ListCertificatesResponse { certificates: Certificate[]; } +export interface ListPublicCertificatesResponse { + certificates: Certificate[]; +} + export interface ListAssessmentResultsResponse { results: AssessmentResult[] } @@ -652,3 +656,20 @@ export async function listCertificates(): Promise { }); } +/** + * Retrieves a list of public certificates from the orchestrator service. + * + * @returns an array of {@link Certificate}s. + */ +export async function listPublicCertificates(): Promise { + const apiUrl = clouditorize(`/v1/orchestrator/public/certificates`) + + return fetch(apiUrl, { + method: 'GET', + }) + .then(throwError) + .then((res) => res.json()) + .then((response: ListPublicCertificatesResponse) => { + return response.certificates; + }); +} \ No newline at end of file diff --git a/src/routes/public/certificates/+page.svelte b/src/routes/public/certificates/+page.svelte new file mode 100644 index 0000000..aa6e257 --- /dev/null +++ b/src/routes/public/certificates/+page.svelte @@ -0,0 +1,24 @@ + + +

Certificates

+ +{#if certificates} + + + {#each certificates as certificate, i} + + + + {/each} + + +{:else} + No certificates issued yet. +{/if} diff --git a/src/routes/public/certificates/+page.ts b/src/routes/public/certificates/+page.ts new file mode 100644 index 0000000..2d9e1e8 --- /dev/null +++ b/src/routes/public/certificates/+page.ts @@ -0,0 +1,17 @@ +import { listPublicCertificates } from '$lib/orchestrator'; +import { redirectLogin } from '$lib/oauth'; + +/** + * @type {import('@sveltejs/kit').PageLoad} + */ +export async function load({ params, fetch, context }) { + return listPublicCertificates() + .then((certificates) => { + return { + certificates: certificates + }; + }) + .catch(() => { + redirectLogin('/cloud'); + }); +}