Skip to content

Commit def3860

Browse files
committed
refactor(credentials): read a reconnect's stored mode and cloud through one per-provider map
1 parent 14a4429 commit def3860

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

‎apps/sim/lib/credentials/application/prepare-workload-identity.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import {
1111
type GoogleStoredDelegation,
1212
storedGoogleDelegation,
1313
} from '@/lib/credentials/google-workload-identity.server'
14-
import {
15-
storedMicrosoftAppAuthType,
16-
storedMicrosoftAppCloud,
17-
} from '@/lib/credentials/microsoft-app-service-account.server'
14+
import { storedMicrosoftAppReconnectFields } from '@/lib/credentials/microsoft-app-service-account.server'
1815
import type { MicrosoftCloudId } from '@/lib/credentials/microsoft-clouds'
1916
import { storedSnowflakeAuthType } from '@/lib/credentials/snowflake-service-account.server'
2017
import {
@@ -73,11 +70,10 @@ function authTypeOnly<P extends WorkloadIdentityProvider>(
7370
}
7471

7572
function storedMicrosoftAppReconnect(decrypted: string): ReconnectFields<'microsoft'> {
76-
const reconnectAuthType = storedMicrosoftAppAuthType(decrypted)
77-
const reconnectCloud = storedMicrosoftAppCloud(decrypted)
73+
const { authType, cloud } = storedMicrosoftAppReconnectFields(decrypted)
7874
return {
79-
...(reconnectAuthType ? { reconnectAuthType } : {}),
80-
...(reconnectCloud ? { reconnectCloud } : {}),
75+
...(authType ? { reconnectAuthType: authType } : {}),
76+
...(cloud ? { reconnectCloud: cloud } : {}),
8177
}
8278
}
8379

‎apps/sim/lib/credentials/microsoft-app-service-account.server.ts‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -497,25 +497,21 @@ async function verifyDataverseApplicationUser(environmentUrl: string, token: str
497497
)
498498
}
499499

500-
/** The auth mode a decrypted Microsoft app credential secret holds, or undefined when it is not one. */
501-
export function storedMicrosoftAppAuthType(
502-
decrypted: string
503-
): 'federated' | 'client_secret' | 'certificate' | undefined {
504-
try {
505-
const parsed = storedSecretSchema.safeParse(JSON.parse(decrypted))
506-
return parsed.success ? parsed.data.config.authType : undefined
507-
} catch {
508-
return undefined
509-
}
510-
}
511-
512-
/** The stored national cloud, for a reconnect to reopen on; absent for a global credential. */
513-
export function storedMicrosoftAppCloud(decrypted: string): MicrosoftCloudId | undefined {
500+
/**
501+
* The auth mode and national cloud a decrypted Microsoft app credential secret holds, for a
502+
* reconnect to reopen on: empty when it is not one, and no cloud for a global credential.
503+
*/
504+
export function storedMicrosoftAppReconnectFields(decrypted: string): {
505+
authType?: MicrosoftAppConfig['authType']
506+
cloud?: MicrosoftCloudId
507+
} {
514508
try {
515509
const parsed = storedSecretSchema.safeParse(JSON.parse(decrypted))
516-
return parsed.success ? parsed.data.config.cloud : undefined
510+
if (!parsed.success) return {}
511+
const { authType, cloud } = parsed.data.config
512+
return cloud ? { authType, cloud } : { authType }
517513
} catch {
518-
return undefined
514+
return {}
519515
}
520516
}
521517

0 commit comments

Comments
 (0)