packages/iam/src/index.js
function loadPolicies() {
  const policyConfigsPath = path.join(process.cwd(), plugin.config.policiesPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforePoliciesLoad')
  .then(() => {
    // Retrieve configuration path of all API specifications
    return fs.readdirAsync(policyConfigsPath);
  })
  .then(policyConfigFiles => {
    // Load all the policy configurations
    const policyPromises = [];
    _.forEach(policyConfigFiles, (filename) => {
      const policyConfigPath = path.join(policyConfigsPath, filename);
      const policyName = path.parse(filename).name;
      policyPromises.push(loadPolicy(policyConfigPath, policyName));
    });
    return Promise.all(policyPromises);
  })
  .then(policies => {
    // This event allows to inject code to add or delete or alter policy configurations
    return plugin.myrmex.fire('afterPoliciesLoad', policies);
  })
  .spread(policies => {
    return Promise.resolve(policies);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === 'policies') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
function loadPolicies() {
  const policyConfigsPath = path.join(process.cwd(), plugin.config.policiesPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforePoliciesLoad')
  .then(() => {
    // Retrieve configuration path of all API specifications
    return fs.readdirAsync(policyConfigsPath);
  })
  .then(policyConfigFiles => {
    // Load all the policy configurations
    const policyPromises = [];
    _.forEach(policyConfigFiles, (filename) => {
      const policyConfigPath = path.join(policyConfigsPath, filename);
      const policyName = path.parse(filename).name;
      policyPromises.push(loadPolicy(policyConfigPath, policyName));
    });
    return Promise.all(policyPromises);
  })
  .then(policies => {
    // This event allows to inject code to add or delete or alter policy configurations
    return plugin.myrmex.fire('afterPoliciesLoad', policies);
  })
  .spread(policies => {
    return Promise.resolve(policies);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === 'policies') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
function loadPolicies ( ) { const policyConfigsPath = path . join ( process . cwd ( ) , plugin . config . policiesPath ) ; // This event allows to inject code before loading all APIs return plugin . myrmex . fire ( 'beforePoliciesLoad' ) . then ( ( ) => { // Retrieve configuration path of all API specifications return fs . readdirAsync ( policyConfigsPath ) ; } ) . then ( policyConfigFiles => { // Load all the policy configurations const policyPromises = [ ] ; _ . forEach ( policyConfigFiles , ( filename ) => { const policyConfigPath = path . join ( policyConfigsPath , filename ) ; const policyName = path . parse ( filename ) . name ; policyPromises . push ( loadPolicy ( policyConfigPath , policyName ) ) ; } ) ; return Promise . all ( policyPromises ) ; } ) . then ( policies => { // This event allows to inject code to add or delete or alter policy configurations return plugin . myrmex . fire ( 'afterPoliciesLoad' , policies ) ; } ) . spread ( policies => { return Promise . resolve ( policies ) ; } ) . catch ( e => { if ( e . code === 'ENOENT' && path . basename ( e . path ) === 'policies' ) { return Promise . resolve ( [ ] ) ; } return Promise . reject ( e ) ; } ) ; }
Load all policy configurations
@return {Promise<[Policy]>} - promise of an array of policies
Load all policy configurations