diff --git a/appengine/analytics/app.js b/appengine/analytics/app.js index 3ad08f9b9f..8a1701b466 100644 --- a/appengine/analytics/app.js +++ b/appengine/analytics/app.js @@ -53,7 +53,7 @@ function trackEvent (category, action, label, value, cb) { } app.get('/', (req, res, next) => { - // Event value must be numeric. + // Event value must be numeric. trackEvent('Example category', 'Example action', 'Example label', '100') .then(() => { res.status(200).send('Event tracked.').end(); diff --git a/appengine/analytics/package.json b/appengine/analytics/package.json index 5f4e96dd39..dbdb07c17a 100644 --- a/appengine/analytics/package.json +++ b/appengine/analytics/package.json @@ -22,11 +22,11 @@ "e2e-test": "repo-tools test deploy" }, "dependencies": { - "express": "4.16.0", - "got": "7.1.0" + "express": "4.16.2", + "got": "8.2.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.0.4" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/appengine/cloudsql/createTables.js b/appengine/cloudsql/createTables.js index 37ccbcb1c7..a0643862d8 100644 --- a/appengine/cloudsql/createTables.js +++ b/appengine/cloudsql/createTables.js @@ -34,20 +34,21 @@ prompt.get(FIELDS, (err, config) => { const knex = Knex({ client: 'mysql', connection: config }); // Create the "visits" table - knex.schema.createTable('visits', (table) => { - table.increments(); - table.timestamp('timestamp'); - table.string('userIp'); - }) - .then(() => { - console.log(`Successfully created 'visits' table.`); - return knex.destroy(); - }) - .catch((err) => { - console.error(`Failed to create 'visits' table:`, err); - if (knex) { - knex.destroy(); - } - }); + knex.schema.createTable('visits', + (table) => { + table.increments(); + table.timestamp('timestamp'); + table.string('userIp'); + }) + .then(() => { + console.log(`Successfully created 'visits' table.`); + return knex.destroy(); + }) + .catch((err) => { + console.error(`Failed to create 'visits' table:`, err); + if (knex) { + knex.destroy(); + } + }); }); // [END createTables] diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 4ec82752e3..674b83bfd9 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -14,26 +14,26 @@ }, "scripts": { "deploy": "gcloud app deploy", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "unit-test": "ava --verbose test/*.test.js", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", - "system-test": "samples test app", + "system-test": "repo-tools test app -- server.js", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", - "test": "samples test run --cmd npm -- run all-test", - "e2e-test": "samples test deploy" + "test": "repo-tools test run --cmd npm -- run all-test", + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "async": "2.5.0", - "express": "4.15.4", - "knex": "0.13.0", - "mysql": "2.14.1", + "async": "2.6.0", + "express": "4.16.3", + "knex": "0.14.4", + "mysql": "2.15.0", "prompt": "1.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0" + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/appengine/cloudsql_postgresql/createTables.js b/appengine/cloudsql_postgresql/createTables.js index cf6f69c929..c421f9d7ee 100644 --- a/appengine/cloudsql_postgresql/createTables.js +++ b/appengine/cloudsql_postgresql/createTables.js @@ -39,15 +39,15 @@ prompt.get(FIELDS, (err, config) => { table.timestamp('timestamp'); table.string('userIp'); }) - .then(() => { - console.log(`Successfully created 'visits' table.`); - return knex.destroy(); - }) - .catch((err) => { - console.error(`Failed to create 'visits' table:`, err); - if (knex) { - knex.destroy(); - } - }); + .then(() => { + console.log(`Successfully created 'visits' table.`); + return knex.destroy(); + }) + .catch((err) => { + console.error(`Failed to create 'visits' table:`, err); + if (knex) { + knex.destroy(); + } + }); }); // [END createTables] diff --git a/appengine/cloudsql_postgresql/package.json b/appengine/cloudsql_postgresql/package.json index 296ee7fbf2..e8a71a7c8d 100644 --- a/appengine/cloudsql_postgresql/package.json +++ b/appengine/cloudsql_postgresql/package.json @@ -14,26 +14,26 @@ }, "scripts": { "deploy": "gcloud app deploy", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "unit-test": "ava --verbose test/*.test.js", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", - "system-test": "samples test app", + "system-test": "repo-tools test app -- server.js", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", - "test": "samples test run --cmd npm -- run all-test", - "e2e-test": "samples test deploy" + "test": "repo-tools test run --cmd npm -- run all-test", + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "async": "2.5.0", - "express": "4.15.4", - "knex": "0.13.0", - "pg": "7.3.0", + "async": "2.6.0", + "express": "4.16.2", + "knex": "0.14.4", + "pg": "7.4.1", "prompt": "1.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/appengine/cloudtasks/createTask.js b/appengine/cloudtasks/createTask.js index 03312bc7b2..40e6a8107b 100644 --- a/appengine/cloudtasks/createTask.js +++ b/appengine/cloudtasks/createTask.js @@ -40,7 +40,7 @@ function createTask (project, location, queue, options) { } const request = { - parent: `projects/${project}/locations/${location}/queues/${queue}`, // TODO: Update placeholder value. + parent: `projects/${project}/locations/${location}/queues/${queue}`, // TODO: Update placeholder value. resource: { task: task }, diff --git a/appengine/cloudtasks/package.json b/appengine/cloudtasks/package.json index 8eb6adfa4d..aed2e91adf 100644 --- a/appengine/cloudtasks/package.json +++ b/appengine/cloudtasks/package.json @@ -22,13 +22,13 @@ "dependencies": { "body-parser": "1.18.2", "express": "4.16.2", - "googleapis": "22.2.0", - "yargs": "10.0.3" + "googleapis": "27.0.0", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.1", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/appengine/datastore/package.json b/appengine/datastore/package.json index dc0718997f..effb513c1b 100644 --- a/appengine/datastore/package.json +++ b/appengine/datastore/package.json @@ -15,18 +15,18 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "repo-tools test app", "test": "npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "@google-cloud/datastore": "1.1.0", - "express": "4.15.4" + "@google-cloud/datastore": "1.3.4", + "express": "4.16.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/appengine/endpoints/package.json b/appengine/endpoints/package.json index f3338774d7..be45cddb92 100644 --- a/appengine/endpoints/package.json +++ b/appengine/endpoints/package.json @@ -15,22 +15,22 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "unit-test": "ava --verbose test/*.test.js", - "system-test": "samples test app", + "system-test": "repo-tools test app", "all-test": "npm run unit-test && npm run system-test", - "test": "samples test run --cmd npm -- run all-test", - "e2e-test": "samples test deploy" + "test": "repo-tools test run --cmd npm -- run all-test", + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "body-parser": "1.17.2", - "express": "4.15.4", + "body-parser": "1.18.2", + "express": "4.16.2", "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0" }, "cloud-repo-tools": { "test": { diff --git a/appengine/errorreporting/package.json b/appengine/errorreporting/package.json index 84d06864b6..d770a4264a 100644 --- a/appengine/errorreporting/package.json +++ b/appengine/errorreporting/package.json @@ -15,22 +15,22 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "unit-test": "ava --verbose test/*.test.js", - "system-test": "samples test app", + "system-test": "repo-tools test app", "test": "npm run unit-test && npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "@google-cloud/error-reporting": "0.2.1", - "express": "4.15.4" + "@google-cloud/error-reporting": "0.2.3", + "express": "4.16.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", - "proxyquire": "1.8.0", - "sinon": "3.2.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "test": { diff --git a/appengine/grunt/package.json b/appengine/grunt/package.json index 43b7ba6569..aad93f08c4 100644 --- a/appengine/grunt/package.json +++ b/appengine/grunt/package.json @@ -13,18 +13,18 @@ "postinstall": "grunt build" }, "dependencies": { - "body-parser": "1.15.2", + "body-parser": "1.18.2", "cookie-parser": "1.4.3", - "debug": "2.6.0", - "express": "4.14.0", - "grunt": "1.0.1", + "debug": "3.1.0", + "express": "4.16.2", + "grunt": "1.0.2", "grunt-cli": "1.2.0", - "grunt-contrib-clean": "1.0.0", - "grunt-contrib-cssmin": "2.0.0", + "grunt-contrib-clean": "1.1.0", + "grunt-contrib-cssmin": "2.2.1", "grunt-contrib-jshint": "1.1.0", "grunt-contrib-watch": "1.0.0", - "morgan": "1.8.0", - "pug": "2.0.0-beta6", - "serve-favicon": "2.3.2" + "morgan": "1.9.0", + "pug": "2.0.0", + "serve-favicon": "2.4.5" } } diff --git a/appengine/hello-world/package.json b/appengine/hello-world/package.json index a90e2bbeba..39537de4e1 100644 --- a/appengine/hello-world/package.json +++ b/appengine/hello-world/package.json @@ -15,17 +15,17 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "repo-tools test app", "test": "npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "express": "4.15.4" + "express": "4.16.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/appengine/loopback/common/models/message.js b/appengine/loopback/common/models/message.js index fc94c5a3be..369308031f 100644 --- a/appengine/loopback/common/models/message.js +++ b/appengine/loopback/common/models/message.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = function(Message) { Message.greet = function(msg, cb) { process.nextTick(function() { diff --git a/appengine/loopback/package.json b/appengine/loopback/package.json index e3a48138ae..a60f02dab2 100644 --- a/appengine/loopback/package.json +++ b/appengine/loopback/package.json @@ -12,22 +12,23 @@ "scripts": { "lint": "eslint .", "start": "node .", + "test": "repo-tools test app -- .", "posttest": "npm run lint && nsp check" }, "dependencies": { - "compression": "1.0.3", - "cors": "2.5.2", - "helmet": "1.3.0", - "loopback-boot": "2.6.5", - "loopback-component-explorer": "2.4.0", - "serve-favicon": "2.3.2", - "strong-error-handler": "1.0.1", - "loopback-datasource-juggler": "2.39.0", - "loopback": "2.22.0" + "compression": "1.7.2", + "cors": "2.8.4", + "helmet": "3.12.0", + "loopback-boot": "2.27.1", + "loopback-component-explorer": "5.3.0", + "serve-favicon": "2.4.5", + "strong-error-handler": "2.3.2", + "loopback-datasource-juggler": "3.15.4", + "loopback": "3.18.2" }, "devDependencies": { - "eslint": "2.13.1", - "eslint-config-loopback": "4.0.0", - "nsp": "2.1.0" + "eslint": "4.18.2", + "eslint-config-loopback": "10.0.0", + "nsp": "3.2.1" } } diff --git a/appengine/mailjet/package.json b/appengine/mailjet/package.json index e833b17ac6..ebe8dddb7c 100644 --- a/appengine/mailjet/package.json +++ b/appengine/mailjet/package.json @@ -15,20 +15,20 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "repo-tools test app", "test": "npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "body-parser": "1.17.2", - "express": "4.15.4", + "body-parser": "1.18.2", + "express": "4.16.2", "jade": "1.11.0", "node-mailjet": "3.2.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/appengine/memcached/package.json b/appengine/memcached/package.json index bf4921f337..2d39a0c67c 100644 --- a/appengine/memcached/package.json +++ b/appengine/memcached/package.json @@ -12,7 +12,7 @@ "start": "node app.js" }, "dependencies": { - "express": "4.14.1", - "memjs": "0.10.0" + "express": "4.16.2", + "memjs": "1.1.0" } } diff --git a/appengine/metadata/package.json b/appengine/metadata/package.json index ac9745196b..7f6292498f 100644 --- a/appengine/metadata/package.json +++ b/appengine/metadata/package.json @@ -13,18 +13,18 @@ "node": ">=4" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "repo-tools test app -- server.js", "test": "npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "express": "4.15.4", - "got": "7.1.0" + "express": "4.16.2", + "got": "8.2.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/appengine/mongodb/package.json b/appengine/mongodb/package.json index 9cf8675c3e..f744b22114 100644 --- a/appengine/mongodb/package.json +++ b/appengine/mongodb/package.json @@ -10,7 +10,7 @@ }, "scripts": { "start": "node server.js", - "test": "samples test app" + "test": "repo-tools test app -- server.js" }, "cloud-repo-tools": { "test": { @@ -29,10 +29,10 @@ } }, "dependencies": { - "mongodb": "2.2.31", - "nconf": "0.8.4" + "mongodb": "3.0.4", + "nconf": "0.10.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^1.4.17" + "@google-cloud/nodejs-repo-tools": "^2.2.1" } } diff --git a/appengine/mongodb/server.js b/appengine/mongodb/server.js index 7ea5397381..d3d718dc7a 100644 --- a/appengine/mongodb/server.js +++ b/appengine/mongodb/server.js @@ -19,9 +19,8 @@ const mongodb = require('mongodb'); const http = require('http'); const nconf = require('nconf'); -// read in keys and secrets. You can store these in a variety of ways. -// I like to use a keys.json file that is in the .gitignore file, -// but you can also store them in environment variables +// Read in keys and secrets. You can store these in +// a keys.json file, or in environment variables nconf.argv().env().file('keys.json'); // Connect to a MongoDB server provisioned over at @@ -37,9 +36,8 @@ let uri = `mongodb://${user}:${pass}@${host}:${port}`; if (nconf.get('mongoDatabase')) { uri = `${uri}/${nconf.get('mongoDatabase')}`; } -console.log(uri); -mongodb.MongoClient.connect(uri, (err, db) => { +mongodb.MongoClient.connect(uri, (err, client) => { if (err) { throw err; } @@ -55,6 +53,7 @@ mongodb.MongoClient.connect(uri, (err, db) => { return; } // Track every IP that has visited this site + const db = client.db(nconf.get('mongoDatabase')); const collection = db.collection('IPs'); const ip = { diff --git a/appengine/parse-server/package.json b/appengine/parse-server/package.json index 66f5364c4d..cf34810301 100644 --- a/appengine/parse-server/package.json +++ b/appengine/parse-server/package.json @@ -9,8 +9,8 @@ "node": ">=4.3.2" }, "dependencies": { - "express": "4.14.1", - "parse-server": "2.3.2", - "nconf": "0.8.4" + "express": "4.16.2", + "parse-server": "2.7.2", + "nconf": "0.10.0" } } diff --git a/appengine/pubsub/app.js b/appengine/pubsub/app.js index 1d7ea87ba4..ea7b1390c8 100644 --- a/appengine/pubsub/app.js +++ b/appengine/pubsub/app.js @@ -47,6 +47,7 @@ const messages = []; const PUBSUB_VERIFICATION_TOKEN = process.env.PUBSUB_VERIFICATION_TOKEN; const topic = pubsub.topic(process.env.PUBSUB_TOPIC); +const publisher = topic.publisher(); // [START index] app.get('/', (req, res) => { @@ -59,9 +60,7 @@ app.post('/', formBodyParser, (req, res, next) => { return; } - topic.publish({ - data: req.body.payload - }, (err) => { + publisher.publish(Buffer.from(req.body.payload), (err) => { if (err) { next(err); return; diff --git a/appengine/pubsub/package.json b/appengine/pubsub/package.json index 9993a90c5c..95e266cfa4 100644 --- a/appengine/pubsub/package.json +++ b/appengine/pubsub/package.json @@ -10,19 +10,19 @@ }, "scripts": { "start": "node app.js", - "test": "samples test app && ava -T 30s */*.test.js" + "test": "repo-tools test app && ava -T 30s */*.test.js" }, "dependencies": { - "@google-cloud/pubsub": "0.13.2", - "body-parser": "1.17.2", - "express": "4.15.4", - "pug": "2.0.0-rc.3", + "@google-cloud/pubsub": "0.16.4", + "body-parser": "1.18.2", + "express": "4.16.2", + "pug": "2.0.0", "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0", - "uuid": "3.1.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "uuid": "3.2.1" }, "cloud-repo-tools": { "requiresProjectId": true, diff --git a/appengine/redis/package.json b/appengine/redis/package.json index 2e305a35b8..f91a7e2617 100644 --- a/appengine/redis/package.json +++ b/appengine/redis/package.json @@ -9,7 +9,7 @@ "node": ">=4.3.2" }, "dependencies": { - "nconf": "0.8.4", - "redis": "2.6.5" + "nconf": "0.10.0", + "redis": "2.8.0" } } diff --git a/appengine/sendgrid/package.json b/appengine/sendgrid/package.json index 97cda9d846..177962b681 100644 --- a/appengine/sendgrid/package.json +++ b/appengine/sendgrid/package.json @@ -12,9 +12,9 @@ "start": "node app.js" }, "dependencies": { - "body-parser": "1.16.0", - "express": "4.14.1", - "pug": "2.0.0-beta6", - "sendgrid": "4.7.1" + "body-parser": "1.18.2", + "express": "4.16.2", + "pug": "2.0.0", + "sendgrid": "5.2.3" } } diff --git a/appengine/static-files/package.json b/appengine/static-files/package.json index f9c2f695e7..dfd7b95eac 100644 --- a/appengine/static-files/package.json +++ b/appengine/static-files/package.json @@ -10,7 +10,7 @@ }, "scripts": { "start": "node app.js", - "test": "samples test app --url localhost:8080/static/main.css" + "test": "repo-tools test app --url localhost:8080/static/main.css" }, "cloud-repo-tools": { "test": { @@ -21,10 +21,10 @@ } }, "dependencies": { - "express": "4.15.4", - "pug": "2.0.0-rc.3" + "express": "4.16.2", + "pug": "2.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" } } diff --git a/appengine/storage/package.json b/appengine/storage/package.json index e9dce13e91..0a1900ff13 100644 --- a/appengine/storage/package.json +++ b/appengine/storage/package.json @@ -9,15 +9,15 @@ "node": ">=4.3.2" }, "dependencies": { - "@google-cloud/storage": "1.2.1", - "body-parser": "1.17.2", - "express": "4.15.4", + "@google-cloud/storage": "1.6.0", + "body-parser": "1.18.2", + "express": "4.16.3", "multer": "1.3.0", - "pug": "2.0.0-rc.3" + "pug": "2.0.3" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0" + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresProjectId": true, diff --git a/appengine/twilio/package.json b/appengine/twilio/package.json index 4698df0236..271aee75c8 100644 --- a/appengine/twilio/package.json +++ b/appengine/twilio/package.json @@ -12,8 +12,8 @@ "start": "node app.js" }, "dependencies": { - "body-parser": "1.16.0", - "express": "4.14.1", - "twilio": "2.11.1" + "body-parser": "1.18.2", + "express": "4.16.2", + "twilio": "3.13.0" } } diff --git a/auth/package.json b/auth/package.json index 13af137e95..d1ff8e0848 100644 --- a/auth/package.json +++ b/auth/package.json @@ -12,17 +12,17 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + "test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "1.2.1", - "yargs": "8.0.2" + "@google-cloud/storage": "1.6.0", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/cloudtasks/package.json b/cloudtasks/package.json index ffdbca3635..6aa99f5e84 100644 --- a/cloudtasks/package.json +++ b/cloudtasks/package.json @@ -15,12 +15,12 @@ "test": "repo-tools test run --cmd npm -- run system-test" }, "dependencies": { - "googleapis": "22.2.0", - "yargs": "10.0.3" + "googleapis": "27.0.0", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/cloudtasks/system-test/tasks.test.js b/cloudtasks/system-test/tasks.test.js index 471f539c55..6198d48538 100644 --- a/cloudtasks/system-test/tasks.test.js +++ b/cloudtasks/system-test/tasks.test.js @@ -20,7 +20,6 @@ const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); const { - spawnAsyncWithIO, runAsync } = require(`@google-cloud/nodejs-repo-tools`); @@ -31,7 +30,7 @@ const cwd = path.join(__dirname, `..`); test.before((t) => { if (!QUEUE) { - t.fail('You must set the GCP_QUEUE environment variable!'); + t.fail(`You must set the GCP_QUEUE environment variable!`); } }); test.before(tools.checkCredentials); @@ -39,35 +38,27 @@ test.before(tools.checkCredentials); let task; test.serial(`should create a task`, async (t) => { - const args = [`create`, PROJECT_ID, `us-central1`, QUEUE]; - const results = await spawnAsyncWithIO(cmd, args, cwd); - t.regex(results.output, /Created task/); + const output = await runAsync(`${cmd} create ${PROJECT_ID} us-central1 "${QUEUE}"`, cwd); + t.true(output.includes('Created task')); }); test.serial(`should pull a task`, async (t) => { t.plan(0); await tools.tryTest(async (assert) => { - const args = [`pull`, PROJECT_ID, `us-central1`, QUEUE]; - const results = await spawnAsyncWithIO(cmd, args, cwd); - const matches = results.output.match(/^Pulled task ({.+})$/); - if (matches) { - const json = JSON.parse(matches[1]); - if (json.tasks && json.tasks.length) { - task = JSON.stringify(json.tasks[0]); - } - } else { - throw new Error(`Should have pulled task.\n${results.output}`); + const output = await runAsync(`${cmd} pull ${PROJECT_ID} us-central1 "${QUEUE}"`, cwd); + const matches = output.match(/^Pulled task ({.+})$/); + if (matches && matches.length > 1) { + task = matches[1]; } - assert(results.output.includes(`Pulled task`)); + assert(output.includes(`Pulled task`)); }).start(); }); test.serial(`should acknowledge a task`, async (t) => { if (task) { - const command = `${cmd} acknowledge '${task}'`; - const output = await runAsync(command, cwd); - t.regex(output, /Acknowledged task/); + const output = await runAsync(`${cmd} acknowledge '${task}'`, cwd); + t.true(output.includes(`Acknowledged task`)); } else { - t.fail('no task to acknowledge'); + t.fail(`no task to acknowledge`); } }); diff --git a/cloudtasks/tasks.js b/cloudtasks/tasks.js index 76a649f426..f4e9e86804 100644 --- a/cloudtasks/tasks.js +++ b/cloudtasks/tasks.js @@ -17,7 +17,7 @@ function createTask (project, location, queue) { // [START cloud_tasks_create_task] - const google = require('googleapis'); + const google = require('googleapis').google; const cloudtasks = google.cloudtasks('v2beta2'); /** @@ -28,7 +28,10 @@ function createTask (project, location, queue) { // const queue = 'Queue ID, e.g. queue-1'; authorize((authClient) => { + const scheduleTime = new Date(); + scheduleTime.setUTCMinutes(scheduleTime.getUTCMinutes() + 2); const task = { + scheduleTime: scheduleTime, pull_message: { payload: Buffer.from('a message for the recipient').toString('base64') } @@ -48,8 +51,8 @@ function createTask (project, location, queue) { return; } - console.log(`Created task ${response.name}.`); - console.log(JSON.stringify(response, null, 2)); + console.log(`Created task ${response.data.name}.`); + console.log(JSON.stringify(response.data, null, 2)); }); }); @@ -71,7 +74,7 @@ function createTask (project, location, queue) { function pullTask (project, location, queue) { // [START cloud_tasks_pull_and_acknowledge_task] - const google = require('googleapis'); + const google = require('googleapis').google; const cloudtasks = google.cloudtasks('v2beta2'); /** @@ -82,25 +85,21 @@ function pullTask (project, location, queue) { // const queue = 'Queue ID, e.g. queue-1'; authorize((authClient) => { - const pullOptions = { - maxTasks: 1, - leaseDuration: '600s', - responseView: 'FULL' - }; - const request = { - name: `projects/${project}/locations/${location}/queues/${queue}`, - resource: pullOptions, + parent: `projects/${project}/locations/${location}/queues/${queue}`, + responseView: 'FULL', + pageSize: 1, auth: authClient }; - cloudtasks.projects.locations.queues.tasks.pull(request, (err, response) => { + cloudtasks.projects.locations.queues.tasks.list(request, (err, response) => { if (err) { console.error(err); return; } - console.log('Pulled task %j', response); + const task = response.data.tasks[0]; + console.log('Pulled task %j', task); }); }); @@ -120,7 +119,7 @@ function pullTask (project, location, queue) { } function acknowledgeTask (task) { - const google = require('googleapis'); + const google = require('googleapis').google; const cloudtasks = google.cloudtasks('v2beta2'); /** @@ -134,9 +133,7 @@ function acknowledgeTask (task) { authorize((authClient) => { const request = { name: task.name, - resource: { - scheduleTime: task.scheduleTime - }, + scheduleTime: task.scheduleTime, auth: authClient }; diff --git a/debugger/package.json b/debugger/package.json index 67fa2e1ddb..3304642851 100644 --- a/debugger/package.json +++ b/debugger/package.json @@ -15,18 +15,18 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "system-test": "samples test app", + "system-test": "repo-tools test app", "test": "npm run system-test", - "e2e-test": "samples test deploy" + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "@google-cloud/debug-agent": "2.1.3", - "express": "4.15.4" + "@google-cloud/debug-agent": "2.3.2", + "express": "4.16.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": { diff --git a/endpoints/getting-started-grpc/package.json b/endpoints/getting-started-grpc/package.json index dd7252037a..e06f9267a5 100644 --- a/endpoints/getting-started-grpc/package.json +++ b/endpoints/getting-started-grpc/package.json @@ -14,19 +14,19 @@ }, "scripts": { "start": "node server.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 1m --verbose system-test/*.test.js" + "test": "repo-tools test run --cmd ava -- -T 1m --verbose system-test/*.test.js" }, "dependencies": { - "google-auth-library": "^0.10.0", - "grpc": "1.4.1", - "jsonwebtoken": "^7.4.1", - "yargs": "8.0.2" + "google-auth-library": "^1.3.1", + "grpc": "1.9.1", + "jsonwebtoken": "^8.2.0", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^1.4.15", - "ava": "0.21.0" + "@google-cloud/nodejs-repo-tools": "^2.2.1", + "ava": "0.25.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/endpoints/getting-started-grpc/system-test/endpoints.test.js b/endpoints/getting-started-grpc/system-test/endpoints.test.js index a446ede08b..f9d98fdf18 100644 --- a/endpoints/getting-started-grpc/system-test/endpoints.test.js +++ b/endpoints/getting-started-grpc/system-test/endpoints.test.js @@ -48,7 +48,7 @@ const JWT_AUTH_TOKEN = jwt.sign({ 'aud': SERVICE_NAME, 'iss': GOOGLE_KEYFILE.client_email, 'iat': parseInt(Date.now() / 1000), - 'exp': parseInt(Date.now() / 1000) + (20 * 60), // 20 minutes + 'exp': parseInt(Date.now() / 1000) + (20 * 60), // 20 minutes 'email': GOOGLE_KEYFILE.client_email, 'sub': GOOGLE_KEYFILE.client_email }, GOOGLE_KEYFILE.private_key, { algorithm: 'RS256' }); diff --git a/endpoints/getting-started/package.json b/endpoints/getting-started/package.json index 57fcbfbd68..a0283616ec 100644 --- a/endpoints/getting-started/package.json +++ b/endpoints/getting-started/package.json @@ -19,15 +19,15 @@ "test": "samples test run --cmd ava -- -T 20s --verbose test/*.test.js" }, "dependencies": { - "body-parser": "1.17.2", - "express": "4.15.4", + "body-parser": "1.18.2", + "express": "4.16.2", "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", - "proxyquire": "1.8.0", - "sinon": "3.2.0", + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2", "supertest": "3.0.0" } } diff --git a/error-reporting/package.json b/error-reporting/package.json index 0c5fb6d054..cdab72ae13 100644 --- a/error-reporting/package.json +++ b/error-reporting/package.json @@ -12,24 +12,24 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "error-test": "samples test app --msg \"Something broke!\" --url \"http://localhost:33332/error\" --port 33332 -- snippets.js express", - "exception-test": "samples test app --code 500 --msg SyntaxError --url \"http://localhost:33333/exception\" --port 33333 -- snippets.js express", + "error-test": "repo-tools test app --msg \"Something broke!\" --url \"http://localhost:33332/error\" --port 33332 -- snippets.js express", + "exception-test": "repo-tools test app --code 500 --msg SyntaxError --url \"http://localhost:33333/exception\" --port 33333 -- snippets.js express", "system-test": "ava -T 1m --verbose system-test/*.test.js", "all-test": "npm run system-test && npm run error-test && npm run exception-test", - "test": "samples test run --cmd npm -- run all-test" + "test": "repo-tools test run --cmd npm -- run all-test" }, "dependencies": { - "@google-cloud/error-reporting": "0.2.1", - "express": "4.15.4", - "yargs": "8.0.2" + "@google-cloud/error-reporting": "0.2.3", + "express": "4.16.2", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", - "proxyquire": "1.8.0", - "sinon": "3.2.0" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/background/package.json b/functions/background/package.json index 212f354255..a2b69cb18f 100644 --- a/functions/background/package.json +++ b/functions/background/package.json @@ -12,7 +12,7 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, @@ -21,10 +21,10 @@ "request-promise": "4.2.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/datastore/package.json b/functions/datastore/package.json index 1d455aea8f..7075383260 100644 --- a/functions/datastore/package.json +++ b/functions/datastore/package.json @@ -19,15 +19,15 @@ "test": "npm run system-test" }, "dependencies": { - "@google-cloud/datastore": "1.3.3", + "@google-cloud/datastore": "1.3.4", "supertest": "^3.0.0" }, "devDependencies": { "@google-cloud/functions-emulator": "^1.0.0-alpha.29", - "@google-cloud/nodejs-repo-tools": "2.1.3", - "ava": "0.24.0", - "proxyquire": "1.8.0", - "sinon": "4.1.3" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/errorreporting/package.json b/functions/errorreporting/package.json index abfd6151bc..542a95e614 100644 --- a/functions/errorreporting/package.json +++ b/functions/errorreporting/package.json @@ -6,6 +6,6 @@ "author": "Google Inc.", "main": "./index.js", "dependencies": { - "@google-cloud/logging": "1.1.1" + "@google-cloud/logging": "1.1.4" } } diff --git a/functions/gcs/package.json b/functions/gcs/package.json index 7eb33730c6..2e38ecdc3f 100644 --- a/functions/gcs/package.json +++ b/functions/gcs/package.json @@ -12,19 +12,19 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "1.4.0", + "@google-cloud/storage": "1.6.0", "request": "2.83.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/helloworld/package.json b/functions/helloworld/package.json index fd3c51cd1e..7c513fa09f 100644 --- a/functions/helloworld/package.json +++ b/functions/helloworld/package.json @@ -15,21 +15,21 @@ "lint": "repo-tools lint", "pretest": "npm run lint", "e2e-test": "export FUNCTIONS_CMD='gcloud beta functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCF_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" ava -T 20s --verbose test/*.test.js", - "test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/index.test.js test/*unit*test.js test/*integration*test.js", - "system-test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/*.test.js" + "test": "export FUNCTIONS_CMD='functions-emulator' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/index.test.js test/*unit*test.js test/*integration*test.js", + "system-test": "export FUNCTIONS_CMD='functions-emulator' && sh test/updateFunctions.sh && export BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" && ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/debug-agent": "2.3.0", - "pug": "2.0.0-rc.4", + "@google-cloud/debug-agent": "2.4.0", + "pug": "2.0.3", "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.3", - "@google-cloud/pubsub": "^0.15.0", + "@google-cloud/nodejs-repo-tools": "2.2.5", + "@google-cloud/pubsub": "^0.17.0", "@google-cloud/storage": "^1.5.0", - "ava": "0.24.0", - "proxyquire": "1.8.0", - "sinon": "4.1.2", + "ava": "0.25.0", + "proxyquire": "2.0.1", + "sinon": "4.4.8", "supertest": "^3.0.0", "uuid": "^3.1.0" }, diff --git a/functions/http/package.json b/functions/http/package.json index e2f62fc186..18638d347b 100644 --- a/functions/http/package.json +++ b/functions/http/package.json @@ -12,15 +12,15 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "dependencies": { "safe-buffer": "5.1.1" diff --git a/functions/imagemagick/package.json b/functions/imagemagick/package.json index 2f95f6e97a..cc13740847 100644 --- a/functions/imagemagick/package.json +++ b/functions/imagemagick/package.json @@ -12,19 +12,19 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "1.4.0", - "@google-cloud/vision": "0.12.0" + "@google-cloud/storage": "1.6.0", + "@google-cloud/vision": "0.16.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/log/package.json b/functions/log/package.json index 24439c508d..68690c8270 100644 --- a/functions/log/package.json +++ b/functions/log/package.json @@ -12,19 +12,19 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/logging": "1.1.1", + "@google-cloud/logging": "1.1.4", "@google-cloud/monitoring": "0.4.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/pubsub/package.json b/functions/pubsub/package.json index 1bdf0eb81a..2d20824b0e 100644 --- a/functions/pubsub/package.json +++ b/functions/pubsub/package.json @@ -12,19 +12,19 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/pubsub": "0.14.5", + "@google-cloud/pubsub": "0.16.4", "safe-buffer": "5.1.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/spanner/package.json b/functions/spanner/package.json index 6dc438f9d2..51e2a85073 100644 --- a/functions/spanner/package.json +++ b/functions/spanner/package.json @@ -12,18 +12,18 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "@google-cloud/spanner": "0.8.0" + "@google-cloud/spanner": "1.1.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "proxyquire": "1.8.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "proxyquire": "2.0.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/uuid/package.json b/functions/uuid/package.json index cf5842b63b..e9d1a94b41 100644 --- a/functions/uuid/package.json +++ b/functions/uuid/package.json @@ -12,17 +12,17 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", "test": "ava -T 20s --verbose test/*.test.js" }, "dependencies": { - "uuid": "3.1.0" + "uuid": "3.2.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.1.0", - "ava": "0.23.0", - "sinon": "4.0.2" + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "sinon": "4.4.2" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/iot/http_example/cloudiot_http_example.js b/iot/http_example/cloudiot_http_example.js index 83741dc948..33ed09fe78 100644 --- a/iot/http_example/cloudiot_http_example.js +++ b/iot/http_example/cloudiot_http_example.js @@ -22,77 +22,77 @@ const request = require('retry-request'); console.log('Google Cloud IoT Core HTTP example.'); var argv = require(`yargs`) - .options({ - projectId: { - default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT, - description: 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.', - requiresArg: true, - type: 'string' - }, - cloudRegion: { - default: 'us-central1', - description: 'GCP cloud region.', - requiresArg: true, - type: 'string' - }, - registryId: { - description: 'Cloud IoT registry ID.', - requiresArg: true, - demandOption: true, - type: 'string' - }, - deviceId: { - description: 'Cloud IoT device ID.', - requiresArg: true, - demandOption: true, - type: 'string' - }, - privateKeyFile: { - description: 'Path to private key file.', - requiresArg: true, - demandOption: true, - type: 'string' - }, - algorithm: { - description: 'Encryption algorithm to generate the RSA or EC JWT.', - requiresArg: true, - demandOption: true, - choices: ['RS256', 'ES256'], - type: 'string' - }, - numMessages: { - default: 100, - description: 'Number of messages to publish.', - requiresArg: true, - type: 'number' - }, - tokenExpMins: { - default: 20, - description: 'Minutes to JWT token expiration.', - requiresArg: true, - type: 'number' - }, - httpBridgeAddress: { - default: 'cloudiotdevice.googleapis.com', - description: 'HTTP bridge address.', - requiresArg: true, - type: 'string' - }, - messageType: { - default: 'events', - description: 'Message type to publish.', - requiresArg: true, - choices: ['events', 'state'], - type: 'string' - } - }) - .example(`node $0 cloudiotHttp_example_nodejs.js --projectId=blue-jet-123 --registryId=my-registry --deviceId=my-node-device --privateKeyFile=../rsaPrivate.pem --algorithm=RS256`) - .wrap(120) - .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/iot-core/docs`) - .help() - .strict() - .argv; + .options({ + projectId: { + default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT, + description: 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.', + requiresArg: true, + type: 'string' + }, + cloudRegion: { + default: 'us-central1', + description: 'GCP cloud region.', + requiresArg: true, + type: 'string' + }, + registryId: { + description: 'Cloud IoT registry ID.', + requiresArg: true, + demandOption: true, + type: 'string' + }, + deviceId: { + description: 'Cloud IoT device ID.', + requiresArg: true, + demandOption: true, + type: 'string' + }, + privateKeyFile: { + description: 'Path to private key file.', + requiresArg: true, + demandOption: true, + type: 'string' + }, + algorithm: { + description: 'Encryption algorithm to generate the RSA or EC JWT.', + requiresArg: true, + demandOption: true, + choices: ['RS256', 'ES256'], + type: 'string' + }, + numMessages: { + default: 100, + description: 'Number of messages to publish.', + requiresArg: true, + type: 'number' + }, + tokenExpMins: { + default: 20, + description: 'Minutes to JWT token expiration.', + requiresArg: true, + type: 'number' + }, + httpBridgeAddress: { + default: 'cloudiotdevice.googleapis.com', + description: 'HTTP bridge address.', + requiresArg: true, + type: 'string' + }, + messageType: { + default: 'events', + description: 'Message type to publish.', + requiresArg: true, + choices: ['events', 'state'], + type: 'string' + } + }) + .example(`node $0 cloudiotHttp_example_nodejs.js --projectId=blue-jet-123 --registryId=my-registry --deviceId=my-node-device --privateKeyFile=../rsaPrivate.pem --algorithm=RS256`) + .wrap(120) + .recommendCommands() + .epilogue(`For more information, see https://cloud.google.com/iot-core/docs`) + .help() + .strict() + .argv; // [START iot_http_variables] // A unique string that identifies this device. For Google Cloud IoT Core, it @@ -104,7 +104,7 @@ const devicePath = `projects/${argv.projectId}/locations/${argv.cloudRegion}/reg // The request path, set accordingly depending on the message type. const pathSuffix = argv.messageType === 'events' - ? ':publishEvent' : ':setState'; + ? ':publishEvent' : ':setState'; const urlBase = `https://${argv.httpBridgeAddress}/v1/${devicePath}`; const url = `${urlBase}${pathSuffix}`; // [END iot_http_variables] @@ -118,7 +118,7 @@ function createJwt (projectId, privateKeyFile, algorithm) { // audience field should always be set to the GCP project ID. const token = { 'iat': parseInt(Date.now() / 1000), - 'exp': parseInt(Date.now() / 1000) + 20 * 60, // 20 minutes + 'exp': parseInt(Date.now() / 1000) + 20 * 60, // 20 minutes 'aud': projectId }; const privateKey = fs.readFileSync(privateKeyFile); diff --git a/iot/http_example/system-test/cloudiot_http_example_test.js b/iot/http_example/system-test/cloudiot_http_example_test.js index e3513edf9d..741eeeb2c3 100644 --- a/iot/http_example/system-test/cloudiot_http_example_test.js +++ b/iot/http_example/system-test/cloudiot_http_example_test.js @@ -54,12 +54,12 @@ test(`should receive configuration message`, async (t) => { await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); await tools.runAsync( - `${helper} createRegistry ${localRegName} ${topicName}`, cwd); + `${helper} createRegistry ${localRegName} ${topicName}`, cwd); await tools.runAsync( - `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); + `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); const output = await tools.runAsync( - `${cmd} --messageType=events --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); + `${cmd} --messageType=events --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); t.regex(output, new RegExp(/Getting config/)); @@ -75,12 +75,12 @@ test(`should send event message`, async (t) => { await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); await tools.runAsync( - `${helper} createRegistry ${localRegName} ${topicName}`, cwd); + `${helper} createRegistry ${localRegName} ${topicName}`, cwd); await tools.runAsync( - `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); + `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); const output = await tools.runAsync( - `${cmd} --messageType=events --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); + `${cmd} --messageType=events --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); t.regex(output, new RegExp(/Publishing message/)); @@ -95,12 +95,12 @@ test(`should send event message`, async (t) => { const localRegName = `${registryName}-rsa256`; await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); await tools.runAsync( - `${helper} createRegistry ${localRegName} ${topicName}`, cwd); + `${helper} createRegistry ${localRegName} ${topicName}`, cwd); await tools.runAsync( - `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); + `${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); const output = await tools.runAsync( - `${cmd} --messageType=state --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); + `${cmd} --messageType=state --numMessages=1 --privateKeyFile=resources/rsa_private.pem --algorithm=RS256`, cwd); t.regex(output, new RegExp(/Publishing message/)); // Check / cleanup diff --git a/iot/manager/manager.js b/iot/manager/manager.js index 353b94aaf9..2a92a84411 100644 --- a/iot/manager/manager.js +++ b/iot/manager/manager.js @@ -110,8 +110,14 @@ function lookupRegistry (client, registryId, projectId, cloudRegion, cb) { // [END iot_lookup_registry] } -function createRegistry (client, registryId, projectId, cloudRegion, - pubsubTopicId, foundCb) { +function createRegistry ( + client, + registryId, + projectId, + cloudRegion, + pubsubTopicId, + foundCb +) { // [START iot_create_registry] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -150,8 +156,13 @@ function createRegistry (client, registryId, projectId, cloudRegion, } // Create a new registry, or look up an existing one if it doesn't exist. -function lookupOrCreateRegistry (client, registryId, projectId, cloudRegion, - pubsubTopicId) { +function lookupOrCreateRegistry ( + client, + registryId, + projectId, + cloudRegion, + pubsubTopicId +) { // [START iot_lookup_or_create_registry] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -160,16 +171,27 @@ function lookupOrCreateRegistry (client, registryId, projectId, cloudRegion, // const registryId = 'my-registry'; // const pubsubTopicId = 'my-iot-topic'; - createRegistry(client, registryId, projectId, cloudRegion, pubsubTopicId, - lookupRegistry); - + createRegistry( + client, + registryId, + projectId, + cloudRegion, + pubsubTopicId, + lookupRegistry + ); // [END iot_lookup_or_create_registry] } // Create a new device with the given id. The body defines the parameters for // the device, such as authentication. -function createUnauthDevice (client, deviceId, registryId, projectId, - cloudRegion, body) { +function createUnauthDevice ( + client, + deviceId, + registryId, + projectId, + cloudRegion, + body +) { // [START iot_create_unauth_device] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -199,8 +221,14 @@ function createUnauthDevice (client, deviceId, registryId, projectId, } // Create a device using RSA256 for authentication. -function createRsaDevice (client, deviceId, registryId, projectId, cloudRegion, - rsaCertificateFile) { +function createRsaDevice ( + client, + deviceId, + registryId, + projectId, + cloudRegion, + rsaCertificateFile +) { // [START iot_create_rsa_device] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -242,8 +270,14 @@ function createRsaDevice (client, deviceId, registryId, projectId, cloudRegion, } // Create a device using ES256 for authentication. -function createEsDevice (client, deviceId, registryId, projectId, cloudRegion, - esCertificateFile) { +function createEsDevice ( + client, + deviceId, + registryId, + projectId, + cloudRegion, + esCertificateFile +) { // [START iot_create_es_device] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -283,8 +317,14 @@ function createEsDevice (client, deviceId, registryId, projectId, cloudRegion, } // Add RSA256 authentication to the given device. -function patchRsa256ForAuth (client, deviceId, registryId, rsaPublicKeyFile, - projectId, cloudRegion) { +function patchRsa256ForAuth ( + client, + deviceId, + registryId, + rsaPublicKeyFile, + projectId, + cloudRegion +) { // [START iot_patch_rsa] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -323,8 +363,14 @@ function patchRsa256ForAuth (client, deviceId, registryId, rsaPublicKeyFile, } // Add ES256 authentication to the given device. -function patchEs256ForAuth (client, deviceId, registryId, esPublicKeyFile, - projectId, cloudRegion) { +function patchEs256ForAuth ( + client, + deviceId, + registryId, + esPublicKeyFile, + projectId, + cloudRegion +) { // [START iot_patch_es] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -413,8 +459,14 @@ function listRegistries (client, projectId, cloudRegion) { } // Delete the given device from the registry. -function deleteDevice (client, deviceId, registryId, projectId, cloudRegion, - cb) { +function deleteDevice ( + client, + deviceId, + registryId, + projectId, + cloudRegion, + cb +) { // [START iot_delete_device] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -477,11 +529,22 @@ function clearRegistry (client, registryId, projectId, cloudRegion) { devices.forEach((device, index) => { console.log(`${device.id} [${index}/${devices.length}] removed`); if (index === devices.length - 1) { - deleteDevice(client, device.id, registryId, projectId, cloudRegion, - after); + deleteDevice( + client, + device.id, + registryId, + projectId, + cloudRegion, + after + ); } else { - deleteDevice(client, device.id, registryId, projectId, cloudRegion - ); + deleteDevice( + client, + device.id, + registryId, + projectId, + cloudRegion + ); } }); } else { @@ -546,8 +609,13 @@ function getDevice (client, deviceId, registryId, projectId, cloudRegion) { } // Retrieve the given device's state from the registry. -function getDeviceState (client, deviceId, registryId, projectId, - cloudRegion) { +function getDeviceState ( + client, + deviceId, + registryId, + projectId, + cloudRegion +) { // [START iot_get_device_state] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -562,20 +630,25 @@ function getDeviceState (client, deviceId, registryId, projectId, }; client.projects.locations.registries.devices.states.list(request, - (err, data) => { - if (err) { - console.log('Could not find device:', deviceId); - console.log(err); - } else { - console.log('State:', data); - } - }); + (err, data) => { + if (err) { + console.log('Could not find device:', deviceId); + console.log(err); + } else { + console.log('State:', data); + } + }); // [END iot_get_device_state] } // Retrieve the given device's configuration history from the registry. -function getDeviceConfigs (client, deviceId, registryId, projectId, - cloudRegion) { +function getDeviceConfigs ( + client, + deviceId, + registryId, + projectId, + cloudRegion +) { // [START iot_get_device_configs] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -590,20 +663,27 @@ function getDeviceConfigs (client, deviceId, registryId, projectId, }; client.projects.locations.registries.devices.configVersions.list(request, - (err, data) => { - if (err) { - console.log('Could not find device:', deviceId); - console.log(err); - } else { - console.log('Configs:', data); - } - }); + (err, data) => { + if (err) { + console.log('Could not find device:', deviceId); + console.log(err); + } else { + console.log('Configs:', data); + } + }); // [END iot_get_device_configs] } // Send configuration data to device. -function setDeviceConfig (client, deviceId, registryId, projectId, - cloudRegion, data, version) { +function setDeviceConfig ( + client, + deviceId, + registryId, + projectId, + cloudRegion, + data, + version +) { // [START iot_set_device_config] // Client retrieved in callback // getClient(serviceAccountJson, function(client) {...}); @@ -624,14 +704,14 @@ function setDeviceConfig (client, deviceId, registryId, projectId, }; client.projects.locations.registries.devices.modifyCloudToDeviceConfig(request, - (err, data) => { - if (err) { - console.log('Could not update config:', deviceId); - console.log('Message: ', err); - } else { - console.log('Success :', data); - } - }); + (err, data) => { + if (err) { + console.log('Could not update config:', deviceId); + console.log('Message: ', err); + } else { + console.log('Success :', data); + } + }); // [END iot_set_device_config] } @@ -718,8 +798,14 @@ function getIamPolicy (client, registryId, projectId, cloudRegion) { } // Sets the IAM permissions for a given registry to a single member / role. -function setIamPolicy (client, registryId, projectId, cloudRegion, member, - role) { +function setIamPolicy ( + client, + registryId, + projectId, + cloudRegion, + member, + role +) { // [START iot_set_iam_policy] // Client retrieved in callback // setClient(serviceAccountJson, function(client) {...}); @@ -788,8 +874,14 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - createRsaDevice(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion, opts.rsaPath); + createRsaDevice( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion, + opts.rsaPath + ); }; getClient(opts.serviceAccount, cb); } @@ -800,8 +892,14 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - createEsDevice(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion, opts.esPath); + createEsDevice( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion, + opts.esPath + ); }; getClient(opts.serviceAccount, cb); } @@ -812,8 +910,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - createUnauthDevice(client, opts.deviceId, opts.registryId, - opts.projectId, opts.cloudRegion); + createUnauthDevice( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -824,8 +927,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - lookupOrCreateRegistry(client, opts.registryId, opts.projectId, - opts.cloudRegion, opts.pubsubTopic); + lookupOrCreateRegistry( + client, + opts.registryId, + opts.projectId, + opts.cloudRegion, + opts.pubsubTopic + ); }; getClient(opts.serviceAccount, cb); } @@ -848,8 +956,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - deleteDevice(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion); + deleteDevice( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -860,8 +973,12 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - clearRegistry(client, opts.registryId, opts.projectId, - opts.cloudRegion); + clearRegistry( + client, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -872,8 +989,12 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - deleteRegistry(client, opts.registryId, opts.projectId, - opts.cloudRegion); + deleteRegistry( + client, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -884,8 +1005,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - getDevice(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion); + getDevice( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -896,8 +1022,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - getDeviceConfigs(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion); + getDeviceConfigs( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -908,8 +1039,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - getDeviceState(client, opts.deviceId, opts.registryId, opts.projectId, - opts.cloudRegion); + getDeviceState( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -953,8 +1089,14 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - patchEs256ForAuth(client, opts.deviceId, opts.registryId, - opts.es256Path, opts.projectId, opts.cloudRegion); + patchEs256ForAuth( + client, + opts.deviceId, + opts.registryId, + opts.es256Path, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -965,8 +1107,14 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - patchRsa256ForAuth(client, opts.deviceId, opts.registryId, - opts.rsa256Path, opts.projectId, opts.cloudRegion); + patchRsa256ForAuth( + client, + opts.deviceId, + opts.registryId, + opts.rsa256Path, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -977,9 +1125,15 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - setDeviceConfig(client, opts.deviceId, opts.registryId, - opts.projectId, opts.cloudRegion, opts.configuration, - opts.version || 0); + setDeviceConfig( + client, + opts.deviceId, + opts.registryId, + opts.projectId, + opts.cloudRegion, + opts.configuration, + opts.version || 0 + ); }; getClient(opts.serviceAccount, cb); } @@ -990,8 +1144,12 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - getIamPolicy(client, opts.registryId, opts.projectId, - opts.cloudRegion); + getIamPolicy( + client, + opts.registryId, + opts.projectId, + opts.cloudRegion + ); }; getClient(opts.serviceAccount, cb); } @@ -1002,8 +1160,13 @@ require(`yargs`) // eslint-disable-line {}, (opts) => { const cb = function (client) { - setIamPolicy(client, opts.registryId, opts.projectId, - opts.cloudRegion, opts.member, opts.role); + setIamPolicy(client, + opts.registryId, + opts.projectId, + opts.cloudRegion, + opts.member, + opts.role + ); }; getClient(opts.serviceAccount, cb); } diff --git a/iot/manager/system-test/manager.test.js b/iot/manager/system-test/manager.test.js index 78aaa31c70..afdbb6348f 100644 --- a/iot/manager/system-test/manager.test.js +++ b/iot/manager/system-test/manager.test.js @@ -51,12 +51,12 @@ test(`should create and delete an unauthorized device`, async (t) => { const localRegName = `${registryName}-unauth`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -66,15 +66,15 @@ test(`should list configs for a device`, async (t) => { const localRegName = `${registryName}-unauth`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} getDeviceConfigs ${localDevice} ${localRegName}`, cwd); + `${cmd} getDeviceConfigs ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Configs`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -84,15 +84,15 @@ test(`should create and delete an RSA256 device`, async (t) => { const localRegName = `${registryName}-rsa256`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); + `${cmd} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} getDeviceState ${localDevice} ${localRegName}`, cwd); + `${cmd} getDeviceState ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`State`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -102,15 +102,15 @@ test(`should create and delete an EC256 device`, async (t) => { const localRegName = `${registryName}-es256`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createEs256Device ${localDevice} ${localRegName} resources/ec_public.pem`, cwd); + `${cmd} createEs256Device ${localDevice} ${localRegName} resources/ec_public.pem`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} getDeviceState ${localDevice} ${localRegName}`, cwd); + `${cmd} getDeviceState ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`State`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -120,15 +120,15 @@ test(`should patch an unauthorized device with RSA256`, async (t) => { const localRegName = `${registryName}-patchRSA`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} patchRsa256 ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); + `${cmd} patchRsa256 ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); t.regex(output, new RegExp(`Patched device:`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -138,15 +138,15 @@ test(`should patch an unauthorized device with RSA256`, async (t) => { const localRegName = `${registryName}-patchES`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} patchEs256 ${localDevice} ${localRegName} resources/ec_public.pem`, cwd); + `${cmd} patchEs256 ${localDevice} ${localRegName} resources/ec_public.pem`, cwd); t.regex(output, new RegExp(`Patched device:`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -156,16 +156,16 @@ test(`should create and list devices`, async (t) => { const localRegName = `${registryName}-list`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} listDevices ${localRegName}`, cwd); + `${cmd} listDevices ${localRegName}`, cwd); t.regex(output, /Current devices in registry:/); t.regex(output, new RegExp(localDevice)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -175,15 +175,15 @@ test(`should create and get a device`, async (t) => { const localRegName = `${registryName}-get`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} createUnauthDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Created device`)); output = await tools.runAsync( - `${cmd} getDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} getDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Found device: ${localDevice}`)); output = await tools.runAsync( - `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); + `${cmd} deleteDevice ${localDevice} ${localRegName}`, cwd); t.regex(output, new RegExp(`Successfully deleted device`)); output = await tools.runAsync(`${cmd} deleteRegistry ${localRegName}`, cwd); }); @@ -194,9 +194,9 @@ test(`should create and get an iam policy`, async (t) => { const localRegName = `${registryName}-get`; let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); + `${cmd} createRegistry ${localRegName} ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} setIamPolicy ${localRegName} ${localMember} ${localRole}`, cwd); + `${cmd} setIamPolicy ${localRegName} ${localMember} ${localRole}`, cwd); t.regex(output, new RegExp(`ETAG`)); output = await tools.runAsync(`${cmd} getIamPolicy ${localRegName}`, cwd); t.regex(output, new RegExp(`dpebot`)); @@ -206,7 +206,7 @@ test(`should create and get an iam policy`, async (t) => { test(`should create and delete a registry`, async (t) => { let output = await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); output = await tools.runAsync( - `${cmd} createRegistry ${registryName} ${topicName}`, cwd); + `${cmd} createRegistry ${registryName} ${topicName}`, cwd); t.regex(output, new RegExp(`Successfully created registry`)); output = await tools.runAsync(`${cmd} deleteRegistry ${registryName}`, cwd); t.regex(output, new RegExp(`Successfully deleted registry`)); diff --git a/iot/mqtt_example/package.json b/iot/mqtt_example/package.json index 5ffbe362b5..eca3faad33 100644 --- a/iot/mqtt_example/package.json +++ b/iot/mqtt_example/package.json @@ -6,13 +6,13 @@ "license": "Apache-2.0", "author": "Google Inc.", "dependencies": { - "@google-cloud/pubsub": "0.13.2", - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0", - "jsonwebtoken": "7.4.1", - "mqtt": "2.15.0", - "uuid": "3.1.0", - "yargs": "8.0.2" + "@google-cloud/pubsub": "0.16.4", + "@google-cloud/nodejs-repo-tools": "2.2.1", + "ava": "0.25.0", + "jsonwebtoken": "8.2.0", + "mqtt": "2.16.0", + "uuid": "3.2.1", + "yargs": "11.0.0" }, "devDependencies": {} } diff --git a/iot/scripts/package.json b/iot/scripts/package.json index 796f6c0939..cf5049af95 100644 --- a/iot/scripts/package.json +++ b/iot/scripts/package.json @@ -5,6 +5,6 @@ "author": "Google Inc.", "license": "Apache-2.0", "dependencies": { - "@google-cloud/pubsub": "0.12.0" + "@google-cloud/pubsub": "0.16.4" } } diff --git a/kms/keys.js b/kms/keys.js index 0a65ee5f37..902aa5dce5 100644 --- a/kms/keys.js +++ b/kms/keys.js @@ -1,4 +1,4 @@ - /** +/** * Copyright 2017, Google, Inc. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,13 +43,13 @@ function createKeyRing (projectId, locationId, keyRingId) { }; // Creates a new key ring - cloudkms.projects.locations.keyRings.create(request, (err, keyRing) => { + cloudkms.projects.locations.keyRings.create(request, (err, response) => { if (err) { console.log(err); return; } - console.log(`Key ring ${keyRing.name} created.`); + console.log(`Key ring ${response.data.name} created.`); }); }); // [END kms_create_keyring] @@ -82,7 +82,7 @@ function listKeyRings (projectId, locationId) { return; } - const keyRings = result.keyRings || []; + const keyRings = result.data.keyRings || []; if (keyRings.length) { keyRings.forEach((keyRing) => { @@ -121,12 +121,13 @@ function getKeyRing (projectId, locationId, keyRingId) { }; // Gets a key ring - cloudkms.projects.locations.keyRings.get(request, (err, keyRing) => { + cloudkms.projects.locations.keyRings.get(request, (err, response) => { if (err) { console.log(err); return; } + const keyRing = response.data; console.log(`Name: ${keyRing.name}`); console.log(`Created: ${new Date(keyRing.createTime)}`); }); @@ -164,8 +165,8 @@ function getKeyRingIamPolicy (projectId, locationId, keyRingId) { return; } - if (policy.bindings) { - policy.bindings.forEach((binding) => { + if (policy.data.bindings) { + policy.data.bindings.forEach((binding) => { if (binding.members && binding.members.length) { console.log(`${binding.role}:`); binding.members.forEach((member) => { @@ -217,7 +218,7 @@ function addMemberToKeyRingPolicy (projectId, locationId, keyRingId, member, rol return; } - policy = Object.assign({ bindings: [] }, policy); + policy = Object.assign({ bindings: [] }, policy.data); const index = policy.bindings.findIndex((binding) => binding.role === role); @@ -250,8 +251,8 @@ function addMemberToKeyRingPolicy (projectId, locationId, keyRingId, member, rol } console.log(`${member}/${role} combo added to policy for key ring ${keyRingId}.`); - if (policy.bindings) { - policy.bindings.forEach((binding) => { + if (policy.data.bindings) { + policy.data.bindings.forEach((binding) => { if (binding.members && binding.members.length) { console.log(`${binding.role}:`); binding.members.forEach((member) => { @@ -304,7 +305,7 @@ function removeMemberFromKeyRingPolicy (projectId, locationId, keyRingId, member return; } - policy = Object.assign({ bindings: [] }, policy); + policy = Object.assign({ bindings: [] }, policy.data); let index = policy.bindings.findIndex((binding) => binding.role === role); @@ -332,13 +333,14 @@ function removeMemberFromKeyRingPolicy (projectId, locationId, keyRingId, member }; // Removes the role/member combo from the policy of the key ring - cloudkms.projects.locations.keyRings.setIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.setIamPolicy(request, (err, response) => { if (err) { console.log(err); return; } console.log(`${member}/${role} combo removed from policy for key ring ${keyRingId}.`); + const policy = response.data; if (policy.bindings) { policy.bindings.forEach((binding) => { if (binding.members && binding.members.length) { @@ -391,12 +393,13 @@ function createCryptoKey (projectId, locationId, keyRingId, cryptoKeyId) { }; // Creates a new key ring - cloudkms.projects.locations.keyRings.cryptoKeys.create(request, (err, cryptoKey) => { + cloudkms.projects.locations.keyRings.cryptoKeys.create(request, (err, response) => { if (err) { console.log(err); return; } + const cryptoKey = response.data; console.log(`Key ${cryptoKey.name} created.`); }); }); @@ -433,7 +436,7 @@ function listCryptoKeys (projectId, locationId, keyRingId) { return; } - const cryptoKeys = result.cryptoKeys || []; + const cryptoKeys = result.data.cryptoKeys || []; if (cryptoKeys.length) { cryptoKeys.forEach((cryptoKey) => { @@ -498,13 +501,14 @@ function encrypt (projectId, locationId, keyRingId, cryptoKeyId, plaintextFileNa }; // Encrypts the file using the specified crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.encrypt(request, (err, result) => { + cloudkms.projects.locations.keyRings.cryptoKeys.encrypt(request, (err, response) => { if (err) { console.log(err); return; } // Writes the encrypted file to disk + const result = response.data; fs.writeFile(ciphertextFileName, Buffer.from(result.ciphertext, 'base64'), (err) => { if (err) { console.log(err); @@ -566,13 +570,14 @@ function decrypt (projectId, locationId, keyRingId, cryptoKeyId, ciphertextFileN }; // Dencrypts the file using the specified crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.decrypt(request, (err, result) => { + cloudkms.projects.locations.keyRings.cryptoKeys.decrypt(request, (err, response) => { if (err) { console.log(err); return; } // Writes the dencrypted file to disk + const result = response.data; fs.writeFile(plaintextFileName, Buffer.from(result.plaintext, 'base64'), (err) => { if (err) { console.log(err); @@ -614,12 +619,13 @@ function getCryptoKey (projectId, locationId, keyRingId, cryptoKeyId) { }; // Gets a crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.get(request, (err, cryptoKey) => { + cloudkms.projects.locations.keyRings.cryptoKeys.get(request, (err, response) => { if (err) { console.log(err); return; } + const cryptoKey = response.data; console.log(`Name: ${cryptoKey.name}:`); console.log(`Created: ${new Date(cryptoKey.createTime)}`); console.log(`Purpose: ${cryptoKey.purpose}`); @@ -665,12 +671,13 @@ function setPrimaryCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKey }; // Sets a crypto key's primary version - cloudkms.projects.locations.keyRings.cryptoKeys.updatePrimaryVersion(request, (err, cryptoKey) => { + cloudkms.projects.locations.keyRings.cryptoKeys.updatePrimaryVersion(request, (err, response) => { if (err) { console.log(err); return; } + const cryptoKey = response.data; console.log(`Set ${version} as primary version for crypto key ${cryptoKeyId}.\n`); console.log(`Name: ${cryptoKey.name}:`); console.log(`Created: ${new Date(cryptoKey.createTime)}`); @@ -710,12 +717,14 @@ function getCryptoKeyIamPolicy (projectId, locationId, keyRingId, cryptoKeyId) { }; // Gets the IAM policy of a crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, response) => { if (err) { console.log(err); return; } + console.log(response); + const policy = response.data; if (policy.bindings) { policy.bindings.forEach((binding) => { if (binding.members && binding.members.length) { @@ -766,13 +775,13 @@ function addMemberToCryptoKeyPolicy (projectId, locationId, keyRingId, cryptoKey }; // Gets the IAM policy of a crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, getResponse) => { if (err) { console.log(err); return; } - policy = Object.assign({ bindings: [] }, policy); + let policy = Object.assign({ bindings: [] }, getResponse.data); const index = policy.bindings.findIndex((binding) => binding.role === role); @@ -798,12 +807,13 @@ function addMemberToCryptoKeyPolicy (projectId, locationId, keyRingId, cryptoKey }; // Adds the member/role combo to the policy of the crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.setIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.cryptoKeys.setIamPolicy(request, (err, setResponse) => { if (err) { console.log(err); return; } + policy = setResponse.data; console.log(`${member}/${role} combo added to policy for crypto key ${cryptoKeyId}.`); if (policy.bindings) { policy.bindings.forEach((binding) => { @@ -856,13 +866,13 @@ function removeMemberFromCryptoKeyPolicy (projectId, locationId, keyRingId, cryp }; // Gets the IAM policy of a crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.cryptoKeys.getIamPolicy(request, (err, getResponse) => { if (err) { console.log(err); return; } - policy = Object.assign({ bindings: [] }, policy); + let policy = Object.assign({ bindings: [] }, getResponse.data); let index = policy.bindings.findIndex((binding) => binding.role === role); @@ -892,13 +902,14 @@ function removeMemberFromCryptoKeyPolicy (projectId, locationId, keyRingId, cryp console.log(JSON.stringify(request, null, 2)); // Removes the member/role combo from the policy of the crypto key - cloudkms.projects.locations.keyRings.cryptoKeys.setIamPolicy(request, (err, policy) => { + cloudkms.projects.locations.keyRings.cryptoKeys.setIamPolicy(request, (err, setResponse) => { if (err) { console.log(err); return; } console.log(`${member}/${role} combo removed from policy for crypto key ${cryptoKeyId}.`); + const policy = setResponse.data; if (policy.bindings) { policy.bindings.forEach((binding) => { if (binding.members && binding.members.length) { @@ -944,13 +955,13 @@ function createCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId) }; // Creates a new crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.create(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.create(request, (err, response) => { if (err) { console.log(err); return; } - console.log(`Crypto key version ${cryptoKeyVersion.name} created.`); + console.log(`Crypto key version ${response.data.name} created.`); }); }); // [END kms_create_cryptokey_version] @@ -989,7 +1000,7 @@ function listCryptoKeyVersions (projectId, locationId, keyRingId, cryptoKeyId) { return; } - const cryptoKeyVersions = result.cryptoKeyVersions || []; + const cryptoKeyVersions = result.data.cryptoKeyVersions || []; if (cryptoKeyVersions.length) { cryptoKeyVersions.forEach((version) => { @@ -1035,13 +1046,13 @@ function destroyCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Destroys a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.destroy(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.destroy(request, (err, response) => { if (err) { console.log(err); return; } - console.log(`Crypto key version ${cryptoKeyVersion.name} destroyed.`); + console.log(`Crypto key version ${response.data.name} destroyed.`); }); }); // [END kms_destroy_cryptokey_version] @@ -1077,13 +1088,13 @@ function restoreCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Restores a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.restore(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.restore(request, (err, response) => { if (err) { console.log(err); return; } - console.log(`Crypto key version ${cryptoKeyVersion.name} restored.`); + console.log(`Crypto key version ${response.data.name} restored.`); }); }); // [END kms_restore_cryptokey_version] @@ -1119,12 +1130,13 @@ function enableCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Gets a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.get(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.get(request, (err, getResponse) => { if (err) { console.log(err); return; } + const cryptoKeyVersion = getResponse.data; cryptoKeyVersion.state = 'ENABLED'; request = { @@ -1137,13 +1149,13 @@ function enableCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Enables a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.patch(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.patch(request, (err, patchResponse) => { if (err) { console.log(err); return; } - console.log(`Crypto key version ${cryptoKeyVersion.name} enabled.`); + console.log(`Crypto key version ${patchResponse.data.name} enabled.`); }); }); }); @@ -1180,12 +1192,13 @@ function disableCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Gets a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.get(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.get(request, (err, getResponse) => { if (err) { console.log(err); return; } + const cryptoKeyVersion = getResponse.data; cryptoKeyVersion.state = 'DISABLED'; request = { @@ -1198,13 +1211,13 @@ function disableCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, }; // Disables a crypto key version - cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.patch(request, (err, cryptoKeyVersion) => { + cloudkms.projects.locations.keyRings.cryptoKeys.cryptoKeyVersions.patch(request, (err, patchResponse) => { if (err) { console.log(err); return; } - console.log(`Crypto key version ${cryptoKeyVersion.name} disabled.`); + console.log(`Crypto key version ${patchResponse.data.name} disabled.`); }); }); }); @@ -1236,7 +1249,7 @@ function disableCryptoKeyVersion (projectId, locationId, keyRingId, cryptoKeyId, function buildAndAuthorizeService (callback) { // Imports the Google APIs client library - const google = require('googleapis'); + const google = require('googleapis').google; // Acquires credentials google.auth.getApplicationDefault((err, authClient) => { @@ -1378,10 +1391,10 @@ const cli = require(`yargs`) (opts) => removeMemberFromCryptoKeyPolicy(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.member, opts.role) ) .command( - `set-primary `, + `set-primary `, `Sets a crypto key's primary version.`, {}, - (opts) => setPrimaryCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.version) + (opts) => setPrimaryCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.keyVersion) ) .command( `versions `, @@ -1395,22 +1408,22 @@ const cli = require(`yargs`) (opts) => createCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey) ) .command( - `destroy `, + `destroy `, `Destroys a crypto key version.`, {}, - (opts) => destroyCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.version) + (opts) => destroyCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.keyVersion) ) .command( - `disable `, + `disable `, `Disables a crypto key version.`, {}, - (opts) => disableCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.version) + (opts) => disableCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.keyVersion) ) .command( - `enable `, + `enable `, `Enables a crypto key version.`, {}, - (opts) => enableCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.version) + (opts) => enableCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.keyVersion) ) .command( `list `, @@ -1419,10 +1432,10 @@ const cli = require(`yargs`) (opts) => listCryptoKeyVersions(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey) ) .command( - `restore `, + `restore `, `Restores a crypto key version.`, {}, - (opts) => restoreCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.version) + (opts) => restoreCryptoKeyVersion(opts.projectId, opts.location, opts.keyRing, opts.cryptoKey, opts.keyVersion) ); }, () => {} diff --git a/kms/package.json b/kms/package.json index 2e4e6dc924..13f19501ad 100644 --- a/kms/package.json +++ b/kms/package.json @@ -12,19 +12,20 @@ "node": ">=4.3.2" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + "test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js" }, "dependencies": { - "googleapis": "20.1.0", + "googleapis": "27.0.0", "safe-buffer": "5.1.1", - "yargs": "8.0.2" + "uuid": "^3.2.1", + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", - "proxyquire": "1.8.0" + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0", + "proxyquire": "2.0.1" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/kms/quickstart.js b/kms/quickstart.js index 5a8b7fae0a..cdd0eb5f47 100644 --- a/kms/quickstart.js +++ b/kms/quickstart.js @@ -17,7 +17,7 @@ // [START kms_quickstart] // Imports the Google APIs client library -const google = require('googleapis'); +const google = require('googleapis').google; // Your Google Cloud Platform project ID const projectId = 'YOUR_PROJECT_ID'; diff --git a/kms/system-test/keys.test.js b/kms/system-test/keys.test.js index c3c5346298..b7b1aa63cd 100644 --- a/kms/system-test/keys.test.js +++ b/kms/system-test/keys.test.js @@ -19,11 +19,12 @@ const fs = require(`fs`); const path = require(`path`); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); +const uuid = require(`uuid`); const cmd = `node keys.js`; const cwd = path.join(__dirname, `..`); -const keyRingName = `nodejs-docs-samples-test-ring`; -const keyNameOne = `nodejs-docs-samples-test-key-one`; +const keyRingName = `test-ring-${uuid.v4()}`; +const keyNameOne = `test-key-${uuid.v4()}`; const member = `allAuthenticatedUsers`; const role = `roles/viewer`; const projectId = process.env.GCLOUD_PROJECT; @@ -58,10 +59,11 @@ test.afterEach.always(tools.restoreConsole); // Key ring tests test.serial(`should create a key ring`, async (t) => { - t.plan(0); const output = await tools.runAsync(`${cmd} keyrings create "${keyRingName}"`, cwd); if (!output.includes(`KeyRing ${formattedKeyRingName} already exists`)) { t.regex(output, new RegExp(`Key ring ${formattedKeyRingName} created.`)); + } else { + t.pass(); } }); @@ -105,10 +107,11 @@ test.serial(`should revoke access to a key ring`, async (t) => { // Crypto key tests test.serial(`should create a key`, async (t) => { - t.plan(0); const output = await tools.runAsync(`${cmd} create "${keyRingName}" "${keyNameOne}"`, cwd); if (!output.includes(`CryptoKey ${formattedKeyName} already exists`)) { t.regex(output, new RegExp(`Key ${formattedKeyName} created.`)); + } else { + t.pass(); } }); diff --git a/language/slackbot/demo_bot.js b/language/slackbot/demo_bot.js index 76acf46767..6f8c5242e1 100755 --- a/language/slackbot/demo_bot.js +++ b/language/slackbot/demo_bot.js @@ -129,14 +129,14 @@ function startBot (bot, cerr) { token = token.replace(/\s/g, ''); bot - .spawn({ token: token }) - .startRTM((err) => { - if (err) { - console.error('Failed to start controller!'); - console.error(err); - process.exit(1); - } - }); + .spawn({ token: token }) + .startRTM((err) => { + if (err) { + console.error('Failed to start controller!'); + console.error(err); + process.exit(1); + } + }); } function handleSimpleReply (bot, message) { diff --git a/package.json b/package.json index 315d1a484d..af67faeb9e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "scripts": { "check": "yarn check --strict-semver --integrity", - "lint": "samples lint", + "lint": "repo-tools lint", "generate": "node ./scripts/generate", "pretest": "npm run lint && node ./scripts/clean coverage", "unit-cover": "nyc --cache npm test && nyc report --reporter=html", @@ -53,11 +53,11 @@ "update-dependencies": "./scripts/update-dependencies.sh" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "@google-cloud/storage": "1.2.1", - "ava": "0.21.0", - "nyc": "11.1.0", - "semistandard": "^11.0.0", - "shelljs": "0.7.8" + "@google-cloud/nodejs-repo-tools": "2.2.5", + "@google-cloud/storage": "1.6.0", + "ava": "0.25.0", + "nyc": "11.6.0", + "semistandard": "^12.0.1", + "shelljs": "0.8.1" } } diff --git a/scripts/update-dependencies.sh b/scripts/update-dependencies.sh index 2ad097fd27..7fb44e898a 100755 --- a/scripts/update-dependencies.sh +++ b/scripts/update-dependencies.sh @@ -20,6 +20,6 @@ # Update dependencies in node_modules (yarn upgrade) # Run tests, and skip that directory if they fail (yarn test -- --fail-fast) # If the directory has not been skipped, add 'yarn.lock' and 'package.json' to the current commit -find . -name "package.json" -not -path "*/node_modules/*" -execdir sh -c "ncu -u && ! git diff --quiet --exit-code . && yarn upgrade && yarn test -- --fail-fast && git add package.json yarn.lock" \; +find . -name "package.json" -not -path "*/node_modules/*" -execdir sh -c "ncu -u && ! git diff --quiet --exit-code . && npm install && npm test && git add package.json" \; # Note: this script deliberately avoids including broken dependencies. \ No newline at end of file diff --git a/storage-transfer/package.json b/storage-transfer/package.json index e9300d69b5..a18727d395 100644 --- a/storage-transfer/package.json +++ b/storage-transfer/package.json @@ -12,25 +12,25 @@ "node": ">=4" }, "scripts": { - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "unit-test": "samples test run --cmd ava -- -T 20s --verbose test/*.test.js", - "system-test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js", + "unit-test": "repo-tools test run --cmd ava -- -T 20s --verbose test/*.test.js", + "system-test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js", "test": "npm run unit-test && npm run system-test" }, "dependencies": { - "@google-cloud/storage": "1.3.0", - "googleapis": "21.3.0", - "moment": "2.18.1", + "@google-cloud/storage": "1.6.0", + "googleapis": "27.0.0", + "moment": "2.21.0", "safe-buffer": "5.1.1", - "yargs": "9.0.1" + "yargs": "11.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.22.0", - "proxyquire": "1.8.0", - "sinon": "3.3.0", - "uuid": "3.1.0" + "@google-cloud/nodejs-repo-tools": "2.2.5", + "ava": "0.25.0", + "proxyquire": "2.0.1", + "sinon": "4.4.8", + "uuid": "3.2.1" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/storage-transfer/test/transfer.test.js b/storage-transfer/test/transfer.test.js index 571d66c921..d1c9f8fffb 100644 --- a/storage-transfer/test/transfer.test.js +++ b/storage-transfer/test/transfer.test.js @@ -32,25 +32,37 @@ function getSample () { const transferOperationMock = {}; const storagetransferMock = { transferJobs: { - create: sinon.stub().yields(null, transferJobMock), - get: sinon.stub().yields(null, transferJobMock), - patch: sinon.stub().yields(null, transferJobMock), - list: sinon.stub().yields(null, { transferJobs: [transferJobMock] }) + create: sinon.stub().yields(null, { data: transferJobMock }), + get: sinon.stub().yields(null, { data: transferJobMock }), + patch: sinon.stub().yields(null, { data: transferJobMock }), + list: sinon.stub().yields(null, { + data: { + transferJobs: [transferJobMock] + } + }) }, transferOperations: { - get: sinon.stub().yields(null, transferOperationMock), - pause: sinon.stub().yields(null, transferOperationMock), - resume: sinon.stub().yields(null, transferOperationMock), - list: sinon.stub().yields(null, { operations: [transferOperationMock] }) + get: sinon.stub().yields(null, { data: transferOperationMock }), + pause: sinon.stub().yields(null, { data: transferOperationMock }), + resume: sinon.stub().yields(null, { data: transferOperationMock }), + list: sinon.stub().yields(null, { + data: { + operations: [transferOperationMock] + } + }) } }; - const googleapisMock = { + const googleMock = { storagetransfer: sinon.stub().returns(storagetransferMock), auth: { getApplicationDefault: sinon.stub().yields(null, {}) } }; + const googleapisMock = { + google: googleMock + }; + return { program: proxyquire(`../transfer`, { googleapis: googleapisMock, @@ -105,7 +117,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.createTransferJob({}, callback); @@ -147,7 +159,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.getTransferJob(jobName, callback); @@ -252,7 +264,7 @@ test.serial(`should handle auth error`, (t) => { field: `status`, value: `DISABLED` }; - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.updateTransferJob(options, callback); @@ -310,7 +322,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.listTransferJobs(callback); @@ -381,7 +393,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.listTransferOperations(undefined, callback); @@ -427,7 +439,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.getTransferOperation(jobName, callback); @@ -472,7 +484,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.pauseTransferOperation(jobName, callback); @@ -517,7 +529,7 @@ test.serial(`should handle auth error`, (t) => { const error = new Error(`error`); const sample = getSample(); const callback = sinon.stub(); - sample.mocks.googleapis.auth.getApplicationDefault.yields(error); + sample.mocks.googleapis.google.auth.getApplicationDefault.yields(error); sample.program.resumeTransferOperation(jobName, callback); diff --git a/storage-transfer/transfer.js b/storage-transfer/transfer.js index 5bed4dc7e5..894fc8a476 100644 --- a/storage-transfer/transfer.js +++ b/storage-transfer/transfer.js @@ -18,7 +18,7 @@ // [START all] // [START setup] var moment = require('moment'); -var google = require('googleapis'); +var google = require('googleapis').google; // Instantiate a storage client var storagetransfer = google.storagetransfer('v1'); @@ -104,11 +104,12 @@ function createTransferJob (options, callback) { storagetransfer.transferJobs.create({ auth: authClient, resource: transferJob - }, function (err, transferJob) { + }, function (err, response) { if (err) { return callback(err); } + const transferJob = response.data; console.log('Created transfer job: %s', transferJob.name); return callback(null, transferJob); }); @@ -133,11 +134,12 @@ function getTransferJob (jobName, callback) { auth: authClient, projectId: process.env.GCLOUD_PROJECT, jobName: jobName - }, function (err, transferJob) { + }, function (err, response) { if (err) { return callback(err); } + const transferJob = response.data; console.log('Found transfer job: %s', transferJob.name); return callback(null, transferJob); }); @@ -181,11 +183,12 @@ function updateTransferJob (options, callback) { auth: authClient, jobName: options.job, resource: patchRequest - }, function (err, transferJob) { + }, function (err, response) { if (err) { return callback(err); } + const transferJob = response.data; console.log('Updated transfer job: %s', transferJob.name); return callback(null, transferJob); }); @@ -208,15 +211,15 @@ function listTransferJobs (callback) { storagetransfer.transferJobs.list({ auth: authClient, filter: JSON.stringify({ project_id: process.env.GCLOUD_PROJECT }) - }, function (err, result) { + }, function (err, response) { if (err) { return callback(err); - } else if (!result.transferJobs) { + } else if (!response.data || !response.data.transferJobs) { return callback(null, []); } - console.log('Found %d jobs!', result.transferJobs.length); - return callback(null, result.transferJobs); + console.log('Found %d jobs!', response.data.transferJobs.length); + return callback(null, response.data.transferJobs); }); }); } @@ -247,15 +250,15 @@ function listTransferOperations (jobName, callback) { name: 'transferOperations', filter: JSON.stringify(filter), auth: authClient - }, function (err, result, apiResponse) { + }, function (err, response, apiResponse) { if (err) { return callback(err); - } else if (!result.operations) { + } else if (!response.data || !response.data.operations) { return callback(null, []); } - console.log('Found %d operations!', result.operations.length); - return callback(null, result.operations); + console.log('Found %d operations!', response.data.operations.length); + return callback(null, response.data.operations); }); }); } @@ -277,11 +280,12 @@ function getTransferOperation (transferOperationName, callback) { storagetransfer.transferOperations.get({ name: transferOperationName, auth: authClient - }, function (err, transferOperation) { + }, function (err, response) { if (err) { return callback(err); } + const transferOperation = response.data; console.log('Found transfer operation: %s', transferOperation); return callback(null, transferOperation); }); diff --git a/trace/package.json b/trace/package.json index 151d157176..01a275cf20 100644 --- a/trace/package.json +++ b/trace/package.json @@ -15,18 +15,18 @@ "scripts": { "deploy": "gcloud app deploy", "start": "node app.js", - "lint": "samples lint", + "lint": "repo-tools lint", "pretest": "npm run lint", - "test": "samples test app", - "e2e-test": "samples test deploy" + "test": "repo-tools test app", + "e2e-test": "repo-tools test deploy" }, "dependencies": { - "@google-cloud/trace-agent": "2.1.3", - "express": "4.15.4", - "got": "7.1.0" + "@google-cloud/trace-agent": "2.5.0", + "express": "4.16.2", + "got": "8.2.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17" + "@google-cloud/nodejs-repo-tools": "2.2.1" }, "cloud-repo-tools": { "test": {