UNPKG

@itentialopensource/adapter-aws_ec2

Version:

This adapter integrates with system described as: Aws_Ec2.

1,265 lines (1,138 loc) 2.62 MB
/* @copyright Itential, LLC 2019 (pre-modifications) */ /* eslint import/no-dynamic-require: warn */ /* eslint-disable consistent-return */ /* eslint object-curly-newline: warn */ /* eslint no-underscore-dangle: warn */ /* eslint camelcase: warn */ /* eslint no-param-reassign: warn */ /* eslint default-param-last: warn */ // Set globals /* global log */ /* Required libraries. */ const path = require('path'); /* const deviceMap = { eos: 'arista-dcs', asa: 'cisco-asa', ios: 'cisco-ios', iosxr: 'cisco-iosxr', nxos: 'cisco-nx', bigip: 'f5-bigip', junos: 'juniper-junos' }; */ const callOptions = { service: 'ec2', datatype: { request: 'URLENCODE', response: 'XML2JSON' } }; const authMethod = 'aws_authentication'; /* Fetch in the other needed components for the this Adaptor */ const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js')); /* * INTERNAL FUNCTION: return stub results based on the path and method */ function processInArray(inArray, currentParams, key) { if (!inArray || !Array.isArray(inArray) || inArray.length === 0) { return; } // Go through the array to convert the items in it for (let i = 0; i < inArray.length; i += 1) { // rare circumstance where data being provided is [ null ] - this prevents an exception if (inArray[i] === undefined || inArray[i] === null) { return; } // are we dealing with just data if (typeof inArray[i] === 'string' || typeof inArray[i] === 'number' || typeof inArray[i] === 'boolean') { currentParams[`${key}.${i + 1}`] = inArray[i]; } else if (typeof inArray[i] === 'object') { // got an object - need to add keys and values const objKeys = Object.keys(inArray[i]); for (let o = 0; o < objKeys.length; o += 1) { const thisKey = objKeys[o].substring(0, 1).toUpperCase() + objKeys[o].substring(1); const thisValue = inArray[i][objKeys[o]]; if (Array.isArray(thisValue)) { processInArray(thisValue, currentParams, `${key}.${i + 1}.${thisKey}`); } else { currentParams[`${key}.${i + 1}.${thisKey}`] = thisValue; } } } } } /** * This is the adapter/interface into Awsec2 */ /* GENERAL ADAPTER FUNCTIONS */ class Awsec2 extends AdapterBaseCl { /** * Awsec2 Adapter * @constructor */ constructor(prongid, properties) { // make sure properties are set - so that we do not break const myProperties = properties; // service should exist and be ec2 if (myProperties && !myProperties.service) { myProperties.service = callOptions.service; } // auth_method should now be aws_authentication if (myProperties && myProperties.authentication && (!myProperties.authentication.auth_method || myProperties.authentication.auth_method === 'no_authentication')) { myProperties.authentication.auth_method = authMethod; } // Instantiate the AdapterBase super class super(prongid, myProperties); /* const restFunctionNames = this.getWorkflowFunctions(); // Dynamically bind emit functions for (let i = 0; i < restFunctionNames.length; i += 1) { // Bind function to have name fnNameEmit for fnName const version = restFunctionNames[i].match(/__v[0-9]+/); const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, ''); const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`; this[fnNameEmit] = function (...args) { // extract the callback const callback = args[args.length - 1]; // slice the callback from args so we can insert our own const functionArgs = args.slice(0, args.length - 1); // create a random name for the listener const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`; // tell the calling class to start listening callback({ event: eventName, status: 'received' }); // store parent for use of this context later const parent = this; // store emission function const func = function (val, err) { parent.removeListener(eventName, func); parent.emit(eventName, val, err); }; // Use apply to call the function in a specific context this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread }; } // Uncomment if you have things to add to the constructor like using your own properties. // Otherwise the constructor in the adapterBase will be used. // Capture my own properties - they need to be defined in propertiesSchema.json // if (this.allProps && this.allProps.myownproperty) { // mypropvariable = this.allProps.myownproperty; // } */ } /** * @callback healthCallback * @param {Object} reqObj - the request to send into the healthcheck * @param {Callback} callback - The results of the call */ healthCheck(reqObj, callback) { // you can modify what is passed into the healthcheck by changing things in the newReq let newReq = null; if (reqObj) { newReq = Object.assign(...reqObj); } super.healthCheck(newReq, callback); } /** * @iapGetAdapterWorkflowFunctions */ iapGetAdapterWorkflowFunctions(inIgnore) { let myIgnore = [ 'healthCheck', 'iapGetAdapterWorkflowFunctions', 'hasEntities' ]; if (!inIgnore && Array.isArray(inIgnore)) { myIgnore = inIgnore; } else if (!inIgnore && typeof inIgnore === 'string') { myIgnore = [inIgnore]; } // The generic adapter functions should already be ignored (e.g. healthCheck) // you can add specific methods that you do not want to be workflow functions to ignore like below // myIgnore.push('myMethodNotInWorkflow'); return super.iapGetAdapterWorkflowFunctions(myIgnore); } /** * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This * allows customers to make changes to adapter configuration without having to be on the * file system. * * @function iapUpdateAdapterConfiguration * @param {string} configFile - the name of the file being updated (required) * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required) * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional) * @param {string} type - the type of entity file to change, (action, schema, mock) (optional) * @param {string} action - the action to be changed, if an action, schema or mock data file (optional) * @param {boolean} replace - true to replace entire mock data, false to merge/append * @param {Callback} callback - The results of the call */ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) { const meth = 'adapter-iapUpdateAdapterConfiguration'; const origin = `${this.id}-${meth}`; log.trace(origin); super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback); } /** * @summary Suspends adapter * * @function iapSuspendAdapter * @param {Callback} callback - callback function */ iapSuspendAdapter(mode, callback) { const meth = 'adapter-iapSuspendAdapter'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapSuspendAdapter(mode, callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary Unsuspends adapter * * @function iapUnsuspendAdapter * @param {Callback} callback - callback function */ iapUnsuspendAdapter(callback) { const meth = 'adapter-iapUnsuspendAdapter'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapUnsuspendAdapter(callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary Get the Adapter Queue * * @function iapGetAdapterQueue * @param {Callback} callback - callback function */ iapGetAdapterQueue(callback) { const meth = 'adapter-iapGetAdapterQueue'; const origin = `${this.id}-${meth}`; log.trace(origin); return super.iapGetAdapterQueue(callback); } /* SCRIPT CALLS */ /** * See if the API path provided is found in this adapter * * @function iapFindAdapterPath * @param {string} apiPath - the api path to check on * @param {Callback} callback - The results of the call */ iapFindAdapterPath(apiPath, callback) { const meth = 'adapter-iapFindAdapterPath'; const origin = `${this.id}-${meth}`; log.trace(origin); super.iapFindAdapterPath(apiPath, callback); } /** * @summary Runs troubleshoot scripts for adapter * * @function iapTroubleshootAdapter * @param {Object} props - the connection, healthcheck and authentication properties * * @param {Callback} callback - The results of the call */ iapTroubleshootAdapter(props, callback) { const meth = 'adapter-iapTroubleshootAdapter'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapTroubleshootAdapter(props, this, callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary runs healthcheck script for adapter * * @function iapRunAdapterHealthcheck * @param {Adapter} adapter - adapter instance to troubleshoot * @param {Callback} callback - callback function */ iapRunAdapterHealthcheck(callback) { const meth = 'adapter-iapRunAdapterHealthcheck'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapRunAdapterHealthcheck(this, callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary runs connectivity check script for adapter * * @function iapRunAdapterConnectivity * @param {Callback} callback - callback function */ iapRunAdapterConnectivity(callback) { const meth = 'adapter-iapRunAdapterConnectivity'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapRunAdapterConnectivity(callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary runs basicGet script for adapter * * @function iapRunAdapterBasicGet * @param {number} maxCalls - how many GET endpoints to test (optional) * @param {Callback} callback - callback function */ iapRunAdapterBasicGet(maxCalls, callback) { const meth = 'adapter-iapRunAdapterBasicGet'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapRunAdapterBasicGet(maxCalls, callback); } catch (error) { log.error(`${origin}: ${error}`); return callback(null, error); } } /** * @summary moves entites into Mongo DB * * @function iapMoveAdapterEntitiesToDB * @param {getCallback} callback - a callback function to return the result (Generics) * or the error */ iapMoveAdapterEntitiesToDB(callback) { const meth = 'adapter-iapMoveAdapterEntitiesToDB'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapMoveAdapterEntitiesToDB(callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Deactivate adapter tasks * * @function iapDeactivateTasks * * @param {Array} tasks - List of tasks to deactivate * @param {Callback} callback */ iapDeactivateTasks(tasks, callback) { const meth = 'adapter-iapDeactivateTasks'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapDeactivateTasks(tasks, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Activate adapter tasks that have previously been deactivated * * @function iapActivateTasks * * @param {Array} tasks - List of tasks to activate * @param {Callback} callback */ iapActivateTasks(tasks, callback) { const meth = 'adapter-iapActivateTasks'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapActivateTasks(tasks, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /* CACHE CALLS */ /** * @summary Populate the cache for the given entities * * @function iapPopulateEntityCache * @param {String/Array of Strings} entityType - the entity type(s) to populate * @param {Callback} callback - whether the cache was updated or not for each entity type * * @returns status of the populate */ iapPopulateEntityCache(entityTypes, callback) { const meth = 'adapter-iapPopulateEntityCache'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapPopulateEntityCache(entityTypes, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Retrieves data from cache for specified entity type * * @function iapRetrieveEntitiesCache * @param {String} entityType - entity of which to retrieve * @param {Object} options - settings of which data to return and how to return it * @param {Callback} callback - the data if it was retrieved */ iapRetrieveEntitiesCache(entityType, options, callback) { const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapRetrieveEntitiesCache(entityType, options, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /* BROKER CALLS */ /** * @summary Determines if this adapter supports any in a list of entities * * @function hasEntities * @param {String} entityType - the entity type to check for * @param {Array} entityList - the list of entities we are looking for * * @param {Callback} callback - A map where the entity is the key and the * value is true or false */ hasEntities(entityType, entityList, callback) { const meth = 'adapter-hasEntities'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.hasEntitiesAuth(entityType, entityList, callOptions, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Get Appliance that match the deviceName * * @function getDevice * @param {String} deviceName - the deviceName to find (required) * * @param {getCallback} callback - a callback function to return the result * (appliance) or the error */ getDevice(deviceName, callback) { const meth = 'adapter-getDevice'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.getDeviceAuth(deviceName, callOptions, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Get Appliances that match the filter * * @function getDevicesFiltered * @param {Object} options - the data to use to filter the appliances (optional) * * @param {getCallback} callback - a callback function to return the result * (appliances) or the error */ getDevicesFiltered(options, callback) { const meth = 'adapter-getDevicesFiltered'; const origin = `${this.id}-${meth}`; log.trace(origin); try { // if no filtering if (!options || !options.filter || !options.filter.name) { return super.getDevicesFilteredAuth({}, callOptions, callback); } // Need to do filtering here because AWS does not support filtering with contains return super.getDevicesFilteredAuth({}, callOptions, (devices, error) => { if (error) { return callback(null, error); } if (devices.list) { const filterDevices = []; for (let i = 0; i < devices.list.length; i += 1) { if (devices.list[i].name.includes(options.filter.name)) { filterDevices.push(devices.list[i]); } } return callback({ total: filterDevices.length, list: filterDevices }); } return devices; }); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Gets the status for the provided appliance * * @function isAlive * @param {String} deviceName - the deviceName of the appliance. (required) * * @param {configCallback} callback - callback function to return the result * (appliance isAlive) or the error */ isAlive(deviceName, callback) { const meth = 'adapter-isAlive'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.isAliveAuth(deviceName, callOptions, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Gets a config for the provided Appliance * * @function getConfig * @param {String} deviceName - the deviceName of the appliance. (required) * @param {String} format - the desired format of the config. (optional) * * @param {configCallback} callback - callback function to return the result * (appliance config) or the error */ getConfig(deviceName, format, callback) { const meth = 'adapter-getConfig'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.getConfigAuth(deviceName, format, callOptions, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * @summary Gets the device count from the system * * @function iapGetDeviceCount * * @param {getCallback} callback - callback function to return the result * (count) or the error */ iapGetDeviceCount(callback) { const meth = 'adapter-iapGetDeviceCount'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapGetDeviceCountAuth(callOptions, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */ /** * Makes the requested generic call * * @function iapExpandedGenericAdapterRequest * @param {Object} metadata - metadata for the call (optional). * Can be a stringified Object. * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional) * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional) * @param {Object} pathVars - the parameters to be put within the url path (optional). * Can be a stringified Object. * @param {Object} queryData - the parameters to be put on the url (optional). * Can be a stringified Object. * @param {Object} requestBody - the body to add to the request (optional). * Can be a stringified Object. * @param {Object} addlHeaders - additional headers to be put on the call (optional). * Can be a stringified Object. * @param {getCallback} callback - a callback function to return the result (Generics) * or the error */ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) { const meth = 'adapter-iapExpandedGenericAdapterRequest'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * Makes the requested generic call * * @function genericAdapterRequest * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required) * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required) * @param {Object} queryData - the parameters to be put on the url (optional). * Can be a stringified Object. * @param {Object} requestBody - the body to add to the request (optional). * Can be a stringified Object. * @param {Object} addlHeaders - additional headers to be put on the call (optional). * Can be a stringified Object. * @param {getCallback} callback - a callback function to return the result (Generics) * or the error */ genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) { const meth = 'adapter-genericAdapterRequest'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /** * Makes the requested generic call with no base path or version * * @function genericAdapterRequestNoBasePath * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required) * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required) * @param {Object} queryData - the parameters to be put on the url (optional). * Can be a stringified Object. * @param {Object} requestBody - the body to add to the request (optional). * Can be a stringified Object. * @param {Object} addlHeaders - additional headers to be put on the call (optional). * Can be a stringified Object. * @param {getCallback} callback - a callback function to return the result (Generics) * or the error */ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) { const meth = 'adapter-genericAdapterRequestNoBasePath'; const origin = `${this.id}-${meth}`; log.trace(origin); try { return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback); } catch (err) { log.error(`${origin}: ${err}`); return callback(null, err); } } /* INVENTORY CALLS */ /** * @summary run the adapter lint script to return the results. * * @function iapRunAdapterLint * @param {Callback} callback - callback function */ iapRunAdapterLint(callback) { const meth = 'adapter-iapRunAdapterLint'; const origin = `${this.id}-${meth}`; log.trace(origin); return super.iapRunAdapterLint(callback); } /** * @summary run the adapter test scripts (baseunit and unit) to return the results. * can not run integration as there can be implications with that. * * @function iapRunAdapterTests * @param {Callback} callback - callback function */ iapRunAdapterTests(callback) { const meth = 'adapter-iapRunAdapterTests'; const origin = `${this.id}-${meth}`; log.trace(origin); return super.iapRunAdapterTests(callback); } /** * @summary provide inventory information abbout the adapter * * @function iapGetAdapterInventory * @param {Callback} callback - callback function */ iapGetAdapterInventory(callback) { const meth = 'adapter-iapGetAdapterInventory'; const origin = `${this.id}-${meth}`; log.trace(origin); return super.iapGetAdapterInventory(callback); } /** * @callback healthCallback * @param {Object} result - the result of the get request (contains an id and a status) */ /** * @callback getCallback * @param {Object} result - the result of the get request (entity/ies) * @param {String} error - any error that occurred */ /** * @callback createCallback * @param {Object} item - the newly created entity * @param {String} error - any error that occurred */ /** * @callback updateCallback * @param {String} status - the status of the update action * @param {String} error - any error that occurred */ /** * @callback deleteCallback * @param {String} status - the status of the delete action * @param {String} error - any error that occurred */ /** * refreshAwsKeys is used to change the access key and the secret key * on the adapter's properties * * @function refreshAwsKeys * @param {string} accessKey - The access key for AWS * @param {string} secretKey - The secret key for AWS * @param {string} sessionToken - The session token for AWS * @param {getCallback} callback - a callback function to return the result */ refreshAwsKeys(accessKey, secretKey, sessionToken, callback) { const meth = 'adapter-refreshProperties'; const origin = `${this.id}-${meth}`; log.trace(origin); /* HERE IS WHERE YOU VALIDATE DATA */ if (accessKey === undefined || accessKey === null || accessKey === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['accessKey'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } if (secretKey === undefined || secretKey === null || secretKey === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['secretKey'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } if (sessionToken === undefined || sessionToken === null || sessionToken === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sessionToken'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } this.allProps.authentication.aws_access_key = accessKey; this.allProps.authentication.aws_secret_key = secretKey; this.allProps.authentication.aws_session_token = sessionToken; const response = { response: 'success' }; return callback(response, null); } /** * @summary Accepts the Convertible Reserved Instance exchange quote described in the GetReservedInstancesExchangeQuote call. * * @function acceptReservedInstancesExchangeQuote * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {array} reservedInstanceId - The IDs of the Convertible Reserved Instances to exchange for another Convertible Reserved Instance of the same or higher value. * @param {array} targetConfiguration - The configuration of the target Convertible Reserved Instance to exchange for your current Convertible Reserved Instances. * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptReservedInstancesExchangeQuote(dryRun, reservedInstanceId, targetConfiguration, callback) { this.acceptReservedInstancesExchangeQuoteSTSRole(dryRun, reservedInstanceId, targetConfiguration, null, null, callback); } /** * @summary Accepts the Convertible Reserved Instance exchange quote described in the GetReservedInstancesExchangeQuote call. * * @function acceptReservedInstancesExchangeQuoteSTSRole * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {array} reservedInstanceId - The IDs of the Convertible Reserved Instances to exchange for another Convertible Reserved Instance of the same or higher value. * @param {array} targetConfiguration - The configuration of the target Convertible Reserved Instance to exchange for your current Convertible Reserved Instances. * @param {object} [stsParams] - STS Parameters to use for authentication. * @param {string} [roleName] - RoleName to authenticate against * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptReservedInstancesExchangeQuoteSTSRole(dryRun, reservedInstanceId, targetConfiguration, stsParams, roleName, callback) { const meth = 'adapter-acceptReservedInstancesExchangeQuoteSTSRole'; const origin = `${this.id}-${meth}`; log.trace(origin); const action = 'acceptReservedInstancesExchangeQuote'; const version = '2016-11-15'; if (this.suspended && this.suspendMode === 'error') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU VALIDATE DATA */ if (reservedInstanceId === undefined || reservedInstanceId === null || reservedInstanceId === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['reservedInstanceId'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */ const queryParamsAvailable = { DryRun: dryRun, Action: action, Version: version }; if (reservedInstanceId && reservedInstanceId.length > 0) { processInArray(reservedInstanceId, queryParamsAvailable, 'ReservedInstanceId'); } if (targetConfiguration && targetConfiguration.length > 0) { processInArray(targetConfiguration, queryParamsAvailable, 'TargetConfiguration'); } const queryParams = {}; const pathVars = []; const bodyVars = {}; // loop in template. long callback arg name to avoid identifier conflicts Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => { if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') { queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable]; } }); let callProperties = null; if (stsParams && stsParams.region) { callProperties = {}; callProperties.region = stsParams.region; callProperties.host = `${this.allProps.service}.${stsParams.region}.amazonaws.com`; delete stsParams.region; if (Object.keys(stsParams).length === 0) { stsParams = null; } } // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders const reqObj = { payload: bodyVars, uriPathVars: pathVars, uriQuery: queryParams, authData: { stsParams, roleName }, callProperties }; try { // Make the call - // identifyRequest(entity, action, requestObj, returnDataFlag, callback) return this.requestHandlerInst.identifyRequest('Instance', 'acceptReservedInstancesExchangeQuote', reqObj, true, (irReturnData, irReturnError) => { // if we received an error or their is no response on the results // return an error if (irReturnError) { /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */ return callback(null, irReturnError); } if (!Object.hasOwnProperty.call(irReturnData, 'response')) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['acceptReservedInstancesExchangeQuoteSTSRole'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */ // return the response return callback(irReturnData, null); }); } catch (ex) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } } /** * @summary Accepts a request to attach a VPC to a transit gateway. The VPC attachment must be in the pendingAcceptance state. Use DescribeTransitGatewayVpcAttachments to view your pending VPC attachment requests. Use RejectTransitGatewayVpcAttachment to reject a VPC attachment request. * * @function acceptTransitGatewayVpcAttachment * @param {string} transitGatewayAttachmentId - The ID of the attachment. * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptTransitGatewayVpcAttachment(transitGatewayAttachmentId, dryRun, callback) { this.acceptTransitGatewayVpcAttachmentSTSRole(transitGatewayAttachmentId, dryRun, null, null, callback); } /** * @summary Accepts a request to attach a VPC to a transit gateway. The VPC attachment must be in the pendingAcceptance state. Use DescribeTransitGatewayVpcAttachments to view your pending VPC attachment requests. Use RejectTransitGatewayVpcAttachment to reject a VPC attachment request. * * @function acceptTransitGatewayVpcAttachmentSTSRole * @param {string} transitGatewayAttachmentId - The ID of the attachment. * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {object} [stsParams] - STS Parameters to use for authentication. * @param {string} [roleName] - RoleName to authenticate against * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptTransitGatewayVpcAttachmentSTSRole(transitGatewayAttachmentId, dryRun, stsParams, roleName, callback) { const meth = 'adapter-acceptTransitGatewayVpcAttachmentSTSRole'; const origin = `${this.id}-${meth}`; log.trace(origin); const action = 'AcceptTransitGatewayVpcAttachment'; const version = '2016-11-15'; if (this.suspended && this.suspendMode === 'error') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU VALIDATE DATA */ if (transitGatewayAttachmentId === undefined || transitGatewayAttachmentId === null || transitGatewayAttachmentId === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['transitGatewayAttachmentId'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */ const queryParamsAvailable = { DryRun: dryRun, TransitGatewayAttachmentId: transitGatewayAttachmentId, Action: action, Version: version }; const queryParams = {}; const pathVars = []; const bodyVars = {}; // loop in template. long callback arg name to avoid identifier conflicts Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => { if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') { queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable]; } }); let callProperties = null; if (stsParams && stsParams.region) { callProperties = {}; callProperties.region = stsParams.region; callProperties.host = `${this.allProps.service}.${stsParams.region}.amazonaws.com`; delete stsParams.region; if (Object.keys(stsParams).length === 0) { stsParams = null; } } // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders const reqObj = { payload: bodyVars, uriPathVars: pathVars, uriQuery: queryParams, authData: { stsParams, roleName }, callProperties }; try { // Make the call - // identifyRequest(entity, action, requestObj, returnDataFlag, callback) return this.requestHandlerInst.identifyRequest('TransitGateway', 'acceptTransitGatewayVpcAttachment', reqObj, true, (irReturnData, irReturnError) => { // if we received an error or their is no response on the results // return an error if (irReturnError) { /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */ return callback(null, irReturnError); } if (!Object.hasOwnProperty.call(irReturnData, 'response')) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['acceptTransitGatewayVpcAttachmentSTSRole'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */ // return the response return callback(irReturnData, null); }); } catch (ex) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } } /** * @summary Accepts one or more interface VPC endpoint connection requests to your VPC endpoint service. * * @function acceptVpcEndpointConnections * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {string} serviceId - The ID of the endpoint service. * @param {array} vpcEndpointId - The IDs of one or more interface VPC endpoints. * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptVpcEndpointConnections(dryRun, serviceId, vpcEndpointId, callback) { this.acceptVpcEndpointConnectionsSTSRole(dryRun, serviceId, vpcEndpointId, null, null, callback); } /** * @summary Accepts one or more interface VPC endpoint connection requests to your VPC endpoint service. * * @function acceptVpcEndpointConnectionsSTSRole * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {string} serviceId - The ID of the endpoint service. * @param {array} vpcEndpointId - The IDs of one or more interface VPC endpoints. * @param {object} [stsParams] - STS Parameters to use for authentication. * @param {string} [roleName] - RoleName to authenticate against * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptVpcEndpointConnectionsSTSRole(dryRun, serviceId, vpcEndpointId, stsParams, roleName, callback) { const meth = 'adapter-acceptVpcEndpointConnectionsSTSRole'; const origin = `${this.id}-${meth}`; log.trace(origin); const action = 'AcceptVpcEndpointConnections'; const version = '2016-11-15'; if (this.suspended && this.suspendMode === 'error') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU VALIDATE DATA */ if (serviceId === undefined || serviceId === null || serviceId === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['serviceId'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } if (vpcEndpointId === undefined || vpcEndpointId === null || vpcEndpointId === '') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['vpcEndpointId'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */ const queryParamsAvailable = { DryRun: dryRun, ServiceId: serviceId, Action: action, Version: version }; if (vpcEndpointId && vpcEndpointId.length > 0) { processInArray(vpcEndpointId, queryParamsAvailable, 'VpcEndpointId'); } const queryParams = {}; const pathVars = []; const bodyVars = {}; // loop in template. long callback arg name to avoid identifier conflicts Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => { if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') { queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable]; } }); let callProperties = null; if (stsParams && stsParams.region) { callProperties = {}; callProperties.region = stsParams.region; callProperties.host = `${this.allProps.service}.${stsParams.region}.amazonaws.com`; delete stsParams.region; if (Object.keys(stsParams).length === 0) { stsParams = null; } } // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders const reqObj = { payload: bodyVars, uriPathVars: pathVars, uriQuery: queryParams, authData: { stsParams, roleName }, callProperties }; try { // Make the call - // identifyRequest(entity, action, requestObj, returnDataFlag, callback) return this.requestHandlerInst.identifyRequest('Vpc', 'acceptVpcEndpointConnections', reqObj, true, (irReturnData, irReturnError) => { // if we received an error or their is no response on the results // return an error if (irReturnError) { /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */ return callback(null, irReturnError); } if (!Object.hasOwnProperty.call(irReturnData, 'response')) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['acceptVpcEndpointConnectionsSTSRole'], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */ // return the response return callback(irReturnData, null); }); } catch (ex) { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } } /** * @summary Accept a VPC peering connection request. To accept a request, the VPC peering connection must be in the pending-acceptance state, and you must be the owner of the peer VPC. Use DescribeVpcPeeringConnections to view your outstanding VPC peering connection requests. For an inter-Region VPC peering connection request, you must accept the VPC peering connection in the Region of the accepter VPC. * * @function acceptVpcPeeringConnection * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {string} vpcPeeringConnectionId - The ID of the VPC peering connection. You must specify this parameter in the request. * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptVpcPeeringConnection(dryRun, vpcPeeringConnectionId, callback) { this.acceptVpcPeeringConnectionSTSRole(dryRun, vpcPeeringConnectionId, null, null, callback); } /** * @summary Accept a VPC peering connection request. To accept a request, the VPC peering connection must be in the pending-acceptance state, and you must be the owner of the peer VPC. Use DescribeVpcPeeringConnections to view your outstanding VPC peering connection requests. For an inter-Region VPC peering connection request, you must accept the VPC peering connection in the Region of the accepter VPC. * * @function acceptVpcPeeringConnectionSTSRole * @param {boolean} dryRun - Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions...(description truncated) * @param {string} vpcPeeringConnectionId - The ID of the VPC peering connection. You must specify this parameter in the request. * @param {object} [stsParams] - STS Parameters to use for authentication. * @param {string} [roleName] - RoleName to authenticate against * @param {getCallback} callback - a callback function to return the result */ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */ acceptVpcPeeringConnectionSTSRole(dryRun, vpcPeeringConnectionId, stsParams, roleName, callback) { const meth = 'adapter-acceptVpcPeeringConnectionSTSRole'; const origin = `${this.id}-${meth}`; log.trace(origin); const action = 'AcceptVpcPeeringConnection'; const version = '2016-11-15'; if (this.suspended && this.suspendMode === 'error') { const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null); log.error(`${origin}: ${errorObj.IAPerror.displayString}`); return callback(null, errorObj); } /* HERE IS WHERE YOU VALIDATE DATA */ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */ const queryParamsAvailable = { DryRun: dryRun, VpcPeeringConnectionId: vpcPeeringConnectionId, Action: action, Version: version }; const queryParams = {}; const pathVars = []; const bodyVars = {}; // loop in template. long callback arg name to avoid identifier conflicts Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => { if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') { queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable]; } }); let callProperties = null; if (stsParams && stsParams.region) { callProperties = {}; callProperties.region = stsParams.region; callProperties.host = `${this.allProps.service}.${stsParams.region}.amazonaws.com`; delete stsParams.region; if (Object.keys(stsParams).length === 0) { stsParams = null; } } // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders const reqObj = { payload: bodyVars, uriPathVars: pathVars, uriQuery: queryParams, authData: { stsParams, roleName }, callProperties }; try { // Make the call - // identifyRequest(entity, action, requestObj, returnDataFlag, callback) return this.requestHandlerInst.identifyRequest('Vpc', 'acceptVpcPeeringConnection', reqObj, true, (irReturnData, irReturnError) => { // if we received an error or their is no response on the results // return an error if (irReturnError) { /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */ return callback(null, irReturnError); } if (!Object.hasOwnProperty.call(irReturnData, 'response')) { const errorObj = this.requestHandlerInst.formatErrorObject(thi