Skip to content

Commit

Permalink
refactor(NODE-5464): renaming workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Nov 9, 2023
1 parent 5cb3b06 commit 2dc6f83
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/cmap/auth/mongodb_oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { HandshakeDocument } from '../connect';
import type { Connection } from '../connection';
import { type AuthContext, AuthProvider } from './auth_provider';
import type { MongoCredentials } from './mongo_credentials';
import { AwsServiceWorkflow } from './mongodb_oidc/aws_service_workflow';
import { AzureServiceWorkflow } from './mongodb_oidc/azure_service_workflow';
import { CallbackWorkflow } from './mongodb_oidc/callback_workflow';
import { AwsMachineWorkflow } from './mongodb_oidc/aws_machine_workflow';
import { AzureMachineWorkflow } from './mongodb_oidc/azure_machine_workflow';
import { HumanWorkflow } from './mongodb_oidc/human_workflow';

/** Error when credentials are missing. */
const MISSING_CREDENTIALS_ERROR = 'AuthContext must provide credentials.';
Expand Down Expand Up @@ -74,9 +74,9 @@ export interface Workflow {

/** @internal */
export const OIDC_WORKFLOWS: Map<ProviderName, Workflow> = new Map();
OIDC_WORKFLOWS.set('callback', new CallbackWorkflow());
OIDC_WORKFLOWS.set('aws', new AwsServiceWorkflow());
OIDC_WORKFLOWS.set('azure', new AzureServiceWorkflow());
OIDC_WORKFLOWS.set('callback', new HumanWorkflow());
OIDC_WORKFLOWS.set('aws', new AwsMachineWorkflow());
OIDC_WORKFLOWS.set('azure', new AzureMachineWorkflow());

/**
* OIDC auth provider.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';

import { MongoAWSError } from '../../../error';
import { ServiceWorkflow } from './service_workflow';
import { MachineWorkflow } from './machine_workflow';

/** Error for when the token is missing in the environment. */
const TOKEN_MISSING_ERROR = 'AWS_WEB_IDENTITY_TOKEN_FILE must be set in the environment.';
Expand All @@ -11,7 +11,7 @@ const TOKEN_MISSING_ERROR = 'AWS_WEB_IDENTITY_TOKEN_FILE must be set in the envi
*
* @internal
*/
export class AwsServiceWorkflow extends ServiceWorkflow {
export class AwsMachineWorkflow extends MachineWorkflow {
constructor() {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MongoAzureError } from '../../../error';
import { request } from '../../../utils';
import type { MongoCredentials } from '../mongo_credentials';
import { AzureTokenCache } from './azure_token_cache';
import { ServiceWorkflow } from './service_workflow';
import { MachineWorkflow } from './machine_workflow';

/** Base URL for getting Azure tokens. */
const AZURE_BASE_URL =
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface AzureAccessToken {
*
* @internal
*/
export class AzureServiceWorkflow extends ServiceWorkflow {
export class AzureMachineWorkflow extends MachineWorkflow {
cache = new AzureTokenCache();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/auth/mongodb_oidc/azure_token_cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AzureAccessToken } from './azure_service_workflow';
import type { AzureAccessToken } from './azure_machine_workflow';
import { Cache, ExpiringCacheEntry } from './cache';

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const NO_REQUEST_CALLBACK = 'No REQUEST_TOKEN_CALLBACK provided for callback wor
* OIDC implementation of a callback based workflow.
* @internal
*/
export class CallbackWorkflow implements Workflow {
export class HumanWorkflow implements Workflow {
/**
* Get the document to add for speculative authentication. This also needs
* to add a db field from the credentials source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AuthMechanism } from '../providers';
* Common behaviour for OIDC device workflows.
* @internal
*/
export abstract class ServiceWorkflow implements Workflow {
export abstract class MachineWorkflow implements Workflow {
/**
* Execute the workflow. Looks for AWS_WEB_IDENTITY_TOKEN_FILE in the environment
* and then attempts to read the token from that path.
Expand Down
26 changes: 26 additions & 0 deletions src/cmap/auth/mongodb_oidc/token_manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { type IdPServerInfo, type IdPServerResponse } from '../mongodb_oidc';

const kGeneration = Symbol('generation');
const kIdpInfo = Symbol('idpInfo');
const kIdpResponse = Symbol('idpResponse');

/** @internal */
export class TokenManager {
[kGeneration] = 0;
[kIdpInfo]: IdPServerInfo;
[kIdpResponse]: IdPServerResponse;

constructor(idpInfo: IdPServerInfo, idpResponse: IdPServerResponse) {
this[kIdpInfo] = idpInfo;
this[kIdpResponse] = idpResponse;
}

set idpInfo(value: IdPServerInfo) {
this[kIdpInfo] = value;
this[kGeneration] += 1;
}

get idpInfo() {
return this[kIdpInfo];
}
}
8 changes: 4 additions & 4 deletions test/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export * from '../src/cmap/auth/mongo_credentials';
export * from '../src/cmap/auth/mongocr';
export * from '../src/cmap/auth/mongodb_aws';
export * from '../src/cmap/auth/mongodb_oidc';
export * from '../src/cmap/auth/mongodb_oidc/aws_service_workflow';
export * from '../src/cmap/auth/mongodb_oidc/azure_service_workflow';
export * from '../src/cmap/auth/mongodb_oidc/aws_machine_workflow';
export * from '../src/cmap/auth/mongodb_oidc/azure_machine_workflow';
export * from '../src/cmap/auth/mongodb_oidc/azure_token_cache';
export * from '../src/cmap/auth/mongodb_oidc/callback_workflow';
export * from '../src/cmap/auth/mongodb_oidc/service_workflow';
export * from '../src/cmap/auth/mongodb_oidc/human_workflow';
export * from '../src/cmap/auth/mongodb_oidc/machine_workflow';
export * from '../src/cmap/auth/plain';
export * from '../src/cmap/auth/providers';
export * from '../src/cmap/auth/scram';
Expand Down

0 comments on commit 2dc6f83

Please sign in to comment.