Skip to content

Commit 50727f8

Browse files
authored
[azure-build-cache] Expose loginFlowFailover in build-cache schema (#5274)
* [azure-build-cache] Expose loginFlowFailover * readonlyify --------- Co-authored-by: David Michon <[email protected]>
1 parent 25ecb0b commit 50727f8

File tree

7 files changed

+167
-19
lines changed

7 files changed

+167
-19
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "[azure-storage-build-cache] Update build-cache.json schema to allow the full range of `loginFlow` options supported by the underlying authentication provider. Add `loginFlowFailover` option to customize fallback sequencing.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

common/reviews/api/rush-azure-storage-build-cache-plugin.api.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ export interface IAzureAuthenticationBaseOptions {
8787
credentialUpdateCommandForLogging?: string | undefined;
8888
// (undocumented)
8989
loginFlow?: LoginFlowType;
90-
loginFlowFailover?: {
91-
[key in LoginFlowType]?: LoginFlowType;
92-
};
90+
loginFlowFailover?: LoginFlowFailoverMap;
9391
}
9492

9593
// @public (undocumented)
@@ -136,6 +134,11 @@ export interface ITryGetCachedCredentialOptionsThrow extends ITryGetCachedCreden
136134
expiredCredentialBehavior: 'throwError';
137135
}
138136

137+
// @public (undocumented)
138+
export type LoginFlowFailoverMap = {
139+
readonly [LoginFlow in LoginFlowType]?: Exclude<LoginFlowType, LoginFlow>;
140+
};
141+
139142
// @public (undocumented)
140143
export type LoginFlowType = 'DeviceCode' | 'InteractiveBrowser' | 'AdoCodespacesAuth' | 'VisualStudioCode' | 'AzureCli' | 'AzureDeveloperCli' | 'AzurePowerShell';
141144

libraries/rush-lib/src/schemas/build-cache.schema.json

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
"items": {
99
"$ref": "#/definitions/anything"
1010
}
11+
},
12+
"entraLoginFlow": {
13+
"type": "string",
14+
"description": "The Primary Entra ID login flow to use. Defaults to 'AdoCodespacesAuth' on GitHub Codespaces, 'VisualStudioCode' otherwise. If this flow fails it will fall back based on the configuration in `loginFlowFailover`.",
15+
"enum": [
16+
"AdoCodespacesAuth",
17+
"InteractiveBrowser",
18+
"DeviceCode",
19+
"VisualStudioCode",
20+
"AzureCli",
21+
"AzureDeveloperCli",
22+
"AzurePowerShell"
23+
]
24+
},
25+
"fallbackEntraLoginFlow": {
26+
"$ref": "#/definitions/entraLoginFlow",
27+
"description": "The Entra ID login flow to fall back to. If null, a failure in this login mode is terminal."
1128
}
1229
},
1330
"type": "object",
@@ -55,9 +72,56 @@
5572
"enum": ["AzurePublicCloud", "AzureChina", "AzureGermany", "AzureGovernment"]
5673
},
5774
"loginFlow": {
58-
"type": "string",
59-
"description": "The Entra ID login flow to use. Defaults to 'AdoCodespacesAuth' on GitHub Codespaces, 'InteractiveBrowser' otherwise.",
60-
"enum": ["AdoCodespacesAuth", "InteractiveBrowser", "DeviceCode"]
75+
"$ref": "#/definitions/entraLoginFlow"
76+
},
77+
"loginFlowFailover": {
78+
"type": "object",
79+
"description": "Optional configuration for a fallback login flow if the primary login flow fails. If not defined, the default order is: AdoCodespacesAuth -> VisualStudioCode -> AzureCli -> AzureDeveloperCli -> AzurePowerShell -> InteractiveBrowser -> DeviceCode.",
80+
"additionalProperties": false,
81+
"properties": {
82+
"AdoCodespacesAuth": {
83+
"allOf": [
84+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
85+
{ "not": { "enum": ["AdoCodespacesAuth"] } }
86+
]
87+
},
88+
"InteractiveBrowser": {
89+
"allOf": [
90+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
91+
{ "not": { "enum": ["InteractiveBrowser"] } }
92+
]
93+
},
94+
"DeviceCode": {
95+
"allOf": [
96+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
97+
{ "not": { "enum": ["DeviceCode"] } }
98+
]
99+
},
100+
"VisualStudioCode": {
101+
"allOf": [
102+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
103+
{ "not": { "enum": ["VisualStudioCode"] } }
104+
]
105+
},
106+
"AzureCli": {
107+
"allOf": [
108+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
109+
{ "not": { "enum": ["AzureCli"] } }
110+
]
111+
},
112+
"AzureDeveloperCli": {
113+
"allOf": [
114+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
115+
{ "not": { "enum": ["AzureDeveloperCli"] } }
116+
]
117+
},
118+
"AzurePowerShell": {
119+
"allOf": [
120+
{ "$ref": "#/definitions/fallbackEntraLoginFlow" },
121+
{ "not": { "enum": ["AzurePowerShell"] } }
122+
]
123+
}
124+
}
61125
},
62126
"blobPrefix": {
63127
"type": "string",

rush-plugins/rush-azure-storage-build-cache-plugin/src/AzureAuthenticationBase.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ export type LoginFlowType =
9595
| 'AzureDeveloperCli'
9696
| 'AzurePowerShell';
9797

98+
/**
99+
* @public
100+
*/
101+
export type LoginFlowFailoverMap = {
102+
readonly [LoginFlow in LoginFlowType]?: Exclude<LoginFlowType, LoginFlow>;
103+
};
104+
98105
/**
99106
* @public
100107
*/
@@ -120,9 +127,7 @@ export interface IAzureAuthenticationBaseOptions {
120127
* }
121128
* ```
122129
*/
123-
loginFlowFailover?: {
124-
[key in LoginFlowType]?: LoginFlowType;
125-
};
130+
loginFlowFailover?: LoginFlowFailoverMap;
126131
}
127132

128133
/**

rush-plugins/rush-azure-storage-build-cache-plugin/src/RushAzureStorageBuildCachePlugin.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// See LICENSE in the project root for license information.
33

44
import type { IRushPlugin, RushSession, RushConfiguration } from '@rushstack/rush-sdk';
5-
import type { AzureEnvironmentName, LoginFlowType } from './AzureAuthenticationBase';
5+
import type { AzureEnvironmentName, LoginFlowFailoverMap, LoginFlowType } from './AzureAuthenticationBase';
66

77
const PLUGIN_NAME: string = 'AzureStorageBuildCachePlugin';
88

@@ -13,38 +13,43 @@ interface IAzureBlobStorageConfigurationJson {
1313
/**
1414
* The name of the the Azure storage account to use for build cache.
1515
*/
16-
storageAccountName: string;
16+
readonly storageAccountName: string;
1717

1818
/**
1919
* The name of the container in the Azure storage account to use for build cache.
2020
*/
21-
storageContainerName: string;
21+
readonly storageContainerName: string;
2222

2323
/**
2424
* The Azure environment the storage account exists in. Defaults to AzureCloud.
2525
*/
26-
azureEnvironment?: AzureEnvironmentName;
26+
readonly azureEnvironment?: AzureEnvironmentName;
2727

2828
/**
2929
* Login flow to use for interactive authentication.
3030
* @defaultValue 'AdoCodespacesAuth' if on GitHub Codespaces, 'InteractiveBrowser' otherwise
3131
*/
3232
readonly loginFlow?: LoginFlowType;
3333

34+
/**
35+
* Fallback login flows to use if the primary login flow fails.
36+
*/
37+
readonly loginFlowFailover?: LoginFlowFailoverMap;
38+
3439
/**
3540
* An optional prefix for cache item blob names.
3641
*/
37-
blobPrefix?: string;
42+
readonly blobPrefix?: string;
3843

3944
/**
4045
* If set to true, allow writing to the cache. Defaults to false.
4146
*/
42-
isCacheWriteAllowed?: boolean;
47+
readonly isCacheWriteAllowed?: boolean;
4348

4449
/**
4550
* If set to true, reading the cache requires authentication. Defaults to false.
4651
*/
47-
readRequiresAuthentication?: boolean;
52+
readonly readRequiresAuthentication?: boolean;
4853
}
4954

5055
/**
@@ -67,6 +72,7 @@ export class RushAzureStorageBuildCachePlugin implements IRushPlugin {
6772
azureEnvironment: azureBlobStorageConfiguration.azureEnvironment,
6873
blobPrefix: azureBlobStorageConfiguration.blobPrefix,
6974
loginFlow: azureBlobStorageConfiguration.loginFlow,
75+
loginFlowFailover: azureBlobStorageConfiguration.loginFlowFailover,
7076
isCacheWriteAllowed: !!azureBlobStorageConfiguration.isCacheWriteAllowed,
7177
readRequiresAuthentication: !!azureBlobStorageConfiguration.readRequiresAuthentication
7278
});

rush-plugins/rush-azure-storage-build-cache-plugin/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {
88
type ICredentialResult,
99
type AzureEnvironmentName,
1010
type LoginFlowType,
11+
type LoginFlowFailoverMap,
1112
type ITryGetCachedCredentialOptionsBase,
1213
type ITryGetCachedCredentialOptionsLogWarning,
1314
type ITryGetCachedCredentialOptionsThrow,

rush-plugins/rush-azure-storage-build-cache-plugin/src/schemas/azure-blob-storage-config.schema.json

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88

99
"required": ["storageAccountName", "storageContainerName"],
1010

11+
"definitions": {
12+
"loginFlow": {
13+
"type": "string",
14+
"description": "The Primary Entra ID login flow to use. Defaults to 'AdoCodespacesAuth' on GitHub Codespaces, 'VisualStudioCode' otherwise. If this flow fails it will fall back based on the configuration in `loginFlowFailover`.",
15+
"enum": [
16+
"AdoCodespacesAuth",
17+
"InteractiveBrowser",
18+
"DeviceCode",
19+
"VisualStudioCode",
20+
"AzureCli",
21+
"AzureDeveloperCli",
22+
"AzurePowerShell"
23+
]
24+
},
25+
"fallbackLoginFlow": {
26+
"$ref": "#/definitions/loginFlow",
27+
"description": "The Entra ID login flow to fall back to. If null, a failure in this login mode is terminal."
28+
}
29+
},
30+
1131
"properties": {
1232
"storageAccountName": {
1333
"type": "string",
@@ -26,9 +46,48 @@
2646
},
2747

2848
"loginFlow": {
29-
"type": "string",
30-
"description": "The Entra ID login flow to use. Defaults to 'AdoCodespacesAuth' on GitHub Codespaces, 'InteractiveBrowser' otherwise.",
31-
"enum": ["AdoCodespacesAuth", "InteractiveBrowser", "DeviceCode"]
49+
"$ref": "#/definitions/loginFlow"
50+
},
51+
52+
"loginFlowFailover": {
53+
"type": "object",
54+
"description": "Optional configuration for a fallback login flow if the primary login flow fails. If not defined, the default order is: AdoCodespacesAuth -> VisualStudioCode -> AzureCli -> AzureDeveloperCli -> AzurePowerShell -> InteractiveBrowser -> DeviceCode.",
55+
"additionalProperties": false,
56+
"properties": {
57+
"AdoCodespacesAuth": {
58+
"allOf": [
59+
{ "$ref": "#/definitions/fallbackLoginFlow" },
60+
{ "not": { "enum": ["AdoCodespacesAuth"] } }
61+
]
62+
},
63+
"InteractiveBrowser": {
64+
"allOf": [
65+
{ "$ref": "#/definitions/fallbackLoginFlow" },
66+
{ "not": { "enum": ["InteractiveBrowser"] } }
67+
]
68+
},
69+
"DeviceCode": {
70+
"allOf": [{ "$ref": "#/definitions/fallbackLoginFlow" }, { "not": { "enum": ["DeviceCode"] } }]
71+
},
72+
"VisualStudioCode": {
73+
"allOf": [
74+
{ "$ref": "#/definitions/fallbackLoginFlow" },
75+
{ "not": { "enum": ["VisualStudioCode"] } }
76+
]
77+
},
78+
"AzureCli": {
79+
"allOf": [{ "$ref": "#/definitions/fallbackLoginFlow" }, { "not": { "enum": ["AzureCli"] } }]
80+
},
81+
"AzureDeveloperCli": {
82+
"allOf": [
83+
{ "$ref": "#/definitions/fallbackLoginFlow" },
84+
{ "not": { "enum": ["AzureDeveloperCli"] } }
85+
]
86+
},
87+
"AzurePowerShell": {
88+
"allOf": [{ "$ref": "#/definitions/fallbackLoginFlow" }, { "not": { "enum": ["AzurePowerShell"] } }]
89+
}
90+
}
3291
},
3392

3493
"blobPrefix": {

0 commit comments

Comments
 (0)