1.1.0 • Published 6 years ago

fi-credentials v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

Fi Credentials

Build Status npm npm

Simple JSON credentials loader for local and S3 sources.

Installing

npm install --save fi-credentials

Usage

const credentials = require('fi-credentials');

Loading credentials

This module exports an Object that exposes the following Functions:

const credentials = require('fi-credentials');

credentials.load(config).then((creds) => {
  console.log('Credentials loaded!', creds);

  creds // All the credentials object.
  credentials.get(); // All the credentials object.

  creds.database; // Database property values only.
  credentials.get('database'); // Database property values only.
})

.catch(err => {
  throw err;
});

IMPORTANT: Your credential's file must be a valid JSON file.

Configuration

It must be an Object with the following parameters:

ParamTypeRequiredDefaultDescription
sourceStringNoundefinedCan be used specify 's3' as source. Anything else will be local by default.
debugFunction\|BooleanNoFunctionCan be a Function to log with or a Boolean. If true it will use console.log.
s3ObjectIf source is 's3'undefinedThis is the get object params config for the AWS SDK S3 client.
s3.bucketStringIf source is 's3'undefinedThe S3 bucket name from where to obtain the object.
s3.keyStringIf source is 's3'undefinedThe S3 bucket key name from where to obtain the credentials file.
s3.apiVersionStringIf source is 's3'undefinedThe S3 API version to use.
localObjectIf source is not 's3'undefinedThe local configuration object.
local.pathStringIf source is not 's3'undefinedThe local path to the credentials file.

Example

const config = {

  source: 's3', // Or anything else for local.

  debug: true, // Or you may use the debug module function.

  s3: {
    key: 'path/to/credentials.json',

    apiVersion: '2006-03-01',

    bucket: 'bucket-name'
  },

  local: {
    path: '/local/path/to/credentials.json'
  }

};

API

View the API docs here.