Skip to content

Commit

Permalink
Mijn 7102 kv certs (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
timvanoostrom authored Nov 2, 2023
1 parent 16e5cb5 commit c86fa4a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 122 deletions.
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

version: 2
updates:
- package-ecosystem: "Docker"
directory: "/"
- package-ecosystem: 'docker'
directory: '/'
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/"
interval: 'weekly'
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: "weekly"
interval: 'weekly'
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

24 changes: 0 additions & 24 deletions docker-compose.yml

This file was deleted.

51 changes: 30 additions & 21 deletions src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
import {
ApiSuccessResponse,
ApiErrorResponse,
ApiPostponeResponse,
} from './../universal/helpers/api';
import { AxiosRequestConfig } from 'axios';
import { CorsOptions } from 'cors';
import { ConfigParams } from 'express-openid-connect';
import fs from 'fs';
import https from 'https';
import jose from 'jose';
import { FeatureToggle } from '../universal/config';
import { IS_OT, IS_TAP } from '../universal/config/env';
import { IS_OT, IS_TEST } from '../universal/config/env';
import {
ApiErrorResponse,
ApiPostponeResponse,
ApiSuccessResponse,
} from './../universal/helpers/api';
import { TokenData } from './helpers/app';

export function getCertificateSync(path?: string, name?: string) {
if (!path) {
if (name) {
console.log(`${name}: Certificate path empty ${path}`);
}
return '';
export function getCertificateSync(envVarName: string | undefined) {
const path = envVarName && process.env[envVarName];
if (path) {
try {
return fs.readFileSync(path).toString();
} catch (error) {}
}

return undefined;
}

function decodeBase64EncodedCertificateFromEnv(name: string | undefined) {
const data = name && process.env[name];
if (data) {
return Buffer.from(data, 'base64').toString('utf-8');
}
let fileContents: string = '';
try {
fileContents = fs.readFileSync(path).toString();
} catch (error) {}
return undefined;
}

return fileContents;
function getCert(envVarName: string | undefined) {
// TODO: Should be only decodeBase64EncodedCertificateFromEnv when we've migrated to AZ
return IS_TEST
? decodeBase64EncodedCertificateFromEnv(envVarName)
: getCertificateSync(envVarName);
}

export const BFF_REQUEST_CACHE_ENABLED =
Expand Down Expand Up @@ -168,10 +179,8 @@ export const ApiConfig: ApiDataRequestConfig = {
postponeFetch: !FeatureToggle.milieuzoneApiActive,
method: 'POST',
httpsAgent: new https.Agent({
cert: IS_TAP
? getCertificateSync(process.env.BFF_SERVER_CLIENT_CERT)
: [],
key: IS_TAP ? getCertificateSync(process.env.BFF_SERVER_CLIENT_KEY) : [],
cert: getCert('BFF_SERVER_CLIENT_CERT'),
key: getCert('BFF_SERVER_CLIENT_KEY'),
}),
},
SIA: {
Expand Down
1 change: 1 addition & 0 deletions src/server/services/buurt/buurt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ vi.mock('../../../universal/config/env', () => {
IS_PRODUCTION: false,
IS_ACCEPTANCE: true,
IS_TAP: true,
IS_TEST: true,
};
});
vi.mock('../../../universal/config/myarea-datasets');
Expand Down

0 comments on commit c86fa4a

Please sign in to comment.