Skip to content

Commit

Permalink
Merge pull request #1031 from bcgov/test
Browse files Browse the repository at this point in the history
Create Latest Release
  • Loading branch information
rustyjux committed Apr 12, 2024
2 parents 4ec063b + 7b1cf07 commit 73d0b1b
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 22 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The repo is setup to create a local deployment of the Portal along with required
docker build -t gwa-api:e2e .
```

1. Build: Back in `api-services-portal`, run `docker compose --profile testsuite build`.
1. Build: Back in `api-services-portal`, run `docker compose build`.
1. Run: `docker compose up`. Wait for startup to complete - look for `Swagger UI registered`.
1. The Portal is now live at http://oauth2proxy.localtest.me:4180
1. To login, use username `janis@idir` and password `awsummer` (or username `local` and password `local`).
Expand All @@ -35,7 +35,12 @@ The repo is setup to create a local deployment of the Portal along with required

### Cypress testing

To run the Cypress test automation suite, run `docker compose --profile testsuite up`.
To run the Cypress test automation suite, run

```sh
docker compose --profile testsuite build
docker compose --profile testsuite up
```

### gwa CLI configuration

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ x-common-variables: &common-variables

services:
keycloak:
image: jboss/keycloak:15.1.1
image: quay.io/keycloak/keycloak:15.1.1
container_name: keycloak
hostname: keycloak
depends_on:
Expand Down
73 changes: 73 additions & 0 deletions src/mocks/resolvers/api-directory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,77 @@
import YAML from 'js-yaml';

const markdown = YAML.load(`
notes: |
Here is some markdown.
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
Then I will do **bold**, _italics_ and ~~strikethrough~~.
#### Heading 4
And some text.
How about a table?
| Col1 | Col2 |
| ---- | ---- |
| Val1 | Val2 |
How about a new line.
And another line.
Try a list:
- one
- two
- three
Or an ordered list:
1. one
1. two
1. three
Then there are images
![image](http://localhost:3000/images/bc_logo_header.svg)
And links [my docs](https://github.com).
Here are some block quotes
> A block quote about something.
What about a bit of code - \`alert("hi")\`.
Code block?
\`\`\`
function (a) {
// comment
}
\`\`\`
`);

const directories = [
{
id: 'api1',
name: 'markdown-test',
title: 'Testing Markdown on Dataset',
notes: markdown.notes,
sector: 'Natural Resources',
license_title: 'Access Only',
view_audience: 'Named users',
security_class: 'LOW-PUBLIC',
record_publish_date: '2020-04-28',
tags: '["API","CDOGS","Document","Document Generation"]',
organization: {
title: 'Ministry of Environment and Climate Change Strategy',
},
organizationUnit: {
title: 'Information Innovation and Technology',
},
},
{
id: 'api1',
name: 'common-service-api',
Expand Down
27 changes: 18 additions & 9 deletions src/nextapp/pages/devportal/api-directory/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ReactMarkdownWithHtml from 'react-markdown/with-html';
import gfm from 'remark-gfm';
import { uid } from 'react-uid';
import { useAuth } from '@/shared/services/auth';
import style from '@/shared/styles/markdown.module.css';

const renderers = {
link: InternalLink,
Expand Down Expand Up @@ -144,20 +145,28 @@ const ApiPage: React.FC<
<Heading size="sm">About This Dataset</Heading>
</Box>
<Box mt={5} mb={9} sx={{ p: { marginBottom: 4 } }}>
<ReactMarkdownWithHtml renderers={renderers} plugins={[gfm]}>
<ReactMarkdownWithHtml
renderers={renderers}
plugins={[gfm]}
className={style.markdown}
>
{data?.notes}
</ReactMarkdownWithHtml>
</Box>
<Card heading="Products">
<Box bg="gray.100">
{data?.products?.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)).map((p) => (
<ApiProductItem
key={uid(p)}
data={p}
id={p.id}
preview={preview}
/>
))}
{data?.products
?.sort((a, b) =>
a.name > b.name ? 1 : b.name > a.name ? -1 : 0
)
.map((p) => (
<ApiProductItem
key={uid(p)}
data={p}
id={p.id}
preview={preview}
/>
))}
</Box>
</Card>
</GridItem>
Expand Down
72 changes: 72 additions & 0 deletions src/nextapp/shared/styles/markdown.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.markdown {
}

.markdown h1 {
margin-bottom: 1em;
}

.markdown h2 {
margin-bottom: 1em;
}

.markdown h3 {
margin-bottom: 1em;
}

.markdown h4 {
margin-bottom: 1em;
}

.markdown ul {
margin-top: 1em;
margin-bottom: 1em;
list-style: disc outside none;
}

.markdown ul li {
margin-left: 2em;
display: list-item;
text-align: -webkit-match-parent;
}

.markdown ol {
margin-top: 1em;
margin-bottom: 1em;
}

.markdown ol li {
margin-left: 2em;
display: list-item;
text-align: -webkit-match-parent;
}

.markdown img {
display: none;
}

.markdown table {
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
border-collapse: collapse;
}

.markdown td {
padding: 8px;
border: 1px solid #cccccc;
}

.markdown th {
padding: 8px;
text-align: left;
border: 1px solid #cccccc;
}

.markdown blockquote {
margin-top: 1em;
margin-bottom: 1em;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
border-left: 10px solid #cccccc;
}
1 change: 1 addition & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"copy-keystone-admin-assets": "ts-node tools/copyKeystoneAdminAssets",
"x-prestart": "npm run build",
"x-dev": "nodemon",
"nextapp-dev": "cross-env NEXT_PUBLIC_MOCKS=on NODE_ENV=development NODE_OPTIONS='--openssl-legacy-provider --no-experimental-fetch --dns-result-order=ipv4first' next dev ./nextapp",
"batch": "cross-env NODE_ENV=development node dist/server-batch.js",
"intg-build": "cross-env NODE_ENV=development npm-run-all delete-assets copy-assets ts-build",
"dev": "cross-env NODE_ENV=development NODE_OPTIONS='--openssl-legacy-provider --no-experimental-fetch --dns-result-order=ipv4first' npm-run-all delete-assets copy-assets tsoa-gen-types tsoa-build-v1 tsoa-build-v2 ts-build ks-dev",
Expand Down
4 changes: 4 additions & 0 deletions src/services/keystone/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export async function lookupApplication(
allApplications(where: {id: $id}) {
id
appId
name
owner {
name
}
}
}`,
variables: { id },
Expand Down
21 changes: 16 additions & 5 deletions src/services/kong/consumer-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
KeyAuthResponse,
KongConsumer,
} from './types';
import { Application } from '../keystone/types';
import { alphanumericNoSpaces } from '../utils';

const logger = Logger('kong.consumer');

Expand Down Expand Up @@ -41,7 +43,8 @@ export class KongConsumerService {

public async createOrGetConsumer(
username: string,
customId: string
customId: string,
app: Application
): Promise<CreateOrGetConsumerResult> {
logger.debug('createOrGetConsumer');
try {
Expand All @@ -51,20 +54,28 @@ export class KongConsumerService {
return { created: false, consumer: result };
} catch (err) {
logger.debug('createOrGetConsumer - CATCH ERROR %s', err);
const result = await this.createKongConsumer(username, customId);
const result = await this.createKongConsumer(username, customId, app);
logger.debug('createOrGetConsumer - CATCH RESULT %j', result);
return { created: false, consumer: result };
return { created: true, consumer: result };
}
}

public async createKongConsumer(username: string, customId: string) {
public async createKongConsumer(
username: string,
customId: string,
app: Application
) {
let body: KongConsumer = {
username: username,
tags: ['aps-portal'],
tags: [],
};
if (customId) {
body['custom_id'] = customId;
}
if (app) {
body.tags.push(`app:${alphanumericNoSpaces(app.name)}`);
body.tags.push(`owner:${alphanumericNoSpaces(app.owner.name)}`);
}
logger.debug('[createKongConsumer] %s', `${this.kongUrl}/consumers`);
try {
let response = await fetch(`${this.kongUrl}/consumers`, {
Expand Down
4 changes: 4 additions & 0 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ export async function fetchWithTimeout(resource: string, options: any = {}) {

return response;
}

export function alphanumericNoSpaces(str: string) {
return str.replace(/[^A-Za-z0-9:-]/gim, '').replace(/[:]/gim, '-');
}
6 changes: 5 additions & 1 deletion src/services/workflow/create-service-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export const CreateServiceAccount = async (
const nickname = client.client.clientId;

const kongApi = new KongConsumerService(process.env.KONG_URL);
const consumer = await kongApi.createKongConsumer(nickname, clientId);
const consumer = await kongApi.createKongConsumer(
nickname,
clientId,
application
);
const consumerPK = await AddClientConsumer(
context,
nickname,
Expand Down
13 changes: 11 additions & 2 deletions src/services/workflow/generate-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const generateCredential = async (

const nickname = clientId;

const newApiKey = await registerApiKey(context, clientId, nickname);
const newApiKey = await registerApiKey(
context,
clientId,
nickname,
application
);

logger.debug('new-api-key CREATED FOR %s', clientId);

Expand Down Expand Up @@ -138,7 +143,11 @@ export const generateCredential = async (
logger.debug('new-client %j', newClient);

const kongApi = new KongConsumerService(process.env.KONG_URL);
const consumer = await kongApi.createKongConsumer(nickname, clientId);
const consumer = await kongApi.createKongConsumer(
nickname,
clientId,
application
);
const consumerPK = await AddClientConsumer(
context,
nickname,
Expand Down
6 changes: 4 additions & 2 deletions src/services/workflow/kong-api-key.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { addKongConsumer } = require('../../services/keystone');

import { Application } from '../keystone/types';
import { KongConsumerService } from '../kong';

/**
Expand All @@ -14,11 +15,12 @@ import { KongConsumerService } from '../kong';
export async function registerApiKey(
context: any,
newClientId: string,
nickname: string
nickname: string,
app: Application
) {
const kongApi = new KongConsumerService(process.env.KONG_URL);

const consumer = await kongApi.createKongConsumer(nickname, newClientId);
const consumer = await kongApi.createKongConsumer(nickname, newClientId, app);

const apiKey = await kongApi.addKeyAuthToConsumer(consumer.id);

Expand Down
1 change: 1 addition & 0 deletions src/services/workflow/link-consumer-to-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const LinkConsumerToNamespace = async (
const kongApi = new KongConsumerService(process.env.KONG_URL);
const consumerResult = await kongApi.createOrGetConsumer(
consumerUsername,
null,
null
);
const consumerPK: any = { id: null };
Expand Down
Loading

0 comments on commit 73d0b1b

Please sign in to comment.