@itentialopensource/adapter-akamai_property_manager
Version:
This adapter integrates with the Akamai Property Manager API.
1,255 lines (1,137 loc) • 303 kB
JavaScript
/* @copyright Itential, LLC 2019 (pre-modifications) */
/* eslint import/no-dynamic-require: warn */
/* eslint object-curly-newline: warn */
// Set globals
/* global log */
/* Required libraries. */
const path = require('path');
const EdgeGrid = require('akamai-edgegrid');
/* Fetch in the other needed components for the this Adaptor */
const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
/**
* This is the adapter/interface into Akamai_property_manager
*/
/* GENERAL ADAPTER FUNCTIONS */
class AkamaiPropertyManager extends AdapterBaseCl {
/**
* AkamaiGtm Adapter
* @constructor
*/
/* Working on changing the way we do Emit methods due to size and time constrainsts */
constructor(prongid, properties) {
// Instantiate the AdapterBase super class
super(prongid, properties);
// set up EdgeGrid
const egUri = `${this.allProps.protocol}://${this.allProps.host}/`;
this.eg = new EdgeGrid(this.allProps.authentication.clientToken, this.allProps.authentication.clientSecret, this.allProps.authentication.accessToken, egUri);
/*
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',
'getAuthorization',
'attachQueryParamsToUri'
];
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.hasEntities(entityType, entityList, 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.getDevice(deviceName, 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 {
return super.getDevicesFiltered(options, callback);
} 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.isAlive(deviceName, 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.getConfig(deviceName, format, 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.iapGetDeviceCount(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
*/
/**
* @summary Gets the edgegrid authorization for the call
*
* @function getAuthorization
* @param {String} method - the method for the action we are setting authorization for
* @param {String} uripath - the path for the action we are setting authorization for
* @param {String} body - the body for the action we are setting authorization for
*
* @return {Object} the headers to add to the request
*/
getAuthorization(method, uripath, body) {
const origin = `${this.id}-adapter-getAuthorization`;
log.trace(origin);
// set up the request to get the proper auth
const options = {
path: uripath,
method,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: {}
};
if (body) {
options.body = body;
}
// get the authentication
const auth = this.eg.auth(options);
// return the headers
return auth;
}
/**
* @summary Attach query parameters to the uri
*
* @function attachQueryParamsToUri
* @param {object} queryParams - the generated query params in the calls
*
* @returns {string} queryParamsPath
*/
attachQueryParamsToUri(queryParams) {
try {
const origin = `${this.id}-adapter-attachQueryParamsToUri`;
log.trace(origin);
let queryUri = '';
if (!queryParams || typeof (queryParams) !== 'object' || queryParams.length || Object.keys(queryParams).length < 1) {
return queryUri;
}
Object.keys(queryParams).forEach((k) => {
queryUri += `${k}=${queryParams[k]}&`;
});
return `?${queryUri.substring(0, queryUri.length - 1)}`;
} catch (error) {
throw new Error(`Could not attach query parameters to the uri ${error}`);
}
}
/**
* @function bulkactivateasetofproperties
* @pronghornType method
* @name bulkactivateasetofproperties
* @summary Bulk activate a set of properties
*
* @param {string} contractId - Optionally filters bulk searches to properties provisioned
under the specified contract. For bulk operations, you can
specify `contractId` and `groupId` independently fro...(description truncated)
* @param {string} groupId - Optionally filters bulk searches to properties provisioned
under the specified group. For bulk operations, you can
specify `contractId` and `groupId` independently from e...(description truncated)
* @param {object} body - body param
* @param {getCallback} callback - a callback function to return the result
* @return {object} results - An object containing the response of the action
*
* @route {POST} /bulkactivateasetofproperties
* @roles admin
* @task true
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
bulkactivateasetofproperties(contractId, groupId, body, callback) {
const meth = 'adapter-bulkactivateasetofproperties';
const origin = `${this.id}-${meth}`;
log.trace(origin);
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 (contractId === undefined || contractId === null || contractId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['contractId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (groupId === undefined || groupId === null || groupId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['groupId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (body === undefined || body === null || body === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], 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 = { contractId, groupId };
const queryParams = {};
const pathVars = [];
const bodyVars = body;
// 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];
}
});
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const thisauth = this.getAuthorization('GET', `${this.allProps.base_path}/${this.allProps.version}/bulk/activations${this.attachQueryParamsToUri(queryParams)}`, null);
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
// see adapter code documentation for more information on the request object's fields
const reqObj = {
payload: bodyVars,
uriPathVars: pathVars,
uriQuery: queryParams,
addlHeaders: thisauth.request.headers
};
try {
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('Activations', 'bulkactivateasetofproperties', 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', ['bulkactivateasetofproperties'], 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);
}
}
/**
* @function listbulkActivatedproperties
* @pronghornType method
* @name listbulkActivatedproperties
* @summary List bulk-activated properties
*
* @param {string} contractId - Optionally filters bulk searches to properties provisioned
under the specified contract. For bulk operations, you can
specify `contractId` and `groupId` independently fro...(description truncated)
* @param {string} groupId - Optionally filters bulk searches to properties provisioned
under the specified group. For bulk operations, you can
specify `contractId` and `groupId` independently from e...(description truncated)
* @param {string} bulkActivationId - (Required) Identifies each bulk activation job.
* @param {getCallback} callback - a callback function to return the result
* @return {object} results - An object containing the response of the action
*
* @route {POST} /listbulkActivatedproperties
* @roles admin
* @task true
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
listbulkActivatedproperties(contractId, groupId, bulkActivationId, callback) {
const meth = 'adapter-listbulkActivatedproperties';
const origin = `${this.id}-${meth}`;
log.trace(origin);
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 (contractId === undefined || contractId === null || contractId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['contractId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (groupId === undefined || groupId === null || groupId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['groupId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (bulkActivationId === undefined || bulkActivationId === null || bulkActivationId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['bulkActivationId'], 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 = { contractId, groupId };
const queryParams = {};
const pathVars = [bulkActivationId];
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];
}
});
// if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
let thisHeaderData = null;
// if the additional headers was passed in as a string parse the json into an object
if (thisHeaderData !== null && thisHeaderData.constructor === String) {
try {
// parse the additional headers object that was passed in
thisHeaderData = JSON.parse(thisHeaderData);
} catch (err) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
} else if (thisHeaderData === null) {
thisHeaderData = { pAPIUsePrefixes: '' };
}
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const thisauth = this.getAuthorization('GET', `${this.allProps.base_path}/${this.allProps.version}/bulk/activations/${bulkActivationId}${this.attachQueryParamsToUri(queryParams)}`, null);
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
// see adapter code documentation for more information on the request object's fields
const reqObj = {
payload: bodyVars,
uriPathVars: pathVars,
uriQuery: queryParams,
addlHeaders: thisauth.request.headers
};
try {
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('Activations', 'listbulkActivatedproperties', 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', ['listbulkActivatedproperties'], 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);
}
}
/**
* @function listactivations
* @pronghornType method
* @name listactivations
* @summary List activations
*
* @param {string} contractId - Unique identifier for the contract.
The parameter is optional if the property has been
provisioned under only one contract.
Otherwise you need to specify it along with th...(description truncated)
* @param {string} groupId - Unique identifier for the group.
The parameter is optional if the property has been
provisioned under only one group.
Otherwise you need to specify it along with the `con...(description truncated)
* @param {string} propertyId - (Required) Unique identifier for the property.
See [ID prefixes](doc:id-prefixes)
for details on omitting the value's `prp_` prefix.
* @param {getCallback} callback - a callback function to return the result
* @return {object} results - An object containing the response of the action
*
* @route {POST} /listactivations
* @roles admin
* @task true
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
listactivations(contractId, groupId, propertyId, callback) {
const meth = 'adapter-listactivations';
const origin = `${this.id}-${meth}`;
log.trace(origin);
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 (contractId === undefined || contractId === null || contractId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['contractId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (groupId === undefined || groupId === null || groupId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['groupId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (propertyId === undefined || propertyId === null || propertyId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['propertyId'], 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 = { contractId, groupId };
const queryParams = {};
const pathVars = [propertyId];
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];
}
});
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const thisauth = this.getAuthorization('GET', `${this.allProps.base_path}/${this.allProps.version}/properties/${propertyId}/activations${this.attachQueryParamsToUri(queryParams)}`, null);
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
// see adapter code documentation for more information on the request object's fields
const reqObj = {
payload: bodyVars,
uriPathVars: pathVars,
uriQuery: queryParams,
addlHeaders: thisauth.request.headers
};
try {
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('Activations', 'listactivations', 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', ['listactivations'], 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);
}
}
/**
* @function createanewactivationordeactivation
* @pronghornType method
* @name createanewactivationordeactivation
* @summary Create a new activation or deactivation
*
* @param {string} contractId - Unique identifier for the contract.
The parameter is optional if the property has been
provisioned under only one contract.
Otherwise you need to specify it along with th...(description truncated)
* @param {string} groupId - Unique identifier for the group.
The parameter is optional if the property has been
provisioned under only one group.
Otherwise you need to specify it along with the `con...(description truncated)
* @param {string} propertyId - (Required) Unique identifier for the property.
See [ID prefixes](doc:id-prefixes)
for details on omitting the value's `prp_` prefix.
* @param {object} body - body param
* @param {getCallback} callback - a callback function to return the result
* @return {object} results - An object containing the response of the action
*
* @route {POST} /createanewactivationordeactivation
* @roles admin
* @task true
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
createanewactivationordeactivation(contractId, groupId, propertyId, body, callback) {
const meth = 'adapter-createanewactivationordeactivation';
const origin = `${this.id}-${meth}`;
log.trace(origin);
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 (contractId === undefined || contractId === null || contractId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['contractId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (groupId === undefined || groupId === null || groupId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['groupId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (propertyId === undefined || propertyId === null || propertyId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['propertyId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (body === undefined || body === null || body === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], 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 = { contractId, groupId };
const queryParams = {};
const pathVars = [propertyId];
const bodyVars = body;
// 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];
}
});
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const thisauth = this.getAuthorization('POST', `${this.allProps.base_path}/${this.allProps.version}/properties/${propertyId}/activations${this.attachQueryParamsToUri(queryParams)}`, body);
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
// see adapter code documentation for more information on the request object's fields
const reqObj = {
payload: bodyVars,
uriPathVars: pathVars,
uriQuery: queryParams,
addlHeaders: thisauth.request.headers
};
try {
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('Activations', 'createanewactivationordeactivation', 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', ['createanewactivationordeactivation'], 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);
}
}
/**
* @function bulkversionasetofproperties
* @pronghornType method
* @name bulkversionasetofproperties
* @summary Bulk version a set of properties
*
* @param {string} contractId - Optionally filters bulk searches to properties provisioned
under the specified contract. For bulk operations, you can
specify `contractId` and `groupId` independently fro...(description truncated)
* @param {string} groupId - Optionally filters bulk searches to properties provisioned
under the specified group. For bulk operations, you can
specify `contractId` and `groupId` independently from e...(description truncated)
* @param {object} body - body param
* @param {getCallback} callback - a callback function to return the result
* @return {object} results - An object containing the response of the action
*
* @route {POST} /bulkversionasetofproperties
* @roles admin
* @task true
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
bulkversionasetofproperties(contractId, groupId, body, callback) {
const meth = 'adapter-bulkversionasetofproperties';
const origin = `${this.id}-${meth}`;
log.trace(origin);
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 (contractId === undefined || contractId === null || contractId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['contractId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (groupId === undefined || groupId === null || groupId === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['groupId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (body === undefined || body === null || body === '') {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], 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 = { contractId, groupId };
const queryParams = {};
const pathVars = [];
const bodyVars = body;
// 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];
}
});
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const thisauth = this.getAuthorization('POST', `${this.allProps.base_path}/${this.allProps.version}/bulk/property-version-creations${this.attachQueryParamsToUri(queryParams)}`, body);
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
// see adapter code documentation for more information on the request object's fields
const reqObj = {
payload: bodyVars,
uriPathVars: pathVars,
uriQuery: queryParams,
addlHeaders: thisauth.request.headers
};
try {
// Make the call -
// identifyRequest(entity, action, reque