plugin-workflow-portainer 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +31 -3
- package/client-v2.js +1 -0
- package/client.js +1 -0
- package/dist/client/127.5012da93825a6e5c.js +10 -0
- package/dist/client/57.ace9538136438718.js +10 -0
- package/dist/client/65.ec4a55173511c06d.js +10 -0
- package/dist/client/660.546c702d1ddf7eff.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/127.0ec4dce7b13750e9.js +10 -0
- package/dist/client-v2/57.e7cfc50fb651ac14.js +10 -0
- package/dist/client-v2/65.9c745ea32ac96e98.js +10 -0
- package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +151 -0
- package/dist/locale/vi-VN.json +151 -0
- package/dist/locale/zh-CN.json +151 -0
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
- package/dist/node_modules/joi/lib/annotate.js +175 -0
- package/dist/node_modules/joi/lib/base.js +1069 -0
- package/dist/node_modules/joi/lib/cache.js +143 -0
- package/dist/node_modules/joi/lib/common.js +216 -0
- package/dist/node_modules/joi/lib/compile.js +283 -0
- package/dist/node_modules/joi/lib/errors.js +271 -0
- package/dist/node_modules/joi/lib/extend.js +312 -0
- package/dist/node_modules/joi/lib/index.d.ts +2365 -0
- package/dist/node_modules/joi/lib/index.js +1 -0
- package/dist/node_modules/joi/lib/manifest.js +476 -0
- package/dist/node_modules/joi/lib/messages.js +207 -0
- package/dist/node_modules/joi/lib/modify.js +267 -0
- package/dist/node_modules/joi/lib/ref.js +414 -0
- package/dist/node_modules/joi/lib/schemas.js +302 -0
- package/dist/node_modules/joi/lib/state.js +166 -0
- package/dist/node_modules/joi/lib/template.js +463 -0
- package/dist/node_modules/joi/lib/trace.js +346 -0
- package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
- package/dist/node_modules/joi/lib/types/any.js +174 -0
- package/dist/node_modules/joi/lib/types/array.js +809 -0
- package/dist/node_modules/joi/lib/types/binary.js +100 -0
- package/dist/node_modules/joi/lib/types/boolean.js +150 -0
- package/dist/node_modules/joi/lib/types/date.js +233 -0
- package/dist/node_modules/joi/lib/types/function.js +93 -0
- package/dist/node_modules/joi/lib/types/keys.js +1084 -0
- package/dist/node_modules/joi/lib/types/link.js +184 -0
- package/dist/node_modules/joi/lib/types/number.js +363 -0
- package/dist/node_modules/joi/lib/types/object.js +22 -0
- package/dist/node_modules/joi/lib/types/string.js +850 -0
- package/dist/node_modules/joi/lib/types/symbol.js +102 -0
- package/dist/node_modules/joi/lib/validator.js +750 -0
- package/dist/node_modules/joi/lib/values.js +263 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
- package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
- package/dist/node_modules/joi/package.json +1 -0
- package/dist/server/actions/portainer.js +192 -0
- package/dist/server/collections/portainer-instances.js +54 -0
- package/dist/server/index.js +54 -0
- package/dist/server/instructions/PortainerStackControlInstruction.js +156 -0
- package/dist/server/instructions/PortainerStackRedeployInstruction.js +254 -0
- package/dist/server/instructions/helpers.js +211 -0
- package/dist/server/plugin.js +170 -0
- package/dist/server/services/PortainerClient.js +497 -0
- package/dist/shared/collection.js +57 -0
- package/dist/shared/constants.js +66 -0
- package/dist/shared/env.js +221 -0
- package/dist/shared/types.js +24 -0
- package/package.json +50 -4
- package/server.js +1 -0
- package/src/client/index.tsx +50 -0
- package/src/client/instructions.tsx +76 -0
- package/src/client-v2/__tests__/workflow-registration.test.tsx +132 -0
- package/src/client-v2/components/ControlFieldset.tsx +46 -0
- package/src/client-v2/components/PortainerEnvEditor.tsx +223 -0
- package/src/client-v2/components/PortainerSettingsPage.tsx +671 -0
- package/src/client-v2/components/PortainerTargetFields.tsx +317 -0
- package/src/client-v2/components/RedeployFieldset.tsx +123 -0
- package/src/client-v2/index.tsx +50 -0
- package/src/client-v2/instructions.tsx +162 -0
- package/src/client-v2/locale.ts +24 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +151 -0
- package/src/locale/vi-VN.json +151 -0
- package/src/locale/zh-CN.json +151 -0
- package/src/server/__tests__/portainer-workflow.test.ts +455 -0
- package/src/server/actions/portainer.ts +196 -0
- package/src/server/collections/portainer-instances.ts +34 -0
- package/src/server/index.ts +13 -0
- package/src/server/instructions/PortainerStackControlInstruction.ts +139 -0
- package/src/server/instructions/PortainerStackRedeployInstruction.ts +255 -0
- package/src/server/instructions/helpers.ts +237 -0
- package/src/server/plugin.ts +167 -0
- package/src/server/services/PortainerClient.ts +589 -0
- package/src/shared/collection.ts +32 -0
- package/src/shared/constants.ts +25 -0
- package/src/shared/env.ts +228 -0
- package/src/shared/types.ts +105 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { SECRET_MASK } from './constants';
|
|
11
|
+
import type { ConfigurableEnvItem, EnvMergeStrategy, PortainerEnvPair } from './types';
|
|
12
|
+
|
|
13
|
+
const ENV_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
14
|
+
const SENSITIVE_ENV_KEY_PATTERN = /(password|passwd|secret|token|api[_-]?key|private[_-]?key|access[_-]?key)/i;
|
|
15
|
+
|
|
16
|
+
export function isValidEnvKey(key: string): boolean {
|
|
17
|
+
return ENV_KEY_PATTERN.test(key.trim());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isLikelySensitiveKey(key: string): boolean {
|
|
21
|
+
return SENSITIVE_ENV_KEY_PATTERN.test(key);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function stripMatchingQuotes(raw: string): string {
|
|
25
|
+
if (raw.length >= 2) {
|
|
26
|
+
const first = raw[0];
|
|
27
|
+
const last = raw[raw.length - 1];
|
|
28
|
+
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
|
29
|
+
return raw.slice(1, -1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function stringifyEnvValue(value: unknown): string {
|
|
36
|
+
if (value === null || typeof value === 'undefined') {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'string') {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
return JSON.stringify(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse multi-line `.env` content (`KEY=VALUE` or `export KEY=VALUE`) into ordered pairs.
|
|
50
|
+
*/
|
|
51
|
+
export function parseDotEnvText(text?: string | null): PortainerEnvPair[] {
|
|
52
|
+
if (!text || typeof text !== 'string') {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const result: PortainerEnvPair[] = [];
|
|
56
|
+
const lines = text.split(/\r?\n/);
|
|
57
|
+
for (const rawLine of lines) {
|
|
58
|
+
const trimmed = rawLine.trim();
|
|
59
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const normalized = trimmed.startsWith('export ') ? trimmed.slice(7).trim() : trimmed;
|
|
63
|
+
const eqIndex = normalized.indexOf('=');
|
|
64
|
+
if (eqIndex <= 0) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const name = normalized.slice(0, eqIndex).trim();
|
|
68
|
+
if (!isValidEnvKey(name)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const rawVal = normalized.slice(eqIndex + 1).trim();
|
|
72
|
+
result.push({
|
|
73
|
+
name,
|
|
74
|
+
value: stripMatchingQuotes(rawVal),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
81
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Normalize dynamic workflow env input from an array (`[{ name, value }]`), record (`{ KEY: val }`),
|
|
86
|
+
* JSON string, or `.env` text fallback.
|
|
87
|
+
*/
|
|
88
|
+
export function parseDynamicEnvInput(input: unknown): PortainerEnvPair[] {
|
|
89
|
+
if (input === null || typeof input === 'undefined' || input === '') {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let resolved: unknown = input;
|
|
94
|
+
if (typeof input === 'string') {
|
|
95
|
+
const trimmed = input.trim();
|
|
96
|
+
if (!trimmed) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
100
|
+
try {
|
|
101
|
+
resolved = JSON.parse(trimmed);
|
|
102
|
+
} catch {
|
|
103
|
+
throw new Error('Dynamic environment JSON is invalid');
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
return parseDotEnvText(trimmed);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (Array.isArray(resolved)) {
|
|
111
|
+
const pairs: PortainerEnvPair[] = [];
|
|
112
|
+
for (const item of resolved) {
|
|
113
|
+
if (!isPlainRecord(item)) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const rawName = typeof item.name === 'string' ? item.name : typeof item.key === 'string' ? item.key : '';
|
|
117
|
+
const name = rawName.trim();
|
|
118
|
+
if (!name || !isValidEnvKey(name)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
pairs.push({
|
|
122
|
+
name,
|
|
123
|
+
value: stringifyEnvValue(item.value),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return pairs;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (isPlainRecord(resolved)) {
|
|
130
|
+
const pairs: PortainerEnvPair[] = [];
|
|
131
|
+
for (const [rawKey, val] of Object.entries(resolved)) {
|
|
132
|
+
const name = rawKey.trim();
|
|
133
|
+
if (!name || !isValidEnvKey(name)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
pairs.push({
|
|
137
|
+
name,
|
|
138
|
+
value: stringifyEnvValue(val),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return pairs;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface MergedEnvResult {
|
|
148
|
+
env: PortainerEnvPair[];
|
|
149
|
+
maskedEnv: Record<string, string>;
|
|
150
|
+
secretKeys: string[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Deterministically build the final Portainer Stack `env` array and a redacted view for logs/job outputs.
|
|
155
|
+
* Precedence: existing Stack.Env (when strategy === 'merge') -> dynamicEnv -> envText -> envPairs.
|
|
156
|
+
*/
|
|
157
|
+
export function buildEffectiveStackEnv(options: {
|
|
158
|
+
existingEnv?: PortainerEnvPair[];
|
|
159
|
+
strategy?: EnvMergeStrategy;
|
|
160
|
+
dynamicEnv?: unknown;
|
|
161
|
+
envText?: string | null;
|
|
162
|
+
envPairs?: ConfigurableEnvItem[];
|
|
163
|
+
}): MergedEnvResult {
|
|
164
|
+
const map = new Map<string, string>();
|
|
165
|
+
const explicitSecrets = new Set<string>();
|
|
166
|
+
|
|
167
|
+
if ((options.strategy ?? 'merge') === 'merge' && Array.isArray(options.existingEnv)) {
|
|
168
|
+
for (const item of options.existingEnv) {
|
|
169
|
+
const name = String(item?.name ?? '').trim();
|
|
170
|
+
if (name) {
|
|
171
|
+
map.set(name, stringifyEnvValue(item.value));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (const item of parseDynamicEnvInput(options.dynamicEnv)) {
|
|
177
|
+
map.set(item.name, item.value);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (const item of parseDotEnvText(options.envText)) {
|
|
181
|
+
map.set(item.name, item.value);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (Array.isArray(options.envPairs)) {
|
|
185
|
+
for (const item of options.envPairs) {
|
|
186
|
+
const name = String(item?.name ?? '').trim();
|
|
187
|
+
if (!name) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!isValidEnvKey(name)) {
|
|
191
|
+
throw new Error(`Invalid environment variable name "${name}"`);
|
|
192
|
+
}
|
|
193
|
+
map.set(name, stringifyEnvValue(item.value));
|
|
194
|
+
if (item.secret) {
|
|
195
|
+
explicitSecrets.add(name);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const env: PortainerEnvPair[] = [];
|
|
201
|
+
const maskedEnv: Record<string, string> = {};
|
|
202
|
+
const secretKeys: string[] = [];
|
|
203
|
+
|
|
204
|
+
for (const [name, value] of map.entries()) {
|
|
205
|
+
env.push({ name, value });
|
|
206
|
+
const shouldMask = explicitSecrets.has(name) || isLikelySensitiveKey(name);
|
|
207
|
+
if (shouldMask) {
|
|
208
|
+
secretKeys.push(name);
|
|
209
|
+
maskedEnv[name] = SECRET_MASK;
|
|
210
|
+
} else {
|
|
211
|
+
maskedEnv[name] = value;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return { env, maskedEnv, secretKeys };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function normalizeGitReference(ref?: string | null, fallback?: string | null): string {
|
|
219
|
+
const raw = String(ref ?? '').trim();
|
|
220
|
+
if (!raw) {
|
|
221
|
+
const fb = String(fallback ?? '').trim();
|
|
222
|
+
return fb || 'refs/heads/main';
|
|
223
|
+
}
|
|
224
|
+
if (raw.startsWith('refs/')) {
|
|
225
|
+
return raw;
|
|
226
|
+
}
|
|
227
|
+
return `refs/heads/${raw}`;
|
|
228
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type ID = string | number;
|
|
11
|
+
|
|
12
|
+
export interface PortainerEnvPair {
|
|
13
|
+
name: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ConfigurableEnvItem {
|
|
18
|
+
name?: string;
|
|
19
|
+
value?: unknown;
|
|
20
|
+
secret?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type RedeployTargetMode = 'stack' | 'webhook';
|
|
24
|
+
export type EnvMergeStrategy = 'merge' | 'replace';
|
|
25
|
+
export type StackControlAction = 'inspect' | 'start' | 'stop';
|
|
26
|
+
|
|
27
|
+
export interface PortainerStackRedeployConfig {
|
|
28
|
+
instanceId?: ID | string | null;
|
|
29
|
+
mode?: RedeployTargetMode;
|
|
30
|
+
endpointId?: ID | string | null;
|
|
31
|
+
stackId?: ID | string | null;
|
|
32
|
+
webhookId?: string | null;
|
|
33
|
+
webhookTag?: string | null;
|
|
34
|
+
gitReference?: string | null;
|
|
35
|
+
repullImage?: boolean;
|
|
36
|
+
prune?: boolean;
|
|
37
|
+
envStrategy?: EnvMergeStrategy;
|
|
38
|
+
dynamicEnv?: unknown;
|
|
39
|
+
envText?: string | null;
|
|
40
|
+
envPairs?: ConfigurableEnvItem[];
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
ignoreFail?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PortainerStackControlConfig {
|
|
46
|
+
instanceId?: ID | string | null;
|
|
47
|
+
endpointId?: ID | string | null;
|
|
48
|
+
stackId?: ID | string | null;
|
|
49
|
+
action?: StackControlAction;
|
|
50
|
+
timeoutMs?: number;
|
|
51
|
+
ignoreFail?: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PortainerEndpointSummary {
|
|
55
|
+
id: number;
|
|
56
|
+
name: string;
|
|
57
|
+
type: number;
|
|
58
|
+
status: number;
|
|
59
|
+
url?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PortainerStackSummary {
|
|
63
|
+
id: number;
|
|
64
|
+
name: string;
|
|
65
|
+
endpointId: number;
|
|
66
|
+
type: number;
|
|
67
|
+
status: number;
|
|
68
|
+
isGitStack: boolean;
|
|
69
|
+
gitRepoUrl?: string;
|
|
70
|
+
gitReference?: string;
|
|
71
|
+
envCount: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface PortainerStackDetail extends PortainerStackSummary {
|
|
75
|
+
env: PortainerEnvPair[];
|
|
76
|
+
hasSavedGitCredential: boolean;
|
|
77
|
+
gitCredentialId: number;
|
|
78
|
+
gitUsername?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface PortainerContainerSummary {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
image: string;
|
|
85
|
+
state: string;
|
|
86
|
+
status: string;
|
|
87
|
+
healthy: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface PortainerInstanceSummary {
|
|
91
|
+
id: number;
|
|
92
|
+
name: string;
|
|
93
|
+
baseUrl: string;
|
|
94
|
+
apiKey?: string;
|
|
95
|
+
gitUsername?: string;
|
|
96
|
+
gitAccessToken?: string;
|
|
97
|
+
gitCredentialId?: number | null;
|
|
98
|
+
allowInsecureTls?: boolean;
|
|
99
|
+
defaultTimeoutMs?: number;
|
|
100
|
+
isDefault?: boolean;
|
|
101
|
+
enabled?: boolean;
|
|
102
|
+
lastHealthStatus?: string | null;
|
|
103
|
+
lastVersion?: string | null;
|
|
104
|
+
lastCheckedAt?: string | null;
|
|
105
|
+
}
|