npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imicros-minio

v0.1.0

Published

Moleculer service for minio object storage

Downloads

14

Readme

imicros-minio

NpmLicense npm

Moleculer service for minio object storage

  • authentification by imicros-auth
  • authorization by imicros-acl
  • encription with AES-256-CBC
  • support of encription keys by imicros-key key-server

Installation

$ npm install imicros-minio --save

Dependencies

Requires a running Minio instance.

Requires a running imicros-keys service for encryption key management.

Usage

Preconditions

Authentication: the service expects user id and email to be set in ctx.meta data as follows (refer to imicros-auth):

ctx.meta.user = {
    id: 'unique ID of the user (number or string)',
    email: '[email protected]'
}

Authorization: the service expects acl data have been set in ctx.meta data as follows (refer to imicros-acl):

ctx.meta.acl = {
    ownerId: 'unique ID of the ressource owner (number or string)',
    ... 
    unrestricted: true, " in case of unrestricted access is granted for the owner
    ... or
    restricted: true,   " in case of restricted access based on grant function(s) 
    grants: [ grant function ]
}

Otherwise the service throws "not authorized" error.

Usage minio service

Minio credentials must be set via environment variables MINIO_ACCESS_KEY and MINIO_SECRET_KEY.

process.env.MINIO_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE";
process.env.MINIO_SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
const { ServiceBroker } = require("moleculer");
const { Minio } = require("imicros-minio");

broker = new ServiceBroker({
    logger: console
});
service = broker.createService(Minio, Object.assign({ 
    settings: { 
        minio: {
            endPoint: process.env.MINIO_ENDPOINT || "play.minio.io",
            port: process.env.MINIO_PORT || "9000",
            useSSL: true
        }
    } 
}));
broker.start();

Actions (minio service)

  • makeBucket { region } => { bucketName = ctx.meta.acl.owner.id, region }
  • removeBucket { } => { bucketName = ctx.meta.acl.owner.id, region }
  • putObject { ReadableStream } => { bucketName = ctx.meta.acl.owner.id, objectName }
  • getObject { objectName } => { ReadableStream }
  • removeObject { objectName } => { bucketName = ctx.meta.acl.owner.id, objectName }
  • removeObjects { objectsList } => true | Error
  • statObject { objectName } => { stat }
  • listObjects { prefix, recursive, startAfter} => { ReadableStream obj }
  • listObjectsArray { prefix, recursive, startAfter} => [ obj ]
  • listBuckets { } => [ bucket ] only for admin service

Usage minio mixin

The bucket for the owner must be created before using the mixin.

Require the Mixin

const { MinioMixin } = require("imicros-minio");

Assign it to your moleculer service under property mixins

broker.createService(MyService, Object.assign({ 
                mixins: [MinioMixin({ service: "v1.minio" })]  // pass the name of the running minio service
            }));

Method getStream

let fstream = fs.createWriteStream("myDesiredFileName.any");
let stream = await this.getStream({ ctx: ctx, objectName: "myObjectKeyExistingInMinio" });
stream.pipe(fstream);
 

Method putStream

let fstream = fs.createReadStream("myExistingFile.any");
let result = await this.putStream({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio", stream: fstream });

Method pipeStream

let fstream = fs.createReadStream("myExistingFile.any");
let stream = await this.pipeStream({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio" });  // get writable stream
fstream.pipe(stream);

Method putString

let s = "any string";
let result = await this.putString({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio", value: s });
console.log(result);	// { bucketName: "", objectName: "myDesiredObjectKeyInMinio" }

Method getString

let s = await this.getString({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio" });
console.log(s);		// "any string"
 

Method putObject

Use of JSON.stringify to convert value to string

let value = { key: "value" };
let result = await this.putObject({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio", value: value });
console.log(result);	// { bucketName: "", objectName: "myDesiredObjectKeyInMinio" }

Method getObject

Use of JSON.parse to convert string back to object

let value = await this.getString({ ctx: ctx, objectName: "myDesiredObjectKeyInMinio" });
console.log(value);		// { key: "value" }