Skip to content

Commit

Permalink
Add public certificates route (#458)
Browse files Browse the repository at this point in the history
* add public certificates route

* Update redirect to /cloud

---------

Co-authored-by: Angelika Schneider <[email protected]>
  • Loading branch information
immqu and anatheka authored Jul 18, 2023
1 parent ff90a59 commit 6bfb892
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/lib/PublicCertificateCard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import { Card, CardBody, CardHeader, CardText } from 'sveltestrap';
import type { Certificate } from '$lib/orchestrator';
export let certificate: Certificate;
</script>

<Card class="mb-3 me-3">
<CardHeader><b>"{certificate.name}"</b></CardHeader>
<CardBody>
<CardText>
<p>
<b>ID:</b>
{certificate.id} <br />
<b>Name:</b>
{certificate.name} <br />
<b>Service ID:</b>
{certificate.cloudServiceId} <br />
<b>Issue Date:</b>
{certificate.issueDate} <br />
<b>Expiration Date:</b>
{certificate.expirationDate} <br />
<b>Schema:</b>
{certificate.standard} <br />
<b>Assurance Level:</b>
{certificate.assuranceLevel} <br />
<b>CAB:</b>
{certificate.cab} <br />
<b>Description:</b>
{certificate.description} <br />
</p>
<hr />
</CardText>
</CardBody>
</Card>
21 changes: 21 additions & 0 deletions src/lib/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export interface ListCertificatesResponse {
certificates: Certificate[];
}

export interface ListPublicCertificatesResponse {
certificates: Certificate[];
}

export interface ListAssessmentResultsResponse {
results: AssessmentResult[]
}
Expand Down Expand Up @@ -652,3 +656,20 @@ export async function listCertificates(): Promise<Certificate[]> {
});
}

/**
* Retrieves a list of public certificates from the orchestrator service.
*
* @returns an array of {@link Certificate}s.
*/
export async function listPublicCertificates(): Promise<Certificate[]> {
const apiUrl = clouditorize(`/v1/orchestrator/public/certificates`)

return fetch(apiUrl, {
method: 'GET',
})
.then(throwError)
.then((res) => res.json())
.then((response: ListPublicCertificatesResponse) => {
return response.certificates;
});
}
24 changes: 24 additions & 0 deletions src/routes/public/certificates/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import { Col, Container, Row } from 'sveltestrap';
import PublicCertificateCard from '$lib/PublicCertificateCard.svelte';
import type { PageData } from './$types';
export let data: PageData;
let { certificates } = data;
</script>

<h3>Certificates</h3>

{#if certificates}
<Container class="mt-4 ms-0 me-0">
<Row cols={2} noGutters>
{#each certificates as certificate, i}
<Col>
<PublicCertificateCard {certificate} />
</Col>
{/each}
</Row>
</Container>
{:else}
No certificates issued yet.
{/if}
17 changes: 17 additions & 0 deletions src/routes/public/certificates/+page.ts
Original file line number Diff line number Diff line change
@@ -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');
});
}

0 comments on commit 6bfb892

Please sign in to comment.