lib/ociUtils.js
/*
 * Send POST, PUT, or PATCH request
 */
Send POST, PUT, or PATCH request
Send POST PUT or PATCH request
function promisifiedSendRequest (options, body) {
  return new Promise((resolve, reject) => {
    var request = https.request(options, function (response) {
      var responseBody = '';
      response.on('data', function (chunk) {
        responseBody += chunk;
      });
      response.on('error', function (error) {
        reject(new Error(error));
      });
      response.on('end', function () {
        if (response.statusCode < 300) {
          (response.headers['content-type'] === 'application/json') ? resolve(JSON.parse(responseBody)) : resolve(responseBody);
        } else {
          if (response.headers['content-type'] === 'application/json') {
            const errorResponse = JSON.parse(responseBody);
            reject(new Error(errorResponse.status + ': ' +
            errorResponse.title + ': ' +
            errorResponse.detail));
          } else {
            reject(new Error(response.statusCode + ': ' + response.statusMessage));
          };
        }
      });
    });
    var signOptions = {
      privateKey: utils.PRIVATE_KEY,
      keyFingerprint: utils.KEY_FINGERPRINT,
      tenancyId: utils.TENANCY_ID,
      userId: utils.AUTH_USER_ID
    };
    if (body) {
      signOptions.body = body;
    }
    ;
    sign(request, signOptions);
    (body) ? request.end(body) : request.end();
    request.on('error', function (error) {
      reject(new Error(error));
    });
  });
}
function promisifiedSendRequest ( options , body ) { return new Promise ( ( resolve , reject ) => { var request = https . request ( options , function ( response ) { var responseBody = '' ; response . on ( 'data' , function ( chunk ) { responseBody += chunk ; } ) ; response . on ( 'error' , function ( error ) { reject ( new Error ( error ) ) ; } ) ; response . on ( 'end' , function ( ) { if ( response . statusCode < 300 ) { ( response . headers [ 'content-type' ] === 'application/json' ) ? resolve ( JSON . parse ( responseBody ) ) : resolve ( responseBody ) ; } else { if ( response . headers [ 'content-type' ] === 'application/json' ) { const errorResponse = JSON . parse ( responseBody ) ; reject ( new Error ( errorResponse . status + ': ' + errorResponse . title + ': ' + errorResponse . detail ) ) ; } else { reject ( new Error ( response . statusCode + ': ' + response . statusMessage ) ) ; } ; } } ) ; } ) ; var signOptions = { privateKey : utils . PRIVATE_KEY , keyFingerprint : utils . KEY_FINGERPRINT , tenancyId : utils . TENANCY_ID , userId : utils . AUTH_USER_ID } ; if ( body ) { signOptions . body = body ; } ; sign ( request , signOptions ) ; ( body ) ? request . end ( body ) : request . end ( ) ; request . on ( 'error' , function ( error ) { reject ( new Error ( error ) ) ; } ) ; } ) ; }
Send POST, PUT, or PATCH request
Send POST PUT or PATCH request