Skip to content

Commit

Permalink
feat: introduce discovery data to status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jan 18, 2024
1 parent e4ce695 commit daf78b6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
10 changes: 9 additions & 1 deletion services/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ app.use(json());
app.use(
morgan('combined', {
skip: (req, res) => {
return req.originalUrl.startsWith('/status');
if (req.originalUrl.startsWith('/status')) {
return req.originalUrl.startsWith('/status')
}
if (req.originalUrl.startsWith('/favicon.ico')) {
return req.originalUrl.startsWith('/favicon.ico')
}
if (req.originalUrl.startsWith('/.well-known')) {
return req.originalUrl.startsWith('/.well-known')
}
},
stream: {
write: message => logger.info(message.trim())
Expand Down
4 changes: 4 additions & 0 deletions services/api/src/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const authenticateJWT = async (
if (req.url === '/status') {
return next();
}
// Allow access to status without auth.
if (req.url === '/.well-known/lagoon') {
return next();
}

// @ts-ignore
const token = getBearerTokenFromHeader(req.get('Authorization'));
Expand Down
4 changes: 4 additions & 0 deletions services/api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express, { Request, Response } from 'express';
import statusRoute from './status';
import keysRoute from './keys';
import wellKnown from './well-known';

export function createRouter() {
const router = express.Router();
Expand All @@ -13,6 +14,9 @@ export function createRouter() {
// Fetch the current api status.
router.get('/status', ...statusRoute);

// Fetch the well-known.
router.get('/.well-known/lagoon', ...wellKnown);

// Return keys of all customers
router.post('/keys', ...keysRoute);

Expand Down
18 changes: 18 additions & 0 deletions services/api/src/routes/well-known.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Request, Response } from 'express';
import { envHasConfig, getConfigFromEnv } from '../util/config';

const wellKnown = (req: Request, res: Response) => {
let discoverData = {
lagoon_version: getConfigFromEnv('LAGOON_VERSION',''),
authorization_endpoint: getConfigFromEnv('KEYCLOAK_URL', ''),
ssh_token_exchange: {
token_endpoint_host: getConfigFromEnv('SSH_TOKEN_ENDPOINT', ''),
token_endpoint_port: parseInt(getConfigFromEnv('SSH_TOKEN_ENDPOINT_PORT', '22'), 10)
},
webhook_endpoint: getConfigFromEnv('WEBHOOK_URL', ''),
ui_url: getConfigFromEnv('UI_URL',''),
}
res.json(discoverData);
};

export default [wellKnown];
2 changes: 1 addition & 1 deletion tests/checks/check-api-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
headers:
Authorization: "Bearer {{ bearer_token }}"
register: result
until: result.content is match(expected_content)
until: result.content is search(expected_content)
retries: 1
delay: 0
2 changes: 1 addition & 1 deletion tests/tests/features/api-token.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
vars:
url: "{{ lookup('env','API_PROTOCOL') }}://{{ lookup('env','API_HOST') }}:{{ lookup('env','API_PORT') }}/"
bearer_token: "{{ token }}"
expected_content: '{"status":"success","data":{}}'
expected_content: 'success'
tasks:
- ansible.builtin.include_tasks: ../../checks/check-api-request.yaml

0 comments on commit daf78b6

Please sign in to comment.