@itentialopensource/adapter-utils
Advanced tools
Comparing version 4.9.4 to 4.10.0
@@ -0,1 +1,11 @@ | ||
## 4.10.0 [08-27-2019] | ||
* Resolves PH-41334: added the support for Global Request Data to be defined in properties | ||
Closes PH-41334 | ||
See merge request itentialopensource/adapter-utils!105 | ||
--- | ||
## 4.9.4 [07-31-2019] | ||
@@ -2,0 +12,0 @@ * Update actionSchema.json |
@@ -17,2 +17,3 @@ /* @copyright Itential, LLC 2018 */ | ||
let basepathGl = null; | ||
let globalRequestGl = null; | ||
@@ -457,3 +458,8 @@ | ||
// prepare the uri options we received | ||
const thisOdata = transUtilInst.formatInputData(uriOptions); | ||
let thisOdata = transUtilInst.formatInputData(uriOptions); | ||
// only add options if a GET | ||
if (entitySchema.method.toUpperCase() === 'GET' && globalRequestGl) { | ||
thisOdata = transUtilInst.mergeObjects(thisOdata, globalRequestGl.uriOptions); | ||
} | ||
let optionString = ''; | ||
@@ -588,26 +594,8 @@ | ||
// merge the headers - priority is incoming over actionfile | ||
if (entitySchema.headers && thisAHdata) { | ||
const thisAHKeys = Object.keys(thisAHdata); | ||
const actHKeys = Object.keys(entitySchema.headers); | ||
if (entitySchema) { | ||
thisAHdata = transUtilInst.mergeObjects(thisAHdata, entitySchema.headers); | ||
} | ||
// go through the headers in the action file | ||
for (let a = 0; a < actHKeys.length; a += 1) { | ||
let found = false; | ||
// go through the headers that came in | ||
for (let h = 0; h < thisAHKeys.length; h += 1) { | ||
// if the keys match, we will not add the header | ||
if (actHKeys[a] === thisAHKeys[h]) { | ||
found = true; | ||
} | ||
} | ||
// if the header was not found, add it | ||
if (!found) { | ||
thisAHdata[actHKeys[a]] = entitySchema.headers[actHKeys[a]]; | ||
} | ||
} | ||
} else if (entitySchema.headers) { | ||
thisAHdata = entitySchema.headers; | ||
if (globalRequestGl) { | ||
thisAHdata = transUtilInst.mergeObjects(thisAHdata, globalRequestGl.addlHeaders); | ||
} | ||
@@ -669,2 +657,7 @@ | ||
// only add body if not a GET | ||
if (entitySchema.method.toUpperCase() !== 'GET' && globalRequestGl) { | ||
thisBdata = transUtilInst.mergeObjects(thisBdata, globalRequestGl.payload); | ||
} | ||
// return the payload if just sending plain text and got plain text | ||
@@ -760,3 +753,10 @@ if (entitySchema && entitySchema.datatype && entitySchema.datatype.toUpperCase() === 'PLAIN') { | ||
this.basepath = properties.base_path; | ||
basepathGl = this.basepath; | ||
basepathGl = this.base_path; | ||
this.globalRequest = null; | ||
// set the request archiving flag (optional - default is false) | ||
if (properties.request.global_request && typeof properties.request.global_request === 'object') { | ||
this.globalRequest = properties.request.global_request; | ||
globalRequestGl = this.globalRequest; | ||
} | ||
} | ||
@@ -763,0 +763,0 @@ |
@@ -22,45 +22,2 @@ /* @copyright Itential, LLC 2018-9 */ | ||
/** | ||
* @summary Takes in two objects and merges them so the returned | ||
* object has secondary only where no primary values were provided. | ||
* | ||
* @function mergeObjects | ||
* @param {Object} object - the primary object | ||
* @param {Object} secondary - the secondary object | ||
* | ||
* @return {Object} the properties with the merged in secondaries | ||
*/ | ||
function mergeObjects(object, secondary) { | ||
const origin = `${id}-translatorUtil-mergeObjects`; | ||
log.trace(origin); | ||
// do not waste time merging if there is nothing to merge | ||
if (!object || typeof object !== 'object') { | ||
return secondary; | ||
} | ||
if (!secondary || typeof secondary !== 'object') { | ||
return object; | ||
} | ||
const combinedObj = secondary; | ||
const keys = Object.keys(object); | ||
// loop through all of the primary object to insert them into the conbined data | ||
for (let k = 0; k < keys.length; k += 1) { | ||
const thisField = object[keys[k]]; | ||
// if this key is to an object | ||
if (thisField && typeof thisField === 'object' && combinedObj.keys[k]) { | ||
// recursive call with primary and secondary object | ||
combinedObj[keys[k]] = mergeObjects(thisField, combinedObj[keys[k]]); | ||
} else if (thisField || !combinedObj.keys[k]) { | ||
// if no secondary or primary has value merge it - overriding the secondary | ||
combinedObj[keys[k]] = thisField; | ||
} | ||
} | ||
// return the merged object | ||
return combinedObj; | ||
} | ||
/** | ||
* @summary Takes in an object and returns the value. If it is an Array, it | ||
@@ -430,3 +387,3 @@ * returns the first element in the array. It returns null if it can not get | ||
// this will merge the two objects - first object is default | ||
mergeObjects(baseObj, location[externalPath[a]]); | ||
this.mergeObjects(baseObj, location[externalPath[a]]); | ||
} else { | ||
@@ -460,3 +417,3 @@ // just put the value in the return object | ||
// this will merge the two objects - first object is default | ||
mergeObjects(baseObj, returnObj[schemaKeys[k]]); | ||
this.mergeObjects(baseObj, returnObj[schemaKeys[k]]); | ||
} else { | ||
@@ -725,2 +682,45 @@ // just put the value in the return object | ||
/** | ||
* @summary Takes in two objects and merges them so the returned | ||
* object has secondary only where no primary values were provided. | ||
* | ||
* @function mergeObjects | ||
* @param {Object} object - the primary object | ||
* @param {Object} secondary - the secondary object | ||
* | ||
* @return {Object} the properties with the merged in secondaries | ||
*/ | ||
mergeObjects(object, secondary) { | ||
const origin = `${this.myid}-translatorUtil-mergeObjects`; | ||
log.trace(origin); | ||
// do not waste time merging if there is nothing to merge | ||
if (!object || typeof object !== 'object') { | ||
return Object.assign({}, secondary); | ||
} | ||
if (!secondary || typeof secondary !== 'object') { | ||
return Object.assign({}, object); | ||
} | ||
const combinedObj = Object.assign({}, secondary); | ||
const keys = Object.keys(object); | ||
// loop through all of the primary object to insert them into the conbined data | ||
for (let k = 0; k < keys.length; k += 1) { | ||
const thisField = object[keys[k]]; | ||
// if this key is to an object | ||
if (thisField && typeof thisField === 'object' && combinedObj.keys[k]) { | ||
// recursive call with primary and secondary object | ||
combinedObj[keys[k]] = this.mergeObjects(thisField, combinedObj[keys[k]]); | ||
} else if (thisField || !combinedObj.keys[k]) { | ||
// if no secondary or primary has value merge it - overriding the secondary | ||
combinedObj[keys[k]] = thisField; | ||
} | ||
} | ||
// return the merged object | ||
return combinedObj; | ||
} | ||
/** | ||
* @summary If the input is a stringified JSON object, return the JSON object. Otherwise, | ||
@@ -727,0 +727,0 @@ * return the object that was provided. |
{ | ||
"name": "@itentialopensource/adapter-utils", | ||
"version": "4.9.4", | ||
"version": "4.10.0", | ||
"description": "Itential Adapter Utility Libraries", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -276,3 +276,3 @@ { | ||
"type": "integer", | ||
"description": "defines the number of request that Pronghorn can send to Ansible Tower at one time", | ||
"description": "defines the number of request that Pronghorn can send to System at one time", | ||
"default": 1, | ||
@@ -291,3 +291,3 @@ "minimum": 1, | ||
"type": "integer", | ||
"description": "an approximate average of how long it takes Ansible Tower to handle each request", | ||
"description": "an approximate average of how long it takes System to handle each request", | ||
"default": 200, | ||
@@ -337,2 +337,24 @@ "minimum": 50, | ||
}, | ||
"global_request": { | ||
"type": "object", | ||
"description": "Global Request data that is overriden by the request object", | ||
"properties": { | ||
"payload": { | ||
"type": "object", | ||
"description": "payload fields that will be appended to the provided payload (excluding GET calls)" | ||
}, | ||
"uriOptions": { | ||
"type": "object", | ||
"description": "options that will be appended to all GET calls" | ||
}, | ||
"addlHeaders": { | ||
"type": "object", | ||
"description": "headers that will be appended to the headers for the call" | ||
}, | ||
"authData": { | ||
"type": "object", | ||
"description": "authentication data that will be appended to the payload for authentication calls" | ||
} | ||
} | ||
}, | ||
"healthcheck_on_timeout": { | ||
@@ -357,3 +379,3 @@ "type": "boolean", | ||
"description": "Whether or not there is a proxy for the Server", | ||
"default": false | ||
"default": false | ||
}, | ||
@@ -406,3 +428,3 @@ "host": { | ||
"description": "Whether or not ssl is enabled on Server", | ||
"default": false | ||
"default": false | ||
}, | ||
@@ -446,3 +468,3 @@ "accept_invalid_cert": { | ||
{ | ||
"if" : { "allOf": [ | ||
"if" : { "allOf": [ | ||
{ "properties" : { "enabled": { "enum": [true] } } }, | ||
@@ -449,0 +471,0 @@ { "properties" : { "accept_invalid_cert": { "enum": [ false ] } } } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10087
1118230