bdy 1.25.39-dev-pr → 1.25.40-dev
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/distTs/package.json +1 -2
- package/distTs/src/api/client.js +1 -191
- package/distTs/src/cliError.js +0 -5
- package/distTs/src/cliIndex.js +0 -3
- package/distTs/src/command/login.js +1 -1
- package/distTs/src/command/variable/inject.js +218 -0
- package/distTs/src/command/variable/injection.js +182 -0
- package/distTs/src/command/variable/secretMask.js +100 -0
- package/distTs/src/command/variable.js +2 -0
- package/distTs/src/output/pipeline.js +56 -54
- package/distTs/src/output.js +22 -85
- package/distTs/src/texts.js +83 -522
- package/distTs/src/tunnel/output/interactive/tunnel.js +10 -14
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +1 -3
- package/distTs/src/utils.js +18 -142
- package/package.json +1 -2
- package/distTs/src/autocomplete.js +0 -90
- package/distTs/src/command/artifact/downloadDir.js +0 -110
- package/distTs/src/command/autocomplete/install.js +0 -16
- package/distTs/src/command/autocomplete/uninstall.js +0 -16
- package/distTs/src/command/autocomplete.js +0 -14
- package/distTs/src/command/environment/resolve.js +0 -39
- package/distTs/src/command/package/create.js +0 -64
- package/distTs/src/command/package/delete.js +0 -38
- package/distTs/src/command/package/docker/login.js +0 -26
- package/distTs/src/command/package/docker.js +0 -11
- package/distTs/src/command/package/download.js +0 -138
- package/distTs/src/command/package/get.js +0 -36
- package/distTs/src/command/package/list.js +0 -31
- package/distTs/src/command/package/publish.js +0 -241
- package/distTs/src/command/package/version/delete.js +0 -39
- package/distTs/src/command/package/version/get.js +0 -45
- package/distTs/src/command/package/version/list.js +0 -47
- package/distTs/src/command/package/version.js +0 -16
- package/distTs/src/command/package.js +0 -26
- package/distTs/src/command/pipeline/run/apply.js +0 -62
- package/distTs/src/command/pr/comment/add.js +0 -66
- package/distTs/src/command/pr/comment/list.js +0 -167
- package/distTs/src/command/pr/comment/status.js +0 -50
- package/distTs/src/command/pr/comment.js +0 -19
- package/distTs/src/command/pr/create.js +0 -44
- package/distTs/src/command/pr/diff.js +0 -337
- package/distTs/src/command/pr/file/list.js +0 -139
- package/distTs/src/command/pr/file/mark.js +0 -45
- package/distTs/src/command/pr/file.js +0 -16
- package/distTs/src/command/pr/get.js +0 -29
- package/distTs/src/command/pr/list.js +0 -79
- package/distTs/src/command/pr/merge.js +0 -67
- package/distTs/src/command/pr/review/request.js +0 -30
- package/distTs/src/command/pr/review/start.js +0 -29
- package/distTs/src/command/pr/review/verdict.js +0 -81
- package/distTs/src/command/pr/review.js +0 -18
- package/distTs/src/command/pr/shared.js +0 -704
- package/distTs/src/command/pr/state.js +0 -38
- package/distTs/src/command/pr/summary.js +0 -341
- package/distTs/src/command/pr/update.js +0 -56
- package/distTs/src/command/pr/updateBranch.js +0 -22
- package/distTs/src/command/pr/versions.js +0 -42
- package/distTs/src/command/pr.js +0 -39
- package/distTs/src/command/scrape/validation.js +0 -154
- package/distTs/src/command/scrape.js +0 -144
- package/distTs/src/command/suiteLink.js +0 -14
- package/distTs/src/command/tests/visual/result/download.js +0 -31
- package/distTs/src/command/tests/visual/result/get.js +0 -68
- package/distTs/src/command/tests/visual/result/list.js +0 -49
- package/distTs/src/command/tests/visual/result.js +0 -23
- package/distTs/src/command/tests/visual/session/get.js +0 -70
- package/distTs/src/command/tests/visual/session/list.js +0 -69
- package/distTs/src/command/tests/visual/session/open.js +0 -22
- package/distTs/src/command/tests/visual/session/reviewUrl.js +0 -37
- package/distTs/src/command/tests/visual/session/update.js +0 -26
- package/distTs/src/command/tests/visual/shared/context.js +0 -144
- package/distTs/src/command/tests/visual/shared/diffRegions.js +0 -172
- package/distTs/src/command/tests/visual/shared/format.js +0 -21
- package/distTs/src/command/tests/visual/shared/lookup.js +0 -107
- package/distTs/src/command/tests/visual/shared/options.js +0 -90
- package/distTs/src/command/tests/visual/shared/review.js +0 -146
- package/distTs/src/command/tests/visual/shared/reviewUrl.js +0 -62
- package/distTs/src/command/tests/visual/shared/session.js +0 -217
- package/distTs/src/command/tests/visual/snapshot/get.js +0 -46
- package/distTs/src/command/tests/visual/snapshot/list.js +0 -68
- package/distTs/src/command/tests/visual/snapshot/open.js +0 -26
- package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +0 -48
- package/distTs/src/command/tests/visual/snapshot.js +0 -28
- package/distTs/src/command/tests/visual/suite/create.js +0 -38
- package/distTs/src/command/tests/visual/suite/delete.js +0 -29
- package/distTs/src/command/tests/visual/suite/get.js +0 -43
- package/distTs/src/command/tests/visual/suite/list.js +0 -35
- package/distTs/src/command/tests/visual/suite/open.js +0 -20
- package/distTs/src/command/tests/visual/suite/update.js +0 -47
- package/distTs/src/command/tests/visual/suite.js +0 -30
- package/distTs/src/command/ut/upload.js +0 -86
- package/distTs/src/command/ut.js +0 -12
- package/distTs/src/command/vt/close.js +0 -27
- package/distTs/src/command/vt/compare/validation.js +0 -46
- package/distTs/src/command/vt/compare.js +0 -100
- package/distTs/src/command/vt/exec.js +0 -82
- package/distTs/src/command/vt/installBrowser.js +0 -20
- package/distTs/src/command/vt/shared/validation.js +0 -145
- package/distTs/src/command/vt/storybook.js +0 -138
- package/distTs/src/command/vt.js +0 -20
- package/distTs/src/command/yaml/agents.js +0 -88
- package/distTs/src/command/yaml/init.js +0 -110
- package/distTs/src/main.js +0 -190
- package/distTs/src/types/options.js +0 -2
- package/distTs/src/types/scrape.js +0 -2
- package/distTs/src/types/visualTests.js +0 -2
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.25.
|
|
4
|
+
"version": "1.25.40-dev",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://buddy.works/docs/cli",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"e2e:target": "vitest run --config e2e/vitest.config.mts e2e/modules/target/",
|
|
33
33
|
"e2e:environment": "vitest run --config e2e/vitest.config.mts e2e/modules/environment/",
|
|
34
34
|
"e2e:yaml": "vitest run --config e2e/vitest.config.mts e2e/modules/yaml/",
|
|
35
|
-
"e2e:pr": "vitest run --config e2e/vitest.config.mts e2e/modules/pr/",
|
|
36
35
|
"unit": "vitest run --config vitest.config.mts"
|
|
37
36
|
},
|
|
38
37
|
"files": [
|
package/distTs/src/api/client.js
CHANGED
|
@@ -254,7 +254,6 @@ class ApiClient {
|
|
|
254
254
|
else {
|
|
255
255
|
let message;
|
|
256
256
|
let nonJsonBody = false;
|
|
257
|
-
let errorBody;
|
|
258
257
|
try {
|
|
259
258
|
const json = await responseBody.json();
|
|
260
259
|
logger_1.default.debug('API CLIENT PARSED RESPONSE:');
|
|
@@ -263,7 +262,6 @@ class ApiClient {
|
|
|
263
262
|
const value = json?.errors?.[0]?.message ?? json?.error_description ?? json?.error;
|
|
264
263
|
if (typeof value === 'string')
|
|
265
264
|
message = value;
|
|
266
|
-
errorBody = json;
|
|
267
265
|
}
|
|
268
266
|
catch (err) {
|
|
269
267
|
nonJsonBody = true;
|
|
@@ -272,10 +270,7 @@ class ApiClient {
|
|
|
272
270
|
// Edge/WAF throttling uses 403 with an HTML body. Preserve the legacy
|
|
273
271
|
// rate-limit classification; JSON 403 responses still report API errors.
|
|
274
272
|
const error = (0, texts_1.ERR_API_DETAILS)(status === 403 && nonJsonBody ? 429 : status, message, path, this.baseUrl, rateLimitReset);
|
|
275
|
-
|
|
276
|
-
cliError.status = status;
|
|
277
|
-
cliError.body = errorBody;
|
|
278
|
-
throw cliError;
|
|
273
|
+
throw new cliError_1.default(error.code, error.message, error.hint);
|
|
279
274
|
}
|
|
280
275
|
}
|
|
281
276
|
// Set by the CLI bootstrap (Input.restApiTokenClient); the transport layer
|
|
@@ -817,191 +812,6 @@ class ApiClient {
|
|
|
817
812
|
parseResponseBody: false,
|
|
818
813
|
});
|
|
819
814
|
}
|
|
820
|
-
// Pull request methods (Buddy-hosted repositories)
|
|
821
|
-
pullsPath(workspace, project, number) {
|
|
822
|
-
const base = `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/repository/pulls`;
|
|
823
|
-
return number === undefined ? base : `${base}/${encodeURIComponent(number)}`;
|
|
824
|
-
}
|
|
825
|
-
static compactQuery(query) {
|
|
826
|
-
const result = {};
|
|
827
|
-
for (const [key, value] of Object.entries(query)) {
|
|
828
|
-
if (value !== undefined && value !== null && value !== '') {
|
|
829
|
-
result[key] = String(value);
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
return result;
|
|
833
|
-
}
|
|
834
|
-
async getPullRequests(workspace, project, query = {}) {
|
|
835
|
-
return await this.request({
|
|
836
|
-
method: 'GET',
|
|
837
|
-
path: this.pullsPath(workspace, project),
|
|
838
|
-
query: ApiClient.compactQuery(query),
|
|
839
|
-
parseResponseBody: true,
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
async getPullRequest(workspace, project, number) {
|
|
843
|
-
return await this.request({
|
|
844
|
-
method: 'GET',
|
|
845
|
-
path: this.pullsPath(workspace, project, number),
|
|
846
|
-
parseResponseBody: true,
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
async createPullRequest(workspace, project, body) {
|
|
850
|
-
return await this.request({
|
|
851
|
-
method: 'POST',
|
|
852
|
-
path: this.pullsPath(workspace, project),
|
|
853
|
-
body,
|
|
854
|
-
parseResponseBody: true,
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
async updatePullRequest(workspace, project, number, body) {
|
|
858
|
-
return await this.request({
|
|
859
|
-
method: 'PATCH',
|
|
860
|
-
path: this.pullsPath(workspace, project, number),
|
|
861
|
-
body,
|
|
862
|
-
parseResponseBody: true,
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
async mergePullRequest(workspace, project, number, body) {
|
|
866
|
-
return await this.request({
|
|
867
|
-
method: 'PUT',
|
|
868
|
-
path: `${this.pullsPath(workspace, project, number)}/merge`,
|
|
869
|
-
body,
|
|
870
|
-
parseResponseBody: true,
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
async updatePullRequestBranch(workspace, project, number) {
|
|
874
|
-
return await this.request({
|
|
875
|
-
method: 'PUT',
|
|
876
|
-
path: `${this.pullsPath(workspace, project, number)}/update-branch`,
|
|
877
|
-
parseResponseBody: true,
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
async getPullRequestVersions(workspace, project, number) {
|
|
881
|
-
return await this.request({
|
|
882
|
-
method: 'GET',
|
|
883
|
-
path: `${this.pullsPath(workspace, project, number)}/versions`,
|
|
884
|
-
parseResponseBody: true,
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
async getPullRequestFiles(workspace, project, number, query = {}) {
|
|
888
|
-
return await this.request({
|
|
889
|
-
method: 'GET',
|
|
890
|
-
path: `${this.pullsPath(workspace, project, number)}/files`,
|
|
891
|
-
query: ApiClient.compactQuery(query),
|
|
892
|
-
parseResponseBody: true,
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
async markPullRequestFilesViewed(workspace, project, number, body) {
|
|
896
|
-
return await this.request({
|
|
897
|
-
method: 'POST',
|
|
898
|
-
path: `${this.pullsPath(workspace, project, number)}/files/viewed`,
|
|
899
|
-
body,
|
|
900
|
-
parseResponseBody: true,
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
async getPullRequestDiff(workspace, project, number, query) {
|
|
904
|
-
return await this.request({
|
|
905
|
-
method: 'GET',
|
|
906
|
-
path: `${this.pullsPath(workspace, project, number)}/diff`,
|
|
907
|
-
query: ApiClient.compactQuery(query),
|
|
908
|
-
parseResponseBody: true,
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
async getPullRequestReview(workspace, project, number) {
|
|
912
|
-
return await this.request({
|
|
913
|
-
method: 'GET',
|
|
914
|
-
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
915
|
-
parseResponseBody: true,
|
|
916
|
-
});
|
|
917
|
-
}
|
|
918
|
-
async startPullRequestReview(workspace, project, number, version) {
|
|
919
|
-
return await this.request({
|
|
920
|
-
method: 'POST',
|
|
921
|
-
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
922
|
-
body: { version },
|
|
923
|
-
parseResponseBody: true,
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
async submitPullRequestVerdict(workspace, project, number, body) {
|
|
927
|
-
return await this.request({
|
|
928
|
-
method: 'PUT',
|
|
929
|
-
path: `${this.pullsPath(workspace, project, number)}/review`,
|
|
930
|
-
body,
|
|
931
|
-
parseResponseBody: true,
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
async getPullRequestReviews(workspace, project, number) {
|
|
935
|
-
return await this.request({
|
|
936
|
-
method: 'GET',
|
|
937
|
-
path: `${this.pullsPath(workspace, project, number)}/reviews`,
|
|
938
|
-
parseResponseBody: true,
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
async requestPullRequestReview(workspace, project, number, reviewers) {
|
|
942
|
-
return await this.request({
|
|
943
|
-
method: 'POST',
|
|
944
|
-
path: `${this.pullsPath(workspace, project, number)}/reviewers`,
|
|
945
|
-
body: { reviewers },
|
|
946
|
-
parseResponseBody: true,
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
async getPullRequestActivity(workspace, project, number, since) {
|
|
950
|
-
return await this.request({
|
|
951
|
-
method: 'GET',
|
|
952
|
-
path: `${this.pullsPath(workspace, project, number)}/activity`,
|
|
953
|
-
query: ApiClient.compactQuery({ since }),
|
|
954
|
-
parseResponseBody: true,
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
async addPullRequestComment(workspace, project, number, comment) {
|
|
958
|
-
return await this.request({
|
|
959
|
-
method: 'POST',
|
|
960
|
-
path: `${this.pullsPath(workspace, project, number)}/comments`,
|
|
961
|
-
body: { comment },
|
|
962
|
-
parseResponseBody: true,
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
async getPullRequestThreads(workspace, project, number, query = {}) {
|
|
966
|
-
return await this.request({
|
|
967
|
-
method: 'GET',
|
|
968
|
-
path: `${this.pullsPath(workspace, project, number)}/threads`,
|
|
969
|
-
query: ApiClient.compactQuery(query),
|
|
970
|
-
parseResponseBody: true,
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
async getPullRequestThread(workspace, project, number, threadId, version) {
|
|
974
|
-
return await this.request({
|
|
975
|
-
method: 'GET',
|
|
976
|
-
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
|
|
977
|
-
query: ApiClient.compactQuery({ version }),
|
|
978
|
-
parseResponseBody: true,
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
async addPullRequestThread(workspace, project, number, body) {
|
|
982
|
-
return await this.request({
|
|
983
|
-
method: 'POST',
|
|
984
|
-
path: `${this.pullsPath(workspace, project, number)}/threads`,
|
|
985
|
-
body,
|
|
986
|
-
parseResponseBody: true,
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
async addPullRequestThreadComment(workspace, project, number, threadId, comment) {
|
|
990
|
-
return await this.request({
|
|
991
|
-
method: 'POST',
|
|
992
|
-
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}/comments`,
|
|
993
|
-
body: { comment },
|
|
994
|
-
parseResponseBody: true,
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
async updatePullRequestThread(workspace, project, number, threadId, body) {
|
|
998
|
-
return await this.request({
|
|
999
|
-
method: 'PATCH',
|
|
1000
|
-
path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
|
|
1001
|
-
body,
|
|
1002
|
-
parseResponseBody: true,
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
815
|
// Environment methods
|
|
1006
816
|
async getEnvironments(workspace, project) {
|
|
1007
817
|
const query = {};
|
package/distTs/src/cliError.js
CHANGED
|
@@ -13,11 +13,6 @@ var SemanticExitCode;
|
|
|
13
13
|
class CliError extends Error {
|
|
14
14
|
code;
|
|
15
15
|
hint;
|
|
16
|
-
// Set by ApiClient for API errors: the HTTP status and the parsed JSON body,
|
|
17
|
-
// so a command can read fields the API sends next to `errors` (e.g. the
|
|
18
|
-
// current version in a 409 of a pull request verdict).
|
|
19
|
-
status;
|
|
20
|
-
body;
|
|
21
16
|
constructor(code, message, hint = null, options) {
|
|
22
17
|
super(message, options);
|
|
23
18
|
this.code = code;
|
package/distTs/src/cliIndex.js
CHANGED
|
@@ -33,7 +33,6 @@ const register_1 = __importDefault(require("./command/register"));
|
|
|
33
33
|
const mcp_1 = __importDefault(require("./command/mcp"));
|
|
34
34
|
const discover_1 = __importDefault(require("./command/discover"));
|
|
35
35
|
const context_1 = __importDefault(require("./command/context"));
|
|
36
|
-
const pr_1 = __importDefault(require("./command/pr"));
|
|
37
36
|
const input_1 = __importDefault(require("./input"));
|
|
38
37
|
const cliCommand_1 = __importDefault(require("./cliCommand"));
|
|
39
38
|
const client_1 = __importDefault(require("./api/client"));
|
|
@@ -51,7 +50,6 @@ function cliIndex() {
|
|
|
51
50
|
program.hook('preAction', pre_1.default);
|
|
52
51
|
program.configureHelp({
|
|
53
52
|
formatHelp: utils_1.formatHelp,
|
|
54
|
-
subcommandTerm: utils_1.subcommandTerm,
|
|
55
53
|
});
|
|
56
54
|
// root options must come before the subcommand, so -v here can't
|
|
57
55
|
// shadow subcommand flags like `sandbox create -v <variable>`
|
|
@@ -78,7 +76,6 @@ function cliIndex() {
|
|
|
78
76
|
program.addCommand(logout_1.default);
|
|
79
77
|
program.addCommand(workspace_1.default);
|
|
80
78
|
program.addCommand(project_1.default);
|
|
81
|
-
program.addCommand(pr_1.default);
|
|
82
79
|
program.addCommand(yaml_1.default);
|
|
83
80
|
program.addCommand(api_1.default);
|
|
84
81
|
program.addCommand(mcp_1.default);
|
|
@@ -172,7 +172,7 @@ async function oauthServer(api, clientId, clientSecret, forceRegisterEmail, forc
|
|
|
172
172
|
else {
|
|
173
173
|
output_1.default.dim(isRegister ? texts_1.TXT_REGISTER_OPEN_URL : texts_1.TXT_LOGIN_OPEN_URL);
|
|
174
174
|
output_1.default.normal('');
|
|
175
|
-
output_1.default.dim(url);
|
|
175
|
+
output_1.default.dim(url.replace(/%/g, '%%'));
|
|
176
176
|
output_1.default.normal('');
|
|
177
177
|
}
|
|
178
178
|
for (;;) {
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_os_1 = require("node:os");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:stream/promises");
|
|
9
|
+
const utils_1 = require("../../utils");
|
|
10
|
+
const texts_1 = require("../../texts");
|
|
11
|
+
const output_1 = __importDefault(require("../../output"));
|
|
12
|
+
const input_1 = __importDefault(require("../../input"));
|
|
13
|
+
const cliError_1 = __importDefault(require("../../cliError"));
|
|
14
|
+
const distro_1 = require("../../types/distro");
|
|
15
|
+
const injection_1 = require("./injection");
|
|
16
|
+
const secretMask_1 = __importDefault(require("./secretMask"));
|
|
17
|
+
const collect = (value, previous = []) => [...previous, value];
|
|
18
|
+
// After the command exits its output may still be on the way: in the pipes,
|
|
19
|
+
// in the masking, in our own stdout. And a process the command left in the
|
|
20
|
+
// background (`sh -c 'daemon & ...'`) inherited the pipes and keeps them open
|
|
21
|
+
// for as long as it lives, writing or silent. bdy is the only reader of those
|
|
22
|
+
// pipes, so it stays until they close - leaving earlier would cut the
|
|
23
|
+
// daemon's output and, on its next write, kill it with SIGPIPE. --wait
|
|
24
|
+
// (seconds, 0 = no limit) bounds that: past it bdy gives up and exits with 1.
|
|
25
|
+
// The time is counted only over checks that came on time: a write to a slow
|
|
26
|
+
// reader (`| less`) blocks bdy (stdout is in blocking mode, index.ts), and
|
|
27
|
+
// output held up that way is not the command's fault - it is never cut.
|
|
28
|
+
const OUTPUT_CHECK_MS = 100;
|
|
29
|
+
const DEFAULT_WAIT_SECONDS = 300;
|
|
30
|
+
const parseWait = (value) => {
|
|
31
|
+
if (!/^\d+$/.test(value)) {
|
|
32
|
+
throw new cliError_1.default('usage_error', (0, texts_1.ERR_VARIABLE_INJECT_WAIT)(value));
|
|
33
|
+
}
|
|
34
|
+
return Number(value);
|
|
35
|
+
};
|
|
36
|
+
// true when all the output got through, false when --wait ran out first
|
|
37
|
+
const waitForOutput = (masks, done, waitSeconds) => new Promise((resolve) => {
|
|
38
|
+
// a destroyed stdout (reader gone) never empties - nothing to wait for
|
|
39
|
+
const unflushed = (stream) => !stream.destroyed && (stream.writableNeedDrain || stream.writableLength > 0);
|
|
40
|
+
const busy = () => unflushed(process.stdout) ||
|
|
41
|
+
unflushed(process.stderr) ||
|
|
42
|
+
masks.some((mask) => mask.writableLength > 0 || mask.readableLength > 0);
|
|
43
|
+
let ended = false;
|
|
44
|
+
let waitedMs = 0;
|
|
45
|
+
let last = Date.now();
|
|
46
|
+
const finish = (complete) => {
|
|
47
|
+
clearInterval(check);
|
|
48
|
+
resolve(complete);
|
|
49
|
+
};
|
|
50
|
+
const check = setInterval(() => {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const elapsed = now - last;
|
|
53
|
+
last = now;
|
|
54
|
+
const held = busy();
|
|
55
|
+
// the pipes closed and our own buffers are empty
|
|
56
|
+
if (ended && !held)
|
|
57
|
+
return finish(true);
|
|
58
|
+
if (held || elapsed > OUTPUT_CHECK_MS * 2)
|
|
59
|
+
return;
|
|
60
|
+
waitedMs += elapsed;
|
|
61
|
+
if (waitSeconds && waitedMs >= waitSeconds * 1000)
|
|
62
|
+
finish(false);
|
|
63
|
+
}, OUTPUT_CHECK_MS);
|
|
64
|
+
void done.then(() => {
|
|
65
|
+
ended = true;
|
|
66
|
+
if (!busy())
|
|
67
|
+
finish(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
// Files written by --var-file. Removed on every way out of the process that
|
|
71
|
+
// runs JavaScript - the command's end, an error, a forwarded signal - as all
|
|
72
|
+
// of them go through process.exit. Only a SIGKILL of bdy leaves them behind.
|
|
73
|
+
const written = [];
|
|
74
|
+
const removeWritten = () => {
|
|
75
|
+
for (const path of written.splice(0)) {
|
|
76
|
+
try {
|
|
77
|
+
(0, node_fs_1.unlinkSync)(path);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// already gone - the command may have removed it itself
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const writeSecretFile = (path, content) => {
|
|
85
|
+
try {
|
|
86
|
+
// wx: never take a file that exists - deleting it afterwards would
|
|
87
|
+
// destroy something of the user's (an ~/.ssh/id_rsa)
|
|
88
|
+
(0, node_fs_1.writeFileSync)(path, content, { flag: 'wx', mode: 0o600 });
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const { code, message } = err;
|
|
92
|
+
if (code === 'EEXIST') {
|
|
93
|
+
throw new cliError_1.default('usage_error', (0, texts_1.ERR_VARIABLE_INJECT_FILE_EXISTS)(path));
|
|
94
|
+
}
|
|
95
|
+
throw new cliError_1.default('command_failed', (0, texts_1.ERR_VARIABLE_INJECT_FILE_WRITE)(path, message));
|
|
96
|
+
}
|
|
97
|
+
written.push(path);
|
|
98
|
+
};
|
|
99
|
+
// Without --scope the lookup of the other environment commands: the project
|
|
100
|
+
// of the context first (-p, BUDDY_PROJECT, linked), then the workspace. With
|
|
101
|
+
// --scope exactly one of them, no fallback - the variables injected must not
|
|
102
|
+
// come from an environment of the same name the user did not mean.
|
|
103
|
+
const resolveEnvironment = async (client, workspace, options) => {
|
|
104
|
+
if (!options.scope) {
|
|
105
|
+
return {
|
|
106
|
+
environmentId: await input_1.default.environmentId(client, workspace, options.environment, options),
|
|
107
|
+
projectIdentifier: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
111
|
+
const scope = input_1.default.scope(project, options.scope);
|
|
112
|
+
const resolved = await client.getEnvironmentByIdentifier(workspace, options.environment, scope === distro_1.SCOPE.PROJECT ? project : null);
|
|
113
|
+
if (!resolved.environment_id) {
|
|
114
|
+
throw new cliError_1.default('not_found', texts_1.ERR_ENVIRONMENT_NOT_FOUND, texts_1.HINT_ENVIRONMENT_LIST);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
environmentId: resolved.environment_id,
|
|
118
|
+
projectIdentifier: scope === distro_1.SCOPE.PROJECT ? (resolved.project_identifier ?? null) : null,
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const commandVariableInject = (0, utils_1.newCommand)('inject', texts_1.DESC_COMMAND_VARIABLE_INJECT, {
|
|
122
|
+
requiredScopes: [
|
|
123
|
+
utils_1.REST_API_SCOPE.VARIABLE_READ,
|
|
124
|
+
utils_1.REST_API_SCOPE.ENVIRONMENT_READ,
|
|
125
|
+
utils_1.REST_API_SCOPE.MASKED_VARIABLE_VALUE_DECRYPTED,
|
|
126
|
+
],
|
|
127
|
+
examples: texts_1.EXAMPLE_VARIABLE_INJECT,
|
|
128
|
+
});
|
|
129
|
+
commandVariableInject.aliases(['exec', 'run']);
|
|
130
|
+
commandVariableInject.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
131
|
+
commandVariableInject.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
132
|
+
commandVariableInject.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
|
|
133
|
+
commandVariableInject.requiredOption('--environment <identifier>', texts_1.OPTION_VARIABLE_INJECT_ENVIRONMENT);
|
|
134
|
+
commandVariableInject.option('--var <key>', texts_1.OPTION_VARIABLE_INJECT_VAR, collect);
|
|
135
|
+
commandVariableInject.option('--var-file <key:path>', texts_1.OPTION_VARIABLE_INJECT_VAR_FILE, collect);
|
|
136
|
+
commandVariableInject.option('--no-masking', texts_1.OPTION_VARIABLE_INJECT_NO_MASKING);
|
|
137
|
+
commandVariableInject.option('--wait <seconds>', texts_1.OPTION_VARIABLE_INJECT_WAIT, parseWait, DEFAULT_WAIT_SECONDS);
|
|
138
|
+
commandVariableInject.argument('<command...>', texts_1.OPTION_VARIABLE_INJECT_COMMAND);
|
|
139
|
+
// everything after the first argument is the command's, even when it looks
|
|
140
|
+
// like an option of ours (`bdy var exec --environment x ls --var`)
|
|
141
|
+
commandVariableInject.passThroughOptions();
|
|
142
|
+
commandVariableInject.action(async (command, options) => {
|
|
143
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
144
|
+
const varFiles = (options.varFile ?? []).map(injection_1.parseVarFile);
|
|
145
|
+
const client = input_1.default.restApiTokenClient();
|
|
146
|
+
const { environmentId, projectIdentifier } = await resolveEnvironment(client, workspace, options);
|
|
147
|
+
const [result, environment] = await Promise.all([
|
|
148
|
+
client.getVariables(workspace, { environmentId }),
|
|
149
|
+
client.getEnvironment(workspace, environmentId),
|
|
150
|
+
]);
|
|
151
|
+
// --scope PROJECT is a statement "the environment of this project": the
|
|
152
|
+
// API is asked along the project line, and the answer verified once more
|
|
153
|
+
if (projectIdentifier && environment.project?.name !== projectIdentifier) {
|
|
154
|
+
throw new cliError_1.default('not_found', texts_1.ERR_ENVIRONMENT_NOT_FOUND, texts_1.HINT_ENVIRONMENT_LIST);
|
|
155
|
+
}
|
|
156
|
+
const injection = (0, injection_1.buildInjection)(result.variables ?? [], environment, options.var ?? [], varFiles);
|
|
157
|
+
process.on('exit', removeWritten);
|
|
158
|
+
for (const { path, content } of injection.files)
|
|
159
|
+
writeSecretFile(path, content);
|
|
160
|
+
// Masking needs the output through bdy, which takes the terminal away from
|
|
161
|
+
// the command. Without anything to mask it keeps the terminal.
|
|
162
|
+
const masking = options.masking !== false && injection.secrets.length > 0;
|
|
163
|
+
if (options.masking !== false && injection.unmasked.length) {
|
|
164
|
+
output_1.default.noteWarning((0, texts_1.WARN_VARIABLE_INJECT_NOT_MASKED)(injection.unmasked));
|
|
165
|
+
}
|
|
166
|
+
const { spawn } = require('cross-spawn');
|
|
167
|
+
const child = spawn(command[0], command.slice(1), {
|
|
168
|
+
env: { ...process.env, ...injection.env },
|
|
169
|
+
stdio: masking ? ['inherit', 'pipe', 'pipe'] : 'inherit',
|
|
170
|
+
});
|
|
171
|
+
// The terminal sends Ctrl+C and Ctrl+\ to the whole foreground group, the
|
|
172
|
+
// command included: let it decide, and end when it ends - passing it on as
|
|
173
|
+
// well would be a second interrupt, which terraform, docker compose or npm
|
|
174
|
+
// take as "force quit now". bdy is on a terminal when any of its stdio is
|
|
175
|
+
// (`echo yes | bdy ...` still is; with masking only the command's output
|
|
176
|
+
// goes through bdy). Without one (a supervisor, `timeout -s INT`) such a
|
|
177
|
+
// signal is meant for bdy alone and is passed on, like SIGTERM and SIGHUP
|
|
178
|
+
// always are, so the command is not left running and the files are
|
|
179
|
+
// removed when it exits. SIGTSTP (Ctrl+Z) keeps its default: bdy stops
|
|
180
|
+
// together with the command, so the shell sees the job stopped and gives
|
|
181
|
+
// the prompt back.
|
|
182
|
+
const onTerminal = process.stdin.isTTY || process.stdout.isTTY || process.stderr.isTTY;
|
|
183
|
+
for (const signal of ['SIGINT', 'SIGQUIT']) {
|
|
184
|
+
process.on(signal, () => {
|
|
185
|
+
if (!onTerminal)
|
|
186
|
+
child.kill(signal);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
for (const signal of ['SIGTERM', 'SIGHUP']) {
|
|
190
|
+
process.on(signal, () => child.kill(signal));
|
|
191
|
+
}
|
|
192
|
+
const masks = masking
|
|
193
|
+
? [new secretMask_1.default(injection.secrets), new secretMask_1.default(injection.secrets)]
|
|
194
|
+
: [];
|
|
195
|
+
const streams = masks.map((mask, i) => (0, promises_1.pipeline)((i ? child.stderr : child.stdout), mask, (i ? process.stderr : process.stdout), { end: false }).catch(() => {
|
|
196
|
+
// our stdout closed by its reader (`| head`): the command gets
|
|
197
|
+
// EPIPE/SIGPIPE on its next write, as it would without bdy
|
|
198
|
+
}));
|
|
199
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
200
|
+
child.on('error', (err) => reject(err.code === 'ENOENT'
|
|
201
|
+
? new cliError_1.default('command_failed', (0, texts_1.ERR_VARIABLE_INJECT_COMMAND_NOT_FOUND)(command[0]))
|
|
202
|
+
: err));
|
|
203
|
+
// exit, not close: close waits for every copy of the stdio pipes, and a
|
|
204
|
+
// process the command left in the background may hold them for as long
|
|
205
|
+
// as it lives - bdy would hang with the secret files still on disk
|
|
206
|
+
child.on('exit', (code, signal) => {
|
|
207
|
+
// the shell convention for a command killed by a signal
|
|
208
|
+
resolve(signal ? 128 + (node_os_1.constants.signals[signal] ?? 0) : (code ?? 1));
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
removeWritten();
|
|
212
|
+
if (!(await waitForOutput(masks, Promise.all(streams), options.wait))) {
|
|
213
|
+
output_1.default.noteWarning((0, texts_1.WARN_VARIABLE_INJECT_WAIT_EXCEEDED)(options.wait));
|
|
214
|
+
output_1.default.exitCode(1);
|
|
215
|
+
}
|
|
216
|
+
output_1.default.exitCode(exitCode);
|
|
217
|
+
});
|
|
218
|
+
exports.default = commandVariableInject;
|