n8n-nodes-soar 0.1.10

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.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright 2022 n8n
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # n8n-nodes-soar
2
+
3
+ This is an n8n community node. It lets you use Docker in your n8n workflows.
4
+
5
+ TBD
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Httpx", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Httpx;
9
+ }
10
+ });
11
+ const _executor = require("../../utils/executor");
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ class Httpx {
26
+ async execute() {
27
+ const result = [];
28
+ const executor = new _executor.SoarExecutor(this);
29
+ for(let idx = 0; idx < this.getInputData().length; idx++){
30
+ const env = {};
31
+ const files = {};
32
+ let collectFiles = [];
33
+ const advanced = this.getNodeParameter("advanced", idx);
34
+ if (advanced) {
35
+ const _env = this.getNodeParameter("env.envs", idx) ?? [];
36
+ Object.assign(env, Object.fromEntries(_env.map(({ key, value })=>[
37
+ key,
38
+ value
39
+ ])));
40
+ const _files = this.getNodeParameter("files.files", idx) ?? [];
41
+ Object.assign(files, Object.fromEntries(_files.map(({ name, content })=>[
42
+ name,
43
+ content
44
+ ])));
45
+ const _collectFiles = this.getNodeParameter("collectFiles.files", idx) ?? [];
46
+ collectFiles = collectFiles.concat(_collectFiles.map(({ name })=>name));
47
+ }
48
+ let targets = [];
49
+ if (this.getNodeParameter("batch", idx)) {
50
+ targets = JSON.parse(this.getNodeParameter("targets", idx)) ?? [];
51
+ } else {
52
+ targets = [
53
+ this.getNodeParameter("target", idx) ?? ""
54
+ ];
55
+ }
56
+ const response = await executor.run(idx, [
57
+ "httpx",
58
+ "-silent",
59
+ "-duc",
60
+ ...targets.flatMap((target)=>[
61
+ "-u",
62
+ target
63
+ ])
64
+ ], env, files, collectFiles);
65
+ result.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response.stdout.trim().split("\n").map((n)=>({
66
+ url: n
67
+ }))), {
68
+ itemData: {
69
+ item: idx
70
+ }
71
+ }));
72
+ }
73
+ return [
74
+ result
75
+ ];
76
+ }
77
+ constructor(){
78
+ _define_property(this, "description", {
79
+ displayName: "Soar: Httpx",
80
+ name: "httpx",
81
+ group: [
82
+ "output"
83
+ ],
84
+ version: 1,
85
+ subtitle: "={{ 'httpx' + ($parameter['batch'] ? ' (Batch)' : ' on ' + $parameter['target']) }}",
86
+ description: "Interact with Httpx",
87
+ defaults: {
88
+ name: "Httpx"
89
+ },
90
+ inputs: [
91
+ "main"
92
+ ],
93
+ outputs: [
94
+ "main"
95
+ ],
96
+ credentials: [
97
+ {
98
+ name: "dockerCredentialsApi"
99
+ },
100
+ {
101
+ name: "kubernetesCredentialsApi"
102
+ }
103
+ ],
104
+ properties: [
105
+ {
106
+ displayName: "Batch",
107
+ name: "batch",
108
+ type: "boolean",
109
+ default: false
110
+ },
111
+ {
112
+ displayName: "Target",
113
+ name: "target",
114
+ type: "string",
115
+ default: "",
116
+ displayOptions: {
117
+ show: {
118
+ batch: [
119
+ false
120
+ ]
121
+ }
122
+ }
123
+ },
124
+ {
125
+ displayName: "Targets",
126
+ name: "targets",
127
+ type: "json",
128
+ default: "[]",
129
+ displayOptions: {
130
+ show: {
131
+ batch: [
132
+ true
133
+ ]
134
+ }
135
+ }
136
+ },
137
+ {
138
+ displayName: "Advanced",
139
+ name: "advanced",
140
+ type: "boolean",
141
+ default: false,
142
+ description: "Whether show advanced options"
143
+ },
144
+ {
145
+ displayName: "Environment Variables",
146
+ name: "env",
147
+ type: "fixedCollection",
148
+ displayOptions: {
149
+ show: {
150
+ advanced: [
151
+ true
152
+ ]
153
+ }
154
+ },
155
+ placeholder: "Add Environment variable",
156
+ typeOptions: {
157
+ multipleValues: true
158
+ },
159
+ default: {
160
+ envs: []
161
+ },
162
+ options: [
163
+ {
164
+ name: "envs",
165
+ displayName: "Envs",
166
+ values: [
167
+ {
168
+ displayName: "Key",
169
+ name: "key",
170
+ type: "string",
171
+ default: ""
172
+ },
173
+ {
174
+ displayName: "Value",
175
+ name: "value",
176
+ type: "string",
177
+ default: ""
178
+ }
179
+ ]
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ displayName: "Write Files",
185
+ name: "files",
186
+ type: "fixedCollection",
187
+ displayOptions: {
188
+ show: {
189
+ advanced: [
190
+ true
191
+ ]
192
+ }
193
+ },
194
+ placeholder: "Add File to write",
195
+ typeOptions: {
196
+ multipleValues: true
197
+ },
198
+ default: {
199
+ files: []
200
+ },
201
+ options: [
202
+ {
203
+ name: "files",
204
+ displayName: "Files",
205
+ values: [
206
+ {
207
+ displayName: "Name",
208
+ name: "name",
209
+ type: "string",
210
+ default: ""
211
+ },
212
+ {
213
+ displayName: "Content",
214
+ name: "content",
215
+ type: "string",
216
+ default: ""
217
+ }
218
+ ]
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ displayName: "Collect Files",
224
+ name: "collectFiles",
225
+ type: "fixedCollection",
226
+ displayOptions: {
227
+ show: {
228
+ advanced: [
229
+ true
230
+ ]
231
+ }
232
+ },
233
+ placeholder: "Add File to collect",
234
+ typeOptions: {
235
+ multipleValues: true
236
+ },
237
+ default: {
238
+ files: []
239
+ },
240
+ options: [
241
+ {
242
+ name: "files",
243
+ displayName: "Files",
244
+ values: [
245
+ {
246
+ displayName: "Name",
247
+ name: "name",
248
+ type: "string",
249
+ default: ""
250
+ }
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ ]
256
+ });
257
+ }
258
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "node": "n8n-nodes-soar.Httpx",
3
+ "nodeVersion": "1.0",
4
+ "codexVersion": "1.0",
5
+ "categories": [
6
+ "Development",
7
+ "Container"
8
+ ]
9
+ }
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Katana", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Katana;
9
+ }
10
+ });
11
+ const _executor = require("../../utils/executor");
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ class Katana {
26
+ async execute() {
27
+ const result = [];
28
+ const executor = new _executor.SoarExecutor(this);
29
+ for(let idx = 0; idx < this.getInputData().length; idx++){
30
+ const env = {};
31
+ const files = {};
32
+ let collectFiles = [];
33
+ const advanced = this.getNodeParameter("advanced", idx);
34
+ if (advanced) {
35
+ const _env = this.getNodeParameter("env.envs", idx) ?? [];
36
+ Object.assign(env, Object.fromEntries(_env.map(({ key, value })=>[
37
+ key,
38
+ value
39
+ ])));
40
+ const _files = this.getNodeParameter("files.files", idx) ?? [];
41
+ Object.assign(files, Object.fromEntries(_files.map(({ name, content })=>[
42
+ name,
43
+ content
44
+ ])));
45
+ const _collectFiles = this.getNodeParameter("collectFiles.files", idx) ?? [];
46
+ collectFiles = collectFiles.concat(_collectFiles.map(({ name })=>name));
47
+ }
48
+ let targets = [];
49
+ if (this.getNodeParameter("batch", idx)) {
50
+ targets = JSON.parse(this.getNodeParameter("targets", idx)) ?? [];
51
+ } else {
52
+ targets = [
53
+ this.getNodeParameter("target", idx) ?? ""
54
+ ];
55
+ }
56
+ const response = await executor.run(idx, [
57
+ "katana",
58
+ "-silent",
59
+ "-duc",
60
+ ...targets.flatMap((target)=>[
61
+ "-u",
62
+ target
63
+ ])
64
+ ], env, files, collectFiles);
65
+ result.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response.stdout.trim().split("\n").map((n)=>({
66
+ url: n
67
+ }))), {
68
+ itemData: {
69
+ item: idx
70
+ }
71
+ }));
72
+ }
73
+ return [
74
+ result
75
+ ];
76
+ }
77
+ constructor(){
78
+ _define_property(this, "description", {
79
+ displayName: "Soar: Katana",
80
+ name: "katana",
81
+ group: [
82
+ "output"
83
+ ],
84
+ version: 1,
85
+ subtitle: "={{ 'katana' + ($parameter['batch'] ? ' (Batch)' : ' on ' + $parameter['target']) }}",
86
+ description: "Interact with Katana",
87
+ defaults: {
88
+ name: "Katana"
89
+ },
90
+ inputs: [
91
+ "main"
92
+ ],
93
+ outputs: [
94
+ "main"
95
+ ],
96
+ credentials: [
97
+ {
98
+ name: "dockerCredentialsApi"
99
+ },
100
+ {
101
+ name: "kubernetesCredentialsApi"
102
+ }
103
+ ],
104
+ properties: [
105
+ {
106
+ displayName: "Batch",
107
+ name: "batch",
108
+ type: "boolean",
109
+ default: false
110
+ },
111
+ {
112
+ displayName: "Target",
113
+ name: "target",
114
+ type: "string",
115
+ default: "",
116
+ displayOptions: {
117
+ show: {
118
+ batch: [
119
+ false
120
+ ]
121
+ }
122
+ }
123
+ },
124
+ {
125
+ displayName: "Targets",
126
+ name: "targets",
127
+ type: "json",
128
+ default: "[]",
129
+ displayOptions: {
130
+ show: {
131
+ batch: [
132
+ true
133
+ ]
134
+ }
135
+ }
136
+ },
137
+ {
138
+ displayName: "Advanced",
139
+ name: "advanced",
140
+ type: "boolean",
141
+ default: false,
142
+ description: "Whether show advanced options"
143
+ },
144
+ {
145
+ displayName: "Environment Variables",
146
+ name: "env",
147
+ type: "fixedCollection",
148
+ displayOptions: {
149
+ show: {
150
+ advanced: [
151
+ true
152
+ ]
153
+ }
154
+ },
155
+ placeholder: "Add Environment variable",
156
+ typeOptions: {
157
+ multipleValues: true
158
+ },
159
+ default: {
160
+ envs: []
161
+ },
162
+ options: [
163
+ {
164
+ name: "envs",
165
+ displayName: "Envs",
166
+ values: [
167
+ {
168
+ displayName: "Key",
169
+ name: "key",
170
+ type: "string",
171
+ default: ""
172
+ },
173
+ {
174
+ displayName: "Value",
175
+ name: "value",
176
+ type: "string",
177
+ default: ""
178
+ }
179
+ ]
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ displayName: "Write Files",
185
+ name: "files",
186
+ type: "fixedCollection",
187
+ displayOptions: {
188
+ show: {
189
+ advanced: [
190
+ true
191
+ ]
192
+ }
193
+ },
194
+ placeholder: "Add File to write",
195
+ typeOptions: {
196
+ multipleValues: true
197
+ },
198
+ default: {
199
+ files: []
200
+ },
201
+ options: [
202
+ {
203
+ name: "files",
204
+ displayName: "Files",
205
+ values: [
206
+ {
207
+ displayName: "Name",
208
+ name: "name",
209
+ type: "string",
210
+ default: ""
211
+ },
212
+ {
213
+ displayName: "Content",
214
+ name: "content",
215
+ type: "string",
216
+ default: ""
217
+ }
218
+ ]
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ displayName: "Collect Files",
224
+ name: "collectFiles",
225
+ type: "fixedCollection",
226
+ displayOptions: {
227
+ show: {
228
+ advanced: [
229
+ true
230
+ ]
231
+ }
232
+ },
233
+ placeholder: "Add File to collect",
234
+ typeOptions: {
235
+ multipleValues: true
236
+ },
237
+ default: {
238
+ files: []
239
+ },
240
+ options: [
241
+ {
242
+ name: "files",
243
+ displayName: "Files",
244
+ values: [
245
+ {
246
+ displayName: "Name",
247
+ name: "name",
248
+ type: "string",
249
+ default: ""
250
+ }
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ ]
256
+ });
257
+ }
258
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "node": "n8n-nodes-soar.katana",
3
+ "nodeVersion": "1.0",
4
+ "codexVersion": "1.0",
5
+ "categories": [
6
+ "Development",
7
+ "Container"
8
+ ]
9
+ }
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "Subfinder", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Subfinder;
9
+ }
10
+ });
11
+ const _executor = require("../../utils/executor");
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ class Subfinder {
26
+ async execute() {
27
+ const result = [];
28
+ const executor = new _executor.SoarExecutor(this);
29
+ for(let idx = 0; idx < this.getInputData().length; idx++){
30
+ const env = {};
31
+ const files = {};
32
+ let collectFiles = [];
33
+ const advanced = this.getNodeParameter("advanced", idx);
34
+ if (advanced) {
35
+ const _env = this.getNodeParameter("env.envs", idx) ?? [];
36
+ Object.assign(env, Object.fromEntries(_env.map(({ key, value })=>[
37
+ key,
38
+ value
39
+ ])));
40
+ const _files = this.getNodeParameter("files.files", idx) ?? [];
41
+ Object.assign(files, Object.fromEntries(_files.map(({ name, content })=>[
42
+ name,
43
+ content
44
+ ])));
45
+ const _collectFiles = this.getNodeParameter("collectFiles.files", idx) ?? [];
46
+ collectFiles = collectFiles.concat(_collectFiles.map(({ name })=>name));
47
+ }
48
+ let targets = [];
49
+ if (this.getNodeParameter("batch", idx)) {
50
+ targets = JSON.parse(this.getNodeParameter("targets", idx)) ?? [];
51
+ } else {
52
+ targets = [
53
+ this.getNodeParameter("target", idx) ?? ""
54
+ ];
55
+ }
56
+ const response = await executor.run(idx, [
57
+ "subfinder",
58
+ "-silent",
59
+ "-duc",
60
+ ...targets.flatMap((target)=>[
61
+ "-d",
62
+ target
63
+ ])
64
+ ], env, files, collectFiles);
65
+ result.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response.stdout.trim().split("\n").map((n)=>({
66
+ url: n
67
+ }))), {
68
+ itemData: {
69
+ item: idx
70
+ }
71
+ }));
72
+ }
73
+ return [
74
+ result
75
+ ];
76
+ }
77
+ constructor(){
78
+ _define_property(this, "description", {
79
+ displayName: "Soar: Subfinder",
80
+ name: "subfinder",
81
+ group: [
82
+ "output"
83
+ ],
84
+ version: 1,
85
+ subtitle: "={{ 'subfinder' + ($parameter['batch'] ? ' (Batch)' : ' on ' + $parameter['target']) }}",
86
+ description: "Interact with Subfinder",
87
+ defaults: {
88
+ name: "Subfinder"
89
+ },
90
+ inputs: [
91
+ "main"
92
+ ],
93
+ outputs: [
94
+ "main"
95
+ ],
96
+ credentials: [
97
+ {
98
+ name: "dockerCredentialsApi"
99
+ },
100
+ {
101
+ name: "kubernetesCredentialsApi"
102
+ }
103
+ ],
104
+ properties: [
105
+ {
106
+ displayName: "Batch",
107
+ name: "batch",
108
+ type: "boolean",
109
+ default: false
110
+ },
111
+ {
112
+ displayName: "Target",
113
+ name: "target",
114
+ type: "string",
115
+ default: "",
116
+ displayOptions: {
117
+ show: {
118
+ batch: [
119
+ false
120
+ ]
121
+ }
122
+ }
123
+ },
124
+ {
125
+ displayName: "Targets",
126
+ name: "targets",
127
+ type: "json",
128
+ default: "[]",
129
+ displayOptions: {
130
+ show: {
131
+ batch: [
132
+ true
133
+ ]
134
+ }
135
+ }
136
+ },
137
+ {
138
+ displayName: "Advanced",
139
+ name: "advanced",
140
+ type: "boolean",
141
+ default: false,
142
+ description: "Whether show advanced options"
143
+ },
144
+ {
145
+ displayName: "Environment Variables",
146
+ name: "env",
147
+ type: "fixedCollection",
148
+ displayOptions: {
149
+ show: {
150
+ advanced: [
151
+ true
152
+ ]
153
+ }
154
+ },
155
+ placeholder: "Add Environment variable",
156
+ typeOptions: {
157
+ multipleValues: true
158
+ },
159
+ default: {
160
+ envs: []
161
+ },
162
+ options: [
163
+ {
164
+ name: "envs",
165
+ displayName: "Envs",
166
+ values: [
167
+ {
168
+ displayName: "Key",
169
+ name: "key",
170
+ type: "string",
171
+ default: ""
172
+ },
173
+ {
174
+ displayName: "Value",
175
+ name: "value",
176
+ type: "string",
177
+ default: ""
178
+ }
179
+ ]
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ displayName: "Write Files",
185
+ name: "files",
186
+ type: "fixedCollection",
187
+ displayOptions: {
188
+ show: {
189
+ advanced: [
190
+ true
191
+ ]
192
+ }
193
+ },
194
+ placeholder: "Add File to write",
195
+ typeOptions: {
196
+ multipleValues: true
197
+ },
198
+ default: {
199
+ files: []
200
+ },
201
+ options: [
202
+ {
203
+ name: "files",
204
+ displayName: "Files",
205
+ values: [
206
+ {
207
+ displayName: "Name",
208
+ name: "name",
209
+ type: "string",
210
+ default: ""
211
+ },
212
+ {
213
+ displayName: "Content",
214
+ name: "content",
215
+ type: "string",
216
+ default: ""
217
+ }
218
+ ]
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ displayName: "Collect Files",
224
+ name: "collectFiles",
225
+ type: "fixedCollection",
226
+ displayOptions: {
227
+ show: {
228
+ advanced: [
229
+ true
230
+ ]
231
+ }
232
+ },
233
+ placeholder: "Add File to collect",
234
+ typeOptions: {
235
+ multipleValues: true
236
+ },
237
+ default: {
238
+ files: []
239
+ },
240
+ options: [
241
+ {
242
+ name: "files",
243
+ displayName: "Files",
244
+ values: [
245
+ {
246
+ displayName: "Name",
247
+ name: "name",
248
+ type: "string",
249
+ default: ""
250
+ }
251
+ ]
252
+ }
253
+ ]
254
+ }
255
+ ]
256
+ });
257
+ }
258
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "node": "n8n-nodes-soar.subfinder",
3
+ "nodeVersion": "1.0",
4
+ "codexVersion": "1.0",
5
+ "categories": [
6
+ "Development",
7
+ "Container"
8
+ ]
9
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SoarExecutor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SoarExecutor;
9
+ }
10
+ });
11
+ const _n8nworkflow = require("n8n-workflow");
12
+ const _dockerrunner = require("./runner/docker.runner");
13
+ const _k8srunner = require("./runner/k8s.runner");
14
+ function _define_property(obj, key, value) {
15
+ if (key in obj) {
16
+ Object.defineProperty(obj, key, {
17
+ value: value,
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true
21
+ });
22
+ } else {
23
+ obj[key] = value;
24
+ }
25
+ return obj;
26
+ }
27
+ class SoarExecutor {
28
+ async getRunner(idx) {
29
+ try {
30
+ const dockerCredentials = await this.func.getCredentials("dockerCredentialsApi", idx);
31
+ return new _dockerrunner.DockerRuneer(dockerCredentials, this.func);
32
+ } catch (e) {
33
+ //
34
+ }
35
+ try {
36
+ const k8sCredentials = await this.func.getCredentials("kubernetesCredentialsApi", idx);
37
+ return new _k8srunner.K8sRunner(k8sCredentials, this.func);
38
+ } catch (e) {
39
+ //
40
+ }
41
+ throw new _n8nworkflow.NodeOperationError(this.func.getNode(), "No credentials got returned!");
42
+ }
43
+ async run(idx, cmdd, env, files, collectFiles = []) {
44
+ const runner = await this.getRunner(idx);
45
+ const cmdline = [
46
+ "/usr/local/bin/runner"
47
+ ];
48
+ for (const [key, value] of Object.entries(files)){
49
+ cmdline.push("--files", `${key}:${btoa(value)}`);
50
+ }
51
+ for (const key of collectFiles){
52
+ cmdline.push("--collect-files", key);
53
+ }
54
+ cmdline.push("--");
55
+ for (const cmd of cmdd){
56
+ cmdline.push(cmd);
57
+ }
58
+ const { stdout, stderr, err, files: resultFiles } = await runner.run(cmdline, env);
59
+ if (err) {
60
+ throw new _n8nworkflow.NodeOperationError(this.func.getNode(), stderr);
61
+ }
62
+ if (stderr) {
63
+ this.func.logger.warn(stderr);
64
+ }
65
+ return {
66
+ stdout,
67
+ files: resultFiles
68
+ };
69
+ }
70
+ constructor(func){
71
+ _define_property(this, "func", void 0);
72
+ this.func = func;
73
+ }
74
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DockerRuneer", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return DockerRuneer;
9
+ }
10
+ });
11
+ const _nodestream = require("node:stream");
12
+ const _dockerode = /*#__PURE__*/ _interop_require_default(require("dockerode"));
13
+ const _n8nworkflow = require("n8n-workflow");
14
+ const _runner = require("./runner");
15
+ function _define_property(obj, key, value) {
16
+ if (key in obj) {
17
+ Object.defineProperty(obj, key, {
18
+ value: value,
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true
22
+ });
23
+ } else {
24
+ obj[key] = value;
25
+ }
26
+ return obj;
27
+ }
28
+ function _interop_require_default(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ class DockerRuneer {
34
+ async run(cmd, env) {
35
+ let stdout = "";
36
+ let stderr = "";
37
+ const outStream = new _nodestream.Writable({
38
+ write (chunk, encoding, done) {
39
+ stdout += chunk.toString();
40
+ done();
41
+ }
42
+ });
43
+ const errStream = new _nodestream.Writable({
44
+ write (chunk, encoding, done) {
45
+ stderr += chunk.toString();
46
+ done();
47
+ }
48
+ });
49
+ await this.docker.pull(_runner.IMAGE);
50
+ await this.docker.run(_runner.IMAGE, cmd, [
51
+ outStream,
52
+ errStream
53
+ ], {
54
+ Tty: false,
55
+ HostConfig: {
56
+ AutoRemove: true
57
+ },
58
+ Env: Object.entries(env || {}).map(([key, value])=>`${key}=${value}`)
59
+ }, {});
60
+ stderr;
61
+ return JSON.parse(stdout);
62
+ }
63
+ constructor(credentials, func){
64
+ _define_property(this, "func", void 0);
65
+ _define_property(this, "docker", void 0);
66
+ this.func = func;
67
+ if (credentials === undefined) {
68
+ throw new _n8nworkflow.NodeOperationError(func.getNode(), "No credentials got returned!");
69
+ }
70
+ this.docker = new _dockerode.default(credentials);
71
+ }
72
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "K8sRunner", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return K8sRunner;
9
+ }
10
+ });
11
+ const _stream = require("stream");
12
+ const _clientnode = /*#__PURE__*/ _interop_require_wildcard(require("@kubernetes/client-node"));
13
+ const _n8nworkflow = require("n8n-workflow");
14
+ const _runner = require("./runner");
15
+ function _define_property(obj, key, value) {
16
+ if (key in obj) {
17
+ Object.defineProperty(obj, key, {
18
+ value: value,
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true
22
+ });
23
+ } else {
24
+ obj[key] = value;
25
+ }
26
+ return obj;
27
+ }
28
+ function _getRequireWildcardCache(nodeInterop) {
29
+ if (typeof WeakMap !== "function") return null;
30
+ var cacheBabelInterop = new WeakMap();
31
+ var cacheNodeInterop = new WeakMap();
32
+ return (_getRequireWildcardCache = function(nodeInterop) {
33
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
34
+ })(nodeInterop);
35
+ }
36
+ function _interop_require_wildcard(obj, nodeInterop) {
37
+ if (!nodeInterop && obj && obj.__esModule) {
38
+ return obj;
39
+ }
40
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
41
+ return {
42
+ default: obj
43
+ };
44
+ }
45
+ var cache = _getRequireWildcardCache(nodeInterop);
46
+ if (cache && cache.has(obj)) {
47
+ return cache.get(obj);
48
+ }
49
+ var newObj = {};
50
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
+ for(var key in obj){
52
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
53
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
54
+ if (desc && (desc.get || desc.set)) {
55
+ Object.defineProperty(newObj, key, desc);
56
+ } else {
57
+ newObj[key] = obj[key];
58
+ }
59
+ }
60
+ }
61
+ newObj.default = obj;
62
+ if (cache) {
63
+ cache.set(obj, newObj);
64
+ }
65
+ return newObj;
66
+ }
67
+ class K8sRunner {
68
+ async run(cmd, env) {
69
+ const kc = this.kubeConfig;
70
+ const k8sCoreApi = kc.makeApiClient(_clientnode.CoreV1Api);
71
+ const watch = new _clientnode.Watch(kc);
72
+ const podName = `n8n-soar-pod-${Date.now()}`;
73
+ const podSpec = {
74
+ metadata: {
75
+ name: podName
76
+ },
77
+ spec: {
78
+ restartPolicy: "Never",
79
+ containers: [
80
+ {
81
+ name: "main-container",
82
+ image: _runner.IMAGE,
83
+ imagePullPolicy: "Always",
84
+ args: cmd,
85
+ env: Object.entries(env ?? {}).map(([name, value])=>({
86
+ name,
87
+ value
88
+ })),
89
+ lifecycle: {}
90
+ }
91
+ ]
92
+ }
93
+ };
94
+ this.func.logger.info("Creating pod " + JSON.stringify(podSpec));
95
+ const namespace = "default";
96
+ await k8sCoreApi.createNamespacedPod(namespace, podSpec);
97
+ try {
98
+ return await new Promise(async (resolve, reject)=>{
99
+ const watchReq = await watch.watch(`/api/v1/namespaces/${namespace}/pods`, {}, (type, obj)=>{
100
+ if (obj.metadata?.name !== podName) {
101
+ return;
102
+ }
103
+ const phase = obj.status?.phase;
104
+ if (phase === "Succeeded" || phase === "Failed") {
105
+ let logs = "";
106
+ const logStream = new _stream.Writable({
107
+ write (chunk, encoding, callback) {
108
+ logs += chunk.toString();
109
+ callback();
110
+ }
111
+ });
112
+ const logApi = new _clientnode.Log(kc);
113
+ logApi.log(namespace, podName, "main-container", logStream).then((req)=>{
114
+ req.on("error", reject);
115
+ req.on("complete", ()=>{
116
+ watchReq?.abort();
117
+ resolve(JSON.parse(logs));
118
+ });
119
+ }).catch((err)=>{
120
+ watchReq?.abort();
121
+ reject(err);
122
+ });
123
+ }
124
+ }, (err)=>{
125
+ reject(err);
126
+ });
127
+ });
128
+ } catch (e) {
129
+ if (e.message === "aborted") {
130
+ // This is fine
131
+ } else {
132
+ throw e;
133
+ }
134
+ } finally{
135
+ await k8sCoreApi.deleteNamespacedPod(podName, namespace);
136
+ }
137
+ }
138
+ constructor(credentials, func){
139
+ _define_property(this, "func", void 0);
140
+ _define_property(this, "kubeConfig", void 0);
141
+ this.func = func;
142
+ if (credentials === undefined) {
143
+ throw new _n8nworkflow.NodeOperationError(func.getNode(), "No credentials got returned!");
144
+ }
145
+ const kubeConfig = new _clientnode.KubeConfig();
146
+ switch(credentials.loadFrom){
147
+ case "automatic":
148
+ kubeConfig.loadFromDefault();
149
+ break;
150
+ case "file":
151
+ if (typeof credentials.filePath !== "string" || credentials.filePath === "") {
152
+ throw new _n8nworkflow.NodeOperationError(func.getNode(), "File path not set!");
153
+ }
154
+ kubeConfig.loadFromFile(credentials.filePath);
155
+ break;
156
+ case "content":
157
+ if (typeof credentials.content !== "string" || credentials.content === "") {
158
+ throw new _n8nworkflow.NodeOperationError(func.getNode(), "Content not set!");
159
+ }
160
+ kubeConfig.loadFromString(credentials.content);
161
+ break;
162
+ default:
163
+ throw new _n8nworkflow.NodeOperationError(func.getNode(), "Load from value not set!");
164
+ }
165
+ this.kubeConfig = kubeConfig;
166
+ }
167
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "IMAGE", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return IMAGE;
9
+ }
10
+ });
11
+ const IMAGE = "registry.yoshino-s.xyz/yoshino-s/soar-image:dev";
package/index.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "n8n-nodes-soar",
3
+ "version": "0.1.10",
4
+ "description": "",
5
+ "keywords": [
6
+ "n8n-community-node-package"
7
+ ],
8
+ "license": "MIT",
9
+ "homepage": "https://github.com/yoshino-s/n8n-nodes-soar.git",
10
+ "author": {
11
+ "name": "Yoshino-s",
12
+ "email": "cy-cui@outlook.com"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/yoshino-s/n8n-nodes-soar.git"
17
+ },
18
+ "main": "index.js",
19
+ "scripts": {
20
+ "prepare": "husky install",
21
+ "build": "swc src -d dist && ts-node ./scripts/copy.ts",
22
+ "build:watch": "ts-node ./scripts/copy.ts && swc src -d dist --watch",
23
+ "new": "ts-node ./scripts/new.ts",
24
+ "lint": "eslint src --ext .ts",
25
+ "lint:fix": "eslint src --ext .ts --fix",
26
+ "prepublishOnly": "yarn build",
27
+ "release": "standard-version",
28
+ "commit": "git-cz",
29
+ "test": "jest"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "n8n": {
35
+ "n8nNodesApiVersion": 1,
36
+ "nodes": [
37
+ "dist/nodes/Katana/Katana.node.js",
38
+ "dist/nodes/Subfinder/Subfinder.node.js",
39
+ "dist/nodes/Httpx/Httpx.node.js"
40
+ ]
41
+ },
42
+ "devDependencies": {
43
+ "@commitlint/cli": "^17.4.2",
44
+ "@commitlint/config-conventional": "^17.4.2",
45
+ "@swc/cli": "^0.1.59",
46
+ "@swc/core": "^1.3.27",
47
+ "@swc/jest": "^0.2.24",
48
+ "@types/dockerode": "^3.3.19",
49
+ "@types/glob": "^8.0.1",
50
+ "@types/jest": "^29.2.6",
51
+ "@types/request-promise-native": "^1.0.18",
52
+ "@typescript-eslint/eslint-plugin": "^5.30.5",
53
+ "@typescript-eslint/parser": "^5.30.5",
54
+ "chalk": "^4",
55
+ "chokidar": "^3.5.3",
56
+ "commitizen": "^4.2.6",
57
+ "conventional-changelog-cli": "^2.2.2",
58
+ "cz-conventional-changelog": "^3.3.0",
59
+ "eslint": "^8.19.0",
60
+ "eslint-config-prettier": "^8.5.0",
61
+ "eslint-import-resolver-typescript": "^3.5.3",
62
+ "eslint-plugin-import": "^2.26.0",
63
+ "eslint-plugin-n8n-nodes-base": "^1.13.0",
64
+ "eslint-plugin-prettier": "^4.2.1",
65
+ "glob": "^8.1.0",
66
+ "husky": "^8.0.3",
67
+ "jest": "^29.3.1",
68
+ "n8n-core": "^1.0.1",
69
+ "n8n-workflow": "^1.0.1",
70
+ "prettier": "^2.8.3",
71
+ "standard-version": "^9.5.0",
72
+ "ts-node": "^10.9.1",
73
+ "typescript": "^4.9.4"
74
+ },
75
+ "config": {
76
+ "commitizen": {
77
+ "path": "cz-conventional-changelog"
78
+ }
79
+ },
80
+ "commitlint": {
81
+ "extends": [
82
+ "@commitlint/config-conventional"
83
+ ]
84
+ },
85
+ "standard-version": {
86
+ "bumpFiles": [
87
+ "package.json"
88
+ ],
89
+ "header": "# Changelog\n\n"
90
+ },
91
+ "dependencies": {
92
+ "dockerode": "^3.3.5",
93
+ "n8n-nodes-container": "^0.1.8"
94
+ }
95
+ }