Skip to content

[rush] Pass the credentials cache into _getCredentialFromTokenAsync. #4922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Pass the initialized credentials cache to `AzureAuthenticationBase._getCredentialFromTokenAsync` in `@rushstack/rush-azure-storage-build-cache-plugin`.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ export abstract class AzureAuthenticationBase {
}
}

const credential: ICredentialResult = await this._getCredentialAsync(terminal, this._loginFlow);
const credential: ICredentialResult = await this._getCredentialAsync(
terminal,
this._loginFlow,
credentialsCache
);
credentialsCache.setCacheEntry(this._credentialCacheId, {
credential: credential.credentialString,
expires: credential.expiresOn,
Expand Down Expand Up @@ -272,12 +276,14 @@ export abstract class AzureAuthenticationBase {

protected abstract _getCredentialFromTokenAsync(
terminal: ITerminal,
tokenCredential: TokenCredential
tokenCredential: TokenCredential,
credentialsCache: CredentialCache
): Promise<ICredentialResult>;

private async _getCredentialAsync(
terminal: ITerminal,
loginFlow: LoginFlowType
loginFlow: LoginFlowType,
credentialsCache: CredentialCache
): Promise<ICredentialResult> {
const authorityHost: string | undefined = AzureAuthorityHosts[this._azureEnvironment];
if (!authorityHost) {
Expand Down Expand Up @@ -319,13 +325,13 @@ export abstract class AzureAuthenticationBase {
}

try {
return await this._getCredentialFromTokenAsync(terminal, tokenCredential);
return await this._getCredentialFromTokenAsync(terminal, tokenCredential, credentialsCache);
} catch (error) {
terminal.writeVerbose(`Failed to get credentials with ${loginFlow}: ${error}`);
const fallbackFlow: LoginFlowType | undefined = this._failoverOrder[loginFlow];
if (fallbackFlow) {
terminal.writeVerbose(`Falling back to ${fallbackFlow} login flow`);
return this._getCredentialAsync(terminal, fallbackFlow);
return this._getCredentialAsync(terminal, fallbackFlow, credentialsCache);
} else {
throw error;
}
Expand Down
Loading