├── .codacy.yaml
├── .codeclimate.yml
├── .editorconfig
├── .eslintrc.js
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── Dockerfile
├── LICENSE
├── README.md
├── docker-compose.yml
├── examples
├── api.service.js
├── data
│ └── tmp
│ │ └── .gitignore
├── docker-compose.yml
├── minio.service.js
└── minio
│ └── data
│ └── .gitignore
├── index.js
├── package.json
├── src
├── errors
│ ├── MinioInitializationError.js
│ ├── MinioPingError.js
│ └── index.js
└── service.js
├── test
└── unit
│ ├── errors
│ ├── MinioInitializationError.spec.js
│ └── MinioPingError.spec.js
│ ├── index.spec.js
│ └── service
│ ├── actions
│ ├── bucketExists.spec.js
│ ├── copyObject.spec.js
│ ├── fGetObject.spec.js
│ ├── fPutObject.spec.js
│ ├── getObject.spec.js
│ ├── getPartialObject.spec.js
│ ├── listBuckets.spec.js
│ ├── listIncompleteUploads.spec.js
│ ├── listObjects.spec.js
│ ├── listObjectsV2.spec.js
│ ├── makeBucket.spec.js
│ ├── presignedGetObject.spec.js
│ ├── presignedPostPolicy.spec.js
│ ├── presignedPutObject.spec.js
│ ├── presignedUrl.spec.js
│ ├── putObject.spec.js
│ ├── removeBucket.spec.js
│ ├── removeIncompleteUpload.spec.js
│ ├── removeObject.spec.js
│ ├── removeObjects.spec.js
│ └── statObject.spec.js
│ ├── created.spec.js
│ ├── methods
│ ├── createMinioClient.spec.js
│ └── ping.spec.js
│ ├── name.spec.js
│ ├── settings.spec.js
│ └── stopped.spec.js
└── yarn.lock
/.codacy.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | exclude_paths:
3 | - 'README.md'
4 | - 'CHANGELOG.md'
5 |
--------------------------------------------------------------------------------
/.codeclimate.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 |
3 | checks:
4 | argument-count:
5 | enabled: false
6 | complex-logic:
7 | enabled: false
8 | file-lines:
9 | enabled: false
10 | method-complexity:
11 | enabled: false
12 | method-count:
13 | enabled: false
14 | method-lines:
15 | enabled: false
16 | nested-control-flow:
17 | enabled: false
18 | return-statements:
19 | enabled: false
20 | similar-code:
21 | enabled: false
22 | identical-code:
23 | enabled: false
24 |
25 | plugins:
26 | duplication:
27 | enabled: false
28 | config:
29 | languages:
30 | - javascript
31 | eslint:
32 | enabled: true
33 | channel: "eslint-4"
34 | fixme:
35 | enabled: true
36 |
37 | exclude_paths:
38 | - test/
39 | - benchmark/
40 | - examples/
41 | - typings/
42 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | # Change these settings to your own preference
10 | indent_style = tab
11 | indent_size = 4
12 | space_after_anon_function = true
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
23 | [{package,bower}.json]
24 | indent_style = space
25 | indent_size = 2
26 |
27 | [*.js]
28 | quote_type = "double"
29 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | "env": {
4 | "node": true,
5 | "commonjs": true,
6 | "es6": true,
7 | "jquery": false,
8 | "jest": true,
9 | "jasmine": true
10 | },
11 | "extends": "eslint:recommended",
12 | "parserOptions": {
13 | "sourceType": "module"
14 | },
15 | "rules": {
16 | "indent": [
17 | "warn",
18 | "tab"
19 | ],
20 | "quotes": [
21 | "warn",
22 | "double"
23 | ],
24 | "semi": [
25 | "error",
26 | "always"
27 | ],
28 | "no-var": [
29 | "error"
30 | ],
31 | "no-console": [
32 | "off"
33 | ],
34 | "no-unused-vars": [
35 | "warn"
36 | ]
37 | }
38 | };
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | coverage/
4 | npm-debug.log
5 | stats.json
6 | yarn-error.log
7 | .idea
8 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .idea
3 | benchmarks
4 | coverage
5 | dev
6 | docs
7 | examples
8 | typings
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | cache:
3 | directories:
4 | - node_modules
5 | node_js:
6 | - "10"
7 | - "8"
8 | after_success:
9 | - npm run coverall
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | -----------------------------
2 |
3 | # 1.0.0 (2018-12-17)
4 |
5 | ## New
6 |
7 | ### Bucket Management
8 | The service exposes actions for creating, listing and removing buckets
9 |
10 | ### Object Management
11 | The service exposes actions for creating, listing and removing objects
12 |
13 | ### Presigned URL Management
14 | The service exposes actions for creating Presigned URLs for the S3 Backend
15 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:14.18-alpine
2 |
3 | # Install git for jest watcher for virus scanning
4 | RUN apk add --update --no-cache git
5 |
6 | # Copy over all Source files
7 | COPY . /usr/src
8 |
9 | # Change the working directory to the source files
10 | WORKDIR /usr/src
11 |
12 | # Set the entrypoint to yarn script runner
13 | ENTRYPOINT ["yarn","run"]
14 |
15 | # Execute the ci task by default
16 | CMD ["ci"]
17 |
18 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 designtesbrot
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/moleculerjs/moleculer)
2 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fdesigntesbrot%2Fmoleculer-minio?ref=badge_shield)
3 |
4 | [](https://travis-ci.com/designtesbrot/moleculer-minio)
5 | [](https://coveralls.io/github/designtesbrot/moleculer-minio?branch=master)
6 | [](https://www.codacy.com/app/designtesbrot/moleculer-minio?utm_source=github.com&utm_medium=referral&utm_content=designtesbrot/moleculer-minio&utm_campaign=Badge_Grade)
7 | [](https://codeclimate.com/github/designtesbrot/moleculer-minio/maintainability)
8 | [](https://snyk.io/test/github/designtesbrot/moleculer-minio)
9 | [](https://badge.fury.io/js/moleculer-minio)
10 | [](https://app.getpostman.com/run-collection/39e921971bba8ef74126)
11 |
12 | # Minio Service for the Moleculer framework
13 |
14 | This Services provides actions for managing buckets and objects in an AWS S3 or [Minio](https://www.minio.io) powered backend. It
15 | utilizes the file streaming capabilities of the moleculer framework
16 |
17 | ## Features
18 |
19 | The following List details which features are implemented
20 |
21 | - Bucket Management (Create, Delete, List)
22 | - Object Management (Put, List, Delete, Stat)
23 | - Presigned URL Management (Generate presigned URLs and Post Policy signed URLs)
24 |
25 | ## Roadmap
26 |
27 | The following List details which features are yet to be implemented
28 |
29 | - Caching
30 | - Broadcasting Bucket Notification as moleculer events
31 |
32 | ## Requirements
33 |
34 | This service relies on [Minio](https://www.minio.io) or a generic AWS S3 endpoint available. Make sure to configure the service properly in
35 | order to connect to your endpoint. Using Minio Gatewy capabilities, you can easily fan out to Azure and the like. This repository includes
36 | an example, which itself includes a docker-compose file connecting to an inlcuded minio backend.
37 |
38 | ## Install
39 |
40 | This package is available in the npm-registry. In order to use it simply install it with yarn (or npm):
41 |
42 | ```bash
43 | yarn add moleculer-minio
44 | ```
45 |
46 | ## Usage
47 |
48 | To make use of this Service, simply require it and create a new service:
49 |
50 | ```js
51 | const fs = require("fs");
52 | let { ServiceBroker } = require("moleculer");
53 | let MinioService = require("moleculer-minio");
54 |
55 | let broker = new ServiceBroker({ logger: console });
56 |
57 | // Create a service
58 | broker.createService({
59 | mixins: MinioService,
60 | settings: {
61 | // ... see settings for connectivity
62 | }
63 | });
64 |
65 | // Start server
66 | broker.start()
67 | .then(() => broker.call('minio.makeBucket', {bucketName: 'my-bucket', region: 'us-east-1'}))
68 | .then(() =>
69 | broker.call(
70 | 'minio.putObject',
71 | fs.createReadStream('./archive.tar.gz'),
72 | {
73 | meta: {
74 | bucketName: 'my-bucket',
75 | objectName: 'my-object.tar.gz',
76 | metaData: {
77 | foo: 'bar'
78 | }
79 | }
80 | }
81 | ))
82 | .then(() =>
83 | broker.call('minio.presignedGetObject', {
84 | bucketName: 'my-bucket',
85 | objectName: 'my-object.tar.gz',
86 | expires: 600
87 | }))
88 | .then(console.log);
89 | ```
90 |
91 | For a more indepth example checkout out the `examples folder`. It includes a docker-compose file, running `docker-compose up` will boot a broker with a minio service, a connected minio backend
92 | and an API Gateway to upload files to. This project includes a [published postman collection](https://app.getpostman.com/run-collection/39e921971bba8ef74126) enabling you to quickly explore the service in your local environment.
93 |
94 | ## Settings
95 |
96 |
97 | | Property | Type | Default | Description |
98 | | -------- | ---- | ------- | ----------- |
99 | | `endPoint` | `String` | **required** | The Hostname minio is running on and available at. Hostname or IP-Address |
100 | | `port` | `Number` | **required** | TCP/IP port number minio is listening on. Default value set to 80 for HTTP and 443 for HTTPs. |
101 | | `useSSL` | `Boolean` | `null` | If set to true, https is used instead of http. Default is true. |
102 | | `accessKey` | `String` | **required** | The AccessKey to use when connecting to minio |
103 | | `secretKey` | `String` | **required** | The SecretKey to use when connecting to minio |
104 | | `region` | `String` | `null` | Set this value to override region cache |
105 | | `transport` | `String` | `null` | Set this value to pass in a custom transport. (Optional) |
106 | | `sessionToken` | `String` | `null` | Set this value to provide x-amz-security-token (AWS S3 specific). (Optional) |
107 | | `minioHealthCheckInterval` | `Number` | `null` | This service will perform a periodic healthcheck of Minio. Use this setting to configure the inverval in which the healthcheck is performed. Set to `0` to turn healthcheks of |
108 |
109 |
110 |
111 |
122 |
123 | ## Actions
124 |
125 |
126 | ## `makeBucket`
127 |
128 | Creates a new Bucket
129 |
130 | ### Parameters
131 | | Property | Type | Default | Description |
132 | | -------- | ---- | ------- | ----------- |
133 | | `bucketName` | `string` | **required** | The name of the bucket |
134 | | `region` | `string` | **required** | The region to create the bucket in. Defaults to "us-east-1" |
135 |
136 | ### Results
137 | **Type:** `PromiseLike.<(undefined|Error)>`
138 |
139 |
140 |
141 |
142 | ## `listBuckets`
143 |
144 | Lists all buckets.
145 |
146 | ### Parameters
147 | | Property | Type | Default | Description |
148 | | -------- | ---- | ------- | ----------- |
149 | *No input parameters.*
150 |
151 | ### Results
152 | **Type:** `PromiseLike.<(Array.|Error)>`
153 |
154 |
155 |
156 |
157 | ## `bucketExists`
158 |
159 | Checks if a bucket exists.
160 |
161 | ### Parameters
162 | | Property | Type | Default | Description |
163 | | -------- | ---- | ------- | ----------- |
164 | | `bucketName` | `string` | **required** | Name of the bucket |
165 |
166 | ### Results
167 | **Type:** `PromiseLike.<(boolean|Error)>`
168 |
169 |
170 |
171 |
172 | ## `removeBucket`
173 |
174 | Removes a bucket.
175 |
176 | ### Parameters
177 | | Property | Type | Default | Description |
178 | | -------- | ---- | ------- | ----------- |
179 | | `bucketName` | `string` | **required** | Name of the bucket |
180 |
181 | ### Results
182 | **Type:** `PromiseLike.<(boolean|Error)>`
183 |
184 |
185 |
186 |
187 | ## `listObjects`
188 |
189 | Lists all objects in a bucket.
190 |
191 | ### Parameters
192 | | Property | Type | Default | Description |
193 | | -------- | ---- | ------- | ----------- |
194 | | `bucketName` | `string` | **required** | Name of the bucket |
195 | | `prefix` | `string` | **required** | The prefix of the objects that should be listed (optional, default ''). |
196 | | `recursive` | `boolean` | **required** | `true` indicates recursive style listing and false indicates directory style listing delimited by '/'. (optional, default `false`). |
197 |
198 | ### Results
199 | **Type:** `PromiseLike.<(Array.