in api/index.js [219:294]
function stackMeta(yaml, light) {
const last = yaml.operations[yaml.operations.length - 1];
let stateLocation = 'unknown';
if (last.options.args) {
const stateArg = last.options.args.find((option) => option.includes('hub.state'));
const locations = stateArg.split(',');
if (locations.length === 2) {
stateLocation = locations[1];
}
}
let dnsDomainParam = {
value: 'unset',
};
let projectId = {
value: 'unset',
};
let userAccount = {
value: last.initiator || 'unset',
};
let sandboxDir = {
value: 'unset',
};
let sandboxCommit = {
value: 'unset',
};
const {stackParameters} = yaml;
if (stackParameters) {
dnsDomainParam = stackParameters.find(({name}) => name === 'dns.domain') ||
stackParameters.find(({name}) => name === 'dns.name') ||
dnsDomainParam;
if (dnsDomainParam.value === 'unset' && stateLocation !== 'unknown') {
const parts = stateLocation.split('/');
const index = parts.indexOf('hub');
if (index > 0) {
dnsDomainParam.value = parts[index - 1];
} else {
dnsDomainParam.value = stateLocation;
}
}
projectId = stackParameters.find(({name}) => name === 'projectId') || projectId;
userAccount = stackParameters.find(({name}) => name === 'hub.userAccount') || userAccount;
sandboxDir = stackParameters.find(({name}) => name === 'hub.sandboxDir') || sandboxDir;
sandboxCommit = stackParameters.find(({name}) => name === 'hub.sandboxCommit') || sandboxCommit;
}
const meta = {
id: dnsDomainParam.value,
projectId: projectId.value,
userAccount: userAccount.value,
name: yaml.meta.name,
stateLocation: {
uri: stateLocation,
kind: 'gcs',
},
sandbox: {
dir: sandboxDir.value,
commit: sandboxCommit.value,
},
status: yaml.status,
components: light ? undefined : Object.keys(yaml.components).map((key) => {
return {
name: key,
status: yaml.components[key].status,
timestamp: yaml.components[key].timestamp,
};
},
),
latestOperation: {
name: last.operation,
timestamp: last.timestamp,
status: last.status,
initiator: userAccount.value, // by default value is last.initiator
phases: last.phases,
},
};
return meta;
}