in api/index.js [16:47]
export async function reporting(file, context) {
if (context.eventType !== 'google.storage.object.finalize') {
return;
}
if (!file.name.includes('hub.state')) {
return;
}
const superhubs = await superhubBuckets();
const stack = await stackByID(file.name, superhubs, false);
const {
REPORTING_URL: reportingEndpoint = 'https://us-central1-superhub.cloudfunctions.net/event',
} = process.env;
const payload = {
stackId: stack.id,
name: stack.name,
status: stack.status,
initiator: stack.latestOperation ? stack.latestOperation.initiator : 'unknown',
project: stack.projectId,
gcpUserAccount: stack.userAccount,
};
try {
await fetch(reportingEndpoint, {
method: 'POST',
body: JSON.stringify(payload),
});
console.log(`Payload ${JSON.stringify(payload)} posted to ${reportingEndpoint}`);
} catch (error) {
console.error(error);
}
}