@inteli.city/node-red-contrib-bucket-collection 1.0.0
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 +202 -0
- package/README.md +132 -0
- package/bucket-config.html +132 -0
- package/bucket-config.js +54 -0
- package/bucket-delete.html +56 -0
- package/bucket-delete.js +19 -0
- package/bucket-get.html +61 -0
- package/bucket-get.js +19 -0
- package/bucket-list.html +61 -0
- package/bucket-list.js +19 -0
- package/bucket-upload.html +62 -0
- package/bucket-upload.js +19 -0
- package/package.json +30 -0
- package/shared/providers/gcs.js +47 -0
- package/shared/providers/s3.js +56 -0
- package/shared/storage-base.js +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# node-red-contrib-bucket-collection
|
|
2
|
+
|
|
3
|
+
Node-RED nodes for MinIO object storage operations.
|
|
4
|
+
|
|
5
|
+
One node per operation. No hidden abstractions.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Nodes
|
|
10
|
+
|
|
11
|
+
| Node | Type | Purpose |
|
|
12
|
+
|------|------|---------|
|
|
13
|
+
| `minio-config` | config | Shared MinIO connection and credentials |
|
|
14
|
+
| `minio.upload` | operation | Upload an object to a bucket |
|
|
15
|
+
| `minio.get` | operation | Download an object from a bucket |
|
|
16
|
+
| `minio.delete` | operation | Delete an object from a bucket |
|
|
17
|
+
| `minio.list` | operation | List all objects in a bucket |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Config Node (`minio-config`)
|
|
22
|
+
|
|
23
|
+
Create one config node per MinIO server. All operation nodes reference it.
|
|
24
|
+
|
|
25
|
+
| Field | Description |
|
|
26
|
+
|-------|-------------|
|
|
27
|
+
| Endpoint | MinIO server hostname or IP |
|
|
28
|
+
| Port | Server port (default: `9000`) |
|
|
29
|
+
| Use SSL | Enable HTTPS |
|
|
30
|
+
| Access Key | Stored as a credential |
|
|
31
|
+
| Secret Key | Stored as a credential (password field) |
|
|
32
|
+
|
|
33
|
+
The MinIO client is instantiated once at deploy time and reused across all messages.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Input / Output Contract
|
|
38
|
+
|
|
39
|
+
All operation nodes follow the same contract:
|
|
40
|
+
|
|
41
|
+
**Input overrides** — `msg.bucket` and `msg.objectName` override the values set in the node config.
|
|
42
|
+
|
|
43
|
+
**Output** — `msg.payload` contains the operation result.
|
|
44
|
+
|
|
45
|
+
**Status indicators:**
|
|
46
|
+
- Yellow dot — operation in progress
|
|
47
|
+
- Green dot — success
|
|
48
|
+
- Red ring — error
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Node Reference
|
|
53
|
+
|
|
54
|
+
### minio.upload
|
|
55
|
+
|
|
56
|
+
Upload an object to a bucket.
|
|
57
|
+
|
|
58
|
+
| Config | Description | Override via |
|
|
59
|
+
|--------|-------------|--------------|
|
|
60
|
+
| Connection | `minio-config` node | — |
|
|
61
|
+
| Bucket | Target bucket name | `msg.bucket` |
|
|
62
|
+
| Object Name | Destination path (e.g. `folder/file.txt`) | `msg.objectName` |
|
|
63
|
+
|
|
64
|
+
**Input:** `msg.payload` — readable stream or Buffer to upload.
|
|
65
|
+
|
|
66
|
+
**Output:** `msg.payload` — result returned by MinIO `putObject`.
|
|
67
|
+
|
|
68
|
+
> No multipart upload support yet. For large files, pipe the stream directly.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### minio.get
|
|
73
|
+
|
|
74
|
+
Download an object from a bucket.
|
|
75
|
+
|
|
76
|
+
| Config | Description | Override via |
|
|
77
|
+
|--------|-------------|--------------|
|
|
78
|
+
| Connection | `minio-config` node | — |
|
|
79
|
+
| Bucket | Source bucket name | `msg.bucket` |
|
|
80
|
+
| Object Name | Object path to retrieve | `msg.objectName` |
|
|
81
|
+
|
|
82
|
+
**Output:** `msg.payload` — readable stream of the object content. Pipe or collect it in a downstream node.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### minio.delete
|
|
87
|
+
|
|
88
|
+
Delete an object from a bucket.
|
|
89
|
+
|
|
90
|
+
| Config | Description | Override via |
|
|
91
|
+
|--------|-------------|--------------|
|
|
92
|
+
| Connection | `minio-config` node | — |
|
|
93
|
+
| Bucket | Target bucket name | `msg.bucket` |
|
|
94
|
+
| Object Name | Object path to delete | `msg.objectName` |
|
|
95
|
+
|
|
96
|
+
**Output:** `msg.payload` — `{ success: true }` on success.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### minio.list
|
|
101
|
+
|
|
102
|
+
List all objects in a bucket recursively.
|
|
103
|
+
|
|
104
|
+
| Config | Description | Override via |
|
|
105
|
+
|--------|-------------|--------------|
|
|
106
|
+
| Connection | `minio-config` node | — |
|
|
107
|
+
| Bucket | Bucket to list | `msg.bucket` |
|
|
108
|
+
|
|
109
|
+
**Output:** `msg.payload` — array of object metadata (name, size, lastModified, etag).
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Known Limitations
|
|
114
|
+
|
|
115
|
+
- `minio.get` returns a stream — the user is responsible for consuming it downstream
|
|
116
|
+
- `minio.upload` expects `msg.payload` to be a stream or Buffer
|
|
117
|
+
- No multipart upload support
|
|
118
|
+
- No retry logic
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Design Principles
|
|
123
|
+
|
|
124
|
+
- **One node, one operation** — no operation selector inside nodes
|
|
125
|
+
- **Config node as single source of truth** — credentials live in one place
|
|
126
|
+
- **Explicit over magical** — no auto-detection, no hidden fallbacks
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
Apache-2.0
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="bucket-config">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
4
|
+
<input type="text" id="node-config-input-name" placeholder="Name">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-config-input-provider"><i class="fa fa-cubes"></i> Provider</label>
|
|
8
|
+
<select id="node-config-input-provider" style="width:70%">
|
|
9
|
+
<option value="s3">S3-compatible (MinIO, AWS S3, Oracle)</option>
|
|
10
|
+
<option value="gcs">Google Cloud Storage</option>
|
|
11
|
+
</select>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<hr>
|
|
15
|
+
|
|
16
|
+
<!-- S3-compatible fields (MinIO, AWS S3, Oracle) -->
|
|
17
|
+
<div id="s3-fields">
|
|
18
|
+
<div class="form-row">
|
|
19
|
+
<label for="node-config-input-endPoint"><i class="fa fa-server"></i> Endpoint</label>
|
|
20
|
+
<input type="text" id="node-config-input-endPoint"
|
|
21
|
+
placeholder="play.min.io (blank for AWS S3)" style="width:70%">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
|
|
25
|
+
<input type="number" id="node-config-input-port"
|
|
26
|
+
placeholder="9000 for MinIO · blank for AWS S3" style="width:70%">
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-config-input-useSSL"><i class="fa fa-lock"></i> Use SSL</label>
|
|
30
|
+
<input type="checkbox" id="node-config-input-useSSL" style="width:auto">
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-config-input-region"><i class="fa fa-globe"></i> Region</label>
|
|
34
|
+
<input type="text" id="node-config-input-region"
|
|
35
|
+
placeholder="us-east-1 (required for AWS S3)" style="width:70%">
|
|
36
|
+
</div>
|
|
37
|
+
<hr>
|
|
38
|
+
<div class="form-row">
|
|
39
|
+
<label for="node-config-input-accessKey"><i class="fa fa-key"></i> Access Key</label>
|
|
40
|
+
<input type="text" id="node-config-input-accessKey"
|
|
41
|
+
placeholder="access key" style="width:70%">
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-row">
|
|
44
|
+
<label for="node-config-input-secretKey"><i class="fa fa-user-secret"></i> Secret Key</label>
|
|
45
|
+
<input type="password" id="node-config-input-secretKey"
|
|
46
|
+
placeholder="secret key" style="width:70%">
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<!-- GCS fields -->
|
|
51
|
+
<div id="gcs-fields" style="display:none">
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-config-input-gcpKeyJson">
|
|
54
|
+
<i class="fa fa-file-code-o"></i> Service Account JSON
|
|
55
|
+
</label>
|
|
56
|
+
<textarea id="node-config-input-gcpKeyJson"
|
|
57
|
+
placeholder='Paste the full contents of your GCS service account JSON key file'
|
|
58
|
+
rows="10"
|
|
59
|
+
style="width:100%;font-family:monospace;font-size:0.85em"></textarea>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script type="text/html" data-help-name="bucket-config">
|
|
65
|
+
<p>Shared connection config for bucket storage operations. Set credentials once and reuse across all operation nodes.</p>
|
|
66
|
+
|
|
67
|
+
<h3>Provider</h3>
|
|
68
|
+
<ul>
|
|
69
|
+
<li><b>S3-compatible</b> — supports MinIO, AWS S3, and Oracle Object Storage (S3-compatible API)</li>
|
|
70
|
+
<li><b>Google Cloud Storage</b> — supports GCS buckets via a service account</li>
|
|
71
|
+
</ul>
|
|
72
|
+
|
|
73
|
+
<h3>S3-compatible fields</h3>
|
|
74
|
+
<ul>
|
|
75
|
+
<li><b>Endpoint</b> — server hostname or IP. Leave blank for AWS S3 (SDK resolves per-region automatically)</li>
|
|
76
|
+
<li><b>Port</b> — 9000 for MinIO; leave blank for AWS S3</li>
|
|
77
|
+
<li><b>Use SSL</b> — enable HTTPS</li>
|
|
78
|
+
<li><b>Region</b> — required for AWS S3 (e.g. <code>us-east-1</code>); optional for MinIO</li>
|
|
79
|
+
<li><b>Access Key</b> — stored as a credential</li>
|
|
80
|
+
<li><b>Secret Key</b> — stored as a credential</li>
|
|
81
|
+
</ul>
|
|
82
|
+
|
|
83
|
+
<h3>Google Cloud Storage fields</h3>
|
|
84
|
+
<ul>
|
|
85
|
+
<li><b>Service Account JSON</b> — full contents of a GCS service account key file. Stored encrypted. The service account must have Storage Object Admin (or equivalent) permissions on the target bucket.</li>
|
|
86
|
+
</ul>
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<script type="text/javascript">
|
|
90
|
+
RED.nodes.registerType('bucket-config', {
|
|
91
|
+
category: 'config',
|
|
92
|
+
defaults: {
|
|
93
|
+
name: { value: '' },
|
|
94
|
+
provider: { value: 's3' },
|
|
95
|
+
endPoint: { value: '' },
|
|
96
|
+
port: { value: '' },
|
|
97
|
+
useSSL: { value: false },
|
|
98
|
+
region: { value: '' }
|
|
99
|
+
},
|
|
100
|
+
credentials: {
|
|
101
|
+
accessKey: { type: 'text' },
|
|
102
|
+
secretKey: { type: 'password' },
|
|
103
|
+
gcpKeyJson: { type: 'password' }
|
|
104
|
+
},
|
|
105
|
+
label: function() {
|
|
106
|
+
return this.name || this.endPoint || 'bucket-config';
|
|
107
|
+
},
|
|
108
|
+
oneditprepare: function() {
|
|
109
|
+
// Normalize the legacy "minio" provider value to "s3" in the UI.
|
|
110
|
+
var provider = this.provider;
|
|
111
|
+
if (!provider || provider === 'minio') {
|
|
112
|
+
provider = 's3';
|
|
113
|
+
}
|
|
114
|
+
$('#node-config-input-provider').val(provider);
|
|
115
|
+
|
|
116
|
+
function toggleFields(p) {
|
|
117
|
+
if (p === 'gcs') {
|
|
118
|
+
$('#s3-fields').hide();
|
|
119
|
+
$('#gcs-fields').show();
|
|
120
|
+
} else {
|
|
121
|
+
$('#s3-fields').show();
|
|
122
|
+
$('#gcs-fields').hide();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
toggleFields(provider);
|
|
127
|
+
$('#node-config-input-provider').on('change', function() {
|
|
128
|
+
toggleFields($(this).val());
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
</script>
|
package/bucket-config.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const SUPPORTED_PROVIDERS = ["s3", "gcs"];
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function BucketConfigNode(n) {
|
|
5
|
+
RED.nodes.createNode(this, n);
|
|
6
|
+
|
|
7
|
+
// "minio" is the legacy value stored in flows created before the provider
|
|
8
|
+
// field was renamed. It is silently mapped to "s3" for backward compatibility.
|
|
9
|
+
const raw = n.provider || "s3";
|
|
10
|
+
this.provider = raw === "minio" ? "s3" : raw;
|
|
11
|
+
|
|
12
|
+
if (!SUPPORTED_PROVIDERS.includes(this.provider)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Unsupported provider: "${this.provider}". ` +
|
|
15
|
+
`Supported providers: ${SUPPORTED_PROVIDERS.join(", ")}.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (this.provider === "s3") {
|
|
20
|
+
const createS3Client = require("./shared/providers/s3");
|
|
21
|
+
this.client = createS3Client({
|
|
22
|
+
endPoint: n.endPoint,
|
|
23
|
+
port: n.port || undefined,
|
|
24
|
+
useSSL: n.useSSL !== undefined ? n.useSSL : true,
|
|
25
|
+
region: n.region || undefined,
|
|
26
|
+
accessKey: this.credentials.accessKey,
|
|
27
|
+
secretKey: this.credentials.secretKey
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.provider === "gcs") {
|
|
32
|
+
const createGcsClient = require("./shared/providers/gcs");
|
|
33
|
+
|
|
34
|
+
let keyFileJson;
|
|
35
|
+
try {
|
|
36
|
+
keyFileJson = JSON.parse(this.credentials.gcpKeyJson || "{}");
|
|
37
|
+
} catch (_) {
|
|
38
|
+
throw new Error("GCS provider: service account JSON is not valid JSON.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.client = createGcsClient({ keyFileJson });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
RED.nodes.registerType("bucket-config", BucketConfigNode, {
|
|
46
|
+
credentials: {
|
|
47
|
+
// S3 / MinIO / Oracle
|
|
48
|
+
accessKey: { type: "text" },
|
|
49
|
+
secretKey: { type: "password" },
|
|
50
|
+
// GCS
|
|
51
|
+
gcpKeyJson: { type: "password" }
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="bucket-delete">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
4
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-config"><i class="fa fa-server"></i> Connection</label>
|
|
8
|
+
<input type="text" id="node-input-config">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<hr>
|
|
12
|
+
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-bucket"><i class="fa fa-archive"></i> Bucket</label>
|
|
15
|
+
<input type="text" id="node-input-bucket" placeholder="my-bucket (or msg.bucket)" style="width:70%">
|
|
16
|
+
</div>
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-input-objectName"><i class="fa fa-file"></i> Object Name</label>
|
|
19
|
+
<input type="text" id="node-input-objectName" placeholder="folder/file.txt (or msg.objectName)" style="width:70%">
|
|
20
|
+
</div>
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script type="text/html" data-help-name="bucket-delete">
|
|
24
|
+
<p>Delete an object from a storage bucket.</p>
|
|
25
|
+
|
|
26
|
+
<h3>Input</h3>
|
|
27
|
+
<ul>
|
|
28
|
+
<li><code>msg.bucket</code> — bucket name (overrides node config)</li>
|
|
29
|
+
<li><code>msg.objectName</code> — object path (overrides node config)</li>
|
|
30
|
+
</ul>
|
|
31
|
+
|
|
32
|
+
<h3>Output</h3>
|
|
33
|
+
<ul>
|
|
34
|
+
<li><code>msg.payload</code> — <code>{ success: true }</code> on success</li>
|
|
35
|
+
</ul>
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<script type="text/javascript">
|
|
39
|
+
RED.nodes.registerType('bucket-delete', {
|
|
40
|
+
category: 'storage',
|
|
41
|
+
color: '#6BA3C7',
|
|
42
|
+
defaults: {
|
|
43
|
+
name: { value: '' },
|
|
44
|
+
config: { value: '', type: 'bucket-config', required: true },
|
|
45
|
+
bucket: { value: '' },
|
|
46
|
+
objectName: { value: '' }
|
|
47
|
+
},
|
|
48
|
+
inputs: 1,
|
|
49
|
+
outputs: 1,
|
|
50
|
+
icon: 'batch.svg',
|
|
51
|
+
paletteLabel: 'bucket.delete',
|
|
52
|
+
label: function() {
|
|
53
|
+
return this.name || 'bucket.delete';
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
</script>
|
package/bucket-delete.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const createStorageHandler = require("./shared/storage-base");
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function Node(n) {
|
|
5
|
+
RED.nodes.createNode(this, n);
|
|
6
|
+
|
|
7
|
+
this.config = n.config;
|
|
8
|
+
this.bucket = n.bucket;
|
|
9
|
+
this.objectName = n.objectName;
|
|
10
|
+
|
|
11
|
+
const handler = createStorageHandler({ operation: "delete", RED });
|
|
12
|
+
|
|
13
|
+
this.on("input", function(msg, send, done) {
|
|
14
|
+
handler(msg, this, send, done);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
RED.nodes.registerType("bucket-delete", Node);
|
|
19
|
+
};
|
package/bucket-get.html
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="bucket-get">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
4
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-config"><i class="fa fa-server"></i> Connection</label>
|
|
8
|
+
<input type="text" id="node-input-config">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<hr>
|
|
12
|
+
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-bucket"><i class="fa fa-archive"></i> Bucket</label>
|
|
15
|
+
<input type="text" id="node-input-bucket" placeholder="my-bucket (or msg.bucket)" style="width:70%">
|
|
16
|
+
</div>
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-input-objectName"><i class="fa fa-file"></i> Object Name</label>
|
|
19
|
+
<input type="text" id="node-input-objectName" placeholder="folder/file.txt (or msg.objectName)" style="width:70%">
|
|
20
|
+
</div>
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script type="text/html" data-help-name="bucket-get">
|
|
24
|
+
<p>Get (download) an object from a storage bucket.</p>
|
|
25
|
+
|
|
26
|
+
<h3>Input</h3>
|
|
27
|
+
<ul>
|
|
28
|
+
<li><code>msg.bucket</code> — bucket name (overrides node config)</li>
|
|
29
|
+
<li><code>msg.objectName</code> — object path (overrides node config)</li>
|
|
30
|
+
</ul>
|
|
31
|
+
|
|
32
|
+
<h3>Output</h3>
|
|
33
|
+
<ul>
|
|
34
|
+
<li><code>msg.payload</code> — readable stream of the object content</li>
|
|
35
|
+
</ul>
|
|
36
|
+
|
|
37
|
+
<h3>Notes</h3>
|
|
38
|
+
<ul>
|
|
39
|
+
<li>Output is a stream — pipe or collect it downstream</li>
|
|
40
|
+
</ul>
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script type="text/javascript">
|
|
44
|
+
RED.nodes.registerType('bucket-get', {
|
|
45
|
+
category: 'storage',
|
|
46
|
+
color: '#6BA3C7',
|
|
47
|
+
defaults: {
|
|
48
|
+
name: { value: '' },
|
|
49
|
+
config: { value: '', type: 'bucket-config', required: true },
|
|
50
|
+
bucket: { value: '' },
|
|
51
|
+
objectName: { value: '' }
|
|
52
|
+
},
|
|
53
|
+
inputs: 1,
|
|
54
|
+
outputs: 1,
|
|
55
|
+
icon: 'file-out.svg',
|
|
56
|
+
paletteLabel: 'bucket.get',
|
|
57
|
+
label: function() {
|
|
58
|
+
return this.name || 'bucket.get';
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
</script>
|
package/bucket-get.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const createStorageHandler = require("./shared/storage-base");
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function Node(n) {
|
|
5
|
+
RED.nodes.createNode(this, n);
|
|
6
|
+
|
|
7
|
+
this.config = n.config;
|
|
8
|
+
this.bucket = n.bucket;
|
|
9
|
+
this.objectName = n.objectName;
|
|
10
|
+
|
|
11
|
+
const handler = createStorageHandler({ operation: "get", RED });
|
|
12
|
+
|
|
13
|
+
this.on("input", function(msg, send, done) {
|
|
14
|
+
handler(msg, this, send, done);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
RED.nodes.registerType("bucket-get", Node);
|
|
19
|
+
};
|
package/bucket-list.html
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="bucket-list">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
4
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-config"><i class="fa fa-server"></i> Connection</label>
|
|
8
|
+
<input type="text" id="node-input-config">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<hr>
|
|
12
|
+
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-bucket"><i class="fa fa-archive"></i> Bucket</label>
|
|
15
|
+
<input type="text" id="node-input-bucket" placeholder="my-bucket (or msg.bucket)" style="width:70%">
|
|
16
|
+
</div>
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-input-objectName"><i class="fa fa-file"></i> Object Name</label>
|
|
19
|
+
<input type="text" id="node-input-objectName" placeholder="prefix filter (or msg.objectName)" style="width:70%">
|
|
20
|
+
</div>
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script type="text/html" data-help-name="bucket-list">
|
|
24
|
+
<p>List all objects in a storage bucket.</p>
|
|
25
|
+
|
|
26
|
+
<h3>Input</h3>
|
|
27
|
+
<ul>
|
|
28
|
+
<li><code>msg.bucket</code> — bucket name (overrides node config)</li>
|
|
29
|
+
</ul>
|
|
30
|
+
|
|
31
|
+
<h3>Output</h3>
|
|
32
|
+
<ul>
|
|
33
|
+
<li><code>msg.payload</code> — array of objects, each with <code>name</code>, <code>size</code>, <code>lastModified</code>, and <code>etag</code></li>
|
|
34
|
+
</ul>
|
|
35
|
+
|
|
36
|
+
<h3>Notes</h3>
|
|
37
|
+
<ul>
|
|
38
|
+
<li>Lists recursively from the bucket root</li>
|
|
39
|
+
<li>Object Name field is unused for this operation</li>
|
|
40
|
+
</ul>
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script type="text/javascript">
|
|
44
|
+
RED.nodes.registerType('bucket-list', {
|
|
45
|
+
category: 'storage',
|
|
46
|
+
color: '#6BA3C7',
|
|
47
|
+
defaults: {
|
|
48
|
+
name: { value: '' },
|
|
49
|
+
config: { value: '', type: 'bucket-config', required: true },
|
|
50
|
+
bucket: { value: '' },
|
|
51
|
+
objectName: { value: '' }
|
|
52
|
+
},
|
|
53
|
+
inputs: 1,
|
|
54
|
+
outputs: 1,
|
|
55
|
+
icon: 'db.svg',
|
|
56
|
+
paletteLabel: 'bucket.list',
|
|
57
|
+
label: function() {
|
|
58
|
+
return this.name || 'bucket.list';
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
</script>
|
package/bucket-list.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const createStorageHandler = require("./shared/storage-base");
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function Node(n) {
|
|
5
|
+
RED.nodes.createNode(this, n);
|
|
6
|
+
|
|
7
|
+
this.config = n.config;
|
|
8
|
+
this.bucket = n.bucket;
|
|
9
|
+
this.objectName = n.objectName;
|
|
10
|
+
|
|
11
|
+
const handler = createStorageHandler({ operation: "list", RED });
|
|
12
|
+
|
|
13
|
+
this.on("input", function(msg, send, done) {
|
|
14
|
+
handler(msg, this, send, done);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
RED.nodes.registerType("bucket-list", Node);
|
|
19
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script type="text/html" data-template-name="bucket-upload">
|
|
2
|
+
<div class="form-row">
|
|
3
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
4
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
5
|
+
</div>
|
|
6
|
+
<div class="form-row">
|
|
7
|
+
<label for="node-input-config"><i class="fa fa-server"></i> Connection</label>
|
|
8
|
+
<input type="text" id="node-input-config">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<hr>
|
|
12
|
+
|
|
13
|
+
<div class="form-row">
|
|
14
|
+
<label for="node-input-bucket"><i class="fa fa-archive"></i> Bucket</label>
|
|
15
|
+
<input type="text" id="node-input-bucket" placeholder="my-bucket (or msg.bucket)" style="width:70%">
|
|
16
|
+
</div>
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-input-objectName"><i class="fa fa-file"></i> Object Name</label>
|
|
19
|
+
<input type="text" id="node-input-objectName" placeholder="folder/file.txt (or msg.objectName)" style="width:70%">
|
|
20
|
+
</div>
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script type="text/html" data-help-name="bucket-upload">
|
|
24
|
+
<p>Upload an object to a storage bucket.</p>
|
|
25
|
+
|
|
26
|
+
<h3>Input</h3>
|
|
27
|
+
<ul>
|
|
28
|
+
<li><code>msg.payload</code> — stream or Buffer to upload</li>
|
|
29
|
+
<li><code>msg.bucket</code> — bucket name (overrides node config)</li>
|
|
30
|
+
<li><code>msg.objectName</code> — object path (overrides node config)</li>
|
|
31
|
+
</ul>
|
|
32
|
+
|
|
33
|
+
<h3>Output</h3>
|
|
34
|
+
<ul>
|
|
35
|
+
<li><code>msg.payload</code> — result returned by the storage provider</li>
|
|
36
|
+
</ul>
|
|
37
|
+
|
|
38
|
+
<h3>Notes</h3>
|
|
39
|
+
<ul>
|
|
40
|
+
<li>msg.payload must be a readable stream or Buffer</li>
|
|
41
|
+
</ul>
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
RED.nodes.registerType('bucket-upload', {
|
|
46
|
+
category: 'storage',
|
|
47
|
+
color: '#6BA3C7',
|
|
48
|
+
defaults: {
|
|
49
|
+
name: { value: '' },
|
|
50
|
+
config: { value: '', type: 'bucket-config', required: true },
|
|
51
|
+
bucket: { value: '' },
|
|
52
|
+
objectName: { value: '' }
|
|
53
|
+
},
|
|
54
|
+
inputs: 1,
|
|
55
|
+
outputs: 1,
|
|
56
|
+
icon: 'file-in.svg',
|
|
57
|
+
paletteLabel: 'bucket.upload',
|
|
58
|
+
label: function() {
|
|
59
|
+
return this.name || 'bucket.upload';
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
</script>
|
package/bucket-upload.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const createStorageHandler = require("./shared/storage-base");
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
function Node(n) {
|
|
5
|
+
RED.nodes.createNode(this, n);
|
|
6
|
+
|
|
7
|
+
this.config = n.config;
|
|
8
|
+
this.bucket = n.bucket;
|
|
9
|
+
this.objectName = n.objectName;
|
|
10
|
+
|
|
11
|
+
const handler = createStorageHandler({ operation: "upload", RED });
|
|
12
|
+
|
|
13
|
+
this.on("input", function(msg, send, done) {
|
|
14
|
+
handler(msg, this, send, done);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
RED.nodes.registerType("bucket-upload", Node);
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inteli.city/node-red-contrib-bucket-collection",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Node-RED nodes for object storage bucket operations (S3-compatible, GCS)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node-red",
|
|
7
|
+
"bucket",
|
|
8
|
+
"object-storage",
|
|
9
|
+
"s3",
|
|
10
|
+
"gcs",
|
|
11
|
+
"minio",
|
|
12
|
+
"google-cloud-storage",
|
|
13
|
+
"storage"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"minio": "^8.0.7",
|
|
18
|
+
"@google-cloud/storage": "^7.0.0"
|
|
19
|
+
},
|
|
20
|
+
"node-red": {
|
|
21
|
+
"version": ">=2.0.0",
|
|
22
|
+
"nodes": {
|
|
23
|
+
"bucket-config": "bucket-config.js",
|
|
24
|
+
"bucket-upload": "bucket-upload.js",
|
|
25
|
+
"bucket-get": "bucket-get.js",
|
|
26
|
+
"bucket-delete": "bucket-delete.js",
|
|
27
|
+
"bucket-list": "bucket-list.js"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { Storage } = require("@google-cloud/storage");
|
|
2
|
+
const { PassThrough } = require("stream");
|
|
3
|
+
|
|
4
|
+
module.exports = function createGcsClient({ keyFileJson }) {
|
|
5
|
+
const storage = new Storage({ credentials: keyFileJson });
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
async upload(bucket, objectName, streamOrBuffer) {
|
|
9
|
+
const file = storage.bucket(bucket).file(objectName);
|
|
10
|
+
const writeStream = file.createWriteStream({ resumable: false });
|
|
11
|
+
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
writeStream.on("finish", () => resolve({ bucket, objectName }));
|
|
14
|
+
writeStream.on("error", reject);
|
|
15
|
+
|
|
16
|
+
if (Buffer.isBuffer(streamOrBuffer)) {
|
|
17
|
+
const pass = new PassThrough();
|
|
18
|
+
pass.end(streamOrBuffer);
|
|
19
|
+
pass.pipe(writeStream);
|
|
20
|
+
} else {
|
|
21
|
+
streamOrBuffer.pipe(writeStream);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
async get(bucket, objectName) {
|
|
27
|
+
return storage.bucket(bucket).file(objectName).createReadStream();
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
async delete(bucket, objectName) {
|
|
31
|
+
await storage.bucket(bucket).file(objectName).delete();
|
|
32
|
+
return { success: true };
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
async list(bucket) {
|
|
36
|
+
// getFiles() auto-paginates by default and returns all objects in one call.
|
|
37
|
+
const [files] = await storage.bucket(bucket).getFiles();
|
|
38
|
+
|
|
39
|
+
return files.map(f => ({
|
|
40
|
+
name: f.name,
|
|
41
|
+
size: Number(f.metadata.size) || 0,
|
|
42
|
+
lastModified: new Date(f.metadata.updated),
|
|
43
|
+
etag: f.metadata.etag || null
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const Minio = require("minio");
|
|
2
|
+
|
|
3
|
+
module.exports = function createS3Client({ endPoint, port, useSSL, region, accessKey, secretKey }) {
|
|
4
|
+
const opts = {
|
|
5
|
+
endPoint,
|
|
6
|
+
useSSL: useSSL !== undefined ? useSSL : true,
|
|
7
|
+
accessKey,
|
|
8
|
+
secretKey
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Port is optional: must be omitted for AWS S3 (SDK uses 443/80 based on useSSL).
|
|
12
|
+
// For MinIO or other self-hosted deployments, set the explicit port.
|
|
13
|
+
if (port) {
|
|
14
|
+
opts.port = Number(port);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Region is required for AWS S3, optional for MinIO (defaults to "us-east-1").
|
|
18
|
+
if (region) {
|
|
19
|
+
opts.region = region;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const minio = new Minio.Client(opts);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
async upload(bucket, objectName, streamOrBuffer) {
|
|
26
|
+
return minio.putObject(bucket, objectName, streamOrBuffer);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
async get(bucket, objectName) {
|
|
30
|
+
return minio.getObject(bucket, objectName);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
async delete(bucket, objectName) {
|
|
34
|
+
await minio.removeObject(bucket, objectName);
|
|
35
|
+
return { success: true };
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async list(bucket) {
|
|
39
|
+
const objects = [];
|
|
40
|
+
const stream = minio.listObjects(bucket, "", true);
|
|
41
|
+
|
|
42
|
+
await new Promise((resolve, reject) => {
|
|
43
|
+
stream.on("data", obj => objects.push({
|
|
44
|
+
name: obj.name,
|
|
45
|
+
size: obj.size,
|
|
46
|
+
lastModified: obj.lastModified,
|
|
47
|
+
etag: obj.etag || null
|
|
48
|
+
}));
|
|
49
|
+
stream.on("end", resolve);
|
|
50
|
+
stream.on("error", reject);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return objects;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module.exports = function createStorageHandler({ operation, RED }) {
|
|
2
|
+
return async function(msg, node, send, done) {
|
|
3
|
+
const configNode = RED.nodes.getNode(node.config);
|
|
4
|
+
|
|
5
|
+
if (!configNode || !configNode.client) {
|
|
6
|
+
node.error("Missing or unconfigured storage config", msg);
|
|
7
|
+
done();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const client = configNode.client;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
node.status({ fill: "yellow", shape: "dot", text: operation });
|
|
15
|
+
|
|
16
|
+
const bucket = node.bucket || msg.bucket;
|
|
17
|
+
const objectName = node.objectName || msg.objectName;
|
|
18
|
+
|
|
19
|
+
let result;
|
|
20
|
+
|
|
21
|
+
if (operation === "upload") {
|
|
22
|
+
result = await client.upload(bucket, objectName, msg.payload);
|
|
23
|
+
} else if (operation === "get") {
|
|
24
|
+
result = await client.get(bucket, objectName);
|
|
25
|
+
} else if (operation === "delete") {
|
|
26
|
+
result = await client.delete(bucket, objectName);
|
|
27
|
+
} else if (operation === "list") {
|
|
28
|
+
result = await client.list(bucket);
|
|
29
|
+
} else {
|
|
30
|
+
throw new Error(`Unknown operation: "${operation}"`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
msg.payload = result;
|
|
34
|
+
|
|
35
|
+
node.status({ fill: "green", shape: "dot", text: "ok" });
|
|
36
|
+
send(msg);
|
|
37
|
+
done();
|
|
38
|
+
|
|
39
|
+
} catch (err) {
|
|
40
|
+
node.status({ fill: "red", shape: "ring", text: "error" });
|
|
41
|
+
node.error(err.message, msg);
|
|
42
|
+
done(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|