From 2dc6f8395a7ff01d1793101fcad33d639dd52ad6 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Thu, 9 Nov 2023 11:29:27 -0500 Subject: [PATCH] refactor(NODE-5464): renaming workflows --- src/cmap/auth/mongodb_oidc.ts | 12 ++++----- ...ce_workflow.ts => aws_machine_workflow.ts} | 4 +-- ..._workflow.ts => azure_machine_workflow.ts} | 4 +-- .../auth/mongodb_oidc/azure_token_cache.ts | 2 +- ...callback_workflow.ts => human_workflow.ts} | 2 +- ...ervice_workflow.ts => machine_workflow.ts} | 2 +- src/cmap/auth/mongodb_oidc/token_manager.ts | 26 +++++++++++++++++++ test/mongodb.ts | 8 +++--- 8 files changed, 43 insertions(+), 17 deletions(-) rename src/cmap/auth/mongodb_oidc/{aws_service_workflow.ts => aws_machine_workflow.ts} (84%) rename src/cmap/auth/mongodb_oidc/{azure_service_workflow.ts => azure_machine_workflow.ts} (95%) rename src/cmap/auth/mongodb_oidc/{callback_workflow.ts => human_workflow.ts} (99%) rename src/cmap/auth/mongodb_oidc/{service_workflow.ts => machine_workflow.ts} (96%) create mode 100644 src/cmap/auth/mongodb_oidc/token_manager.ts diff --git a/src/cmap/auth/mongodb_oidc.ts b/src/cmap/auth/mongodb_oidc.ts index d2b0e93093d..95265df21e1 100644 --- a/src/cmap/auth/mongodb_oidc.ts +++ b/src/cmap/auth/mongodb_oidc.ts @@ -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.'; @@ -74,9 +74,9 @@ export interface Workflow { /** @internal */ export const OIDC_WORKFLOWS: Map = 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. diff --git a/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts b/src/cmap/auth/mongodb_oidc/aws_machine_workflow.ts similarity index 84% rename from src/cmap/auth/mongodb_oidc/aws_service_workflow.ts rename to src/cmap/auth/mongodb_oidc/aws_machine_workflow.ts index 5dd07b1d28e..138954b29af 100644 --- a/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +++ b/src/cmap/auth/mongodb_oidc/aws_machine_workflow.ts @@ -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.'; @@ -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(); } diff --git a/src/cmap/auth/mongodb_oidc/azure_service_workflow.ts b/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts similarity index 95% rename from src/cmap/auth/mongodb_oidc/azure_service_workflow.ts rename to src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts index fadbf5e9fd9..7e4db0fdd66 100644 --- a/src/cmap/auth/mongodb_oidc/azure_service_workflow.ts +++ b/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts @@ -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 = @@ -33,7 +33,7 @@ export interface AzureAccessToken { * * @internal */ -export class AzureServiceWorkflow extends ServiceWorkflow { +export class AzureMachineWorkflow extends MachineWorkflow { cache = new AzureTokenCache(); /** diff --git a/src/cmap/auth/mongodb_oidc/azure_token_cache.ts b/src/cmap/auth/mongodb_oidc/azure_token_cache.ts index f68725120e8..07794c7f3aa 100644 --- a/src/cmap/auth/mongodb_oidc/azure_token_cache.ts +++ b/src/cmap/auth/mongodb_oidc/azure_token_cache.ts @@ -1,4 +1,4 @@ -import type { AzureAccessToken } from './azure_service_workflow'; +import type { AzureAccessToken } from './azure_machine_workflow'; import { Cache, ExpiringCacheEntry } from './cache'; /** @internal */ diff --git a/src/cmap/auth/mongodb_oidc/callback_workflow.ts b/src/cmap/auth/mongodb_oidc/human_workflow.ts similarity index 99% rename from src/cmap/auth/mongodb_oidc/callback_workflow.ts rename to src/cmap/auth/mongodb_oidc/human_workflow.ts index 535edf19798..22110ba2abe 100644 --- a/src/cmap/auth/mongodb_oidc/callback_workflow.ts +++ b/src/cmap/auth/mongodb_oidc/human_workflow.ts @@ -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. diff --git a/src/cmap/auth/mongodb_oidc/service_workflow.ts b/src/cmap/auth/mongodb_oidc/machine_workflow.ts similarity index 96% rename from src/cmap/auth/mongodb_oidc/service_workflow.ts rename to src/cmap/auth/mongodb_oidc/machine_workflow.ts index fb01e2c24ce..c48e859b43f 100644 --- a/src/cmap/auth/mongodb_oidc/service_workflow.ts +++ b/src/cmap/auth/mongodb_oidc/machine_workflow.ts @@ -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. diff --git a/src/cmap/auth/mongodb_oidc/token_manager.ts b/src/cmap/auth/mongodb_oidc/token_manager.ts new file mode 100644 index 00000000000..b5580a8da1b --- /dev/null +++ b/src/cmap/auth/mongodb_oidc/token_manager.ts @@ -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]; + } +} diff --git a/test/mongodb.ts b/test/mongodb.ts index de6ffc65541..7333ccc63bf 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -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';