-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathk8s_machine_workflow.ts
More file actions
30 lines (26 loc) · 1.08 KB
/
k8s_machine_workflow.ts
File metadata and controls
30 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { type MongoClient } from '../../../mongo_client';
import { type MongoCredentials } from '../mongo_credentials';
import { type AccessToken, MachineWorkflow } from './machine_workflow';
/** The fallback file name */
const FALLBACK_FILENAME = '/var/run/secrets/kubernetes.io/serviceaccount/token';
/** The azure environment variable for the file name. */
const AZURE_FILENAME = 'AZURE_FEDERATED_TOKEN_FILE';
/** The AWS environment variable for the file name. */
const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
export class K8SMachineWorkflow extends MachineWorkflow {
/**
* Get the token from the environment.
*/
async getToken(_credentials: MongoCredentials, client: MongoClient): Promise<AccessToken> {
let filename: string;
if (process.env[AZURE_FILENAME]) {
filename = process.env[AZURE_FILENAME];
} else if (process.env[AWS_FILENAME]) {
filename = process.env[AWS_FILENAME];
} else {
filename = FALLBACK_FILENAME;
}
const token = await client.io.fs.readFile(filename, { encoding: 'utf8' });
return { access_token: token };
}
}