How to use the microgateway-config.get function in microgateway-config

To help you get started, we’ve selected a few microgateway-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apigee-internal / microgateway / cli / lib / verify.js View on Github external
return cb(new Error('analytics synthetic - got 401 Unauthorized. Invalid key/secret credentials.'));
          } else if (res.statusCode !== 200) {
            writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'verifying analytics with payload: FAIL');
            return cb(new Error('analytics synthetic - got code: ' + res.statusCode));
          } else {
            writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'verifying analytics with payload: OK');
            return cb();
          }
        })
        .write(JSON.stringify(payload));
    }
  ];

  const cachePath = configLocations.getCachePath(options.org, options.env);

  edgeconfig.get({ source: sourcePath, keys: keys }, function (err, config) {
    edgeconfig.save(config, cachePath);
    agentLib({ keys: keys, target: cachePath }, (err, agent, config) => {
      if (err) {
        return printError(err);
      }
      downloadedConfig = config;
      async.series(tasks, function ( /*asyncErr, res */ ) {
        writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'verification complete');
        agent.close(process.exit); // close and stop agent
      });
    })
  });


}
function printError(err) {
github apigee-internal / microgateway / cli / lib / gateway.js View on Github external
var reloadOnConfigChange = (oldConfig, cache, opts) => {
            writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'Checking for change in configuration');
            if (configurl) opts.configurl = configurl;
            //var self = this;
            edgeconfig.get(opts, (err, newConfig) => {
                if(validator(newConfig) === false && !err) {
                    err = {};
                }
                if (err) {
                    // failed to check new config. so try to check again after pollInterval
                    writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'Failed to check for change in Config. Will retry after ' + pollInterval + ' seconds');
                    setTimeout(() => {
                        reloadOnConfigChange(oldConfig, cache, opts);
                    }, pollInterval * 1000);
                } else {
                    pollInterval = config.edgemicro.config_change_poll_interval ? config.edgemicro.config_change_poll_interval : pollInterval;
                    var isConfigChanged = hasConfigChanged(oldConfig, newConfig);
                    if (isConfigChanged) {
                        writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'Configuration change detected. Saving new config and Initiating reload');
                        edgeconfig.save(newConfig, cache);
                        clientSocket.sendMessage({
github apigee-internal / microgateway / lib / proc.js View on Github external
if (err) {
          return cb(err);
        }
        cb(null,configChanged);

      })

    });
  }
  switch (true) {
    case operation === 'reload' :
      const keys = {
        key: edgeConf.analytics.key,
        secret: edgeConf.analytics.secret
      };
      edgeconfig.get({source: defaultConfigSource, target: null, keys: keys}, function (err, conf) {
        configChanged = true;
        if (err) {
          return cb(err);
        }
        if (conf._hash !== edgeConf._hash) {
          edgeConf = conf; // save updated conf, and initiate a graceful restart
          restart(cb);
        } else {
          return cb(err,configChanged);
        }
      });

      break;
    case operation === 'stop':
      gatewayService.stop((err)=> {
        started = 0;
github apigee-internal / microgateway / cli / lib / gateway.js View on Github external
const localproxy = {
        apiProxyName: options.apiProxyName,
        revision: options.revision,
        basePath: options.basepath,
        targetEndpoint: options.target
    };

    var configOptions = {
        source: source,
        keys: keys,
        localproxy: localproxy,
        org: options.org,
        env: options.env
    }

    edgeconfig.get(configOptions, (err, config) => {
        if (err) {
            const exists = fs.existsSync(cache);
            writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},"failed to retieve config from gateway. continuing, will try cached copy..");
            writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},err);
            if (!exists) {
                writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP},'cache configuration ' + cache + ' does not exist. exiting.');
                return;
            } else {
                writeConsoleLog('log',{component: CONSOLE_LOG_TAG_COMP},'using cached configuration from %s', cache);
                config = edgeconfig.load({
                    source: cache
                });
                if (options.port) {
                    config.edgemicro.port = parseInt(options.port);
                }
            }

microgateway-config

Apigee Microgateway Handler

Apache-2.0
Latest version published 8 months ago

Package Health Score

60 / 100
Full package analysis

Similar packages