Skip to content

Commit

Permalink
Fixing issue with addhosts (and improving delhosts) for modify
Browse files Browse the repository at this point in the history
  • Loading branch information
synedra committed Jan 20, 2018
1 parent 947136a commit a77815f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class WebSite {
//TODO: this will only be called for LATEST, CURRENT_PROD and CURRENT_STAGE. How do we handle collecting hostnames of different versions?
_getHostnameList(propertyId, versionLookup=0, newConfig = false, edgeHostnameId=null) {
let property;
if (newConfig || edgeHostnameId) {
if (newConfig) {
return Promise.resolve();
}

Expand Down Expand Up @@ -1168,9 +1168,9 @@ class WebSite {

return this._getHostnameList(configName,version,false, edgeHostnameId)
.then(hostnamelist => {
if (!edgeHostnameId && hostnamelist.hostnames.items.length > 0) {
if (hostnamelist.hostnames.items.length > 0) {
hostnamelist.hostnames.items.map(host => {
hostnames.push(host.cnameFrom)
hostnames.push(host)
if (!edgeHostnameId) {
edgeHostnameId = host.cnameTo ? host.cnameTo : host.edgeHostnameId
}
Expand All @@ -1184,14 +1184,13 @@ class WebSite {
})
.then(() => {
return new Promise((resolve, reject) => {
let seenHosts = []
console.info('Updating property hostnames');
console.time('... updating hostname');
if (deleteHosts) {
hostnames.map(host => {
myDelete = false;
for (let i = 0; i < deleteHosts.length; i++) {
if (deleteHosts[i] == host) {
if (deleteHosts[i] == host || deleteHosts[i] == host.cnameFrom) {
myDelete = true;
}
}
Expand All @@ -1204,28 +1203,38 @@ class WebSite {
}

let hostSet = new Set(hostsToProcess)
let hostNamelist = []

hostSet.forEach(hostname => {
let assignHostnameObj;
if (edgeHostnameId && edgeHostnameId.includes("ehn_")) {
let skip = 0;
if ((hostNamelist.indexOf(hostname) != -1 || hostNamelist.indexOf(hostname.cnameFrom) != -1)) {
console.log("Skipping duplicate " + hostname);
skip = 1;
} else if (hostname.cnameFrom) {
hostNamelist.push(hostname.cnameFrom)
assignHostnameObj = hostname;
} else if (edgeHostnameId && edgeHostnameId.includes("ehn_")) {
assignHostnameObj = {
"cnameType": "EDGE_HOSTNAME",
"edgeHostnameId": edgeHostnameId,
"cnameFrom": hostname
}
hostNamelist.push(hostname)
} else if (edgeHostnameId) {
assignHostnameObj = {
"cnameType": "EDGE_HOSTNAME",
"cnameTo": edgeHostnameId,
"cnameFrom": hostname
}
hostNamelist.push(hostname)
}
if (newHostnameArray.indexOf(assignHostnameObj) == -1) {
if (!skip) {
console.log("Adding hostname " + assignHostnameObj["cnameFrom"]);
newHostnameArray.push(assignHostnameObj);
}
})

let request = {
method: 'PUT',
path: `/papi/v1/properties/${propertyId}/versions/${version}/hostnames/?contractId=${contractId}&groupId=${groupId}`,
Expand Down

0 comments on commit a77815f

Please sign in to comment.