File tree Expand file tree Collapse file tree 4 files changed +16
-12
lines changed
src/cmap/auth/mongodb_oidc Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1
1
import { addAzureParams , AZURE_BASE_URL } from '../../../client-side-encryption/providers/azure' ;
2
2
import { MongoAzureError } from '../../../error' ;
3
3
import { get } from '../../../utils' ;
4
- import type { OIDCCallbackParams , OIDCResponse } from '../mongodb_oidc' ;
4
+ import type { OIDCCallbackFunction , OIDCCallbackParams , OIDCResponse } from '../mongodb_oidc' ;
5
5
6
6
/** Azure request headers. */
7
7
const AZURE_HEADERS = Object . freeze ( { Metadata : 'true' , Accept : 'application/json' } ) ;
@@ -19,7 +19,9 @@ const TOKEN_RESOURCE_MISSING_ERROR =
19
19
* @param params - The OIDC callback parameters.
20
20
* @returns The OIDC response.
21
21
*/
22
- export async function callback ( params : OIDCCallbackParams ) : Promise < OIDCResponse > {
22
+ export const callback : OIDCCallbackFunction = async (
23
+ params : OIDCCallbackParams
24
+ ) : Promise < OIDCResponse > => {
23
25
const tokenAudience = params . tokenAudience ;
24
26
const username = params . username ;
25
27
if ( ! tokenAudience ) {
@@ -30,7 +32,7 @@ export async function callback(params: OIDCCallbackParams): Promise<OIDCResponse
30
32
throw new MongoAzureError ( ENDPOINT_RESULT_ERROR ) ;
31
33
}
32
34
return response ;
33
- }
35
+ } ;
34
36
35
37
/**
36
38
* Hit the Azure endpoint to get the token data.
Original file line number Diff line number Diff line change 1
1
import { MongoGCPError } from '../../../error' ;
2
2
import { get } from '../../../utils' ;
3
- import type { OIDCCallbackParams , OIDCResponse } from '../mongodb_oidc' ;
3
+ import type { OIDCCallbackFunction , OIDCCallbackParams , OIDCResponse } from '../mongodb_oidc' ;
4
4
5
5
/** GCP base URL. */
6
6
const GCP_BASE_URL =
@@ -18,13 +18,15 @@ const TOKEN_RESOURCE_MISSING_ERROR =
18
18
* @param params - The OIDC callback parameters.
19
19
* @returns The OIDC response.
20
20
*/
21
- export async function callback ( params : OIDCCallbackParams ) : Promise < OIDCResponse > {
21
+ export const callback : OIDCCallbackFunction = async (
22
+ params : OIDCCallbackParams
23
+ ) : Promise < OIDCResponse > => {
22
24
const tokenAudience = params . tokenAudience ;
23
25
if ( ! tokenAudience ) {
24
26
throw new MongoGCPError ( TOKEN_RESOURCE_MISSING_ERROR ) ;
25
27
}
26
28
return await getGcpTokenData ( tokenAudience ) ;
27
- }
29
+ } ;
28
30
29
31
/**
30
32
* Hit the GCP endpoint to get the token data.
Original file line number Diff line number Diff line change 1
1
import { readFile } from 'fs/promises' ;
2
2
3
- import type { OIDCResponse } from '../mongodb_oidc' ;
3
+ import type { OIDCCallbackFunction , OIDCResponse } from '../mongodb_oidc' ;
4
4
5
5
/** The fallback file name */
6
6
const FALLBACK_FILENAME = '/var/run/secrets/kubernetes.io/serviceaccount/token' ;
@@ -16,7 +16,7 @@ const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
16
16
* @param params - The OIDC callback parameters.
17
17
* @returns The OIDC response.
18
18
*/
19
- export async function callback ( ) : Promise < OIDCResponse > {
19
+ export const callback : OIDCCallbackFunction = async ( ) : Promise < OIDCResponse > = > {
20
20
let filename : string ;
21
21
if ( process . env [ AZURE_FILENAME ] ) {
22
22
filename = process . env [ AZURE_FILENAME ] ;
@@ -27,4 +27,4 @@ export async function callback(): Promise<OIDCResponse> {
27
27
}
28
28
const token = await readFile ( filename , 'utf8' ) ;
29
29
return { accessToken : token } ;
30
- }
30
+ } ;
Original file line number Diff line number Diff line change 1
1
import * as fs from 'fs' ;
2
2
3
3
import { MongoAWSError } from '../../../error' ;
4
- import { type OIDCResponse } from '../mongodb_oidc' ;
4
+ import type { OIDCCallbackFunction , OIDCResponse } from '../mongodb_oidc' ;
5
5
6
6
/** Error for when the token is missing in the environment. */
7
7
const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.' ;
@@ -11,11 +11,11 @@ const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.';
11
11
* @param params - The OIDC callback parameters.
12
12
* @returns The OIDC response.
13
13
*/
14
- export async function callback ( ) : Promise < OIDCResponse > {
14
+ export const callback : OIDCCallbackFunction = async ( ) : Promise < OIDCResponse > = > {
15
15
const tokenFile = process . env . OIDC_TOKEN_FILE ;
16
16
if ( ! tokenFile ) {
17
17
throw new MongoAWSError ( TOKEN_MISSING_ERROR ) ;
18
18
}
19
19
const token = await fs . promises . readFile ( tokenFile , 'utf8' ) ;
20
20
return { accessToken : token } ;
21
- }
21
+ } ;
You can’t perform that action at this time.
0 commit comments