@rushstack/rush-http-build-cache-plugin 5.110.0 → 5.110.2
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/.rush/temp/operation/_phase_build/all.log +6 -6
- package/.rush/temp/operation/_phase_build/state.json +1 -1
- package/.rush/temp/operation/_phase_test/all.log +15 -15
- package/.rush/temp/operation/_phase_test/state.json +1 -1
- package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_build-6123140279635b4e69641307e04c82615d4a5778.tar.log → rushstack+rush-http-build-cache-plugin-_phase_build-44d119020b2846f013b0b59f95544625e9d86ab5.tar.log} +2 -2
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_build-44d119020b2846f013b0b59f95544625e9d86ab5.untar.log +10 -0
- package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_test-78333a9310f75472822f70554dee637804eb3b97.tar.log → rushstack+rush-http-build-cache-plugin-_phase_test-0bc01f397b348cba40823329640020e159633e7c.tar.log} +2 -2
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_test-0bc01f397b348cba40823329640020e159633e7c.untar.log +10 -0
- package/README.md +116 -116
- package/config/jest.config.json +14 -14
- package/config/rig.json +18 -18
- package/coverage/HttpBuildCacheProvider.ts.html +1 -1
- package/coverage/RushHttpBuildCachePlugin.ts.html +1 -1
- package/coverage/cobertura-coverage.xml +5 -5
- package/coverage/index.html +1 -1
- package/coverage/index.ts.html +1 -1
- package/coverage/junit.xml +4 -4
- package/lib/HttpBuildCacheProvider.js.map +1 -1
- package/lib/RushHttpBuildCachePlugin.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/schemas/plugin-config.schema.json +52 -52
- package/lib/test/HttpBuildCacheProvider.test.js.map +1 -1
- package/package.json +5 -5
- package/rush-logs/rush-http-build-cache-plugin._phase_build.cache.log +8 -8
- package/rush-logs/rush-http-build-cache-plugin._phase_build.log +6 -6
- package/rush-logs/rush-http-build-cache-plugin._phase_test.cache.log +17 -17
- package/rush-logs/rush-http-build-cache-plugin._phase_test.log +15 -15
- package/rush-plugin-manifest.json +11 -11
- package/src/HttpBuildCacheProvider.ts +424 -424
- package/src/RushHttpBuildCachePlugin.ts +81 -81
- package/src/index.ts +4 -4
- package/src/schemas/plugin-config.schema.json +52 -52
- package/src/test/HttpBuildCacheProvider.test.ts +115 -115
- package/temp/build/typescript/ts_l9Fw4VUO.json +1 -1
- package/tsconfig.json +3 -3
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_build-6123140279635b4e69641307e04c82615d4a5778.untar.log +0 -10
- package/.rush/temp/rushstack+rush-http-build-cache-plugin-_phase_test-78333a9310f75472822f70554dee637804eb3b97.untar.log +0 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Invoking: heft run --only build -- --clean --production
|
|
2
|
-
---- build started ----
|
|
3
|
-
[build:typescript] Using TypeScript version 5.0.4
|
|
4
|
-
[build:typescript] Copied 1 folder or file and linked 0 files
|
|
5
|
-
---- build finished (
|
|
6
|
-
-------------------- Finished (
|
|
1
|
+
Invoking: heft run --only build -- --clean --production
|
|
2
|
+
---- build started ----
|
|
3
|
+
[build:typescript] Using TypeScript version 5.0.4
|
|
4
|
+
[build:typescript] Copied 1 folder or file and linked 0 files
|
|
5
|
+
---- build finished (6.182s) ----
|
|
6
|
+
-------------------- Finished (6.19s) --------------------
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
|
8
|
-
[test:jest] PASS lib
|
|
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 (
|
|
15
|
-
-------------------- Finished (
|
|
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.013s, 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 (2.676s) ----
|
|
15
|
+
-------------------- Finished (2.686s) --------------------
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Start time:
|
|
2
|
-
Invoking "
|
|
1
|
+
Start time: Thu Nov 16 2023 01:34:36 GMT+0000 (Coordinated Universal Time)
|
|
2
|
+
Invoking "/usr/bin/tar -c -f /mnt/vss/_work/1/s/common/temp/build-cache/rushstack+rush-http-build-cache-plugin-_phase_build-44d119020b2846f013b0b59f95544625e9d86ab5-98b41b4169792d02.temp -z --files-from=-"
|
|
3
3
|
|
|
4
4
|
======= BEGIN PROCESS INPUT ======
|
|
5
5
|
.rush/temp/operation/_phase_build/all.log
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Start time: Thu Nov 16 2023 01:36:06 GMT+0000 (Coordinated Universal Time)
|
|
2
|
+
Invoking "/usr/bin/tar -x -m -f /mnt/vss/_work/1/s/common/temp/build-cache/rushstack+rush-http-build-cache-plugin-_phase_build-44d119020b2846f013b0b59f95544625e9d86ab5"
|
|
3
|
+
|
|
4
|
+
======= BEGIN PROCESS INPUT ======
|
|
5
|
+
|
|
6
|
+
======== END PROCESS INPUT =======
|
|
7
|
+
======= BEGIN PROCESS OUTPUT =======
|
|
8
|
+
======== END PROCESS OUTPUT ========
|
|
9
|
+
|
|
10
|
+
Exited with code "0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Start time:
|
|
2
|
-
Invoking "
|
|
1
|
+
Start time: Thu Nov 16 2023 01:34:39 GMT+0000 (Coordinated Universal Time)
|
|
2
|
+
Invoking "/usr/bin/tar -c -f /mnt/vss/_work/1/s/common/temp/build-cache/rushstack+rush-http-build-cache-plugin-_phase_test-0bc01f397b348cba40823329640020e159633e7c-690a4df1dae3ae4e.temp -z --files-from=-"
|
|
3
3
|
|
|
4
4
|
======= BEGIN PROCESS INPUT ======
|
|
5
5
|
.rush/temp/operation/_phase_test/all.log
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Start time: Thu Nov 16 2023 01:36:06 GMT+0000 (Coordinated Universal Time)
|
|
2
|
+
Invoking "/usr/bin/tar -x -m -f /mnt/vss/_work/1/s/common/temp/build-cache/rushstack+rush-http-build-cache-plugin-_phase_test-0bc01f397b348cba40823329640020e159633e7c"
|
|
3
|
+
|
|
4
|
+
======= BEGIN PROCESS INPUT ======
|
|
5
|
+
|
|
6
|
+
======== END PROCESS INPUT =======
|
|
7
|
+
======= BEGIN PROCESS OUTPUT =======
|
|
8
|
+
======== END PROCESS OUTPUT ========
|
|
9
|
+
|
|
10
|
+
Exited with code "0"
|
package/README.md
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
# @rushstack/rush-http-build-cache-plugin
|
|
2
|
-
|
|
3
|
-
A Rush plugin that uses HTTP/HTTPS to manage cache objects.
|
|
4
|
-
|
|
5
|
-
Authentication is provided via standard `Authorization` HTTP headers, with the value (a Bearer or Basic token) configured using a custom node script. Your "tokenHandler" node script is automatically called when the user updates their cloud credentials.
|
|
6
|
-
|
|
7
|
-
## Configuration
|
|
8
|
-
|
|
9
|
-
To use the HTTP build cache plugin, enable it in `common/config/rush/build-cache.json`:
|
|
10
|
-
|
|
11
|
-
```json
|
|
12
|
-
{
|
|
13
|
-
"buildCacheEnabled": true,
|
|
14
|
-
|
|
15
|
-
"cacheProvider": "http"
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Then customize the `httpConfiguration` block. For typical use cases, where you'll use a remote HTTP URL with authentication, you'll need to provide at least the `url` and `tokenHandler` options:
|
|
20
|
-
|
|
21
|
-
```json
|
|
22
|
-
{
|
|
23
|
-
"httpConfiguration": {
|
|
24
|
-
"url": "https://build-cache.example.com",
|
|
25
|
-
"tokenHandler": {
|
|
26
|
-
"exec": "node",
|
|
27
|
-
"args": ["common/scripts/custom-script-that-returns-an-authentication-header.js"]
|
|
28
|
-
},
|
|
29
|
-
"isCacheWriteAllowed": false
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
(For more detail on the above properties and additional optional properties, consult the default `build-cache.json` file.)
|
|
35
|
-
|
|
36
|
-
## Authorization Details
|
|
37
|
-
|
|
38
|
-
The HTTP build cache plugin offloads authorization to an external executable script that you define. A typical use case would be to create a simple script, for example `common/scripts/cache-auth.js`, that prints an Authorization header value when executed.
|
|
39
|
-
|
|
40
|
-
For example:
|
|
41
|
-
|
|
42
|
-
```console
|
|
43
|
-
node common/scripts/cache-auth.js
|
|
44
|
-
# => Bearer 0284357923592790DDb979dBcd2zz
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
How the script generates authorization values is up to you, and depends on the configuration of your remote cache server.
|
|
48
|
-
|
|
49
|
-
Possible implementations:
|
|
50
|
-
|
|
51
|
-
- The script could read simple environment variables (`CACHE_USER` and `CACHE_TOKEN`) defined by the developer
|
|
52
|
-
- It could reuse existing credentials your developers have, like NPM tokens, GitHub credentials, or jFrog API tokens
|
|
53
|
-
- It could make an HTTP call to another server accessible by your developers that returns temporary credentials
|
|
54
|
-
|
|
55
|
-
## HTTP Cache Server Requirements
|
|
56
|
-
|
|
57
|
-
The HTTP build cache plugin can use almost any HTTP/HTTPS backend for remote caching, as long as it honors the following rules:
|
|
58
|
-
|
|
59
|
-
- Uses `Authorization: Bearer xxx` or `Authorization: Basic xxx` headers for authentication.
|
|
60
|
-
- Accepts GET requests for cache reads.
|
|
61
|
-
- Accepts PUT requests for cache writes (with a raw request body -- no `form/multipart` MIME types).
|
|
62
|
-
- Cache hits return HTTP 200 with the file in the response body.
|
|
63
|
-
- Successful cache writes return HTTP 2xx (200-299).
|
|
64
|
-
- Cache misses return HTTP 404 or HTTP 403.
|
|
65
|
-
- Invalid or missing authentication returns HTTP 401.
|
|
66
|
-
|
|
67
|
-
## Examples
|
|
68
|
-
|
|
69
|
-
### Gradle Build Cache Server
|
|
70
|
-
|
|
71
|
-
The Gradle Build Cache Server (typically used to support Gradle Remote Build Cache) meets all of the requirements above, so if you don't have another server in mind, you can use it as your remote backend.
|
|
72
|
-
|
|
73
|
-
First, start up and configure your build cache node locally:
|
|
74
|
-
|
|
75
|
-
- Download latest JAR file from https://docs.gradle.com/build-cache-node/
|
|
76
|
-
- Start the service: `java -jar build-cache-node-14.0.jar start`
|
|
77
|
-
- Copy the startup banner information, and navigate to the specified localhost port
|
|
78
|
-
- Enter the temporary username/password credentials printed in the startup banner
|
|
79
|
-
- Click Build Cache > Settings > Cache Access Control and grant "Read & write" access to Anonymous
|
|
80
|
-
|
|
81
|
-
Second, configure your `build-cache.json` file as described in the Configuration section:
|
|
82
|
-
|
|
83
|
-
- Note that your `url` must end with `/cache/`, for example, `http://localhost:5071/cache/`.
|
|
84
|
-
- To test reading and writing, set `isCacheWriteAllowed: true`.
|
|
85
|
-
- Configure `tokenHandler` to point to a script that prints a Basic or Bearer Authorization value (this can be a dummy string if you granted Read and Write to Anonymous in your build cache node configuration).
|
|
86
|
-
|
|
87
|
-
Note that the Gradle Build Cache Server has a stricter format for its cache keys (they should be a simple hexadecimal hash with no non-alphanumeric characters). Configure this setting in your `build-cache.json` file:
|
|
88
|
-
|
|
89
|
-
```json
|
|
90
|
-
{
|
|
91
|
-
"cacheEntryNamePattern": "[hash]"
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Last, initialize your cache credentials using Rush:
|
|
96
|
-
|
|
97
|
-
```console
|
|
98
|
-
rush update-cloud-credentials --interactive
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
To test out your remote build cache with full debugging output (for spotting any errors reading or writing the cache), run with the `--debug` flag:
|
|
102
|
-
|
|
103
|
-
```console
|
|
104
|
-
rush --debug build --verbose
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
> If you go on to deploy Rush remote build caching to your developers using the Gradle Build Cache, update your `tokenHandler`
|
|
108
|
-
> script to reflect your use case -- for example, you could require each developer to have a designated username/token configured
|
|
109
|
-
> via environment variables, and configure Cache Access Control with the corresponding entries. In this case the `tokenHandler`
|
|
110
|
-
> script should read the environment variables and print out an Authorization header, for example:
|
|
111
|
-
>
|
|
112
|
-
> ```javascript
|
|
113
|
-
> // common/scripts/build-cache-auth.js
|
|
114
|
-
> const credentials = `${process.env.CACHE_USER}:${process.env.CACHE_TOKEN}`;
|
|
115
|
-
> console.log('Basic ' + Buffer.from(credentials).toString('base64'));
|
|
116
|
-
> ```
|
|
1
|
+
# @rushstack/rush-http-build-cache-plugin
|
|
2
|
+
|
|
3
|
+
A Rush plugin that uses HTTP/HTTPS to manage cache objects.
|
|
4
|
+
|
|
5
|
+
Authentication is provided via standard `Authorization` HTTP headers, with the value (a Bearer or Basic token) configured using a custom node script. Your "tokenHandler" node script is automatically called when the user updates their cloud credentials.
|
|
6
|
+
|
|
7
|
+
## Configuration
|
|
8
|
+
|
|
9
|
+
To use the HTTP build cache plugin, enable it in `common/config/rush/build-cache.json`:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"buildCacheEnabled": true,
|
|
14
|
+
|
|
15
|
+
"cacheProvider": "http"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then customize the `httpConfiguration` block. For typical use cases, where you'll use a remote HTTP URL with authentication, you'll need to provide at least the `url` and `tokenHandler` options:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"httpConfiguration": {
|
|
24
|
+
"url": "https://build-cache.example.com",
|
|
25
|
+
"tokenHandler": {
|
|
26
|
+
"exec": "node",
|
|
27
|
+
"args": ["common/scripts/custom-script-that-returns-an-authentication-header.js"]
|
|
28
|
+
},
|
|
29
|
+
"isCacheWriteAllowed": false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
(For more detail on the above properties and additional optional properties, consult the default `build-cache.json` file.)
|
|
35
|
+
|
|
36
|
+
## Authorization Details
|
|
37
|
+
|
|
38
|
+
The HTTP build cache plugin offloads authorization to an external executable script that you define. A typical use case would be to create a simple script, for example `common/scripts/cache-auth.js`, that prints an Authorization header value when executed.
|
|
39
|
+
|
|
40
|
+
For example:
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
node common/scripts/cache-auth.js
|
|
44
|
+
# => Bearer 0284357923592790DDb979dBcd2zz
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
How the script generates authorization values is up to you, and depends on the configuration of your remote cache server.
|
|
48
|
+
|
|
49
|
+
Possible implementations:
|
|
50
|
+
|
|
51
|
+
- The script could read simple environment variables (`CACHE_USER` and `CACHE_TOKEN`) defined by the developer
|
|
52
|
+
- It could reuse existing credentials your developers have, like NPM tokens, GitHub credentials, or jFrog API tokens
|
|
53
|
+
- It could make an HTTP call to another server accessible by your developers that returns temporary credentials
|
|
54
|
+
|
|
55
|
+
## HTTP Cache Server Requirements
|
|
56
|
+
|
|
57
|
+
The HTTP build cache plugin can use almost any HTTP/HTTPS backend for remote caching, as long as it honors the following rules:
|
|
58
|
+
|
|
59
|
+
- Uses `Authorization: Bearer xxx` or `Authorization: Basic xxx` headers for authentication.
|
|
60
|
+
- Accepts GET requests for cache reads.
|
|
61
|
+
- Accepts PUT requests for cache writes (with a raw request body -- no `form/multipart` MIME types).
|
|
62
|
+
- Cache hits return HTTP 200 with the file in the response body.
|
|
63
|
+
- Successful cache writes return HTTP 2xx (200-299).
|
|
64
|
+
- Cache misses return HTTP 404 or HTTP 403.
|
|
65
|
+
- Invalid or missing authentication returns HTTP 401.
|
|
66
|
+
|
|
67
|
+
## Examples
|
|
68
|
+
|
|
69
|
+
### Gradle Build Cache Server
|
|
70
|
+
|
|
71
|
+
The Gradle Build Cache Server (typically used to support Gradle Remote Build Cache) meets all of the requirements above, so if you don't have another server in mind, you can use it as your remote backend.
|
|
72
|
+
|
|
73
|
+
First, start up and configure your build cache node locally:
|
|
74
|
+
|
|
75
|
+
- Download latest JAR file from https://docs.gradle.com/build-cache-node/
|
|
76
|
+
- Start the service: `java -jar build-cache-node-14.0.jar start`
|
|
77
|
+
- Copy the startup banner information, and navigate to the specified localhost port
|
|
78
|
+
- Enter the temporary username/password credentials printed in the startup banner
|
|
79
|
+
- Click Build Cache > Settings > Cache Access Control and grant "Read & write" access to Anonymous
|
|
80
|
+
|
|
81
|
+
Second, configure your `build-cache.json` file as described in the Configuration section:
|
|
82
|
+
|
|
83
|
+
- Note that your `url` must end with `/cache/`, for example, `http://localhost:5071/cache/`.
|
|
84
|
+
- To test reading and writing, set `isCacheWriteAllowed: true`.
|
|
85
|
+
- Configure `tokenHandler` to point to a script that prints a Basic or Bearer Authorization value (this can be a dummy string if you granted Read and Write to Anonymous in your build cache node configuration).
|
|
86
|
+
|
|
87
|
+
Note that the Gradle Build Cache Server has a stricter format for its cache keys (they should be a simple hexadecimal hash with no non-alphanumeric characters). Configure this setting in your `build-cache.json` file:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"cacheEntryNamePattern": "[hash]"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Last, initialize your cache credentials using Rush:
|
|
96
|
+
|
|
97
|
+
```console
|
|
98
|
+
rush update-cloud-credentials --interactive
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
To test out your remote build cache with full debugging output (for spotting any errors reading or writing the cache), run with the `--debug` flag:
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
rush --debug build --verbose
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
> If you go on to deploy Rush remote build caching to your developers using the Gradle Build Cache, update your `tokenHandler`
|
|
108
|
+
> script to reflect your use case -- for example, you could require each developer to have a designated username/token configured
|
|
109
|
+
> via environment variables, and configure Cache Access Control with the corresponding entries. In this case the `tokenHandler`
|
|
110
|
+
> script should read the environment variables and print out an Authorization header, for example:
|
|
111
|
+
>
|
|
112
|
+
> ```javascript
|
|
113
|
+
> // common/scripts/build-cache-auth.js
|
|
114
|
+
> const credentials = `${process.env.CACHE_USER}:${process.env.CACHE_TOKEN}`;
|
|
115
|
+
> console.log('Basic ' + Buffer.from(credentials).toString('base64'));
|
|
116
|
+
> ```
|
package/config/jest.config.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "local-node-rig/profiles/default/config/jest.config.json",
|
|
3
|
-
"clearMocks": true,
|
|
4
|
-
"restoreMocks": true,
|
|
5
|
-
"collectCoverage": true,
|
|
6
|
-
"coverageThreshold": {
|
|
7
|
-
"global": {
|
|
8
|
-
"branches": 4,
|
|
9
|
-
"functions": 15,
|
|
10
|
-
"lines": 4,
|
|
11
|
-
"statements": 4
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "local-node-rig/profiles/default/config/jest.config.json",
|
|
3
|
+
"clearMocks": true,
|
|
4
|
+
"restoreMocks": true,
|
|
5
|
+
"collectCoverage": true,
|
|
6
|
+
"coverageThreshold": {
|
|
7
|
+
"global": {
|
|
8
|
+
"branches": 4,
|
|
9
|
+
"functions": 15,
|
|
10
|
+
"lines": 4,
|
|
11
|
+
"statements": 4
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/config/rig.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
// The "rig.json" file directs tools to look for their config files in an external package.
|
|
3
|
-
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
|
|
4
|
-
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* (Required) The name of the rig package to inherit from.
|
|
8
|
-
* It should be an NPM package name with the "-rig" suffix.
|
|
9
|
-
*/
|
|
10
|
-
"rigPackageName": "local-node-rig",
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* (Optional) Selects a config profile from the rig package. The name must consist of
|
|
14
|
-
* lowercase alphanumeric words separated by hyphens, for example "sample-profile".
|
|
15
|
-
* If omitted, then the "default" profile will be used."
|
|
16
|
-
*/
|
|
17
|
-
"rigProfile": "default"
|
|
18
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// The "rig.json" file directs tools to look for their config files in an external package.
|
|
3
|
+
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
|
|
4
|
+
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* (Required) The name of the rig package to inherit from.
|
|
8
|
+
* It should be an NPM package name with the "-rig" suffix.
|
|
9
|
+
*/
|
|
10
|
+
"rigPackageName": "local-node-rig",
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* (Optional) Selects a config profile from the rig package. The name must consist of
|
|
14
|
+
* lowercase alphanumeric words separated by hyphens, for example "sample-profile".
|
|
15
|
+
* If omitted, then the "default" profile will be used."
|
|
16
|
+
*/
|
|
17
|
+
"rigProfile": "default"
|
|
18
|
+
}
|
|
@@ -1342,7 +1342,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
|
|
|
1342
1342
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
1343
1343
|
Code coverage generated by
|
|
1344
1344
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
1345
|
-
at 2023-
|
|
1345
|
+
at 2023-11-16T01:34:39.317Z
|
|
1346
1346
|
</div>
|
|
1347
1347
|
<script src="prettify.js"></script>
|
|
1348
1348
|
<script>
|
|
@@ -313,7 +313,7 @@
|
|
|
313
313
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
314
314
|
Code coverage generated by
|
|
315
315
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
316
|
-
at 2023-
|
|
316
|
+
at 2023-11-16T01:34:39.317Z
|
|
317
317
|
</div>
|
|
318
318
|
<script src="prettify.js"></script>
|
|
319
319
|
<script>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<?xml version="1.0" ?>
|
|
2
2
|
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
|
|
3
|
-
<coverage lines-valid="509" lines-covered="276" line-rate="0.5422" branches-valid="60" branches-covered="32" branch-rate="0.5333" timestamp="
|
|
3
|
+
<coverage lines-valid="509" lines-covered="276" line-rate="0.5422" branches-valid="60" branches-covered="32" branch-rate="0.5333" timestamp="1700098479291" complexity="0" version="0.1">
|
|
4
4
|
<sources>
|
|
5
|
-
<source
|
|
5
|
+
<source>/mnt/vss/_work/1/s/rush-plugins/rush-http-build-cache-plugin</source>
|
|
6
6
|
</sources>
|
|
7
7
|
<packages>
|
|
8
8
|
<package name="main" line-rate="0.5422" branch-rate="0.5333">
|
|
9
9
|
<classes>
|
|
10
|
-
<class name="HttpBuildCacheProvider.ts" filename="src
|
|
10
|
+
<class name="HttpBuildCacheProvider.ts" filename="src/HttpBuildCacheProvider.ts" line-rate="0.6509" branch-rate="0.5517">
|
|
11
11
|
<methods>
|
|
12
12
|
<method name="get isCacheWriteAllowed" hits="0" signature="()V">
|
|
13
13
|
<lines>
|
|
@@ -502,7 +502,7 @@
|
|
|
502
502
|
<line number="424" hits="1" branch="false"/>
|
|
503
503
|
</lines>
|
|
504
504
|
</class>
|
|
505
|
-
<class name="RushHttpBuildCachePlugin.ts" filename="src
|
|
505
|
+
<class name="RushHttpBuildCachePlugin.ts" filename="src/RushHttpBuildCachePlugin.ts" line-rate="0" branch-rate="0">
|
|
506
506
|
<methods>
|
|
507
507
|
<method name="(empty-report)" hits="0" signature="()V">
|
|
508
508
|
<lines>
|
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
<line number="81" hits="0" branch="false"/>
|
|
595
595
|
</lines>
|
|
596
596
|
</class>
|
|
597
|
-
<class name="index.ts" filename="src
|
|
597
|
+
<class name="index.ts" filename="src/index.ts" line-rate="0" branch-rate="0">
|
|
598
598
|
<methods>
|
|
599
599
|
<method name="(empty-report)" hits="0" signature="()V">
|
|
600
600
|
<lines>
|
package/coverage/index.html
CHANGED
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
132
132
|
Code coverage generated by
|
|
133
133
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
134
|
-
at 2023-
|
|
134
|
+
at 2023-11-16T01:34:39.317Z
|
|
135
135
|
</div>
|
|
136
136
|
<script src="prettify.js"></script>
|
|
137
137
|
<script>
|
package/coverage/index.ts.html
CHANGED
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
83
83
|
Code coverage generated by
|
|
84
84
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
85
|
-
at 2023-
|
|
85
|
+
at 2023-11-16T01:34:39.317Z
|
|
86
86
|
</div>
|
|
87
87
|
<script src="prettify.js"></script>
|
|
88
88
|
<script>
|
package/coverage/junit.xml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<testsuites name="jest tests" tests="2" failures="0" errors="0" time="1.
|
|
3
|
-
<testsuite name="HttpBuildCacheProvider" errors="0" failures="0" skipped="0" timestamp="2023-
|
|
4
|
-
<testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync > " name="prints warning if read credentials are not available (lib
|
|
2
|
+
<testsuites name="jest tests" tests="2" failures="0" errors="0" time="1.291">
|
|
3
|
+
<testsuite name="HttpBuildCacheProvider" errors="0" failures="0" skipped="0" timestamp="2023-11-16T01:34:37" time="1.013" tests="2">
|
|
4
|
+
<testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync > " name="prints warning if read credentials are not available (lib/test/HttpBuildCacheProvider.test.js)" time="0.018">
|
|
5
5
|
</testcase>
|
|
6
|
-
<testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync > " name="attempts up to 3 times to download a cache entry (lib
|
|
6
|
+
<testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync > " name="attempts up to 3 times to download a cache entry (lib/test/HttpBuildCacheProvider.test.js)" time="0.008">
|
|
7
7
|
</testcase>
|
|
8
8
|
</testsuite>
|
|
9
9
|
</testsuites>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBuildCacheProvider.js","sourceRoot":"","sources":["../src/HttpBuildCacheProvider.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA4E;AAC5E,kDAM6B;AAC7B,4DAAuD;AAEvD,IAAK,kBAIJ;AAJD,WAAK,kBAAkB;IACrB,mEAAQ,CAAA;IACR,mEAAQ,CAAA;IACR,2DAAI,CAAA;AACN,CAAC,EAJI,kBAAkB,KAAlB,kBAAkB,QAItB;AAED,IAAK,WAMJ;AAND,WAAK,WAAW;IACd,6CAAI,CAAA;IACJ,+DAAa,CAAA;IACb,mDAAO,CAAA;IACP,+CAAK,CAAA;IACL,iEAAc,CAAA;AAChB,CAAC,EANI,WAAW,KAAX,WAAW,QAMf;AAsBD,MAAM,uBAAuB,GAAW,CA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,CACb;oBACE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,GAAG;oBAC9E,mDAAmD;oBACnD,6FAA6F;oBAC7F,EAAE;oBACF,4BAA4B;oBAC5B,EAAE;oBACF,iDAAiD;oBACjD,EAAE;iBACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;aACH;SACF;IACH,CAAC;CACF;AAxXD,wDAwXC","sourcesContent":["import { ITerminal, Executable, Async } from '@rushstack/node-core-library';\r\nimport {\r\n ICloudBuildCacheProvider,\r\n ICredentialCacheEntry,\r\n CredentialCache,\r\n RushSession,\r\n EnvironmentConfiguration\r\n} from '@rushstack/rush-sdk';\r\nimport fetch, { BodyInit, Response } from 'node-fetch';\r\n\r\nenum CredentialsOptions {\r\n Optional,\r\n Required,\r\n Omit\r\n}\r\n\r\nenum FailureType {\r\n None,\r\n Informational,\r\n Warning,\r\n Error,\r\n Authentication\r\n}\r\n\r\nexport interface IHttpBuildCacheTokenHandler {\r\n exec: string;\r\n args?: string[];\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface IHttpBuildCacheProviderOptions {\r\n url: string;\r\n tokenHandler?: IHttpBuildCacheTokenHandler;\r\n uploadMethod?: string;\r\n minHttpRetryDelayMs?: number;\r\n headers?: Record<string, string>;\r\n cacheKeyPrefix?: string;\r\n isCacheWriteAllowed: boolean;\r\n pluginName: string;\r\n rushJsonFolder: string;\r\n}\r\n\r\nconst MAX_HTTP_CACHE_ATTEMPTS: number = 3;\r\nconst DEFAULT_MIN_HTTP_RETRY_DELAY_MS = 2500;\r\n\r\nexport class HttpBuildCacheProvider implements ICloudBuildCacheProvider {\r\n private readonly _pluginName: string;\r\n private readonly _rushProjectRoot: string;\r\n private readonly _environmentCredential: string | undefined;\r\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\r\n private readonly _url: URL;\r\n private readonly _uploadMethod: string;\r\n private readonly _headers: Record<string, string>;\r\n private readonly _cacheKeyPrefix: string;\r\n private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;\r\n private readonly _minHttpRetryDelayMs: number;\r\n private __credentialCacheId: string | undefined;\r\n\r\n public get isCacheWriteAllowed(): boolean {\r\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\r\n }\r\n\r\n public constructor(options: IHttpBuildCacheProviderOptions, rushSession: RushSession) {\r\n this._pluginName = options.pluginName;\r\n this._rushProjectRoot = options.rushJsonFolder;\r\n\r\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\r\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\r\n this._url = new URL(options.url.endsWith('/') ? options.url : options.url + '/');\r\n this._uploadMethod = options.uploadMethod ?? 'PUT';\r\n this._headers = options.headers ?? {};\r\n this._tokenHandler = options.tokenHandler;\r\n this._cacheKeyPrefix = options.cacheKeyPrefix ?? '';\r\n this._minHttpRetryDelayMs = options.minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;\r\n }\r\n\r\n public async tryGetCacheEntryBufferByIdAsync(\r\n terminal: ITerminal,\r\n cacheId: string\r\n ): Promise<Buffer | undefined> {\r\n try {\r\n const result = await this._http({\r\n terminal: terminal,\r\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\r\n method: 'GET',\r\n body: undefined,\r\n warningText: 'Could not get cache entry',\r\n readBody: true,\r\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\r\n });\r\n\r\n return Buffer.isBuffer(result) ? result : undefined;\r\n } catch (e) {\r\n terminal.writeWarningLine(`Error getting cache entry: ${e}`);\r\n return undefined;\r\n }\r\n }\r\n\r\n public async trySetCacheEntryBufferAsync(\r\n terminal: ITerminal,\r\n cacheId: string,\r\n objectBuffer: Buffer\r\n ): Promise<boolean> {\r\n if (!this.isCacheWriteAllowed) {\r\n terminal.writeErrorLine('Writing to cache is not allowed in the current configuration.');\r\n return false;\r\n }\r\n\r\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\r\n\r\n try {\r\n const result = await this._http({\r\n terminal: terminal,\r\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\r\n method: this._uploadMethod,\r\n body: objectBuffer,\r\n warningText: 'Could not write cache entry',\r\n readBody: false,\r\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\r\n });\r\n\r\n return result !== false;\r\n } catch (e) {\r\n terminal.writeWarningLine(`Error uploading cache entry: ${e}`);\r\n return false;\r\n }\r\n }\r\n\r\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\r\n await CredentialCache.usingAsync(\r\n {\r\n supportEditing: true\r\n },\r\n async (credentialsCache: CredentialCache) => {\r\n credentialsCache.setCacheEntry(this._credentialCacheId, {\r\n credential: credential\r\n });\r\n await credentialsCache.saveIfModifiedAsync();\r\n }\r\n );\r\n }\r\n\r\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\r\n if (!this._tokenHandler) {\r\n throw new Error(\r\n `The interactive cloud credentials flow is not configured.\\n` +\r\n `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 ` +\r\n `or provide your credentials to rush using the --credential flag instead. Credentials must be the ` +\r\n `'Authorization' header expected by ${this._url.href}`\r\n );\r\n }\r\n\r\n const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;\r\n terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);\r\n const result = Executable.spawnSync(this._tokenHandler.exec, this._tokenHandler.args || [], {\r\n currentWorkingDirectory: this._rushProjectRoot\r\n });\r\n\r\n terminal.writeErrorLine(result.stderr);\r\n\r\n if (result.error) {\r\n throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);\r\n }\r\n\r\n const credential = result.stdout.trim();\r\n terminal.writeVerboseLine('Got credentials');\r\n\r\n await this.updateCachedCredentialAsync(terminal, credential);\r\n\r\n terminal.writeLine('Updated credentials cache');\r\n }\r\n\r\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\r\n await CredentialCache.usingAsync(\r\n {\r\n supportEditing: true\r\n },\r\n async (credentialsCache: CredentialCache) => {\r\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\r\n await credentialsCache.saveIfModifiedAsync();\r\n }\r\n );\r\n }\r\n\r\n private get _credentialCacheId(): string {\r\n if (!this.__credentialCacheId) {\r\n const cacheIdParts: string[] = [this._url.href];\r\n\r\n if (this._isCacheWriteAllowedByConfiguration) {\r\n cacheIdParts.push('cacheWriteAllowed');\r\n }\r\n\r\n this.__credentialCacheId = cacheIdParts.join('|');\r\n }\r\n\r\n return this.__credentialCacheId;\r\n }\r\n\r\n private async _http(options: {\r\n terminal: ITerminal;\r\n relUrl: string;\r\n method: string;\r\n body: BodyInit | undefined;\r\n warningText: string;\r\n readBody: boolean;\r\n maxAttempts: number;\r\n credentialOptions?: CredentialsOptions;\r\n }): Promise<Buffer | boolean> {\r\n const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;\r\n const safeCredentialOptions = credentialOptions ?? CredentialsOptions.Optional;\r\n const credentials = await this._tryGetCredentials(safeCredentialOptions);\r\n const url = new URL(relUrl, this._url).href;\r\n\r\n const headers: Record<string, string> = {};\r\n if (typeof credentials === 'string') {\r\n headers.Authorization = credentials;\r\n }\r\n\r\n for (const [key, value] of Object.entries(this._headers)) {\r\n if (typeof value === 'string') {\r\n headers[key] = value;\r\n }\r\n }\r\n\r\n const bodyLength = (body as { length: number })?.length || 'unknown';\r\n\r\n terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);\r\n\r\n const response = await fetch(url, {\r\n method: method,\r\n headers: headers,\r\n body: body,\r\n redirect: 'follow'\r\n });\r\n\r\n if (!response.ok) {\r\n const isNonCredentialResponse = response.status >= 500 && response.status < 600;\r\n\r\n if (\r\n !isNonCredentialResponse &&\r\n typeof credentials !== 'string' &&\r\n safeCredentialOptions === CredentialsOptions.Optional\r\n ) {\r\n // If we don't already have credentials yet, and we got a response from the server\r\n // that is a \"normal\" failure (4xx), then we assume that credentials are probably\r\n // required. Re-attempt the request, requiring credentials this time.\r\n //\r\n // This counts as part of the \"first attempt\", so it is not included in the max attempts\r\n return await this._http({ ...options, credentialOptions: CredentialsOptions.Required });\r\n }\r\n\r\n if (options.maxAttempts > 1) {\r\n // Pause a bit before retrying in case the server is busy\r\n // Add some random jitter to the retry so we can spread out load on the remote service\r\n // A proper solution might add exponential back off in case the retry count is high (10 or more)\r\n const factor = 1.0 + Math.random(); // A random number between 1.0 and 2.0\r\n const retryDelay = Math.floor(factor * this._minHttpRetryDelayMs);\r\n\r\n await Async.sleep(retryDelay);\r\n\r\n return await this._http({ ...options, maxAttempts: options.maxAttempts - 1 });\r\n }\r\n\r\n this._reportFailure(terminal, method, response, false, warningText);\r\n return false;\r\n }\r\n\r\n const result: Buffer | boolean = readBody ? Buffer.from(await response.arrayBuffer()) : true;\r\n\r\n terminal.writeDebugLine(\r\n `[http-build-cache] actual response: ${response.status} ${url} ${\r\n result === true ? 'true' : result.length\r\n } bytes`\r\n );\r\n\r\n return result;\r\n }\r\n\r\n private async _tryGetCredentials(options: CredentialsOptions.Required): Promise<string>;\r\n private async _tryGetCredentials(options: CredentialsOptions.Optional): Promise<string | undefined>;\r\n private async _tryGetCredentials(options: CredentialsOptions.Omit): Promise<undefined>;\r\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined>;\r\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined> {\r\n if (options === CredentialsOptions.Omit) {\r\n return;\r\n }\r\n\r\n let credentials: string | undefined = this._environmentCredential;\r\n\r\n if (credentials === undefined) {\r\n credentials = await this._tryGetCredentialsFromCache();\r\n }\r\n\r\n if (typeof credentials !== 'string' && options === CredentialsOptions.Required) {\r\n throw new Error(\r\n [\r\n `Credentials for ${this._url.href} have not been provided.`,\r\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\r\n ``,\r\n `For local developers, run:`,\r\n ``,\r\n ` rush update-cloud-credentials --interactive`,\r\n ``\r\n ].join('\\n')\r\n );\r\n }\r\n\r\n return credentials;\r\n }\r\n\r\n private async _tryGetCredentialsFromCache(): Promise<string | undefined> {\r\n let cacheEntry: ICredentialCacheEntry | undefined;\r\n\r\n await CredentialCache.usingAsync(\r\n {\r\n supportEditing: false\r\n },\r\n (credentialsCache: CredentialCache) => {\r\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\r\n }\r\n );\r\n\r\n if (cacheEntry) {\r\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\r\n if (!expirationTime || expirationTime >= Date.now()) {\r\n return cacheEntry.credential;\r\n }\r\n }\r\n }\r\n\r\n private _getFailureType(requestMethod: string, response: Response, isRedirect: boolean): FailureType {\r\n if (response.ok) {\r\n return FailureType.None;\r\n }\r\n\r\n switch (response.status) {\r\n case 503: {\r\n // We select 503 specifically because this represents \"service unavailable\" and\r\n // \"rate limit throttle\" errors, which are transient issues.\r\n //\r\n // There are other 5xx errors, such as 501, that can occur if the request is\r\n // malformed, so as a general rule we want to let through other 5xx errors\r\n // so the user can troubleshoot.\r\n\r\n // Don't fail production builds with warnings for transient issues\r\n return FailureType.Informational;\r\n }\r\n\r\n case 401:\r\n case 403:\r\n case 407: {\r\n if (requestMethod === 'GET' && (isRedirect || response.redirected)) {\r\n // Cache misses for GET requests are not errors\r\n // This is a workaround behavior where a server can issue a redirect and we fail to authenticate at the new location.\r\n // We do not want to signal this as an authentication failure because the authorization header is not passed on to redirects.\r\n // i.e The authentication header was accepted for the first request and therefore subsequent failures\r\n // where it was not present should not be attributed to the header.\r\n // This scenario usually comes up with services that redirect to pre-signed URLS that don't actually exist.\r\n // Those services then usually treat the 404 as a 403 to prevent leaking information.\r\n return FailureType.None;\r\n }\r\n\r\n return FailureType.Authentication;\r\n }\r\n\r\n case 404: {\r\n if (requestMethod === 'GET') {\r\n // Cache misses for GET requests are not errors\r\n return FailureType.None;\r\n }\r\n }\r\n }\r\n\r\n // Let dev builds succeed, let Prod builds fail\r\n return FailureType.Warning;\r\n }\r\n\r\n private _reportFailure(\r\n terminal: ITerminal,\r\n requestMethod: string,\r\n response: Response,\r\n isRedirect: boolean,\r\n message: string\r\n ): void {\r\n switch (this._getFailureType(requestMethod, response, isRedirect)) {\r\n default: {\r\n terminal.writeErrorLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\r\n break;\r\n }\r\n\r\n case FailureType.Warning: {\r\n terminal.writeWarningLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\r\n break;\r\n }\r\n\r\n case FailureType.Informational: {\r\n terminal.writeLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\r\n break;\r\n }\r\n\r\n case FailureType.None: {\r\n terminal.writeDebugLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\r\n break;\r\n }\r\n\r\n case FailureType.Authentication: {\r\n throw new Error(\r\n [\r\n `${this._url.href} responded with ${response.status}: ${response.statusText}.`,\r\n `Credentials may be misconfigured or have expired.`,\r\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\r\n ``,\r\n `For local developers, run:`,\r\n ``,\r\n ` rush update-cloud-credentials --interactive`,\r\n ``\r\n ].join('\\n')\r\n );\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"HttpBuildCacheProvider.js","sourceRoot":"","sources":["../src/HttpBuildCacheProvider.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA4E;AAC5E,kDAM6B;AAC7B,4DAAuD;AAEvD,IAAK,kBAIJ;AAJD,WAAK,kBAAkB;IACrB,mEAAQ,CAAA;IACR,mEAAQ,CAAA;IACR,2DAAI,CAAA;AACN,CAAC,EAJI,kBAAkB,KAAlB,kBAAkB,QAItB;AAED,IAAK,WAMJ;AAND,WAAK,WAAW;IACd,6CAAI,CAAA;IACJ,+DAAa,CAA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KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;gBACvF,MAAM;aACP;YAED,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC;gBAC/B,MAAM,IAAI,KAAK,CACb;oBACE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,GAAG;oBAC9E,mDAAmD;oBACnD,6FAA6F;oBAC7F,EAAE;oBACF,4BAA4B;oBAC5B,EAAE;oBACF,iDAAiD;oBACjD,EAAE;iBACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;aACH;SACF;IACH,CAAC;CACF;AAxXD,wDAwXC","sourcesContent":["import { ITerminal, Executable, Async } from '@rushstack/node-core-library';\nimport {\n ICloudBuildCacheProvider,\n ICredentialCacheEntry,\n CredentialCache,\n RushSession,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\nimport fetch, { BodyInit, Response } from 'node-fetch';\n\nenum CredentialsOptions {\n Optional,\n Required,\n Omit\n}\n\nenum FailureType {\n None,\n Informational,\n Warning,\n Error,\n Authentication\n}\n\nexport interface IHttpBuildCacheTokenHandler {\n exec: string;\n args?: string[];\n}\n\n/**\n * @public\n */\nexport interface IHttpBuildCacheProviderOptions {\n url: string;\n tokenHandler?: IHttpBuildCacheTokenHandler;\n uploadMethod?: string;\n minHttpRetryDelayMs?: number;\n headers?: Record<string, string>;\n cacheKeyPrefix?: string;\n isCacheWriteAllowed: boolean;\n pluginName: string;\n rushJsonFolder: string;\n}\n\nconst MAX_HTTP_CACHE_ATTEMPTS: number = 3;\nconst DEFAULT_MIN_HTTP_RETRY_DELAY_MS = 2500;\n\nexport class HttpBuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _pluginName: string;\n private readonly _rushProjectRoot: string;\n private readonly _environmentCredential: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private readonly _url: URL;\n private readonly _uploadMethod: string;\n private readonly _headers: Record<string, string>;\n private readonly _cacheKeyPrefix: string;\n private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;\n private readonly _minHttpRetryDelayMs: number;\n private __credentialCacheId: string | undefined;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n public constructor(options: IHttpBuildCacheProviderOptions, rushSession: RushSession) {\n this._pluginName = options.pluginName;\n this._rushProjectRoot = options.rushJsonFolder;\n\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n this._url = new URL(options.url.endsWith('/') ? options.url : options.url + '/');\n this._uploadMethod = options.uploadMethod ?? 'PUT';\n this._headers = options.headers ?? {};\n this._tokenHandler = options.tokenHandler;\n this._cacheKeyPrefix = options.cacheKeyPrefix ?? '';\n this._minHttpRetryDelayMs = options.minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const result = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: 'GET',\n body: undefined,\n warningText: 'Could not get cache entry',\n readBody: true,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return Buffer.isBuffer(result) ? result : undefined;\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry: ${e}`);\n return undefined;\n }\n }\n\n public async trySetCacheEntryBufferAsync(\n terminal: ITerminal,\n cacheId: string,\n objectBuffer: Buffer\n ): Promise<boolean> {\n if (!this.isCacheWriteAllowed) {\n terminal.writeErrorLine('Writing to cache is not allowed in the current configuration.');\n return false;\n }\n\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\n\n try {\n const result = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: this._uploadMethod,\n body: objectBuffer,\n warningText: 'Could not write cache entry',\n readBody: false,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return result !== false;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry: ${e}`);\n return false;\n }\n }\n\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.setCacheEntry(this._credentialCacheId, {\n credential: credential\n });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n if (!this._tokenHandler) {\n throw new Error(\n `The interactive cloud credentials flow is not configured.\\n` +\n `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 ` +\n `or provide your credentials to rush using the --credential flag instead. Credentials must be the ` +\n `'Authorization' header expected by ${this._url.href}`\n );\n }\n\n const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;\n terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);\n const result = Executable.spawnSync(this._tokenHandler.exec, this._tokenHandler.args || [], {\n currentWorkingDirectory: this._rushProjectRoot\n });\n\n terminal.writeErrorLine(result.stderr);\n\n if (result.error) {\n throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);\n }\n\n const credential = result.stdout.trim();\n terminal.writeVerboseLine('Got credentials');\n\n await this.updateCachedCredentialAsync(terminal, credential);\n\n terminal.writeLine('Updated credentials cache');\n }\n\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = [this._url.href];\n\n if (this._isCacheWriteAllowedByConfiguration) {\n cacheIdParts.push('cacheWriteAllowed');\n }\n\n this.__credentialCacheId = cacheIdParts.join('|');\n }\n\n return this.__credentialCacheId;\n }\n\n private async _http(options: {\n terminal: ITerminal;\n relUrl: string;\n method: string;\n body: BodyInit | undefined;\n warningText: string;\n readBody: boolean;\n maxAttempts: number;\n credentialOptions?: CredentialsOptions;\n }): Promise<Buffer | boolean> {\n const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;\n const safeCredentialOptions = credentialOptions ?? CredentialsOptions.Optional;\n const credentials = await this._tryGetCredentials(safeCredentialOptions);\n const url = new URL(relUrl, this._url).href;\n\n const headers: Record<string, string> = {};\n if (typeof credentials === 'string') {\n headers.Authorization = credentials;\n }\n\n for (const [key, value] of Object.entries(this._headers)) {\n if (typeof value === 'string') {\n headers[key] = value;\n }\n }\n\n const bodyLength = (body as { length: number })?.length || 'unknown';\n\n terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);\n\n const response = await fetch(url, {\n method: method,\n headers: headers,\n body: body,\n redirect: 'follow'\n });\n\n if (!response.ok) {\n const isNonCredentialResponse = response.status >= 500 && response.status < 600;\n\n if (\n !isNonCredentialResponse &&\n typeof credentials !== 'string' &&\n safeCredentialOptions === CredentialsOptions.Optional\n ) {\n // If we don't already have credentials yet, and we got a response from the server\n // that is a \"normal\" failure (4xx), then we assume that credentials are probably\n // required. Re-attempt the request, requiring credentials this time.\n //\n // This counts as part of the \"first attempt\", so it is not included in the max attempts\n return await this._http({ ...options, credentialOptions: CredentialsOptions.Required });\n }\n\n if (options.maxAttempts > 1) {\n // Pause a bit before retrying in case the server is busy\n // Add some random jitter to the retry so we can spread out load on the remote service\n // A proper solution might add exponential back off in case the retry count is high (10 or more)\n const factor = 1.0 + Math.random(); // A random number between 1.0 and 2.0\n const retryDelay = Math.floor(factor * this._minHttpRetryDelayMs);\n\n await Async.sleep(retryDelay);\n\n return await this._http({ ...options, maxAttempts: options.maxAttempts - 1 });\n }\n\n this._reportFailure(terminal, method, response, false, warningText);\n return false;\n }\n\n const result: Buffer | boolean = readBody ? Buffer.from(await response.arrayBuffer()) : true;\n\n terminal.writeDebugLine(\n `[http-build-cache] actual response: ${response.status} ${url} ${\n result === true ? 'true' : result.length\n } bytes`\n );\n\n return result;\n }\n\n private async _tryGetCredentials(options: CredentialsOptions.Required): Promise<string>;\n private async _tryGetCredentials(options: CredentialsOptions.Optional): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions.Omit): Promise<undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined> {\n if (options === CredentialsOptions.Omit) {\n return;\n }\n\n let credentials: string | undefined = this._environmentCredential;\n\n if (credentials === undefined) {\n credentials = await this._tryGetCredentialsFromCache();\n }\n\n if (typeof credentials !== 'string' && options === CredentialsOptions.Required) {\n throw new Error(\n [\n `Credentials for ${this._url.href} have not been provided.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n\n return credentials;\n }\n\n private async _tryGetCredentialsFromCache(): Promise<string | undefined> {\n let cacheEntry: ICredentialCacheEntry | undefined;\n\n await CredentialCache.usingAsync(\n {\n supportEditing: false\n },\n (credentialsCache: CredentialCache) => {\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\n }\n );\n\n if (cacheEntry) {\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\n if (!expirationTime || expirationTime >= Date.now()) {\n return cacheEntry.credential;\n }\n }\n }\n\n private _getFailureType(requestMethod: string, response: Response, isRedirect: boolean): FailureType {\n if (response.ok) {\n return FailureType.None;\n }\n\n switch (response.status) {\n case 503: {\n // We select 503 specifically because this represents \"service unavailable\" and\n // \"rate limit throttle\" errors, which are transient issues.\n //\n // There are other 5xx errors, such as 501, that can occur if the request is\n // malformed, so as a general rule we want to let through other 5xx errors\n // so the user can troubleshoot.\n\n // Don't fail production builds with warnings for transient issues\n return FailureType.Informational;\n }\n\n case 401:\n case 403:\n case 407: {\n if (requestMethod === 'GET' && (isRedirect || response.redirected)) {\n // Cache misses for GET requests are not errors\n // This is a workaround behavior where a server can issue a redirect and we fail to authenticate at the new location.\n // We do not want to signal this as an authentication failure because the authorization header is not passed on to redirects.\n // i.e The authentication header was accepted for the first request and therefore subsequent failures\n // where it was not present should not be attributed to the header.\n // This scenario usually comes up with services that redirect to pre-signed URLS that don't actually exist.\n // Those services then usually treat the 404 as a 403 to prevent leaking information.\n return FailureType.None;\n }\n\n return FailureType.Authentication;\n }\n\n case 404: {\n if (requestMethod === 'GET') {\n // Cache misses for GET requests are not errors\n return FailureType.None;\n }\n }\n }\n\n // Let dev builds succeed, let Prod builds fail\n return FailureType.Warning;\n }\n\n private _reportFailure(\n terminal: ITerminal,\n requestMethod: string,\n response: Response,\n isRedirect: boolean,\n message: string\n ): void {\n switch (this._getFailureType(requestMethod, response, isRedirect)) {\n default: {\n terminal.writeErrorLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Warning: {\n terminal.writeWarningLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Informational: {\n terminal.writeLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.None: {\n terminal.writeDebugLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Authentication: {\n throw new Error(\n [\n `${this._url.href} responded with ${response.status}: ${response.statusText}.`,\n `Credentials may be misconfigured or have expired.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n }\n }\n}\n"]}
|