Sha256: 4b7f43ff06eade62d071a804e38f79f33fd01649fad8559f7bb6e2cb79501b34

Contents?: true

Size: 1.63 KB

Versions: 35

Compression:

Stored size: 1.63 KB

Contents

var AWS = require('./core');
var os = require('os');
var path = require('path');

/**
 * @api private
 */
module.exports = AWS.util.inherit({
  constructor: function SharedIniFile(options) {
    options = options || {};

    this.isConfig = options.isConfig === true;
    this.filename = options.filename || this.getDefaultFilepath();
  },

  ensureFileLoaded: function loadFile() {
    if (!this.parsedContents) {
      this.parsedContents = AWS.util.ini.parse(
        AWS.util.readFileSync(this.filename)
      );
    }
  },

  getDefaultFilepath: function getDefaultFilepath() {
    return path.join(
      this.getHomeDir(),
      '.aws',
      this.isConfig ? 'config' : 'credentials'
    );
  },

  getHomeDir: function getHomeDir() {
    var env = process.env;
    var home = env.HOME ||
      env.USERPROFILE ||
      (env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null);

    if (home) {
      return home;
    }

    if (typeof os.homedir === 'function') {
      return os.homedir();
    }

    throw AWS.util.error(
      new Error('Cannot load credentials, HOME path not set')
    );
  },

  getProfile: function loadProfile(profile) {
    this.ensureFileLoaded();

    var profileIndex = profile !== AWS.util.defaultProfile && this.isConfig ?
      'profile ' + profile : profile;

    return this.parsedContents[profileIndex];
  },

  getProfiles: function loadProfileNames() {
    this.ensureFileLoaded();
    var isConfig = this.isConfig;

    return Object.keys(this.parsedContents).map(function(profileName) {
      if (isConfig) {
        return profileName.replace(/^profile\s/, '');
      }

      return profileName;
    });
  }
});

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sumomo-0.10.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.12 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.11 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.10 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.9 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js
sumomo-0.8.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/shared_ini.js