bdy 1.25.31 → 1.25.33-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 -1
- package/distTs/src/api/client.js +61 -0
- package/distTs/src/cliIndex.js +2 -0
- package/distTs/src/command/integration/catalog.js +172 -52
- package/distTs/src/command/integration/get.js +3 -0
- package/distTs/src/command/integration/types.js +3 -3
- package/distTs/src/command/variable/create.js +55 -0
- package/distTs/src/command/variable/delete.js +37 -0
- package/distTs/src/command/variable/get.js +51 -0
- package/distTs/src/command/variable/list.js +56 -0
- package/distTs/src/command/variable/scope.js +161 -0
- package/distTs/src/command/variable/update.js +92 -0
- package/distTs/src/command/variable.js +20 -0
- package/distTs/src/input.js +65 -0
- package/distTs/src/texts.js +161 -29
- package/distTs/src/utils.js +14 -3
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
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 utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const scope_1 = require("./scope");
|
|
11
|
+
const commandVariableDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_VARIABLE_DELETE, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.VARIABLE_MANAGE],
|
|
13
|
+
examples: texts_1.EXAMPLE_VARIABLE_DELETE,
|
|
14
|
+
});
|
|
15
|
+
commandVariableDelete.alias('rm');
|
|
16
|
+
commandVariableDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandVariableDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandVariableDelete.option('--pipeline <identifier>', texts_1.OPTION_VARIABLE_PIPELINE);
|
|
19
|
+
commandVariableDelete.option('--environment <identifier>', texts_1.OPTION_VARIABLE_ENVIRONMENT);
|
|
20
|
+
commandVariableDelete.option('--sandbox <identifier>', texts_1.OPTION_VARIABLE_SANDBOX);
|
|
21
|
+
commandVariableDelete.option('--scope <scope>', texts_1.OPT_COMMAND_VARIABLE_SCOPE);
|
|
22
|
+
commandVariableDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
|
|
23
|
+
commandVariableDelete.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
24
|
+
commandVariableDelete.argument('<key>', texts_1.OPTION_VARIABLE_KEY);
|
|
25
|
+
commandVariableDelete.action(async (key, options) => {
|
|
26
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
27
|
+
const client = input_1.default.restApiTokenClient();
|
|
28
|
+
const { variable, scope } = await (0, scope_1.resolveVariable)(client, workspace, key, options,
|
|
29
|
+
/* strictScope */ true);
|
|
30
|
+
const json = options.format === 'json';
|
|
31
|
+
const confirmed = await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_VARIABLE_DELETE_CONFIRM)(key, scope), json);
|
|
32
|
+
if (!confirmed)
|
|
33
|
+
output_1.default.exitResult(json, { deleted: null });
|
|
34
|
+
await client.deleteVariable(workspace, variable.id);
|
|
35
|
+
output_1.default.exitResult(json, { deleted: key }, (0, texts_1.TXT_VARIABLE_DELETED)(key));
|
|
36
|
+
});
|
|
37
|
+
exports.default = commandVariableDelete;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const scope_1 = require("./scope");
|
|
11
|
+
const commandVariableGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_VARIABLE_GET, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.VARIABLE_READ],
|
|
13
|
+
examples: texts_1.EXAMPLE_VARIABLE_GET,
|
|
14
|
+
});
|
|
15
|
+
commandVariableGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandVariableGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandVariableGet.option('--pipeline <identifier>', texts_1.OPTION_VARIABLE_PIPELINE);
|
|
18
|
+
commandVariableGet.option('--environment <identifier>', texts_1.OPTION_VARIABLE_ENVIRONMENT);
|
|
19
|
+
commandVariableGet.option('--sandbox <identifier>', texts_1.OPTION_VARIABLE_SANDBOX);
|
|
20
|
+
commandVariableGet.option('--scope <scope>', texts_1.OPT_COMMAND_VARIABLE_SCOPE);
|
|
21
|
+
commandVariableGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
22
|
+
commandVariableGet.argument('<key>', texts_1.OPTION_VARIABLE_KEY);
|
|
23
|
+
commandVariableGet.action(async (key, options) => {
|
|
24
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
25
|
+
const client = input_1.default.restApiTokenClient();
|
|
26
|
+
const { variable, scope } = await (0, scope_1.resolveVariable)(client, workspace, key, options);
|
|
27
|
+
if (options.format === 'json') {
|
|
28
|
+
output_1.default.json(variable);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const data = [
|
|
32
|
+
['Field', 'Value'],
|
|
33
|
+
['ID', String(variable.id)],
|
|
34
|
+
['Key', variable.key],
|
|
35
|
+
['Value', (0, scope_1.variableValueOf)(variable)],
|
|
36
|
+
['Type', variable.type || '-'],
|
|
37
|
+
['Scope', scope],
|
|
38
|
+
['Encrypted', variable.encrypted ? 'true' : 'false'],
|
|
39
|
+
['Settable', variable.settable ? 'true' : 'false'],
|
|
40
|
+
['Disabled', variable.disabled ? 'true' : 'false'],
|
|
41
|
+
['Note', variable.note || '-'],
|
|
42
|
+
['Agent note', variable.agent_note || '-'],
|
|
43
|
+
];
|
|
44
|
+
if (variable.html_url) {
|
|
45
|
+
data.push(['URL', variable.html_url]);
|
|
46
|
+
}
|
|
47
|
+
output_1.default.table(data);
|
|
48
|
+
}
|
|
49
|
+
output_1.default.exitNormal();
|
|
50
|
+
});
|
|
51
|
+
exports.default = commandVariableGet;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const scope_1 = require("./scope");
|
|
11
|
+
const commandVariableList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_VARIABLE_LIST, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.VARIABLE_READ],
|
|
13
|
+
examples: texts_1.EXAMPLE_VARIABLE_LIST,
|
|
14
|
+
});
|
|
15
|
+
commandVariableList.alias('ls');
|
|
16
|
+
commandVariableList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandVariableList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandVariableList.option('--pipeline <identifier>', texts_1.OPTION_VARIABLE_PIPELINE);
|
|
19
|
+
commandVariableList.option('--environment <identifier>', texts_1.OPTION_VARIABLE_ENVIRONMENT);
|
|
20
|
+
commandVariableList.option('--sandbox <identifier>', texts_1.OPTION_VARIABLE_SANDBOX);
|
|
21
|
+
commandVariableList.option('--scope <scope>', texts_1.OPT_COMMAND_VARIABLE_SCOPE);
|
|
22
|
+
commandVariableList.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
23
|
+
commandVariableList.action(async (options) => {
|
|
24
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
25
|
+
const { project, scope } = (0, scope_1.variableScope)(options);
|
|
26
|
+
input_1.default.projectScopeNote(options, project, scope, 'variables');
|
|
27
|
+
const client = input_1.default.restApiTokenClient();
|
|
28
|
+
const params = await (0, scope_1.resolveVariableScope)(client, workspace, project, scope, options);
|
|
29
|
+
const result = await client.getVariables(workspace, params);
|
|
30
|
+
const variables = result.variables || [];
|
|
31
|
+
if (options.format === 'json') {
|
|
32
|
+
output_1.default.json(variables);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (variables.length === 0) {
|
|
36
|
+
output_1.default.exitNormal(texts_1.TXT_VARIABLE_NOT_FOUND);
|
|
37
|
+
}
|
|
38
|
+
const data = [
|
|
39
|
+
['KEY', 'VALUE', 'TYPE', 'ENCRYPTED', 'SETTABLE', 'SCOPE'],
|
|
40
|
+
];
|
|
41
|
+
for (const variable of variables) {
|
|
42
|
+
data.push([
|
|
43
|
+
variable.key,
|
|
44
|
+
(0, scope_1.variableValueOf)(variable, 40),
|
|
45
|
+
variable.type || '-',
|
|
46
|
+
variable.encrypted ? 'true' : 'false',
|
|
47
|
+
variable.settable ? 'true' : 'false',
|
|
48
|
+
// the list is exact-scope and its items carry no owner object
|
|
49
|
+
scope,
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
output_1.default.table(data);
|
|
53
|
+
}
|
|
54
|
+
output_1.default.exitNormal();
|
|
55
|
+
});
|
|
56
|
+
exports.default = commandVariableList;
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
exports.variableValueOf = exports.variableScopeOf = exports.variableUpdateBody = exports.resolveVariable = exports.resolveVariableScope = exports.variableScope = void 0;
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const cliError_1 = __importDefault(require("../../cliError"));
|
|
10
|
+
const input_1 = __importDefault(require("../../input"));
|
|
11
|
+
// Scope of the variable from flags/env, validated (Input.variableScope).
|
|
12
|
+
const variableScope = (options) => {
|
|
13
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
14
|
+
const scope = input_1.default.variableScope(project, options.pipeline, options.environment, options.sandbox, options.scope);
|
|
15
|
+
return { project, scope };
|
|
16
|
+
};
|
|
17
|
+
exports.variableScope = variableScope;
|
|
18
|
+
// Identifiers of the scope -> the ids the variables endpoints take.
|
|
19
|
+
// Environments and sandboxes exist on both workspace and project level, so
|
|
20
|
+
// for them project is optional and narrows the lookup when given.
|
|
21
|
+
const resolveVariableScope = async (client, workspace, project, scope, options) => {
|
|
22
|
+
const params = {};
|
|
23
|
+
if (scope === utils_1.VARIABLE_SCOPE.PIPELINE) {
|
|
24
|
+
const { pipeline_id } = await client.getPipelineByIdentifier(workspace, project, options.pipeline);
|
|
25
|
+
if (!pipeline_id) {
|
|
26
|
+
throw new cliError_1.default('not_found', texts_1.ERR_PIPELINE_NOT_FOUND, texts_1.HINT_PIPELINE_LIST);
|
|
27
|
+
}
|
|
28
|
+
params.pipelineId = pipeline_id;
|
|
29
|
+
}
|
|
30
|
+
else if (scope === utils_1.VARIABLE_SCOPE.ENVIRONMENT) {
|
|
31
|
+
params.environmentId = await input_1.default.environmentId(client, workspace, options.environment, options);
|
|
32
|
+
}
|
|
33
|
+
else if (scope === utils_1.VARIABLE_SCOPE.SANDBOX) {
|
|
34
|
+
params.sandboxId = await resolveSandboxId(client, workspace, project, options);
|
|
35
|
+
}
|
|
36
|
+
else if (scope === utils_1.VARIABLE_SCOPE.PROJECT) {
|
|
37
|
+
params.project = project;
|
|
38
|
+
}
|
|
39
|
+
return params;
|
|
40
|
+
};
|
|
41
|
+
exports.resolveVariableScope = resolveVariableScope;
|
|
42
|
+
// Like Input.environmentId: a project implied by BUDDY_PROJECT or a linked
|
|
43
|
+
// directory must not hide a workspace sandbox, an explicit -p does.
|
|
44
|
+
const resolveSandboxId = async (client, workspace, project, options) => {
|
|
45
|
+
const identifier = options.sandbox;
|
|
46
|
+
let sandboxId;
|
|
47
|
+
if (project) {
|
|
48
|
+
const resolved = await client.getSandboxByIdentifier(workspace, project, identifier);
|
|
49
|
+
sandboxId = resolved.sandbox_id;
|
|
50
|
+
}
|
|
51
|
+
if (!sandboxId && !options.project) {
|
|
52
|
+
sandboxId = await client.findSandboxByIdentifier(workspace, identifier, null);
|
|
53
|
+
}
|
|
54
|
+
if (!sandboxId) {
|
|
55
|
+
throw new cliError_1.default('not_found', texts_1.ERR_SANDBOX_NOT_FOUND, texts_1.HINT_SANDBOX_LIST);
|
|
56
|
+
}
|
|
57
|
+
return sandboxId;
|
|
58
|
+
};
|
|
59
|
+
// Variables are not in /identifiers: a key is unique within its scope, so the
|
|
60
|
+
// variable is looked up by key in the list of that exact scope. The list
|
|
61
|
+
// items carry no owner object (project, pipeline, ...), so the scope comes
|
|
62
|
+
// back from here rather than from variableScopeOf.
|
|
63
|
+
//
|
|
64
|
+
// Reads fall back to the workspace variable when the PROJECT scope was only
|
|
65
|
+
// implied (BUDDY_PROJECT or a linked project), the way targets do. strictScope
|
|
66
|
+
// is for commands that change the variable (update/delete): the scope the
|
|
67
|
+
// command runs in is the one acted on, no fallback. A miss there still looks
|
|
68
|
+
// at the workspace, only to point at --scope WORKSPACE: get finds the
|
|
69
|
+
// variable through the fallback, so a bare "not found" from rm would be
|
|
70
|
+
// a dead end.
|
|
71
|
+
const resolveVariable = async (client, workspace, key, options, strictScope = false) => {
|
|
72
|
+
const { project, scope } = (0, exports.variableScope)(options);
|
|
73
|
+
const find = async (s) => {
|
|
74
|
+
const params = await (0, exports.resolveVariableScope)(client, workspace, project, s, options);
|
|
75
|
+
const result = await client.getVariables(workspace, params);
|
|
76
|
+
return (result.variables || []).find((v) => v.key === key);
|
|
77
|
+
};
|
|
78
|
+
let variable = await find(scope);
|
|
79
|
+
if (variable)
|
|
80
|
+
return { variable, scope };
|
|
81
|
+
if (scope === utils_1.VARIABLE_SCOPE.PROJECT &&
|
|
82
|
+
!options.project &&
|
|
83
|
+
!options.scope) {
|
|
84
|
+
variable = await find(utils_1.VARIABLE_SCOPE.WORKSPACE);
|
|
85
|
+
if (variable && !strictScope) {
|
|
86
|
+
return { variable, scope: utils_1.VARIABLE_SCOPE.WORKSPACE };
|
|
87
|
+
}
|
|
88
|
+
if (variable) {
|
|
89
|
+
throw new cliError_1.default('not_found', texts_1.ERR_VARIABLE_NOT_FOUND, texts_1.HINT_VARIABLE_LIST_WORKSPACE);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
throw new cliError_1.default('not_found', texts_1.ERR_VARIABLE_NOT_FOUND, texts_1.HINT_VARIABLE_LIST);
|
|
93
|
+
};
|
|
94
|
+
exports.resolveVariable = resolveVariable;
|
|
95
|
+
// The PATCH is not partial: a writable field left out of the body is reset
|
|
96
|
+
// (an absent settable turns false). So the update re-sends what is stored,
|
|
97
|
+
// minus the read-only and owner fields and the secrets - value, password and
|
|
98
|
+
// passphrase are kept by the API when absent.
|
|
99
|
+
const VARIABLE_NOT_CARRIED = [
|
|
100
|
+
'url',
|
|
101
|
+
'html_url',
|
|
102
|
+
'id',
|
|
103
|
+
'type',
|
|
104
|
+
'value',
|
|
105
|
+
'password',
|
|
106
|
+
'passphrase',
|
|
107
|
+
'public_value',
|
|
108
|
+
'key_fingerprint',
|
|
109
|
+
'checksum',
|
|
110
|
+
'binary',
|
|
111
|
+
'project',
|
|
112
|
+
'pipeline',
|
|
113
|
+
'action',
|
|
114
|
+
'sandbox',
|
|
115
|
+
'environment',
|
|
116
|
+
'base_environment',
|
|
117
|
+
];
|
|
118
|
+
const variableUpdateBody = (variable, changes) => {
|
|
119
|
+
const body = {};
|
|
120
|
+
for (const [field, value] of Object.entries(variable)) {
|
|
121
|
+
if (!VARIABLE_NOT_CARRIED.includes(field))
|
|
122
|
+
body[field] = value;
|
|
123
|
+
}
|
|
124
|
+
return { ...body, ...changes };
|
|
125
|
+
};
|
|
126
|
+
exports.variableUpdateBody = variableUpdateBody;
|
|
127
|
+
// For API responses of create/update, which carry the owner object. An
|
|
128
|
+
// action-scoped variable also carries its pipeline, so the action goes first.
|
|
129
|
+
const variableScopeOf = (variable) => {
|
|
130
|
+
if (variable.action)
|
|
131
|
+
return 'ACTION';
|
|
132
|
+
if (variable.pipeline)
|
|
133
|
+
return utils_1.VARIABLE_SCOPE.PIPELINE;
|
|
134
|
+
if (variable.sandbox)
|
|
135
|
+
return utils_1.VARIABLE_SCOPE.SANDBOX;
|
|
136
|
+
if (variable.environment)
|
|
137
|
+
return utils_1.VARIABLE_SCOPE.ENVIRONMENT;
|
|
138
|
+
if (variable.project)
|
|
139
|
+
return utils_1.VARIABLE_SCOPE.PROJECT;
|
|
140
|
+
return utils_1.VARIABLE_SCOPE.WORKSPACE;
|
|
141
|
+
};
|
|
142
|
+
exports.variableScopeOf = variableScopeOf;
|
|
143
|
+
// Text views never print an encrypted value: the API already masks it, but
|
|
144
|
+
// the masked form is noise. Multi-line values (keys, files) are cut to the
|
|
145
|
+
// first line so a table stays readable; the full value is in --format json.
|
|
146
|
+
const variableValueOf = (variable, maxLength) => {
|
|
147
|
+
if (variable.encrypted)
|
|
148
|
+
return '***';
|
|
149
|
+
const value = variable.value ?? '';
|
|
150
|
+
if (!value)
|
|
151
|
+
return '-';
|
|
152
|
+
const lines = value.split('\n');
|
|
153
|
+
let shown = lines[0];
|
|
154
|
+
let cut = lines.length > 1;
|
|
155
|
+
if (maxLength && shown.length > maxLength) {
|
|
156
|
+
shown = shown.slice(0, maxLength);
|
|
157
|
+
cut = true;
|
|
158
|
+
}
|
|
159
|
+
return cut ? `${shown}...` : shown;
|
|
160
|
+
};
|
|
161
|
+
exports.variableValueOf = variableValueOf;
|
|
@@ -0,0 +1,92 @@
|
|
|
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 utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const cliError_1 = __importDefault(require("../../cliError"));
|
|
11
|
+
const scope_1 = require("./scope");
|
|
12
|
+
const commandVariableUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_VARIABLE_UPDATE, {
|
|
13
|
+
requiredScopes: [utils_1.REST_API_SCOPE.VARIABLE_WRITE],
|
|
14
|
+
examples: texts_1.EXAMPLE_VARIABLE_UPDATE,
|
|
15
|
+
});
|
|
16
|
+
commandVariableUpdate.alias('edit');
|
|
17
|
+
commandVariableUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
18
|
+
commandVariableUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
19
|
+
commandVariableUpdate.option('--pipeline <identifier>', texts_1.OPTION_VARIABLE_PIPELINE);
|
|
20
|
+
commandVariableUpdate.option('--environment <identifier>', texts_1.OPTION_VARIABLE_ENVIRONMENT);
|
|
21
|
+
commandVariableUpdate.option('--sandbox <identifier>', texts_1.OPTION_VARIABLE_SANDBOX);
|
|
22
|
+
commandVariableUpdate.option('--scope <scope>', texts_1.OPT_COMMAND_VARIABLE_SCOPE);
|
|
23
|
+
commandVariableUpdate.option('--file <path>', texts_1.OPTION_VARIABLE_FILE);
|
|
24
|
+
commandVariableUpdate.option('--key <key>', texts_1.OPTION_VARIABLE_RENAME);
|
|
25
|
+
commandVariableUpdate.option('--encrypted', texts_1.OPTION_VARIABLE_ENCRYPTED);
|
|
26
|
+
commandVariableUpdate.option('--no-encrypted', texts_1.OPTION_VARIABLE_NO_ENCRYPTED);
|
|
27
|
+
commandVariableUpdate.option('--settable', texts_1.OPTION_VARIABLE_SETTABLE);
|
|
28
|
+
commandVariableUpdate.option('--no-settable', texts_1.OPTION_VARIABLE_NO_SETTABLE);
|
|
29
|
+
commandVariableUpdate.option('--enable', texts_1.OPTION_VARIABLE_ENABLE);
|
|
30
|
+
commandVariableUpdate.option('--disable', texts_1.OPTION_VARIABLE_DISABLE);
|
|
31
|
+
commandVariableUpdate.option('--note <note>', texts_1.OPT_COMMAND_NOTE);
|
|
32
|
+
commandVariableUpdate.option('--agent-note <note>', texts_1.OPT_COMMAND_AGENT_NOTE);
|
|
33
|
+
commandVariableUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
34
|
+
commandVariableUpdate.argument('<key>', texts_1.OPTION_VARIABLE_KEY);
|
|
35
|
+
commandVariableUpdate.argument('[value]', texts_1.OPTION_VARIABLE_VALUE);
|
|
36
|
+
// Only what was passed changes; the rest of the stored variable is re-sent
|
|
37
|
+
// (variableUpdateBody), as the PATCH resets fields left out. A value left out
|
|
38
|
+
// stays as stored.
|
|
39
|
+
commandVariableUpdate.action(async (key, value, options) => {
|
|
40
|
+
if (options.enable && options.disable) {
|
|
41
|
+
output_1.default.exitError(texts_1.ERR_VARIABLE_ENABLE_DISABLE);
|
|
42
|
+
}
|
|
43
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
44
|
+
const newValue = input_1.default.variableValue(value, options.file);
|
|
45
|
+
// The API answers turning encryption off without a value by clearing it
|
|
46
|
+
if (options.encrypted === false && newValue === undefined) {
|
|
47
|
+
output_1.default.exitError(new cliError_1.default('usage_error', texts_1.ERR_VARIABLE_DECRYPT_NO_VALUE));
|
|
48
|
+
}
|
|
49
|
+
const changes = {};
|
|
50
|
+
let changed = false;
|
|
51
|
+
if (options.key && options.key !== key) {
|
|
52
|
+
changes.key = options.key;
|
|
53
|
+
changed = true;
|
|
54
|
+
}
|
|
55
|
+
if (newValue !== undefined) {
|
|
56
|
+
changes.value = newValue;
|
|
57
|
+
changed = true;
|
|
58
|
+
}
|
|
59
|
+
if (options.encrypted !== undefined) {
|
|
60
|
+
changes.encrypted = options.encrypted;
|
|
61
|
+
changed = true;
|
|
62
|
+
}
|
|
63
|
+
if (options.settable !== undefined) {
|
|
64
|
+
changes.settable = options.settable;
|
|
65
|
+
changed = true;
|
|
66
|
+
}
|
|
67
|
+
if (options.enable || options.disable) {
|
|
68
|
+
changes.disabled = !!options.disable;
|
|
69
|
+
changed = true;
|
|
70
|
+
}
|
|
71
|
+
if (options.note !== undefined) {
|
|
72
|
+
changes.note = options.note;
|
|
73
|
+
changed = true;
|
|
74
|
+
}
|
|
75
|
+
if (options.agentNote !== undefined) {
|
|
76
|
+
changes.agent_note = options.agentNote;
|
|
77
|
+
changed = true;
|
|
78
|
+
}
|
|
79
|
+
if (!changed) {
|
|
80
|
+
output_1.default.exitError(texts_1.ERR_COMMAND_NO_UPDATE);
|
|
81
|
+
}
|
|
82
|
+
const client = input_1.default.restApiTokenClient();
|
|
83
|
+
const { variable, scope } = await (0, scope_1.resolveVariable)(client, workspace, key, options,
|
|
84
|
+
/* strictScope */ true);
|
|
85
|
+
const result = await client.updateVariable(workspace, variable.id, (0, scope_1.variableUpdateBody)(variable, changes));
|
|
86
|
+
if (options.format === 'json') {
|
|
87
|
+
output_1.default.json(result);
|
|
88
|
+
output_1.default.exitNormal();
|
|
89
|
+
}
|
|
90
|
+
output_1.default.exitSuccess((0, texts_1.TXT_VARIABLE_UPDATED)(result.key, scope));
|
|
91
|
+
});
|
|
92
|
+
exports.default = commandVariableUpdate;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 utils_1 = require("../utils");
|
|
7
|
+
const texts_1 = require("../texts");
|
|
8
|
+
const list_1 = __importDefault(require("./variable/list"));
|
|
9
|
+
const get_1 = __importDefault(require("./variable/get"));
|
|
10
|
+
const create_1 = __importDefault(require("./variable/create"));
|
|
11
|
+
const update_1 = __importDefault(require("./variable/update"));
|
|
12
|
+
const delete_1 = __importDefault(require("./variable/delete"));
|
|
13
|
+
const commandVariable = (0, utils_1.newCommand)('variable', texts_1.DESC_COMMAND_VARIABLE);
|
|
14
|
+
commandVariable.alias('var');
|
|
15
|
+
commandVariable.addCommand(list_1.default);
|
|
16
|
+
commandVariable.addCommand(get_1.default);
|
|
17
|
+
commandVariable.addCommand(create_1.default);
|
|
18
|
+
commandVariable.addCommand(update_1.default);
|
|
19
|
+
commandVariable.addCommand(delete_1.default);
|
|
20
|
+
exports.default = commandVariable;
|
package/distTs/src/input.js
CHANGED
|
@@ -1470,6 +1470,71 @@ class Input {
|
|
|
1470
1470
|
environment,
|
|
1471
1471
|
};
|
|
1472
1472
|
}
|
|
1473
|
+
// Variables live on one of the target lines or on a sandbox, which is its
|
|
1474
|
+
// own line: a sandbox belongs to a project (narrowing the lookup) or the
|
|
1475
|
+
// workspace, never to a pipeline or an environment line.
|
|
1476
|
+
static variableScope(project, pipeline, environment, sandbox, scope) {
|
|
1477
|
+
if (sandbox && (pipeline || environment)) {
|
|
1478
|
+
output_1.default.exitError(texts_1.ERR_VARIABLE_LINE_CONFLICT);
|
|
1479
|
+
}
|
|
1480
|
+
Input.targetLine(project, pipeline, environment);
|
|
1481
|
+
if (scope) {
|
|
1482
|
+
scope = scope.toUpperCase();
|
|
1483
|
+
if (scope === utils_1.VARIABLE_SCOPE.WORKSPACE) {
|
|
1484
|
+
return scope;
|
|
1485
|
+
}
|
|
1486
|
+
if (scope === utils_1.VARIABLE_SCOPE.PROJECT) {
|
|
1487
|
+
if (!project)
|
|
1488
|
+
output_1.default.exitError(texts_1.ERR_COMMAND_SCOPE_NO_PROJECT);
|
|
1489
|
+
return scope;
|
|
1490
|
+
}
|
|
1491
|
+
if (scope === utils_1.VARIABLE_SCOPE.PIPELINE) {
|
|
1492
|
+
if (!pipeline)
|
|
1493
|
+
output_1.default.exitError(texts_1.ERR_TARGET_SCOPE_NO_PIPELINE);
|
|
1494
|
+
return scope;
|
|
1495
|
+
}
|
|
1496
|
+
if (scope === utils_1.VARIABLE_SCOPE.ENVIRONMENT) {
|
|
1497
|
+
if (!environment)
|
|
1498
|
+
output_1.default.exitError(texts_1.ERR_TARGET_SCOPE_NO_ENVIRONMENT);
|
|
1499
|
+
return scope;
|
|
1500
|
+
}
|
|
1501
|
+
if (scope === utils_1.VARIABLE_SCOPE.SANDBOX) {
|
|
1502
|
+
if (!sandbox)
|
|
1503
|
+
output_1.default.exitError(texts_1.ERR_VARIABLE_SCOPE_NO_SANDBOX);
|
|
1504
|
+
return scope;
|
|
1505
|
+
}
|
|
1506
|
+
return output_1.default.exitError(texts_1.ERR_VARIABLE_SCOPE);
|
|
1507
|
+
}
|
|
1508
|
+
if (pipeline)
|
|
1509
|
+
return utils_1.VARIABLE_SCOPE.PIPELINE;
|
|
1510
|
+
if (environment)
|
|
1511
|
+
return utils_1.VARIABLE_SCOPE.ENVIRONMENT;
|
|
1512
|
+
if (sandbox)
|
|
1513
|
+
return utils_1.VARIABLE_SCOPE.SANDBOX;
|
|
1514
|
+
if (project)
|
|
1515
|
+
return utils_1.VARIABLE_SCOPE.PROJECT;
|
|
1516
|
+
return utils_1.VARIABLE_SCOPE.WORKSPACE;
|
|
1517
|
+
}
|
|
1518
|
+
// Value from the argument or from a file (`-` = stdin, which keeps a secret
|
|
1519
|
+
// out of the shell history and the process list). Undefined when neither is
|
|
1520
|
+
// given: create stores an empty value, update leaves the stored one intact.
|
|
1521
|
+
// stdin drops the one line ending `echo` adds - an encrypted value is never
|
|
1522
|
+
// shown again, so a token with a stray newline would go unnoticed. A file is
|
|
1523
|
+
// taken byte for byte: keys and JSON may need their exact content.
|
|
1524
|
+
static variableValue(value, file) {
|
|
1525
|
+
if (value !== undefined && file) {
|
|
1526
|
+
output_1.default.exitError(new cliError_1.default('usage_error', texts_1.ERR_VARIABLE_VALUE_CONFLICT));
|
|
1527
|
+
}
|
|
1528
|
+
if (!file)
|
|
1529
|
+
return value;
|
|
1530
|
+
if (file === '-')
|
|
1531
|
+
return node_fs_1.default.readFileSync(0, 'utf8').replace(/\r?\n$/, '');
|
|
1532
|
+
const p = (0, node_path_1.resolve)(file);
|
|
1533
|
+
if (!node_fs_1.default.existsSync(p)) {
|
|
1534
|
+
output_1.default.exitError(new cliError_1.default('file_not_found', (0, texts_1.ERR_VARIABLE_FILE_NOT_FOUND)(file)));
|
|
1535
|
+
}
|
|
1536
|
+
return node_fs_1.default.readFileSync(p, 'utf8');
|
|
1537
|
+
}
|
|
1473
1538
|
/**
|
|
1474
1539
|
* Resolve `--project` / `--scope` / `--environment` into the filter the sandbox
|
|
1475
1540
|
* endpoints take. Only one of the two is ever set: a sandbox belongs to a
|