From bce81f48092f1958aaf17229b9c375f934e7ffd2 Mon Sep 17 00:00:00 2001 From: chenyumic Date: Wed, 23 May 2018 14:49:22 -0700 Subject: [PATCH] Update appengine/metadata/standard sample (#624) * Update appengine/metadata/standard sample * Fix the test --- appengine/metadata/standard/package.json | 4 ++-- appengine/metadata/standard/server.js | 19 +++++++++---------- circle.yml | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/appengine/metadata/standard/package.json b/appengine/metadata/standard/package.json index 79e55be338..73173068d7 100644 --- a/appengine/metadata/standard/package.json +++ b/appengine/metadata/standard/package.json @@ -15,7 +15,7 @@ "scripts": { "lint": "samples lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "samples test app -- ./server.js", "test": "npm run system-test" }, "dependencies": { @@ -28,7 +28,7 @@ "cloud-repo-tools": { "test": { "app": { - "msg": "External IP:", + "msg": "Project ID:", "args": [ "server.js" ] diff --git a/appengine/metadata/standard/server.js b/appengine/metadata/standard/server.js index 7ea0a849e0..98e1a99e96 100644 --- a/appengine/metadata/standard/server.js +++ b/appengine/metadata/standard/server.js @@ -22,31 +22,30 @@ const request = require('got'); const app = express(); app.enable('trust proxy'); -const METADATA_NETWORK_INTERFACE_URL = 'http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip'; +const METADATA_PROJECT_ID_URL = 'http://metadata.google.internal/computeMetadata/v1/project/project-id'; -function getExternalIp () { +function getProjectId () { const options = { headers: { 'Metadata-Flavor': 'Google' - }, - json: true + } }; - return request(METADATA_NETWORK_INTERFACE_URL, options) + return request(METADATA_PROJECT_ID_URL, options) .then((response) => response.body) .catch((err) => { if (err && err.statusCode !== 200) { - console.log('Error while talking to metadata server, assuming localhost'); - return 'localhost'; + console.log('Error while talking to metadata server.'); + return 'Unknown_Project_ID'; } return Promise.reject(err); }); } app.get('/', (req, res, next) => { - getExternalIp() - .then((externalIp) => { - res.status(200).send(`External IP: ${externalIp}`).end(); + getProjectId() + .then((projectId) => { + res.status(200).send(`Project ID: ${projectId}`).end(); }) .catch(next); }); diff --git a/circle.yml b/circle.yml index 455873585e..3e5d0b82a1 100644 --- a/circle.yml +++ b/circle.yml @@ -101,7 +101,8 @@ deployment: - node scripts/build "appengine/errorreporting" - node scripts/build "appengine/hello-world" - node scripts/build "appengine/mailjet" - - node scripts/build "appengine/metadata" + - node scripts/build "appengine/metadata/flexible" + - node scripts/build "appengine/metadata/standard" - node scripts/build "appengine/static-files" - GCLOUD_STORAGE_BUCKET=docs-samples-gae-test-$(uuid); node scripts/build "appengine/storage" - node scripts/build "auth"