Skip to content

Commit

Permalink
azure-devops-backend: mark config as required and use mock token
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
  • Loading branch information
Rugvip committed Sep 29, 2021
1 parent 9aa3d98 commit 299b43f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-buckets-relax.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-azure-devops-backend': patch
---

Marked all configuration values as required in the schema.
2 changes: 1 addition & 1 deletion app-config.yaml
Expand Up @@ -403,5 +403,5 @@ jenkins:

azureDevOps:
host: dev.azure.com
token: ${AZURE_TOKEN}
token: my-token
organization: my-company
4 changes: 2 additions & 2 deletions plugins/azure-devops-backend/config.d.ts
Expand Up @@ -16,7 +16,7 @@

export interface Config {
/** Configuration options for the azure-devops-backend plugin */
azureDevOps?: {
azureDevOps: {
/**
* The hostname of the given Azure instance
*/
Expand All @@ -25,7 +25,7 @@ export interface Config {
* Token used to authenticate requests.
* @visibility secret
*/
token?: string;
token: string;
/**
* The organization of the given Azure instance
*/
Expand Down
5 changes: 1 addition & 4 deletions plugins/azure-devops-backend/src/service/router.test.ts
Expand Up @@ -62,10 +62,7 @@ describe('createRouter', () => {
const response = await request(app).get('/health');

expect(response.status).toEqual(200);
expect(response.body).toEqual({
status: 'Healthy',
details: 'All required config has been provided',
});
expect(response.body).toEqual({ status: 'ok' });
});
});

Expand Down
38 changes: 5 additions & 33 deletions plugins/azure-devops-backend/src/service/router.ts
Expand Up @@ -36,9 +36,9 @@ export async function createRouter(
const { logger } = options;
const config = options.config.getConfig('azureDevOps');

const token: string = config.getString('token');
const host: string = config.getString('host');
const organization: string = config.getString('organization');
const token = config.getString('token');
const host = config.getString('host');
const organization = config.getString('organization');

const authHandler = getPersonalAccessTokenHandler(token);
const webApi = new WebApi(`https://${host}/${organization}`, authHandler);
Expand All @@ -49,36 +49,8 @@ export async function createRouter(
const router = Router();
router.use(express.json());

router.get('/health', (_, response) => {
let code: number = 200;
let status: string = '';
let details: string = '';

if (token && host && organization) {
code = 200;
status = 'Healthy';
details = 'All required config has been provided';
}

if (!token) {
code = 500;
status = 'Unhealthy';
details = 'Token is missing';
}

if (!host) {
code = 500;
status = 'Unhealthy';
details = 'Host is missing';
}

if (!organization) {
code = 500;
status = 'Unhealthy';
details = 'Organization is missing';
}

response.status(code).json({ status: status, details: details });
router.get('/health', (_req, res) => {
res.status(200).json({ status: 'ok' });
});

router.get('/repository/:projectName/:repoName', async (req, res) => {
Expand Down

0 comments on commit 299b43f

Please sign in to comment.