server/boot/load-model.js
function handshakeWithAPIm(app, apimanager, private_key, cb) {
  logger.debug('handshakeWithAPIm entry');

  async.series([
    function(callback) {
      var body = JSON.stringify({ gatewayVersion: version });
      var headers = { 'content-type': 'application/json' };

      addSignatureHeaders(body, headers, 'micro-gw-catalog/' + apimanager.catalog, private_key);

      if (logger.debug()) {
        logger.debug(JSON.stringify(headers, null, 2));
      }

      var apimHandshakeUrlObj = {
        protocol: 'https',
        hostname: apimanager.host,
        port: apimanager.port,
        pathname: '/v1/catalogs/' + apimanager.catalog + '/handshake/' };
      var apimHandshakeUrl = url.format(apimHandshakeUrlObj);

      Request(
        { url: apimHandshakeUrl,
          method: 'POST',
          json: body,
          headers: headers,
          agentOptions: {
            //FIXME: need to eventually remove this
            rejectUnauthorized: false } },
        function(err, res, body) {
          if (err) {
            logger.error('Failed to communicate with %s: %s ', apimHandshakeUrl, err);
            return callback(err);
          }

          logger.debug('statusCode: ' + res.statusCode);
          if (res.statusCode !== 200) {
            logger.error(apimHandshakeUrl, ' failed with: ', res.statusCode);
            return callback(new Error(apimHandshakeUrl + ' failed with: ' + res.statusCode));
          }

          var json = decryptAPIMResponse(body, private_key);
          //sensitive data
          //if (logger.debug()) {
          //  logger.debug(JSON.stringify(json, null, 2));
          //}

          if (!json.microGateway) {
            return callback(new Error(apimHandshakeUrl + ' response did not contain "microGateway" section'));
          }

          var ugw = json.microGateway;
          apimanager.clicert = ugw.cert;
          apimanager.clikey = ugw.key;
          apimanager.clientid = ugw.clientID;

          //sensitive data
          //if (logger.debug()) {
          //  logger.debug('apimanager: %s', JSON.stringify(apimanager, null, 2));
          //}
          callback(null);
        });
    } ],
    function(err) {
      if (err) {
        apimanager.handshakeOk = false;
        logger.error('Unsuccessful handshake with API Connect server');
      } else {
        apimanager.handshakeOk = true;
        logger.info('Successful handshake with API Connect server');
      }
      logger.debug('handshakeWithAPIm exit');
      cb(err);
    });
}
function handshakeWithAPIm(app, apimanager, private_key, cb) {
  logger.debug('handshakeWithAPIm entry');

  async.series([
    function(callback) {
      var body = JSON.stringify({ gatewayVersion: version });
      var headers = { 'content-type': 'application/json' };

      addSignatureHeaders(body, headers, 'micro-gw-catalog/' + apimanager.catalog, private_key);

      if (logger.debug()) {
        logger.debug(JSON.stringify(headers, null, 2));
      }

      var apimHandshakeUrlObj = {
        protocol: 'https',
        hostname: apimanager.host,
        port: apimanager.port,
        pathname: '/v1/catalogs/' + apimanager.catalog + '/handshake/' };
      var apimHandshakeUrl = url.format(apimHandshakeUrlObj);

      Request(
        { url: apimHandshakeUrl,
          method: 'POST',
          json: body,
          headers: headers,
          agentOptions: {
            //FIXME: need to eventually remove this
            rejectUnauthorized: false } },
        function(err, res, body) {
          if (err) {
            logger.error('Failed to communicate with %s: %s ', apimHandshakeUrl, err);
            return callback(err);
          }

          logger.debug('statusCode: ' + res.statusCode);
          if (res.statusCode !== 200) {
            logger.error(apimHandshakeUrl, ' failed with: ', res.statusCode);
            return callback(new Error(apimHandshakeUrl + ' failed with: ' + res.statusCode));
          }

          var json = decryptAPIMResponse(body, private_key);
          //sensitive data
          //if (logger.debug()) {
          //  logger.debug(JSON.stringify(json, null, 2));
          //}

          if (!json.microGateway) {
            return callback(new Error(apimHandshakeUrl + ' response did not contain "microGateway" section'));
          }

          var ugw = json.microGateway;
          apimanager.clicert = ugw.cert;
          apimanager.clikey = ugw.key;
          apimanager.clientid = ugw.clientID;

          //sensitive data
          //if (logger.debug()) {
          //  logger.debug('apimanager: %s', JSON.stringify(apimanager, null, 2));
          //}
          callback(null);
        });
    } ],
    function(err) {
      if (err) {
        apimanager.handshakeOk = false;
        logger.error('Unsuccessful handshake with API Connect server');
      } else {
        apimanager.handshakeOk = true;
        logger.info('Successful handshake with API Connect server');
      }
      logger.debug('handshakeWithAPIm exit');
      cb(err);
    });
}
function handshakeWithAPIm ( app , apimanager , private_key , cb ) { logger . debug ( 'handshakeWithAPIm entry' ) ; async . series ( [ function ( callback ) { var body = JSON . stringify ( { gatewayVersion : version } ) ; var headers = { 'content-type' : 'application/json' } ; addSignatureHeaders ( body , headers , 'micro-gw-catalog/' + apimanager . catalog , private_key ) ; if ( logger . debug ( ) ) { logger . debug ( JSON . stringify ( headers , null , 2 ) ) ; } var apimHandshakeUrlObj = { protocol : 'https' , hostname : apimanager . host , port : apimanager . port , pathname : '/v1/catalogs/' + apimanager . catalog + '/handshake/' } ; var apimHandshakeUrl = url . format ( apimHandshakeUrlObj ) ; Request ( { url : apimHandshakeUrl , method : 'POST' , json : body , headers : headers , agentOptions : { //FIXME: need to eventually remove this rejectUnauthorized : false } } , function ( err , res , body ) { if ( err ) { logger . error ( 'Failed to communicate with %s: %s ' , apimHandshakeUrl , err ) ; return callback ( err ) ; } logger . debug ( 'statusCode: ' + res . statusCode ) ; if ( res . statusCode !== 200 ) { logger . error ( apimHandshakeUrl , ' failed with: ' , res . statusCode ) ; return callback ( new Error ( apimHandshakeUrl + ' failed with: ' + res . statusCode ) ) ; } var json = decryptAPIMResponse ( body , private_key ) ; //sensitive data //if (logger.debug()) { //  logger.debug(JSON.stringify(json, null, 2)); //} if ( ! json . microGateway ) { return callback ( new Error ( apimHandshakeUrl + ' response did not contain "microGateway" section' ) ) ; } var ugw = json . microGateway ; apimanager . clicert = ugw . cert ; apimanager . clikey = ugw . key ; apimanager . clientid = ugw . clientID ; //sensitive data //if (logger.debug()) { //  logger.debug('apimanager: %s', JSON.stringify(apimanager, null, 2)); //} callback ( null ) ; } ) ; } ] , function ( err ) { if ( err ) { apimanager . handshakeOk = false ; logger . error ( 'Unsuccessful handshake with API Connect server' ) ; } else { apimanager . handshakeOk = true ; logger . info ( 'Successful handshake with API Connect server' ) ; } logger . debug ( 'handshakeWithAPIm exit' ) ; cb ( err ) ; } ) ; }
Attempt to handshake from APIm server
@param {???} app - loopback application
@param {Object} apimanager - configuration pointing to APIm server
@param {string} privatekey - private key to be used for handshake
@param {callback} cb - callback that handles error
Attempt to handshake from APIm server