Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function quickstart() {
// check to see if this code can access a metadata server
const isAvailable = await gcpMetadata.isAvailable();
console.log(`Is available: ${isAvailable}`);
// Instance and Project level metadata will only be available if
// running inside of a Google Cloud compute environment such as
// Cloud Functions, App Engine, Kubernetes Engine, or Compute Engine.
if (isAvailable) {
// grab all top level metadata from the service
const instanceMetadata = await gcpMetadata.instance();
console.log('Instance metadata:');
console.log(instanceMetadata);
// get all project level metadata
const projectMetadata = await gcpMetadata.project();
console.log('Project metadata:');
console.log(projectMetadata);
}
async function main() {
const isAvailable = await gcpMetadata.isAvailable();
console.log(`isAvailable: ${isAvailable}`);
await gcpMetadata.instance(`service-accounts/default/token`);
const svc = await gcpMetadata.instance({
property: 'service-accounts/',
params: {recursive: 'true'},
});
console.log('serviceAccounts:');
console.log(
JSON.stringify(svc)
.split('\n')
.join()
);
}
static runningOnGCP(): Promise {
return metadata.isAvailable();
}
async function isRunningOnComputeEngine() {
return gcpMetadata.isAvailable();
}
async function isComputeEngine() {
return gcpMetadata.isAvailable();
}