An open API service indexing awesome lists of open source software.

https://github.com/hyper63/hyper-adapter-minio

Minio / S3 adapter for Hyper Storage port
https://github.com/hyper63/hyper-adapter-minio

bucket clean-architecture deno hyper minio ports-and-adapters s3 service-framework storage

Last synced: about 2 months ago
JSON representation

Minio / S3 adapter for Hyper Storage port

Awesome Lists containing this project

README

        

hyper-adapter-minio


A Storage port adapter that can use S3 or MinIO for object storage in the hyper service framework


Test
Current Version

---

- [Getting Started](#getting-started)
- [Credentials](#credentials)
- [From the URL](#from-the-url)
- [from ENV VARS](#from-env-vars)
- [Usage with AWS S3](#usage-with-aws-s3)
- [Multiple Buckets or Namespaced Single Bucket](#multiple-buckets-or-namespaced-single-bucket)
- [Features](#features)
- [Methods](#methods)
- [Testing](#testing)
- [License](#license)

## Getting Started

`hyper.config.js`

```js
import { default as minio } from 'https://raw.githubusercontent.com/hyper63/hyper-adapter-minio/main/mod.js'

export default {
app,
adapter: [
{
port: 'storage',
plugins: [
minio({ url: 'https://minioadmin:[email protected]', bucketPrefix: 'uniquePrefix' }),
],
},
],
}
```

When you configure the hyper service with this adapter, you must provide a unique bucket prefix.
This helps ensure your bucket name is globally unique

> The unique name is an alphanumeric string that contains identifing information, this will enable
> you to identify the buckets created by this adapter.

### Credentials

There are two credentials needed in order for this adapter to interact with the underlying S3 or
MinIO resource: an `accessKey` and a `secretKey`. These credentials can be provided to this adapter
in a couple ways.

#### From the URL

The first is simply in the `url` as the `username` and `password`:

```js
minio({ url: 'https://accessKey:[email protected]', bucketPrefix: 'uniquePrefix' })
```

### from ENV VARS

You can also set the environment variables `MINIO_ROOT_USER` to your `accessKey` and
`MINIO_ROOT_PASSWORD` to your `secretKey`.

> Credentials provided in the `url` will supercede any credentials pulled from environment
> variables. In other words, if credentials are provided in both ways, the credentials derived from
> the url will be used.

## Usage with AWS S3

This adapter can also be used on top on AWS' popular S3 service. To do so, simply adjust the `host`
in the `url` provided to the adapter to point to `s3`:

```js
minio({
url: 'https://accessKey:[email protected]',
region: 'us-east-2',
bucketPrefix: 'uniquePrefix',
})
```

> `region` defaults to `us-east-1`

## Multiple Buckets or Namespaced Single Bucket

This adapter can be configured to either create a bucket, in the underying S3 or MinIO, per hyper
Storage Service, or instead to use a _single namespaced_ bucket to store all objects across all
hyper Storage services. In the latter configuration, each hyper Storage service is represented as a
_prefix_ in the single namespaced bucket.

> Among other reasons, using a _single namespaced_ bucket is a great option, if you're concerned
> with surpassing AWS'
> [S3 Bucket Count Restriction](https://docs.aws.amazon.com/AmazonS3/latest/userguide/BucketRestrictions.html)

**By default, the adapter uses the bucket per hyper Storage Service implementation**. To enable the
_single namespaced_ bucket approach, pass the `useNamespacedBucket` flag into the adapter:

```js
minio({
url: 'https://accessKey:[email protected]',
bucketPrefix: 'uniquePrefix',
useNamespacedBucket: true,
})
```

This will make the adapter create only a single bucket called `uniquePrefix-namespaced`. Each hyper
Storage Service is then implemented as a private prefix within the bucket. For example, if you had
hyper Storage services `foo` and `bar`, the structure of the bucket would look like:

```
- uniquePrefix-namespaced
--|/foo
---| foo.png
---| .... # all objects in the 'foo' Storage Service here
--| /bar
---| bar.png
---| .... # all objects in the 'bar' Storage Service here
```

## Features

- Create an `s3` compatible bucket
- Remove an `s3` compatible bucket
- List `s3` compatible buckets
- Put an object into an `s3` compatible bucket
- Remove an object from an `s3` compatible bucket
- Get an object from an `s3` compatible bucket
- List objects in an `s3` compatible bucket

## Methods

This adapter fully implements the Storage port and can be used as the
[hyper Storage service](https://docs.hyper.io/docs/api-reference/rest/storage.html) adapter

See the full port [here](https://github.com/hyper63/hyper/tree/main/packages/port-storage)

## Testing

```
deno task test
```

To lint, check formatting, and run unit tests

To run the test harness, run `deno task test:harness`. a `hyper` server with the adapter installed
will be running on port `6363`

## License

Apache-2.0