Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public certificates route #458

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
}
Loading