@rushstack/rush-http-build-cache-plugin 5.150.0 → 5.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/lib/HttpBuildCacheProvider.d.ts +0 -2
- package/lib/HttpBuildCacheProvider.d.ts.map +1 -1
- package/lib/HttpBuildCacheProvider.js +5 -2
- package/lib/HttpBuildCacheProvider.js.map +1 -1
- package/lib/RushHttpBuildCachePlugin.js +17 -7
- package/lib/RushHttpBuildCachePlugin.js.map +1 -1
- package/package.json +7 -7
- package/rush-plugin-manifest.json +1 -1
- package/.eslintrc.js +0 -12
- package/.rush/temp/chunked-rush-logs/rush-http-build-cache-plugin._phase_build.chunks.jsonl +0 -7
- package/.rush/temp/chunked-rush-logs/rush-http-build-cache-plugin._phase_test.chunks.jsonl +0 -15
- package/.rush/temp/operation/_phase_build/all.log +0 -7
- package/.rush/temp/operation/_phase_build/log-chunks.jsonl +0 -7
- package/.rush/temp/operation/_phase_build/state.json +0 -3
- package/.rush/temp/operation/_phase_test/all.log +0 -15
- package/.rush/temp/operation/_phase_test/log-chunks.jsonl +0 -15
- package/.rush/temp/operation/_phase_test/state.json +0 -3
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_build-2024be7372f51761b010f9514adf1d86d16d703b.tar.log +0 -32
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_test-070a8df8efa2a6dea51faad619eb159c90c69c2c.tar.log +0 -25
- package/.rush/temp/shrinkwrap-deps.json +0 -9
- package/config/jest.config.json +0 -14
- package/config/rig.json +0 -18
- package/coverage/HttpBuildCacheProvider.ts.html +0 -1426
- package/coverage/RushHttpBuildCachePlugin.ts.html +0 -328
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/cobertura-coverage.xml +0 -641
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -146
- package/coverage/index.ts.html +0 -106
- package/coverage/junit.xml +0 -9
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/lib/test/HttpBuildCacheProvider.test.d.ts +0 -2
- package/lib/test/HttpBuildCacheProvider.test.d.ts.map +0 -1
- package/lib/test/HttpBuildCacheProvider.test.js +0 -94
- package/lib/test/HttpBuildCacheProvider.test.js.map +0 -1
- package/rush-logs/rush-http-build-cache-plugin._phase_build.cache.log +0 -3
- package/rush-logs/rush-http-build-cache-plugin._phase_build.log +0 -7
- package/rush-logs/rush-http-build-cache-plugin._phase_test.cache.log +0 -3
- package/rush-logs/rush-http-build-cache-plugin._phase_test.log +0 -15
- package/src/HttpBuildCacheProvider.ts +0 -447
- package/src/RushHttpBuildCachePlugin.ts +0 -81
- package/src/index.ts +0 -7
- package/src/schemas/plugin-config.schema.json +0 -52
- package/src/test/HttpBuildCacheProvider.test.ts +0 -128
- package/temp/build/lint/_eslint-it73M-Rx.json +0 -4
- package/temp/build/typescript/file-copy.json +0 -1
- package/temp/build/typescript/ts_l9Fw4VUO.json +0 -1
- package/temp/test/jest/haste-map-8bff56e236187dbf28a94cdea7ee2158-1f8f3a8b20228094c245723445dd2c9a-e95bfd62c357a87bf3c5f47c6c3a2910 +0 -0
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/33/core_3305ad7ebc3e67008b0e3d5efb3c89fa +0 -159
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/66/data_662ee7a852684a50b5465ea7d1610925 +0 -14
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/74/jsonschemadraft07_74eae8d0e8c71a9be8c8f3e605321373 +0 -152
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/7b/data_7bd2e7b754ae682e8489f2e419bf314d +0 -14
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/b7/jsonschemadraft04_b75c7627c284f64550e887c2057ef2b6 +0 -139
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/c2/core_c2aa2d30a753f979fb7064944ea7e770 +0 -163
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/d5/core_d54674276357d38b544776746c491fe4 +0 -159
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/e0/core_e0f97ce5582728aab20c89fda7e102ec +0 -163
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/ef/jsonschemadraft07_ef987ddfbeb03ba4a34e7532df7928e0 +0 -152
- package/temp/test/jest/jest-transform-cache-8bff56e236187dbf28a94cdea7ee2158-79ef2876fae7ca75eedb2aa53dc48338/f8/jsonschemadraft04_f814157dc4b13278270c74e697ca146f +0 -139
- package/temp/test/jest/perf-cache-8bff56e236187dbf28a94cdea7ee2158-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
- package/tsconfig.json +0 -3
- /package/lib/schemas/{plugin-config.schema.json → http-config.schema.json} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Invoking: heft run --only build -- --clean --production
|
|
2
|
-
---- build started ----
|
|
3
|
-
[build:typescript] Using TypeScript version 5.4.2
|
|
4
|
-
[build:lint] Using ESLint version 8.57.0
|
|
5
|
-
[build:typescript] Copied 1 file and linked 0 files
|
|
6
|
-
---- build finished (10.268s) ----
|
|
7
|
-
-------------------- Finished (10.274s) --------------------
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Invoking: heft run --only test -- --clean --production
|
|
2
|
-
The provided list of phases does not contain all phase dependencies. You may need to run the excluded phases manually.
|
|
3
|
-
---- test started ----
|
|
4
|
-
[test:jest] Using Jest version 29.5.0
|
|
5
|
-
[test:jest]
|
|
6
|
-
[test:jest] Run start. 1 test suite
|
|
7
|
-
[test:jest] START lib/test/HttpBuildCacheProvider.test.js
|
|
8
|
-
[test:jest] PASS lib/test/HttpBuildCacheProvider.test.js (duration: 1.623s, 2 passed, 0 failed)
|
|
9
|
-
[test:jest]
|
|
10
|
-
[test:jest] Tests finished:
|
|
11
|
-
[test:jest] Successes: 2
|
|
12
|
-
[test:jest] Failures: 0
|
|
13
|
-
[test:jest] Total: 2
|
|
14
|
-
---- test finished (3.315s) ----
|
|
15
|
-
-------------------- Finished (3.323s) --------------------
|
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
-
// See LICENSE in the project root for license information.
|
|
3
|
-
|
|
4
|
-
import { Executable, Async } from '@rushstack/node-core-library';
|
|
5
|
-
import type { ITerminal } from '@rushstack/terminal';
|
|
6
|
-
import {
|
|
7
|
-
type ICloudBuildCacheProvider,
|
|
8
|
-
type ICredentialCacheEntry,
|
|
9
|
-
CredentialCache,
|
|
10
|
-
type RushSession,
|
|
11
|
-
EnvironmentConfiguration
|
|
12
|
-
} from '@rushstack/rush-sdk';
|
|
13
|
-
import { WebClient, type IWebClientResponse } from '@rushstack/rush-sdk/lib/utilities/WebClient';
|
|
14
|
-
import type { SpawnSyncReturns } from 'child_process';
|
|
15
|
-
|
|
16
|
-
enum CredentialsOptions {
|
|
17
|
-
Optional,
|
|
18
|
-
Required,
|
|
19
|
-
Omit
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
enum FailureType {
|
|
23
|
-
None,
|
|
24
|
-
Informational,
|
|
25
|
-
Warning,
|
|
26
|
-
Error,
|
|
27
|
-
Authentication
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IHttpBuildCacheTokenHandler {
|
|
31
|
-
exec: string;
|
|
32
|
-
args?: string[];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export type UploadMethod = 'PUT' | 'POST' | 'PATCH';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
export interface IHttpBuildCacheProviderOptions {
|
|
44
|
-
url: string;
|
|
45
|
-
tokenHandler?: IHttpBuildCacheTokenHandler;
|
|
46
|
-
uploadMethod?: UploadMethod;
|
|
47
|
-
minHttpRetryDelayMs?: number;
|
|
48
|
-
headers?: Record<string, string>;
|
|
49
|
-
cacheKeyPrefix?: string;
|
|
50
|
-
isCacheWriteAllowed: boolean;
|
|
51
|
-
pluginName: string;
|
|
52
|
-
rushJsonFolder: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const MAX_HTTP_CACHE_ATTEMPTS: number = 3;
|
|
56
|
-
const DEFAULT_MIN_HTTP_RETRY_DELAY_MS: number = 2500;
|
|
57
|
-
|
|
58
|
-
export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
|
|
59
|
-
private readonly _pluginName: string;
|
|
60
|
-
private readonly _rushProjectRoot: string;
|
|
61
|
-
private readonly _environmentCredential: string | undefined;
|
|
62
|
-
private readonly _isCacheWriteAllowedByConfiguration: boolean;
|
|
63
|
-
private readonly _url: URL;
|
|
64
|
-
private readonly _uploadMethod: UploadMethod;
|
|
65
|
-
private readonly _headers: Record<string, string>;
|
|
66
|
-
private readonly _cacheKeyPrefix: string;
|
|
67
|
-
private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;
|
|
68
|
-
private readonly _minHttpRetryDelayMs: number;
|
|
69
|
-
private __credentialCacheId: string | undefined;
|
|
70
|
-
|
|
71
|
-
public get isCacheWriteAllowed(): boolean {
|
|
72
|
-
return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public constructor(options: IHttpBuildCacheProviderOptions, rushSession: RushSession) {
|
|
76
|
-
this._pluginName = options.pluginName;
|
|
77
|
-
this._rushProjectRoot = options.rushJsonFolder;
|
|
78
|
-
|
|
79
|
-
this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;
|
|
80
|
-
this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;
|
|
81
|
-
this._url = new URL(options.url.endsWith('/') ? options.url : options.url + '/');
|
|
82
|
-
this._uploadMethod = options.uploadMethod ?? 'PUT';
|
|
83
|
-
this._headers = options.headers ?? {};
|
|
84
|
-
this._tokenHandler = options.tokenHandler;
|
|
85
|
-
this._cacheKeyPrefix = options.cacheKeyPrefix ?? '';
|
|
86
|
-
this._minHttpRetryDelayMs = options.minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public async tryGetCacheEntryBufferByIdAsync(
|
|
90
|
-
terminal: ITerminal,
|
|
91
|
-
cacheId: string
|
|
92
|
-
): Promise<Buffer | undefined> {
|
|
93
|
-
try {
|
|
94
|
-
const result: boolean | Buffer = await this._makeHttpRequestAsync({
|
|
95
|
-
terminal: terminal,
|
|
96
|
-
relUrl: `${this._cacheKeyPrefix}${cacheId}`,
|
|
97
|
-
method: 'GET',
|
|
98
|
-
body: undefined,
|
|
99
|
-
warningText: 'Could not get cache entry',
|
|
100
|
-
readBody: true,
|
|
101
|
-
maxAttempts: MAX_HTTP_CACHE_ATTEMPTS
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return Buffer.isBuffer(result) ? result : undefined;
|
|
105
|
-
} catch (e) {
|
|
106
|
-
terminal.writeWarningLine(`Error getting cache entry: ${e}`);
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public async trySetCacheEntryBufferAsync(
|
|
112
|
-
terminal: ITerminal,
|
|
113
|
-
cacheId: string,
|
|
114
|
-
objectBuffer: Buffer
|
|
115
|
-
): Promise<boolean> {
|
|
116
|
-
if (!this.isCacheWriteAllowed) {
|
|
117
|
-
terminal.writeErrorLine('Writing to cache is not allowed in the current configuration.');
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
const result: boolean | Buffer = await this._makeHttpRequestAsync({
|
|
125
|
-
terminal: terminal,
|
|
126
|
-
relUrl: `${this._cacheKeyPrefix}${cacheId}`,
|
|
127
|
-
method: this._uploadMethod,
|
|
128
|
-
body: objectBuffer,
|
|
129
|
-
warningText: 'Could not write cache entry',
|
|
130
|
-
readBody: false,
|
|
131
|
-
maxAttempts: MAX_HTTP_CACHE_ATTEMPTS
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return result !== false;
|
|
135
|
-
} catch (e) {
|
|
136
|
-
terminal.writeWarningLine(`Error uploading cache entry: ${e}`);
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {
|
|
142
|
-
await CredentialCache.usingAsync(
|
|
143
|
-
{
|
|
144
|
-
supportEditing: true
|
|
145
|
-
},
|
|
146
|
-
async (credentialsCache: CredentialCache) => {
|
|
147
|
-
credentialsCache.setCacheEntry(this._credentialCacheId, {
|
|
148
|
-
credential: credential
|
|
149
|
-
});
|
|
150
|
-
await credentialsCache.saveIfModifiedAsync();
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {
|
|
156
|
-
if (!this._tokenHandler) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
`The interactive cloud credentials flow is not configured.\n` +
|
|
159
|
-
`Set the 'tokenHandler' setting in 'common/config/rush-plugins/${this._pluginName}.json' to a command that writes your credentials to standard output and exits with code 0 ` +
|
|
160
|
-
`or provide your credentials to rush using the --credential flag instead. Credentials must be the ` +
|
|
161
|
-
`'Authorization' header expected by ${this._url.href}`
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;
|
|
166
|
-
terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);
|
|
167
|
-
const result: SpawnSyncReturns<string> = Executable.spawnSync(
|
|
168
|
-
this._tokenHandler.exec,
|
|
169
|
-
this._tokenHandler.args || [],
|
|
170
|
-
{
|
|
171
|
-
currentWorkingDirectory: this._rushProjectRoot
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
terminal.writeErrorLine(result.stderr);
|
|
176
|
-
|
|
177
|
-
if (result.error) {
|
|
178
|
-
throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const credential: string = result.stdout.trim();
|
|
182
|
-
terminal.writeVerboseLine('Got credentials');
|
|
183
|
-
|
|
184
|
-
await this.updateCachedCredentialAsync(terminal, credential);
|
|
185
|
-
|
|
186
|
-
terminal.writeLine('Updated credentials cache');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {
|
|
190
|
-
await CredentialCache.usingAsync(
|
|
191
|
-
{
|
|
192
|
-
supportEditing: true
|
|
193
|
-
},
|
|
194
|
-
async (credentialsCache: CredentialCache) => {
|
|
195
|
-
credentialsCache.deleteCacheEntry(this._credentialCacheId);
|
|
196
|
-
await credentialsCache.saveIfModifiedAsync();
|
|
197
|
-
}
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private get _credentialCacheId(): string {
|
|
202
|
-
if (!this.__credentialCacheId) {
|
|
203
|
-
const cacheIdParts: string[] = [this._url.href];
|
|
204
|
-
|
|
205
|
-
if (this._isCacheWriteAllowedByConfiguration) {
|
|
206
|
-
cacheIdParts.push('cacheWriteAllowed');
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.__credentialCacheId = cacheIdParts.join('|');
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return this.__credentialCacheId;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private async _makeHttpRequestAsync(options: {
|
|
216
|
-
terminal: ITerminal;
|
|
217
|
-
relUrl: string;
|
|
218
|
-
method: 'GET' | UploadMethod;
|
|
219
|
-
body: Buffer | undefined;
|
|
220
|
-
warningText: string;
|
|
221
|
-
readBody: boolean;
|
|
222
|
-
maxAttempts: number;
|
|
223
|
-
credentialOptions?: CredentialsOptions;
|
|
224
|
-
}): Promise<Buffer | boolean> {
|
|
225
|
-
const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;
|
|
226
|
-
const safeCredentialOptions: CredentialsOptions = credentialOptions ?? CredentialsOptions.Optional;
|
|
227
|
-
const credentials: string | undefined = await this._tryGetCredentialsAsync(safeCredentialOptions);
|
|
228
|
-
const url: string = new URL(relUrl, this._url).href;
|
|
229
|
-
|
|
230
|
-
const headers: Record<string, string> = {};
|
|
231
|
-
if (typeof credentials === 'string') {
|
|
232
|
-
headers.Authorization = credentials;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
for (const [key, value] of Object.entries(this._headers)) {
|
|
236
|
-
if (typeof value === 'string') {
|
|
237
|
-
headers[key] = value;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const bodyLength: number | 'unknown' = (body as { length: number })?.length || 'unknown';
|
|
242
|
-
|
|
243
|
-
terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);
|
|
244
|
-
|
|
245
|
-
const webClient: WebClient = new WebClient();
|
|
246
|
-
const response: IWebClientResponse = await webClient.fetchAsync(url, {
|
|
247
|
-
verb: method,
|
|
248
|
-
headers: headers,
|
|
249
|
-
body: body,
|
|
250
|
-
redirect: 'follow',
|
|
251
|
-
timeoutMs: 0 // Use the default timeout
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
if (!response.ok) {
|
|
255
|
-
const isNonCredentialResponse: boolean = response.status >= 500 && response.status < 600;
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
!isNonCredentialResponse &&
|
|
259
|
-
typeof credentials !== 'string' &&
|
|
260
|
-
safeCredentialOptions === CredentialsOptions.Optional
|
|
261
|
-
) {
|
|
262
|
-
// If we don't already have credentials yet, and we got a response from the server
|
|
263
|
-
// that is a "normal" failure (4xx), then we assume that credentials are probably
|
|
264
|
-
// required. Re-attempt the request, requiring credentials this time.
|
|
265
|
-
//
|
|
266
|
-
// This counts as part of the "first attempt", so it is not included in the max attempts
|
|
267
|
-
return await this._makeHttpRequestAsync({
|
|
268
|
-
...options,
|
|
269
|
-
credentialOptions: CredentialsOptions.Required
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (options.maxAttempts > 1) {
|
|
274
|
-
// Pause a bit before retrying in case the server is busy
|
|
275
|
-
// Add some random jitter to the retry so we can spread out load on the remote service
|
|
276
|
-
// A proper solution might add exponential back off in case the retry count is high (10 or more)
|
|
277
|
-
const factor: number = 1.0 + Math.random(); // A random number between 1.0 and 2.0
|
|
278
|
-
const retryDelay: number = Math.floor(factor * this._minHttpRetryDelayMs);
|
|
279
|
-
|
|
280
|
-
await Async.sleepAsync(retryDelay);
|
|
281
|
-
|
|
282
|
-
return await this._makeHttpRequestAsync({ ...options, maxAttempts: options.maxAttempts - 1 });
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
this._reportFailure(terminal, method, response, false, warningText);
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const result: Buffer | boolean = readBody ? await response.getBufferAsync() : true;
|
|
290
|
-
|
|
291
|
-
terminal.writeDebugLine(
|
|
292
|
-
`[http-build-cache] actual response: ${response.status} ${url} ${
|
|
293
|
-
result === true ? 'true' : result.length
|
|
294
|
-
} bytes`
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
return result;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
private async _tryGetCredentialsAsync(options: CredentialsOptions.Required): Promise<string>;
|
|
301
|
-
private async _tryGetCredentialsAsync(options: CredentialsOptions.Optional): Promise<string | undefined>;
|
|
302
|
-
private async _tryGetCredentialsAsync(options: CredentialsOptions.Omit): Promise<undefined>;
|
|
303
|
-
private async _tryGetCredentialsAsync(options: CredentialsOptions): Promise<string | undefined>;
|
|
304
|
-
private async _tryGetCredentialsAsync(options: CredentialsOptions): Promise<string | undefined> {
|
|
305
|
-
if (options === CredentialsOptions.Omit) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
let credentials: string | undefined = this._environmentCredential;
|
|
310
|
-
|
|
311
|
-
if (credentials === undefined) {
|
|
312
|
-
credentials = await this._tryGetCredentialsFromCacheAsync();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (typeof credentials !== 'string' && options === CredentialsOptions.Required) {
|
|
316
|
-
throw new Error(
|
|
317
|
-
[
|
|
318
|
-
`Credentials for ${this._url.href} have not been provided.`,
|
|
319
|
-
`In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,
|
|
320
|
-
``,
|
|
321
|
-
`For local developers, run:`,
|
|
322
|
-
``,
|
|
323
|
-
` rush update-cloud-credentials --interactive`,
|
|
324
|
-
``
|
|
325
|
-
].join('\n')
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return credentials;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
private async _tryGetCredentialsFromCacheAsync(): Promise<string | undefined> {
|
|
333
|
-
let cacheEntry: ICredentialCacheEntry | undefined;
|
|
334
|
-
|
|
335
|
-
await CredentialCache.usingAsync(
|
|
336
|
-
{
|
|
337
|
-
supportEditing: false
|
|
338
|
-
},
|
|
339
|
-
(credentialsCache: CredentialCache) => {
|
|
340
|
-
cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
if (cacheEntry) {
|
|
345
|
-
const expirationTime: number | undefined = cacheEntry.expires?.getTime();
|
|
346
|
-
if (!expirationTime || expirationTime >= Date.now()) {
|
|
347
|
-
return cacheEntry.credential;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
private _getFailureType(
|
|
353
|
-
requestMethod: string,
|
|
354
|
-
response: IWebClientResponse,
|
|
355
|
-
isRedirect: boolean
|
|
356
|
-
): FailureType {
|
|
357
|
-
if (response.ok) {
|
|
358
|
-
return FailureType.None;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
switch (response.status) {
|
|
362
|
-
case 503: {
|
|
363
|
-
// We select 503 specifically because this represents "service unavailable" and
|
|
364
|
-
// "rate limit throttle" errors, which are transient issues.
|
|
365
|
-
//
|
|
366
|
-
// There are other 5xx errors, such as 501, that can occur if the request is
|
|
367
|
-
// malformed, so as a general rule we want to let through other 5xx errors
|
|
368
|
-
// so the user can troubleshoot.
|
|
369
|
-
|
|
370
|
-
// Don't fail production builds with warnings for transient issues
|
|
371
|
-
return FailureType.Informational;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
case 401:
|
|
375
|
-
case 403:
|
|
376
|
-
case 407: {
|
|
377
|
-
if (requestMethod === 'GET' && (isRedirect || response.redirected)) {
|
|
378
|
-
// Cache misses for GET requests are not errors
|
|
379
|
-
// This is a workaround behavior where a server can issue a redirect and we fail to authenticate at the new location.
|
|
380
|
-
// We do not want to signal this as an authentication failure because the authorization header is not passed on to redirects.
|
|
381
|
-
// i.e The authentication header was accepted for the first request and therefore subsequent failures
|
|
382
|
-
// where it was not present should not be attributed to the header.
|
|
383
|
-
// This scenario usually comes up with services that redirect to pre-signed URLS that don't actually exist.
|
|
384
|
-
// Those services then usually treat the 404 as a 403 to prevent leaking information.
|
|
385
|
-
return FailureType.None;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return FailureType.Authentication;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
case 404: {
|
|
392
|
-
if (requestMethod === 'GET') {
|
|
393
|
-
// Cache misses for GET requests are not errors
|
|
394
|
-
return FailureType.None;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// Let dev builds succeed, let Prod builds fail
|
|
400
|
-
return FailureType.Warning;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
private _reportFailure(
|
|
404
|
-
terminal: ITerminal,
|
|
405
|
-
requestMethod: string,
|
|
406
|
-
response: IWebClientResponse,
|
|
407
|
-
isRedirect: boolean,
|
|
408
|
-
message: string
|
|
409
|
-
): void {
|
|
410
|
-
switch (this._getFailureType(requestMethod, response, isRedirect)) {
|
|
411
|
-
default: {
|
|
412
|
-
terminal.writeErrorLine(`${message}: HTTP ${response.status}: ${response.statusText}`);
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
case FailureType.Warning: {
|
|
417
|
-
terminal.writeWarningLine(`${message}: HTTP ${response.status}: ${response.statusText}`);
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
case FailureType.Informational: {
|
|
422
|
-
terminal.writeLine(`${message}: HTTP ${response.status}: ${response.statusText}`);
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
case FailureType.None: {
|
|
427
|
-
terminal.writeDebugLine(`${message}: HTTP ${response.status}: ${response.statusText}`);
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
case FailureType.Authentication: {
|
|
432
|
-
throw new Error(
|
|
433
|
-
[
|
|
434
|
-
`${this._url.href} responded with ${response.status}: ${response.statusText}.`,
|
|
435
|
-
`Credentials may be misconfigured or have expired.`,
|
|
436
|
-
`In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,
|
|
437
|
-
``,
|
|
438
|
-
`For local developers, run:`,
|
|
439
|
-
``,
|
|
440
|
-
` rush update-cloud-credentials --interactive`,
|
|
441
|
-
``
|
|
442
|
-
].join('\n')
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
-
// See LICENSE in the project root for license information.
|
|
3
|
-
|
|
4
|
-
import type { IRushPlugin, RushSession, RushConfiguration } from '@rushstack/rush-sdk';
|
|
5
|
-
import type { IHttpBuildCacheProviderOptions, UploadMethod } from './HttpBuildCacheProvider';
|
|
6
|
-
|
|
7
|
-
const PLUGIN_NAME: string = 'HttpBuildCachePlugin';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export interface IRushHttpBuildCachePluginConfig {
|
|
13
|
-
/**
|
|
14
|
-
* The URL of the server that stores the caches (e.g. "https://build-caches.example.com").
|
|
15
|
-
*/
|
|
16
|
-
url: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The HTTP method to use when writing to the cache (defaults to PUT).
|
|
20
|
-
*/
|
|
21
|
-
uploadMethod?: UploadMethod;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* An optional set of HTTP headers to pass to the cache server.
|
|
25
|
-
*/
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* An optional command that prints the endpoint's credentials to stdout. Provide the
|
|
30
|
-
* command or script to execute and, optionally, any arguments to pass to the script.
|
|
31
|
-
*/
|
|
32
|
-
tokenHandler?: {
|
|
33
|
-
exec: string;
|
|
34
|
-
args?: string[];
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Prefix for cache keys.
|
|
39
|
-
*/
|
|
40
|
-
cacheKeyPrefix?: string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* If set to true, allow writing to the cache. Defaults to false.
|
|
44
|
-
*/
|
|
45
|
-
isCacheWriteAllowed?: boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export class RushHttpBuildCachePlugin implements IRushPlugin {
|
|
52
|
-
public readonly pluginName: string = PLUGIN_NAME;
|
|
53
|
-
|
|
54
|
-
public apply(rushSession: RushSession, rushConfig: RushConfiguration): void {
|
|
55
|
-
rushSession.hooks.initialize.tap(this.pluginName, () => {
|
|
56
|
-
rushSession.registerCloudBuildCacheProviderFactory('http', async (buildCacheConfig) => {
|
|
57
|
-
const config: IRushHttpBuildCachePluginConfig = (
|
|
58
|
-
buildCacheConfig as typeof buildCacheConfig & {
|
|
59
|
-
httpConfiguration: IRushHttpBuildCachePluginConfig;
|
|
60
|
-
}
|
|
61
|
-
).httpConfiguration;
|
|
62
|
-
|
|
63
|
-
const { url, uploadMethod, headers, tokenHandler, cacheKeyPrefix, isCacheWriteAllowed } = config;
|
|
64
|
-
|
|
65
|
-
const options: IHttpBuildCacheProviderOptions = {
|
|
66
|
-
pluginName: this.pluginName,
|
|
67
|
-
rushJsonFolder: rushConfig.rushJsonFolder,
|
|
68
|
-
url: url,
|
|
69
|
-
uploadMethod: uploadMethod,
|
|
70
|
-
headers: headers,
|
|
71
|
-
tokenHandler: tokenHandler,
|
|
72
|
-
cacheKeyPrefix: cacheKeyPrefix,
|
|
73
|
-
isCacheWriteAllowed: !!isCacheWriteAllowed
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const { HttpBuildCacheProvider } = await import('./HttpBuildCacheProvider');
|
|
77
|
-
return new HttpBuildCacheProvider(options, rushSession);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
-
// See LICENSE in the project root for license information.
|
|
3
|
-
|
|
4
|
-
import { RushHttpBuildCachePlugin } from './RushHttpBuildCachePlugin';
|
|
5
|
-
|
|
6
|
-
export default RushHttpBuildCachePlugin;
|
|
7
|
-
export type { IHttpBuildCacheProviderOptions, UploadMethod } from './HttpBuildCacheProvider';
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
3
|
-
"title": "Configuration for build cache with HTTPS server",
|
|
4
|
-
"type": "object",
|
|
5
|
-
"required": ["url"],
|
|
6
|
-
"properties": {
|
|
7
|
-
"url": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "(Required) The URL of the server that stores the caches (e.g. \"https://build-caches.example.com\").",
|
|
10
|
-
"format": "uri"
|
|
11
|
-
},
|
|
12
|
-
"uploadMethod": {
|
|
13
|
-
"type": "string",
|
|
14
|
-
"description": "(Optional) The HTTP method to use when writing to the cache (defaults to PUT).",
|
|
15
|
-
"enum": ["PUT", "POST", "PATCH"],
|
|
16
|
-
"default": "PUT"
|
|
17
|
-
},
|
|
18
|
-
"headers": {
|
|
19
|
-
"type": "object",
|
|
20
|
-
"description": "(Optional) HTTP headers to pass to the cache server",
|
|
21
|
-
"properties": {},
|
|
22
|
-
"additionalProperties": {
|
|
23
|
-
"type": "string"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"tokenHandler": {
|
|
27
|
-
"type": "object",
|
|
28
|
-
"description": "(Optional) Shell command that prints the authorization token needed to communicate with the HTTPS server and exits with code 0. This command will be executed from the root of the monorepo.",
|
|
29
|
-
"properties": {
|
|
30
|
-
"exec": {
|
|
31
|
-
"type": "string",
|
|
32
|
-
"description": "(Required) The command or script to execute."
|
|
33
|
-
},
|
|
34
|
-
"args": {
|
|
35
|
-
"type": "array",
|
|
36
|
-
"description": "(Optional) Arguments to pass to the command or script.",
|
|
37
|
-
"items": {
|
|
38
|
-
"type": "string"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"cacheKeyPrefix": {
|
|
44
|
-
"type": "string",
|
|
45
|
-
"description": "(Optional) prefix for cache keys."
|
|
46
|
-
},
|
|
47
|
-
"isCacheWriteAllowed": {
|
|
48
|
-
"type": "boolean",
|
|
49
|
-
"description": "(Optional) If set to true, allow writing to the cache. Defaults to false."
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|