From e0d6b3ce05512a0440f9a3932f901ab3c7789c6d Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Tue, 22 Nov 2016 13:15:05 -0800 Subject: [PATCH 1/3] Update storage samples. --- storage/README.md | 76 +++-- storage/acl.js | 344 +++++++++++------------ storage/buckets.js | 113 ++++---- storage/encryption.js | 106 ++++--- storage/files.js | 367 ++++++++++++------------- storage/package.json | 9 +- storage/quickstart.js | 13 +- storage/system-test/acl.test.js | 64 ++--- storage/system-test/buckets.test.js | 34 +-- storage/system-test/encryption.test.js | 47 ++-- storage/system-test/files.test.js | 80 +++--- storage/system-test/quickstart.test.js | 47 ++-- storage/test/acl.test.js | 74 ----- storage/test/buckets.test.js | 45 --- storage/test/encryption.test.js | 50 ---- storage/test/files.test.js | 62 ----- storage/test/quickstart.test.js | 44 --- 17 files changed, 593 insertions(+), 982 deletions(-) delete mode 100644 storage/test/acl.test.js delete mode 100644 storage/test/buckets.test.js delete mode 100644 storage/test/encryption.test.js delete mode 100644 storage/test/files.test.js delete mode 100644 storage/test/quickstart.test.js diff --git a/storage/README.md b/storage/README.md index b76f23caec..8776088a3b 100644 --- a/storage/README.md +++ b/storage/README.md @@ -33,7 +33,7 @@ amount of data at any time. View the [documentation][acl_docs] or the [source code][acl_code]. -__Usage:__ `node acl --help` +__Usage:__ `node acl.js --help` ``` Commands: @@ -49,26 +49,19 @@ Commands: remove-file-owner Removes a user from the ACL of a file. Options: - --help Show help [boolean] + --help Show help [boolean] Examples: - node acl print-bucket-acl my-bucket Prints the ACL for a bucket named "my-bucket". - node acl print-bucket-acl-for-user my-bucket bob@company.com Prints a user's ACL for a bucket named "my-bucket". - node acl add-bucket-owner my-bucket bob@company.com Adds "bob@company.com" as an owner of a bucket named - "my-bucket". - node acl remove-bucket-owner my-bucket bob@company.com Removes "bob@company.com" from the ACL of a bucket named - "my-bucket". - node acl add-bucket-default-owner my-bucket bob@company.com Adds "bob@company.com" as an owner in the default ACL of - a bucket named "my-bucket". - node acl remove-bucket-default-owner my-bucket Removes "bob@company.com" from the default ACL of a - bob@company.com bucket named "my-bucket". - node acl print-file-acl my-bucket file.txt Prints the ACL for a file named "file.txt". - node acl print-file-acl-for-user my-bucket file.txt Prints a user's ACL for a file named "file.txt". - bob@company.com - node acl add-file-owner my-bucket file.txt bob@company.com Adds "bob@company.com" as an owner of a file named - "file.txt". - node acl remove-file-owner my-bucket file.txt Removes "bob@company.com" from the ACL of a file named - bob@company.com "file.txt". + node acl.js print-bucket-acl my-bucket + node acl.js print-bucket-acl-for-user my-bucket bob@company.com + node acl.js add-bucket-owner my-bucket bob@company.com + node acl.js remove-bucket-owner my-bucket bob@company.com + node acl.js add-bucket-default-owner my-bucket bob@company.com + node acl.js remove-bucket-default-owner my-bucket bob@company.com + node acl.js print-file-acl my-bucket file.txt + node acl.js print-file-acl-for-user my-bucket file.txt bob@company.com + node acl.js add-file-owner my-bucket file.txt bob@company.com + node acl.js remove-file-owner my-bucket file.txt bob@company.com For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists ``` @@ -80,7 +73,7 @@ For more information, see https://cloud.google.com/storage/docs/access-control/c View the [documentation][buckets_docs] or the [source code][buckets_code]. -__Usage:__ `node buckets --help` +__Usage:__ `node buckets.js --help` ``` Commands: @@ -89,12 +82,12 @@ Commands: delete Deletes a bucket. Options: - --help Show help [boolean] + --help Show help [boolean] Examples: - node buckets create my-bucket Creates a new bucket named "my-bucket". - node buckets list Lists all buckets in the current project. - node buckets delete my-bucket Deletes a bucket named "my-bucket". + node buckets.js create my-bucket Creates a new bucket named "my-bucket". + node buckets.js list Lists all buckets in the current project. + node buckets.js delete my-bucket Deletes a bucket named "my-bucket". For more information, see https://cloud.google.com/storage/docs ``` @@ -106,7 +99,7 @@ For more information, see https://cloud.google.com/storage/docs View the [documentation][encryption_docs] or the [source code][encryption_code]. -__Usage:__ `node encryption --help` +__Usage:__ `node encryption.js --help` ``` Commands: @@ -119,12 +112,12 @@ Options: --help Show help [boolean] Examples: - node encryption generate-encryption-key Generate a sample encryption key. - node encryption upload my-bucket ./resources/test.txt Encrypts and uploads "resources/test.txt" to + node encryption.js generate-encryption-key Generate a sample encryption key. + node encryption.js upload my-bucket ./resources/test.txt Encrypts and uploads "resources/test.txt" to file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt". - node encryption download my-bucket file_encrypted.txt Decrypts and downloads + node encryption.js download my-bucket file_encrypted.txt Decrypts and downloads ./file.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt" to "./file.txt". - node encryption rotate my-bucket file_encrypted.txt Rotates encryptiong keys for + node encryption.js rotate my-bucket file_encrypted.txt Rotates encryption keys for QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q= "gs://my-bucket/file_encrypted.txt". For more information, see https://cloud.google.com/storage/docs @@ -137,7 +130,7 @@ For more information, see https://cloud.google.com/storage/docs View the [documentation][files_docs] or the [source code][files_code]. -__Usage:__ `node files --help` +__Usage:__ `node files.js --help` ``` Commands: @@ -158,19 +151,20 @@ Options: --help Show help [boolean] Examples: - node files list my-bucket Lists files in "my-bucket". - node files list my-bucket public/ Lists files in "my-bucket" filtered by prefix "public/". - node files upload my-bucket ./file.txt Uploads "./file.txt" to "my-bucket". - node files download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt". - node files delete my-bucket file.txt Deletes "gs://my-bucket/file.txt". - node files get-metadata my-bucket file.txt Gets the metadata for "gs://my-bucket/file.txt". - node files make-public my-bucket file.txt Makes "gs://my-bucket/file.txt" public. - node files move my-bucket file.txt file2.txt Renames "gs://my-bucket/file.txt" to - "gs://my-bucket/file2.txt". - node files copy my-bucket file.txt my-other-bucket file.txt Copies "gs://my-bucket/file.txt" to - "gs://my-other-bucket/file.txt". + node files.js list my-bucket Lists files in "my-bucket". + node files.js list my-bucket public/ Lists files in "my-bucket" filtered by prefix "public/". + node files.js upload my-bucket ./file.txt Uploads "./file.txt" to "my-bucket". + node files.js download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt". + node files.js delete my-bucket file.txt Deletes "gs://my-bucket/file.txt". + node files.js get-metadata my-bucket file.txt Gets the metadata for "gs://my-bucket/file.txt". + node files.js make-public my-bucket file.txt Makes "gs://my-bucket/file.txt" public. + node files.js move my-bucket file.txt file2.txt Renames "gs://my-bucket/file.txt" to + "gs://my-bucket/file2.txt". + node files.js copy my-bucket file.txt my-other-bucket Copies "gs://my-bucket/file.txt" to + file.txt "gs://my-other-bucket/file.txt". For more information, see https://cloud.google.com/storage/docs + ``` [files_docs]: https://cloud.google.com/storage/docs diff --git a/storage/acl.js b/storage/acl.js index 50bf805b54..10b6d88304 100644 --- a/storage/acl.js +++ b/storage/acl.js @@ -26,35 +26,32 @@ const Storage = require('@google-cloud/storage'); // [START storage_print_bucket_acl] -function printBucketAcl (bucketName, callback) { +function printBucketAcl (bucketName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Gets the ACL for the bucket - bucket.acl.get((err, aclObjects) => { - if (err) { - callback(err); - return; - } + return bucket.acl.get() + .then((results) => { + const acls = results[0]; - aclObjects.forEach((aclObject) => { - console.log(`${aclObject.role}: ${aclObject.entity}`); + acls.forEach((acl) => console.log(`${acl.role}: ${acl.entity}`)); + + return acls; }); - callback(); - }); } // [END storage_print_bucket_acl] // [START storage_print_bucket_acl_for_user] -function printBucketAclForUser (bucketName, userEmail, callback) { +function printBucketAclForUser (bucketName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); const options = { // Specify the user @@ -62,145 +59,121 @@ function printBucketAclForUser (bucketName, userEmail, callback) { }; // Gets the user's ACL for the bucket - bucket.acl.get(options, (err, aclObject) => { - if (err) { - callback(err); - return; - } - - console.log(`${aclObject.role}: ${aclObject.entity}`); - callback(); - }); + return bucket.acl.get(options) + .then((results) => { + const aclObject = results[0]; + + console.log(`${aclObject.role}: ${aclObject.entity}`); + + return aclObject; + }); } // [END storage_print_bucket_acl_for_user] // [START storage_add_bucket_owner] -function addBucketOwner (bucketName, userEmail, callback) { +function addBucketOwner (bucketName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Makes the user an owner of the bucket. You can use addAllUsers(), // addDomain(), addProject(), addGroup(), and addAllAuthenticatedUsers() // to grant access to different types of entities. You can also use "readers" // and "writers" to grant different roles. - bucket.acl.owners.addUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Added user ${userEmail} as an owner on bucket ${bucketName}.`); - callback(); - }); + return bucket.acl.owners.addUser(userEmail) + .then(() => { + console.log(`Added user ${userEmail} as an owner on bucket ${bucket.name}.`); + }); } // [END storage_add_bucket_owner] // [START storage_remove_bucket_owner] -function removeBucketOwner (bucketName, userEmail, callback) { +function removeBucketOwner (bucketName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Removes the user from the access control list of the bucket. You can use // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and // deleteAllAuthenticatedUsers() to remove access for different types of entities. - bucket.acl.owners.deleteUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Removed user ${userEmail} from bucket ${bucketName}.`); - callback(); - }); + return bucket.acl.owners.deleteUser(userEmail) + .then(() => { + console.log(`Removed user ${userEmail} from bucket ${bucket.name}.`); + }); } // [END storage_remove_bucket_owner] // [START storage_add_bucket_default_owner] -function addBucketDefaultOwner (bucketName, userEmail, callback) { +function addBucketDefaultOwner (bucketName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Makes the user an owner in the default ACL of the bucket. You can use // addAllUsers(), addDomain(), addProject(), addGroup(), and // addAllAuthenticatedUsers() to grant access to different types of entities. // You can also use "readers" and "writers" to grant different roles. - bucket.acl.default.owners.addUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Added user ${userEmail} as an owner on bucket ${bucketName}.`); - callback(); - }); + return bucket.acl.default.owners.addUser(userEmail) + .then(() => { + console.log(`Added user ${userEmail} as an owner on bucket ${bucket.name}.`); + }); } // [END storage_add_bucket_default_owner] // [START storage_remove_bucket_default_owner] -function removeBucketDefaultOwner (bucketName, userEmail, callback) { +function removeBucketDefaultOwner (bucketName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Removes the user from the access control list of the bucket. You can use // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and // deleteAllAuthenticatedUsers() to remove access for different types of entities. - bucket.acl.default.owners.deleteUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Removed user ${userEmail} from bucket ${bucketName}.`); - callback(); - }); + return bucket.acl.default.owners.deleteUser(userEmail) + .then(() => { + console.log(`Removed user ${userEmail} from bucket ${bucket.name}.`); + }); } // [END storage_remove_bucket_default_owner] // [START storage_print_file_acl] -function printFileAcl (bucketName, fileName, callback) { +function printFileAcl (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); // Gets the ACL for the file - file.acl.get((err, aclObjects) => { - if (err) { - callback(err); - return; - } + return file.acl.get() + .then((results) => { + const acls = results[0]; - aclObjects.forEach((aclObject) => { - console.log(`${aclObject.role}: ${aclObject.entity}`); + acls.forEach((acl) => console.log(`${acl.role}: ${acl.entity}`)); + + return acls; }); - callback(); - }); } // [END storage_print_file_acl] // [START storage_print_file_acl_for_user] -function printFileAclForUser (bucketName, fileName, userEmail, callback) { +function printFileAclForUser (bucketName, fileName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); @@ -211,25 +184,24 @@ function printFileAclForUser (bucketName, fileName, userEmail, callback) { }; // Gets the user's ACL for the file - file.acl.get(options, (err, aclObject) => { - if (err) { - callback(err); - return; - } - - console.log(`${aclObject.role}: ${aclObject.entity}`); - callback(); - }); + return file.acl.get(options) + .then((results) => { + const aclObject = results[0]; + + console.log(`${aclObject.role}: ${aclObject.entity}`); + + return aclObject; + }); } // [END storage_print_file_acl_for_user] // [START storage_add_file_owner] -function addFileOwner (bucketName, fileName, userEmail, callback) { +function addFileOwner (bucketName, fileName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); @@ -238,25 +210,20 @@ function addFileOwner (bucketName, fileName, userEmail, callback) { // addDomain(), addProject(), addGroup(), and addAllAuthenticatedUsers() // to grant access to different types of entities. You can also use "readers" // and "writers" to grant different roles. - file.acl.owners.addUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Added user ${userEmail} as an owner on file ${fileName}.`); - callback(); - }); + return file.acl.owners.addUser(userEmail) + .then(() => { + console.log(`Added user ${userEmail} as an owner on file ${file.name}.`); + }); } // [END storage_add_file_owner] // [START storage_remove_file_owner] -function removeFileOwner (bucketName, fileName, userEmail, callback) { +function removeFileOwner (bucketName, fileName, userEmail) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); @@ -264,85 +231,88 @@ function removeFileOwner (bucketName, fileName, userEmail, callback) { // Removes the user from the access control list of the file. You can use // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and // deleteAllAuthenticatedUsers() to remove access for different types of entities. - file.acl.owners.deleteUser(userEmail, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`Removed user ${userEmail} from file ${fileName}.`); - callback(); - }); + return file.acl.owners.deleteUser(userEmail) + .then(() => { + console.log(`Removed user ${userEmail} from file ${file.name}.`); + }); } // [END storage_remove_file_owner] -// The command-line program -const cli = require(`yargs`); -const utils = require(`../utils`); - -const program = module.exports = { - printBucketAcl: printBucketAcl, - printBucketAclForUser: printBucketAclForUser, - addBucketOwner: addBucketOwner, - removeBucketOwner: removeBucketOwner, - addBucketDefaultOwner: addBucketDefaultOwner, - removeBucketDefaultOwner: removeBucketDefaultOwner, - printFileAcl: printFileAcl, - printFileAclForUser: printFileAclForUser, - addFileOwner: addFileOwner, - removeFileOwner: removeFileOwner, - main: function (args) { - // Run the command-line program - cli.help().strict().parse(args).argv; - } -}; - -cli +require(`yargs`) .demand(1) - .command(`print-bucket-acl `, `Prints the ACL for a bucket.`, {}, (opts) => { - program.printBucketAcl(opts.bucketName, utils.noop); - }) - .command(`print-bucket-acl-for-user `, `Prints a user's ACL for a bucket.`, {}, (opts) => { - program.printBucketAclForUser(opts.bucketName, opts.userEmail, utils.noop); - }) - .command(`add-bucket-owner `, `Adds a user as an owner of a bucket.`, {}, (opts) => { - program.addBucketOwner(opts.bucketName, opts.userEmail, utils.noop); - }) - .command(`remove-bucket-owner `, `Removes a user from the ACL of a bucket.`, {}, (opts) => { - program.removeBucketOwner(opts.bucketName, opts.userEmail, utils.noop); - }) - .command(`add-bucket-default-owner `, `Adds a user as an owner in the default ACL of a bucket.`, {}, (opts) => { - program.addBucketDefaultOwner(opts.bucketName, opts.userEmail, utils.noop); - }) - .command(`remove-bucket-default-owner `, `Removes a user from the default ACL of a bucket.`, {}, (opts) => { - program.removeBucketDefaultOwner(opts.bucketName, opts.userEmail, utils.noop); - }) - .command(`print-file-acl `, `Prints the ACL for a file.`, {}, (opts) => { - program.printFileAcl(opts.bucketName, opts.fileName, utils.noop); - }) - .command(`print-file-acl-for-user `, `Prints a user's ACL for a file.`, {}, (opts) => { - program.printFileAclForUser(opts.bucketName, opts.fileName, opts.userEmail, utils.noop); - }) - .command(`add-file-owner `, `Adds a user as an owner of a file.`, {}, (opts) => { - program.addFileOwner(opts.bucketName, opts.fileName, opts.userEmail, utils.noop); - }) - .command(`remove-file-owner `, `Removes a user from the ACL of a file.`, {}, (opts) => { - program.removeFileOwner(opts.bucketName, opts.fileName, opts.userEmail, utils.noop); - }) - .example(`node $0 print-bucket-acl my-bucket`, `Prints the ACL for a bucket named "my-bucket".`) - .example(`node $0 print-bucket-acl-for-user my-bucket bob@company.com`, `Prints a user's ACL for a bucket named "my-bucket".`) - .example(`node $0 add-bucket-owner my-bucket bob@company.com`, `Adds "bob@company.com" as an owner of a bucket named "my-bucket".`) - .example(`node $0 remove-bucket-owner my-bucket bob@company.com`, `Removes "bob@company.com" from the ACL of a bucket named "my-bucket".`) - .example(`node $0 add-bucket-default-owner my-bucket bob@company.com`, `Adds "bob@company.com" as an owner in the default ACL of a bucket named "my-bucket".`) - .example(`node $0 remove-bucket-default-owner my-bucket bob@company.com`, `Removes "bob@company.com" from the default ACL of a bucket named "my-bucket".`) - .example(`node $0 print-file-acl my-bucket file.txt`, `Prints the ACL for a file named "file.txt".`) - .example(`node $0 print-file-acl-for-user my-bucket file.txt bob@company.com`, `Prints a user's ACL for a file named "file.txt".`) - .example(`node $0 add-file-owner my-bucket file.txt bob@company.com`, `Adds "bob@company.com" as an owner of a file named "file.txt".`) - .example(`node $0 remove-file-owner my-bucket file.txt bob@company.com`, `Removes "bob@company.com" from the ACL of a file named "file.txt".`) + .command( + `print-bucket-acl `, + `Prints the ACL for a bucket.`, + {}, + (opts) => printBucketAcl(opts.bucketName) + ) + .command( + `print-bucket-acl-for-user `, + `Prints a user's ACL for a bucket.`, + {}, + (opts) => printBucketAclForUser(opts.bucketName, opts.userEmail) + ) + .command( + `add-bucket-owner `, + `Adds a user as an owner of a bucket.`, + {}, + (opts) => addBucketOwner(opts.bucketName, opts.userEmail) + ) + .command( + `remove-bucket-owner `, + `Removes a user from the ACL of a bucket.`, + {}, + (opts) => removeBucketOwner(opts.bucketName, opts.userEmail) + ) + .command( + `add-bucket-default-owner `, + `Adds a user as an owner in the default ACL of a bucket.`, + {}, + (opts) => addBucketDefaultOwner(opts.bucketName, opts.userEmail) + ) + .command( + `remove-bucket-default-owner `, + `Removes a user from the default ACL of a bucket.`, + {}, + (opts) => removeBucketDefaultOwner(opts.bucketName, opts.userEmail) + ) + .command( + `print-file-acl `, + `Prints the ACL for a file.`, + {}, + (opts) => printFileAcl(opts.bucketName, opts.fileName) + ) + .command( + `print-file-acl-for-user `, + `Prints a user's ACL for a file.`, + {}, + (opts) => printFileAclForUser(opts.bucketName, opts.fileName, opts.userEmail) + ) + .command( + `add-file-owner `, + `Adds a user as an owner of a file.`, + {}, + (opts) => addFileOwner(opts.bucketName, opts.fileName, opts.userEmail) + ) + .command( + `remove-file-owner `, + `Removes a user from the ACL of a file.`, + {}, + (opts) => removeFileOwner(opts.bucketName, opts.fileName, opts.userEmail) + ) + .example(`node $0 print-bucket-acl my-bucket`) + .example(`node $0 print-bucket-acl-for-user my-bucket bob@company.com`) + .example(`node $0 add-bucket-owner my-bucket bob@company.com`) + .example(`node $0 remove-bucket-owner my-bucket bob@company.com`) + .example(`node $0 add-bucket-default-owner my-bucket bob@company.com`) + .example(`node $0 remove-bucket-default-owner my-bucket bob@company.com`) + .example(`node $0 print-file-acl my-bucket file.txt`) + .example(`node $0 print-file-acl-for-user my-bucket file.txt bob@company.com`) + .example(`node $0 add-file-owner my-bucket file.txt bob@company.com`) + .example(`node $0 remove-file-owner my-bucket file.txt bob@company.com`) .wrap(120) .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists`); - -if (module === require.main) { - program.main(process.argv.slice(2)); -} + .epilogue(`For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists`) + .help() + .strict() + .argv; diff --git a/storage/buckets.js b/storage/buckets.js index 53a20e03ce..f33f10c094 100644 --- a/storage/buckets.js +++ b/storage/buckets.js @@ -23,100 +23,85 @@ 'use strict'; -// [START all] const Storage = require('@google-cloud/storage'); // [START storage_create_bucket] -function createBucket (bucketName, callback) { +function createBucket (bucketName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // Creates a new bucket, e.g. "my-new-bucket" - storageClient.createBucket(bucketName, (err, bucket) => { - if (err) { - callback(err); - return; - } + return storage.createBucket(bucketName) + .then((results) => { + const bucket = results[0]; - console.log(`Bucket ${bucket.name} created.`); - callback(); - }); + console.log(`Bucket ${bucket.name} created.`); + + return bucket; + }); } // [END storage_create_bucket] // [START storage_list_buckets] -function listBuckets (callback) { +function listBuckets () { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // Lists all buckets in the current project - storageClient.getBuckets((err, buckets) => { - if (err) { - callback(err); - return; - } + return storage.getBuckets() + .then((results) => { + const buckets = results[0]; + + console.log('Buckets:'); + buckets.forEach((bucket) => console.log(bucket.name)); - console.log('Buckets:'); - buckets.forEach((bucket) => console.log(bucket.name)); - callback(); - }); + return buckets; + }); } // [END storage_list_buckets] // [START storage_delete_bucket] -function deleteBucket (bucketName, callback) { +function deleteBucket (bucketName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Deletes the bucket - bucket.delete((err) => { - if (err) { - callback(err); - return; - } - - console.log(`Bucket ${bucket.name} deleted.`); - callback(); - }); + return bucket.delete() + .then(() => { + console.log(`Bucket ${bucket.name} deleted.`); + }); } // [END storage_delete_bucket] -// [END all] - -// The command-line program -const cli = require(`yargs`); -const noop = require(`../utils`).noop; -const program = module.exports = { - createBucket: createBucket, - listBuckets: listBuckets, - deleteBucket: deleteBucket, - main: (args) => { - // Run the command-line program - cli.help().strict().parse(args).argv; - } -}; - -cli +require(`yargs`) .demand(1) - .command(`create `, `Creates a new bucket.`, {}, (options) => { - program.createBucket(options.bucket, noop); - }) - .command(`list`, `Lists all buckets in the current project.`, {}, () => { - program.listBuckets(noop); - }) - .command(`delete `, `Deletes a bucket.`, {}, (options) => { - program.deleteBucket(options.bucket, noop); - }) + .command( + `create `, + `Creates a new bucket.`, + {}, + (opts) => createBucket(opts.bucket) + ) + .command( + `list`, + `Lists all buckets in the current project.`, + {}, + listBuckets + ) + .command( + `delete `, + `Deletes a bucket.`, + {}, + (opts) => deleteBucket(opts.bucket) + ) .example(`node $0 create my-bucket`, `Creates a new bucket named "my-bucket".`) .example(`node $0 list`, `Lists all buckets in the current project.`) .example(`node $0 delete my-bucket`, `Deletes a bucket named "my-bucket".`) .wrap(120) .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/storage/docs`); - -if (module === require.main) { - program.main(process.argv.slice(2)); -} + .epilogue(`For more information, see https://cloud.google.com/storage/docs`) + .help() + .strict() + .argv; diff --git a/storage/encryption.js b/storage/encryption.js index 11c7dd2510..446a641aec 100644 --- a/storage/encryption.js +++ b/storage/encryption.js @@ -24,9 +24,10 @@ 'use strict'; const Storage = require('@google-cloud/storage'); -const crypto = require('crypto'); // [START storage_generate_encryption_key] +const crypto = require('crypto'); + /** * Generates a 256 bit (32 byte) AES encryption key and prints the base64 * representation. @@ -48,7 +49,7 @@ function generateEncryptionKey () { // [END storage_generate_encryption_key] // [START storage_upload_encrypted_file] -function uploadEncryptedFile (bucketName, srcFileName, destFileName, key, callback) { +function uploadEncryptedFile (bucketName, srcFileName, destFileName, key) { // Instantiates a client const storageClient = Storage(); @@ -64,20 +65,19 @@ function uploadEncryptedFile (bucketName, srcFileName, destFileName, key, callba // Encrypts and uploads a local file, e.g. "./local/path/to/file.txt". // The file will only be retrievable using the key used to upload it. - bucket.upload(srcFileName, config, (err, file) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${srcFileName} uploaded to ${file.name}.`); - callback(); - }); + return bucket.upload(srcFileName, config) + .then((results) => { + const file = results[0]; + + console.log(`File ${srcFileName} uploaded to ${file.name}.`); + + return file; + }); } // [END storage_upload_encrypted_file] // [START storage_download_encrypted_file] -function downloadEncryptedFile (bucketName, srcFileName, destFileName, key, callback) { +function downloadEncryptedFile (bucketName, srcFileName, destFileName, key) { // Instantiates a client const storageClient = Storage(); @@ -97,62 +97,52 @@ function downloadEncryptedFile (bucketName, srcFileName, destFileName, key, call // Descrypts and downloads the file. This can only be done with the key used // to encrypt and upload the file. - file.download(config, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${file.name} downloaded to ${destFileName}.`); - callback(); - }); + return file.download(config) + .then(() => { + console.log(`File ${file.name} downloaded to ${destFileName}.`); + }); } // [END storage_download_encrypted_file] // [START storage_rotate_encryption_key] -function rotateEncryptionKey (callback) { - callback(new Error('This is currently not available using the Cloud Client Library.')); +function rotateEncryptionKey () { + throw new Error('This is currently not available using the Cloud Client Library.'); } // [END storage_rotate_encryption_key] -// [END all] - -// The command-line program -const cli = require(`yargs`); -const noop = require(`../utils`).noop; - -const program = module.exports = { - generateEncryptionKey: generateEncryptionKey, - uploadEncryptedFile: uploadEncryptedFile, - downloadEncryptedFile: downloadEncryptedFile, - rotateEncryptionKey: rotateEncryptionKey, - main: (args) => { - // Run the command-line program - cli.help().strict().parse(args).argv; - } -}; - -cli + +require(`yargs`) .demand(1) - .command(`generate-encryption-key`, `Generate a sample encryption key.`, {}, () => { - program.generateEncryptionKey(); - }) - .command(`upload `, `Encrypts and uploads a file.`, {}, (opts) => { - program.uploadEncryptedFile(opts.bucketName, opts.srcFileName, opts.destFileName, opts.key, noop); - }) - .command(`download `, `Decrypts and downloads a file.`, {}, (opts) => { - program.downloadEncryptedFile(opts.bucketName, opts.srcFileName, opts.destFileName, opts.key, noop); - }) - .command(`rotate `, `Rotates encryption keys for a file.`, {}, () => { - program.rotateEncryptionKey(noop); - }) + .command( + `generate-encryption-key`, + `Generate a sample encryption key.`, + {}, + generateEncryptionKey + ) + .command( + `upload `, + `Encrypts and uploads a file.`, + {}, + (opts) => uploadEncryptedFile(opts.bucketName, opts.srcFileName, opts.destFileName, opts.key) + ) + .command( + `download `, + `Decrypts and downloads a file.`, + {}, + (opts) => downloadEncryptedFile(opts.bucketName, opts.srcFileName, opts.destFileName, opts.key) + ) + .command( + `rotate `, + `Rotates encryption keys for a file.`, + {}, + rotateEncryptionKey + ) .example(`node $0 generate-encryption-key`, `Generate a sample encryption key.`) .example(`node $0 upload my-bucket ./resources/test.txt file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q=`, `Encrypts and uploads "resources/test.txt" to "gs://my-bucket/file_encrypted.txt".`) .example(`node $0 download my-bucket file_encrypted.txt ./file.txt QxhqaZEqBGVTW55HhQw9Q=`, `Decrypts and downloads "gs://my-bucket/file_encrypted.txt" to "./file.txt".`) .example(`node $0 rotate my-bucket file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q=`, `Rotates encryption keys for "gs://my-bucket/file_encrypted.txt".`) .wrap(120) .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/storage/docs`); - -if (module === require.main) { - program.main(process.argv.slice(2)); -} + .epilogue(`For more information, see https://cloud.google.com/storage/docs`) + .help() + .strict() + .argv; diff --git a/storage/files.js b/storage/files.js index d08fddae95..eb84cecf79 100644 --- a/storage/files.js +++ b/storage/files.js @@ -26,34 +26,33 @@ const Storage = require('@google-cloud/storage'); // [START storage_list_files] -function listFiles (bucketName, callback) { +function listFiles (bucketName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Lists files in the bucket - bucket.getFiles((err, files) => { - if (err) { - callback(err); - return; - } + return bucket.getFiles() + .then((results) => { + const files = results[0]; + + console.log('Files:'); + files.forEach((file) => console.log(file.name)); - console.log('Files:'); - files.forEach((file) => console.log(file.name)); - callback(); - }); + return files; + }); } // [END storage_list_files] // [START storage_list_files_with_prefix] -function listFilesByPrefix (bucketName, prefix, delimiter, callback) { +function listFilesByPrefix (bucketName, prefix, delimiter) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); /** * This can be used to list all blobs in a "folder", e.g. "public/". @@ -82,47 +81,45 @@ function listFilesByPrefix (bucketName, prefix, delimiter, callback) { } // Lists files in the bucket, filtered by a prefix - bucket.getFiles(options, (err, files) => { - if (err) { - callback(err); - return; - } + return bucket.getFiles(options) + .then((results) => { + const files = results[0]; - console.log('Files:'); - files.forEach((file) => console.log(file.name)); - callback(); - }); + console.log('Files:'); + files.forEach((file) => console.log(file.name)); + + return files; + }); } // [END storage_list_files_with_prefix] // [START storage_upload_file] -function uploadFile (bucketName, fileName, callback) { +function uploadFile (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // Uploads a local file to the bucket, e.g. "./local/path/to/file.txt" - bucket.upload(fileName, (err, file) => { - if (err) { - callback(err); - return; - } + return bucket.upload(fileName) + .then((results) => { + const file = results[0]; + + console.log(`File ${file.name} uploaded.`); - console.log(`File ${file.name} uploaded.`); - callback(); - }); + return file; + }); } // [END storage_upload_file] // [START storage_download_file] -function downloadFile (bucketName, srcFileName, destFileName, callback) { +function downloadFile (bucketName, srcFileName, destFileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(srcFileName); @@ -133,115 +130,99 @@ function downloadFile (bucketName, srcFileName, destFileName, callback) { }; // Downloads the file - file.download(options, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${file.name} downloaded to ${destFileName}.`); - callback(); - }); + return file.download(options) + .then(() => { + console.log(`File ${file.name} downloaded to ${destFileName}.`); + }); } // [END storage_download_file] // [START storage_delete_file] -function deleteFile (bucketName, fileName, callback) { +function deleteFile (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); // Deletes the file from the bucket - file.delete((err) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${fileName} deleted.`); - callback(); - }); + return file.delete() + .then(() => { + console.log(`File ${fileName} deleted.`); + }); } // [END storage_delete_file] // [START storage_get_metadata] -function getMetadata (bucketName, fileName, callback) { +function getMetadata (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); // Gets the metadata for the file - file.getMetadata((err, metadata) => { - if (err) { - callback(err); - return; - } - - console.log(`File: ${metadata.name}`); - console.log(`Bucket: ${metadata.bucket}`); - console.log(`Storage class: ${metadata.storageClass}`); - console.log(`ID: ${metadata.id}`); - console.log(`Size: ${metadata.size}`); - console.log(`Updated: ${metadata.updated}`); - console.log(`Generation: ${metadata.generation}`); - console.log(`Metageneration: ${metadata.metageneration}`); - console.log(`Etag: ${metadata.etag}`); - console.log(`Owner: ${metadata.owner}`); - console.log(`Component count: ${metadata.component_count}`); - console.log(`Crc32c: ${metadata.crc32c}`); - console.log(`md5Hash: ${metadata.md5Hash}`); - console.log(`Cache-control: ${metadata.cacheControl}`); - console.log(`Content-type: ${metadata.contentType}`); - console.log(`Content-disposition: ${metadata.contentDisposition}`); - console.log(`Content-encoding: ${metadata.contentEncoding}`); - console.log(`Content-language: ${metadata.contentLanguage}`); - console.log(`Metadata: ${metadata.metadata}`); - callback(); - }); + return file.getMetadata() + .then((results) => { + const metadata = results[0]; + + console.log(`File: ${metadata.name}`); + console.log(`Bucket: ${metadata.bucket}`); + console.log(`Storage class: ${metadata.storageClass}`); + console.log(`ID: ${metadata.id}`); + console.log(`Size: ${metadata.size}`); + console.log(`Updated: ${metadata.updated}`); + console.log(`Generation: ${metadata.generation}`); + console.log(`Metageneration: ${metadata.metageneration}`); + console.log(`Etag: ${metadata.etag}`); + console.log(`Owner: ${metadata.owner}`); + console.log(`Component count: ${metadata.component_count}`); + console.log(`Crc32c: ${metadata.crc32c}`); + console.log(`md5Hash: ${metadata.md5Hash}`); + console.log(`Cache-control: ${metadata.cacheControl}`); + console.log(`Content-type: ${metadata.contentType}`); + console.log(`Content-disposition: ${metadata.contentDisposition}`); + console.log(`Content-encoding: ${metadata.contentEncoding}`); + console.log(`Content-language: ${metadata.contentLanguage}`); + console.log(`Metadata: ${metadata.metadata}`); + + return metadata; + }); } // [END storage_get_metadata] // [START storage_make_public] -function makePublic (bucketName, fileName, callback) { +function makePublic (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); // Makes the file public - file.makePublic((err) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${file.name} is now public.`); - callback(); - }); + return file.makePublic() + .then(() => { + console.log(`File ${file.name} is now public.`); + }); } // [END storage_make_public] // [START storage_generate_signed_url] -function generateSignedUrl (bucketName, fileName, callback) { +function generateSignedUrl (bucketName, fileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(fileName); @@ -253,126 +234,127 @@ function generateSignedUrl (bucketName, fileName, callback) { }; // Get a signed URL for the file - file.getSignedUrl(options, (err, url) => { - if (err) { - callback(err); - return; - } + return file.getSignedUrl(options) + .then((results) => { + const url = results[0]; - console.log(`The signed url for ${file.name} is ${url}.`); - callback(); - }); + console.log(`The signed url for ${file.name} is ${url}.`); + + return url; + }); } // [END storage_generate_signed_url] // [START storage_move_file] -function moveFile (bucketName, srcFileName, destFileName, callback) { +function moveFile (bucketName, srcFileName, destFileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(bucketName); + const bucket = storage.bucket(bucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(srcFileName); // Moves the file within the bucket - file.move(destFileName, (err) => { - if (err) { - callback(err); - return; - } - - console.log(`File ${file.name} moved to ${destFileName}.`); - callback(); - }); + return file.move(destFileName) + .then(() => { + console.log(`File ${file.name} moved to ${destFileName}.`); + }); } // [END storage_move_file] // [START storage_copy_file] -function copyFile (srcBucketName, srcFileName, destBucketName, destFileName, callback) { +function copyFile (srcBucketName, srcFileName, destBucketName, destFileName) { // Instantiates a client - const storageClient = Storage(); + const storage = Storage(); // References an existing bucket, e.g. "my-bucket" - const bucket = storageClient.bucket(srcBucketName); + const bucket = storage.bucket(srcBucketName); // References an existing file, e.g. "file.txt" const file = bucket.file(srcFileName); // References another existing bucket, e.g. "my-other-bucket" - const destBucket = storageClient.bucket(destBucketName); + const destBucket = storage.bucket(destBucketName); // Creates a reference to a destination file, e.g. "file.txt" const destFile = destBucket.file(destFileName); // Copies the file to the other bucket - file.copy(destFile, (err, file) => { - if (err) { - callback(err); - return; - } + return file.copy(destFile) + .then((results) => { + const file = results[0]; + + console.log(`File ${srcFileName} copied to ${file.name} in ${destBucket.name}.`); - console.log(`File ${srcFileName} copied to ${file.name} in ${destBucket.name}.`); - callback(); - }); + return file; + }); } // [END storage_copy_file] -// The command-line program -const cli = require(`yargs`); -const noop = require(`../utils`).noop; - -const program = module.exports = { - listFiles: listFiles, - listFilesByPrefix: listFilesByPrefix, - uploadFile: uploadFile, - downloadFile: downloadFile, - deleteFile: deleteFile, - getMetadata: getMetadata, - makePublic: makePublic, - generateSignedUrl: generateSignedUrl, - moveFile: moveFile, - copyFile: copyFile, - main: (args) => { - // Run the command-line program - cli.help().strict().parse(args).argv; - } -}; - -cli +require(`yargs`) .demand(1) - .command(`list [prefix] [delimiter]`, `Lists files in a bucket, optionally filtering by a prefix.`, {}, (opts) => { - if (opts.prefix) { - program.listFilesByPrefix(opts.bucketName, opts.prefix, opts.delimiter, noop); - } else { - program.listFiles(opts.bucketName, noop); + .command( + `list [prefix] [delimiter]`, + `Lists files in a bucket, optionally filtering by a prefix.`, + {}, + (opts) => { + if (opts.prefix) { + listFilesByPrefix(opts.bucketName, opts.prefix, opts.delimiter); + } else { + listFiles(opts.bucketName); + } } - }) - .command(`upload `, `Uploads a local file to a bucket.`, {}, (opts) => { - program.uploadFile(opts.bucketName, opts.srcFileName, noop); - }) - .command(`download `, `Downloads a file from a bucket.`, {}, (opts) => { - program.downloadFile(opts.bucketName, opts.srcFileName, opts.destFileName, noop); - }) - .command(`delete `, `Deletes a file from a bucket.`, {}, (opts) => { - program.deleteFile(opts.bucketName, opts.fileName, noop); - }) - .command(`get-metadata `, `Gets the metadata for a file.`, {}, (opts) => { - program.getMetadata(opts.bucketName, opts.fileName, noop); - }) - .command(`make-public `, `Makes a file public.`, {}, (opts) => { - program.makePublic(opts.bucketName, opts.fileName, noop); - }) - .command(`generate-signed-url `, `Generates a signed URL for a file.`, {}, (opts) => { - program.generateSignedUrl(opts.bucketName, opts.fileName, noop); - }) - .command(`move `, `Moves a file to a new location within the same bucket, i.e. rename the file.`, {}, (opts) => { - program.moveFile(opts.bucketName, opts.srcFileName, opts.destFileName, noop); - }) - .command(`copy `, `Copies a file in a bucket to another bucket.`, {}, (opts) => { - program.copyFile(opts.srcBucketName, opts.srcFileName, opts.destBucketName, opts.destFileName, noop); - }) + ) + .command( + `upload `, + `Uploads a local file to a bucket.`, + {}, + (opts) => uploadFile(opts.bucketName, opts.srcFileName) + ) + .command( + `download `, + `Downloads a file from a bucket.`, + {}, + (opts) => downloadFile(opts.bucketName, opts.srcFileName, opts.destFileName) + ) + .command( + `delete `, + `Deletes a file from a bucket.`, + {}, + (opts) => deleteFile(opts.bucketName, opts.fileName) + ) + .command( + `get-metadata `, + `Gets the metadata for a file.`, + {}, + (opts) => getMetadata(opts.bucketName, opts.fileName) + ) + .command( + `make-public `, + `Makes a file public.`, + {}, + (opts) => makePublic(opts.bucketName, opts.fileName) + ) + .command( + `generate-signed-url `, + `Generates a signed URL for a file.`, + {}, + (opts) => generateSignedUrl(opts.bucketName, opts.fileName) + ) + .command( + `move `, + `Moves a file to a new location within the same bucket, i.e. rename the file.`, + {}, + (opts) => moveFile(opts.bucketName, opts.srcFileName, opts.destFileName) + ) + .command( + `copy `, + `Copies a file in a bucket to another bucket.`, + {}, + (opts) => copyFile(opts.srcBucketName, opts.srcFileName, opts.destBucketName, opts.destFileName) + ) .example(`node $0 list my-bucket`, `Lists files in "my-bucket".`) .example(`node $0 list my-bucket public/`, `Lists files in "my-bucket" filtered by prefix "public/".`) .example(`node $0 upload my-bucket ./file.txt`, `Uploads "./file.txt" to "my-bucket".`) @@ -384,8 +366,7 @@ cli .example(`node $0 copy my-bucket file.txt my-other-bucket file.txt`, `Copies "gs://my-bucket/file.txt" to "gs://my-other-bucket/file.txt".`) .wrap(120) .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/storage/docs`); - -if (module === require.main) { - program.main(process.argv.slice(2)); -} + .epilogue(`For more information, see https://cloud.google.com/storage/docs`) + .help() + .strict() + .argv; diff --git a/storage/package.json b/storage/package.json index 41fb6a577a..734f95803b 100644 --- a/storage/package.json +++ b/storage/package.json @@ -9,13 +9,12 @@ "system-test": "cd ..; npm run st -- storage/system-test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "0.4.0", - "googleapis": "14.2.0", - "moment": "2.15.1", - "yargs": "6.4.0" + "@google-cloud/storage": "0.5.0", + "googleapis": "15.0.0", + "moment": "2.17.1", + "yargs": "6.5.0" }, "devDependencies": { - "mocha": "3.1.0", "node-uuid": "1.4.7" }, "engines": { diff --git a/storage/quickstart.js b/storage/quickstart.js index dca56ed1c9..10606cb442 100644 --- a/storage/quickstart.js +++ b/storage/quickstart.js @@ -31,12 +31,9 @@ const storageClient = Storage({ const bucketName = 'my-new-bucket'; // Creates the new bucket -storageClient.createBucket(bucketName, (err, bucket) => { - if (err) { - console.error(err); - return; - } - - console.log(`Bucket ${bucket.name} created.`); -}); +storageClient.createBucket(bucketName) + .then((results) => { + const bucket = results[0]; + console.log(`Bucket ${bucket.name} created.`); + }); // [END storage_quickstart] diff --git a/storage/system-test/acl.test.js b/storage/system-test/acl.test.js index 78c98878fc..c91cb8d4c4 100644 --- a/storage/system-test/acl.test.js +++ b/storage/system-test/acl.test.js @@ -22,45 +22,37 @@ const run = require(`../../utils`).run; const cwd = path.join(__dirname, `..`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; +const bucket = storage.bucket(bucketName); const userEmail = `00b4903a973860a50828a620e09dde96aae6122ca4f0835bd469384659f1a5b8`; const fileName = `test.txt`; const filePath = path.join(__dirname, `../resources`, fileName); const cmd = `node acl.js`; describe('storage:acl', () => { - before((done) => { - storage.createBucket(bucketName, (err, bucket) => { - assert.ifError(err); - bucket.upload(filePath, done); - }); - }); + before(() => bucket.create().then((results) => results[0].upload(filePath))); - after((done) => { - storage.bucket(bucketName).file(fileName).delete(() => { - // Ignore error - setTimeout(() => { - storage.bucket(bucketName).delete(() => { - // Ignore error - done(); - }); - }, 2000); - }); + after(() => { + // Try deleting all files twice, just to make sure. Ignore any errors. + return bucket.deleteFiles({ force: true }) + .then(() => bucket.deleteFiles({ force: true }), () => {}) + .then(() => bucket.delete(), () => {}) + .catch(() => {}); }); it(`should print acl for a bucket`, () => { const output = run(`${cmd} print-bucket-acl ${bucketName}`, cwd); - assert.equal(/OWNER: project-editors-/.test(output), true); - assert.equal(/OWNER: project-owners-/.test(output), true); - assert.equal(/READER: project-viewers-/.test(output), true); + assert.equal(output.includes(`OWNER: project-editors-`), true); + assert.equal(output.includes(`OWNER: project-owners-`), true); + assert.equal(output.includes(`READER: project-viewers-`), true); }); - it(`should print a user's acl for a bucket`, (done) => { - storage.bucket(bucketName).acl.readers.addUser(userEmail, (err) => { - assert.ifError(err); - const output = run(`${cmd} print-bucket-acl-for-user ${bucketName} ${userEmail}`, cwd); - assert.equal(output, `READER: user-${userEmail}`); - storage.bucket(bucketName).acl.readers.deleteUser(userEmail, done); - }); + it(`should print a user's acl for a bucket`, () => { + return bucket.acl.readers.addUser(userEmail) + .then(() => { + const output = run(`${cmd} print-bucket-acl-for-user ${bucketName} ${userEmail}`, cwd); + assert.equal(output, `READER: user-${userEmail}`); + return bucket.acl.readers.deleteUser(userEmail); + }); }); it(`should add a user as an owner on a bucket`, () => { @@ -85,18 +77,18 @@ describe('storage:acl', () => { it(`should print acl for a file`, () => { const output = run(`${cmd} print-file-acl ${bucketName} ${fileName}`, cwd); - assert.equal(/OWNER: project-editors-/.test(output), true); - assert.equal(/OWNER: project-owners-/.test(output), true); - assert.equal(/READER: project-viewers-/.test(output), true); + assert.equal(output.includes(`OWNER: project-editors-`), true); + assert.equal(output.includes(`OWNER: project-owners-`), true); + assert.equal(output.includes(`READER: project-viewers-`), true); }); - it(`should print a user's acl for a file`, (done) => { - storage.bucket(bucketName).file(fileName).acl.readers.addUser(userEmail, (err) => { - assert.ifError(err); - const output = run(`${cmd} print-file-acl-for-user ${bucketName} ${fileName} ${userEmail}`, cwd); - assert.equal(output, `READER: user-${userEmail}`); - storage.bucket(bucketName).file(fileName).acl.readers.deleteUser(userEmail, done); - }); + it(`should print a user's acl for a file`, () => { + return bucket.file(fileName).acl.readers.addUser(userEmail) + .then(() => { + const output = run(`${cmd} print-file-acl-for-user ${bucketName} ${fileName} ${userEmail}`, cwd); + assert.equal(output, `READER: user-${userEmail}`); + return bucket.file(fileName).acl.readers.deleteUser(userEmail); + }); }); it(`should add a user as an owner on a bucket`, () => { diff --git a/storage/system-test/buckets.test.js b/storage/system-test/buckets.test.js index f53ba56ee4..03d83affc9 100644 --- a/storage/system-test/buckets.test.js +++ b/storage/system-test/buckets.test.js @@ -22,43 +22,37 @@ const run = require(`../../utils`).run; const cwd = path.join(__dirname, `..`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; +const bucket = storage.bucket(bucketName); const cmd = `node buckets.js`; describe('storage:buckets', () => { - after((done) => { - storage.bucket(bucketName).delete(() => { - // Ignore any error - done(); - }); - }); + after(() => bucket.delete().catch(() => {})); - it(`should create a bucket`, (done) => { + it(`should create a bucket`, () => { const output = run(`${cmd} create ${bucketName}`, cwd); assert.equal(output, `Bucket ${bucketName} created.`); - storage.bucket(bucketName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, true); - done(); - }); + return bucket.exists() + .then((results) => { + assert.equal(results[0], true); + }); }); it(`should list buckets`, (done) => { // Listing is eventually consistent. Give the indexes time to update. setTimeout(() => { const output = run(`${cmd} list`, cwd); - assert.notEqual(output.indexOf(`Buckets:`), -1); - assert.notEqual(output.indexOf(bucketName), -1); + assert.equal(output.includes(`Buckets:`), true); + assert.equal(output.includes(bucketName), true); done(); }, 5000); }); - it(`should delete a bucket`, (done) => { + it(`should delete a bucket`, () => { const output = run(`${cmd} delete ${bucketName}`, cwd); assert.equal(output, `Bucket ${bucketName} deleted.`); - storage.bucket(bucketName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, false); - done(); - }); + return bucket.exists() + .then((results) => { + assert.equal(results[0], false); + }); }); }); diff --git a/storage/system-test/encryption.test.js b/storage/system-test/encryption.test.js index c654a3c6dd..233912b8ce 100644 --- a/storage/system-test/encryption.test.js +++ b/storage/system-test/encryption.test.js @@ -17,13 +17,13 @@ const fs = require('fs'); const path = require('path'); -const program = require('../encryption'); const run = require(`../../utils`).run; const storage = require('@google-cloud/storage')(); const uuid = require('node-uuid'); const cwd = path.join(__dirname, `..`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; +const bucket = storage.bucket(bucketName); const cmd = `node encryption.js`; const fileName = `test.txt`; @@ -33,52 +33,43 @@ const downloadFilePath = path.join(__dirname, `../resources/downloaded.txt`); describe('storage:encryption', () => { let key; - before((done) => { - // Create an encryption key to use throughout the test - key = program.generateEncryptionKey(); - // Create a test bucket - storage.createBucket(bucketName, done); - }); + before(() => bucket.create(bucketName)); - after((done) => { + after(() => { try { // Delete the downloaded file fs.unlinkSync(downloadFilePath); } catch (err) { console.log(err); } - // Delete any files that were uploaded - storage.bucket(bucketName).deleteFiles({ force: true }, (err) => { - assert.ifError(err); - // Delete the test bucket - storage.bucket(bucketName).delete(done); - }); + // Try deleting all files twice, just to make sure. Ignore any errors. + return bucket.deleteFiles({ force: true }) + .then(() => bucket.deleteFiles({ force: true }), () => {}) + .then(() => bucket.delete(), () => {}) + .catch(() => {}); }); it(`should generate a key`, () => { const output = run(`${cmd} generate-encryption-key`, cwd); - assert.notEqual(output.indexOf(`Base 64 encoded encryption key:`), -1); + assert.equal(output.includes(`Base 64 encoded encryption key:`), true); + const test = /^Base 64 encoded encryption key: (.+)$/; + key = output.match(test)[1]; }); - it(`should upload a file`, (done) => { + it(`should upload a file`, () => { const output = run(`${cmd} upload ${bucketName} ${filePath} ${fileName} ${key}`, cwd); assert.equal(output, `File ${filePath} uploaded to ${fileName}.`); - storage.bucket(bucketName).file(fileName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, true); - done(); - }); + return bucket.file(fileName).exists() + .then((results) => { + assert.equal(results[0], true); + }); }); - it(`should download a file`, (done) => { + it(`should download a file`, () => { const output = run(`${cmd} download ${bucketName} ${fileName} ${downloadFilePath} ${key}`, cwd); assert.equal(output, `File ${fileName} downloaded to ${downloadFilePath}.`); - storage.bucket(bucketName).file(fileName).exists((err, exists) => { - assert.ifError(err); - assert.doesNotThrow(() => { - fs.statSync(downloadFilePath); - }); - done(); + assert.doesNotThrow(() => { + fs.statSync(downloadFilePath); }); }); diff --git a/storage/system-test/files.test.js b/storage/system-test/files.test.js index 02e55c6463..b59124c41a 100644 --- a/storage/system-test/files.test.js +++ b/storage/system-test/files.test.js @@ -23,6 +23,7 @@ const run = require(`../../utils`).run; const cwd = path.join(__dirname, `..`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; +const bucket = storage.bucket(bucketName); const fileName = `test.txt`; const movedFileName = `test2.txt`; const copiedFileName = `test3.txt`; @@ -31,30 +32,28 @@ const downloadFilePath = path.join(__dirname, `../resources/downloaded.txt`); const cmd = `node files.js`; describe('storage:files', () => { - before((done) => { - storage.createBucket(bucketName, done); - }); + before(() => bucket.create()); - after((done) => { + after(() => { try { fs.unlinkSync(downloadFilePath); } catch (err) { console.log(err); } - storage.bucket(bucketName).deleteFiles({ force: true }, (err) => { - assert.ifError(err); - setTimeout(() => storage.bucket(bucketName).delete(done), 2000); - }); + // Try deleting all files twice, just to make sure. Ignore any errors. + return bucket.deleteFiles({ force: true }) + .then(() => bucket.deleteFiles({ force: true }), () => {}) + .then(() => bucket.delete(), () => {}) + .catch(() => {}); }); - it('should upload a file', (done) => { + it('should upload a file', () => { const output = run(`${cmd} upload ${bucketName} ${filePath}`, cwd); assert.equal(output, `File ${fileName} uploaded.`); - storage.bucket(bucketName).file(fileName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, true); - done(); - }); + return bucket.file(fileName).exists() + .then((results) => { + assert.equal(results[0], true); + }); }); it('should download a file', () => { @@ -63,44 +62,42 @@ describe('storage:files', () => { assert.doesNotThrow(() => fs.statSync(downloadFilePath)); }); - it('should move a file', (done) => { + it('should move a file', () => { const output = run(`${cmd} move ${bucketName} ${fileName} ${movedFileName}`, cwd); assert.equal(output, `File ${fileName} moved to ${movedFileName}.`); - storage.bucket(bucketName).file(movedFileName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, true); - done(); - }); + return bucket.file(movedFileName).exists() + .then((results) => { + assert.equal(results[0], true); + }); }); - it('should copy a file', (done) => { + it('should copy a file', () => { const output = run(`${cmd} copy ${bucketName} ${movedFileName} ${bucketName} ${copiedFileName}`, cwd); assert.equal(output, `File ${movedFileName} copied to ${copiedFileName} in ${bucketName}.`); - storage.bucket(bucketName).file(copiedFileName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, true); - done(); - }); + return bucket.file(copiedFileName).exists() + .then((results) => { + assert.equal(results[0], true); + }); }); it('should list files', (done) => { // Listing is eventually consistent, give the indexes time to update setTimeout(() => { const output = run(`${cmd} list ${bucketName}`, cwd); - assert.notEqual(output.indexOf(`Files:`), -1); - assert.notEqual(output.indexOf(movedFileName), -1); - assert.notEqual(output.indexOf(copiedFileName), -1); + assert.equal(output.includes(`Files:`), true); + assert.equal(output.includes(movedFileName), true); + assert.equal(output.includes(copiedFileName), true); done(); }, 5000); }); it('should list files by a prefix', () => { let output = run(`${cmd} list ${bucketName} test "/"`, cwd); - assert.notEqual(output.indexOf(`Files:`), -1); - assert.notEqual(output.indexOf(movedFileName), -1); - assert.notEqual(output.indexOf(copiedFileName), -1); + assert.equal(output.includes(`Files:`), true); + assert.equal(output.includes(movedFileName), true); + assert.equal(output.includes(copiedFileName), true); output = run(`${cmd} list ${bucketName} foo`, cwd); - assert.notEqual(output.indexOf(`Files:`), -1); + assert.equal(output.includes(`Files:`), true); assert.equal(output.indexOf(movedFileName), -1); assert.equal(output.indexOf(copiedFileName), -1); }); @@ -112,22 +109,21 @@ describe('storage:files', () => { it('should generate a signed URL for a file', () => { const output = run(`${cmd} generate-signed-url ${bucketName} ${copiedFileName}`, cwd); - assert.notEqual(output.indexOf(`The signed url for ${copiedFileName} is `), -1); + assert.equal(output.includes(`The signed url for ${copiedFileName} is `), true); }); it('should get metadata for a file', () => { const output = run(`${cmd} get-metadata ${bucketName} ${copiedFileName}`, cwd); - assert.notEqual(output.indexOf(`File: ${copiedFileName}`), -1); - assert.notEqual(output.indexOf(`Bucket: ${bucketName}`), -1); + assert.equal(output.includes(`File: ${copiedFileName}`), true); + assert.equal(output.includes(`Bucket: ${bucketName}`), true); }); - it('should delete a file', (done) => { + it('should delete a file', () => { const output = run(`${cmd} delete ${bucketName} ${copiedFileName}`, cwd); assert.equal(output, `File ${copiedFileName} deleted.`); - storage.bucket(bucketName).file(copiedFileName).exists((err, exists) => { - assert.ifError(err); - assert.equal(exists, false); - done(); - }); + return bucket.file(copiedFileName).exists() + .then((results) => { + assert.equal(results[0], false); + }); }); }); diff --git a/storage/system-test/quickstart.test.js b/storage/system-test/quickstart.test.js index cbf1069756..c7c6925c3e 100644 --- a/storage/system-test/quickstart.test.js +++ b/storage/system-test/quickstart.test.js @@ -20,41 +20,38 @@ const storage = proxyquire(`@google-cloud/storage`, {})(); const uuid = require(`node-uuid`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; +const bucket = storage.bucket(bucketName); describe(`storage:quickstart`, () => { - let storageMock, StorageMock; + after(() => bucket.delete().catch(() => {})); - after((done) => { - storage.bucket(bucketName).delete(() => { - // Ignore any error, the topic might not have been created - done(); - }); - }); - - it(`should create a topic`, (done) => { + it(`should create a bucket`, (done) => { const expectedBucketName = `my-new-bucket`; - storageMock = { - createBucket: (_bucketName, _callback) => { + const storageMock = { + createBucket: (_bucketName) => { assert.equal(_bucketName, expectedBucketName); - assert.equal(typeof _callback, 'function'); - - storage.createBucket(bucketName, (err, bucket, apiResponse) => { - _callback(err, bucket, apiResponse); - assert.ifError(err); - assert.notEqual(bucket, undefined); - assert.equal(bucket.name, bucketName); - assert.notEqual(apiResponse, undefined); - assert.equal(console.log.calledOnce, true); - assert.deepEqual(console.log.firstCall.args, [`Bucket ${bucket.name} created.`]); - done(); - }); + + return bucket.create() + .then((results) => { + const bucket = results[0]; + + assert.notEqual(bucket, undefined); + assert.equal(bucket.name, bucketName); + + setTimeout(() => { + assert.equal(console.log.calledOnce, true); + assert.deepEqual(console.log.firstCall.args, [`Bucket ${bucket.name} created.`]); + done(); + }, 200); + + return results; + }); } }; - StorageMock = sinon.stub().returns(storageMock); proxyquire(`../quickstart`, { - '@google-cloud/storage': StorageMock + '@google-cloud/storage': sinon.stub().returns(storageMock) }); }); }); diff --git a/storage/test/acl.test.js b/storage/test/acl.test.js deleted file mode 100644 index 71014b9d5e..0000000000 --- a/storage/test/acl.test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`storage:acl`, () => { - it(`should handle errors`, () => { - const bucketName = `foo`; - const fileName = `file.txt`; - const userEmail = `bob@company.com`; - const error = new Error(`error`); - const callback = sinon.spy(); - const fileMock = { - acl: { - get: sinon.stub().yields(error), - owners: { - addUser: sinon.stub().yields(error), - deleteUser: sinon.stub().yields(error) - } - } - }; - const bucketMock = { - acl: { - get: sinon.stub().yields(error), - owners: { - addUser: sinon.stub().yields(error), - deleteUser: sinon.stub().yields(error) - }, - default: { - owners: { - addUser: sinon.stub().yields(error), - deleteUser: sinon.stub().yields(error) - } - } - }, - file: sinon.stub().returns(fileMock) - }; - const storageMock = { - bucket: sinon.stub().returns(bucketMock) - }; - const StorageMock = sinon.stub().returns(storageMock); - const program = proxyquire(`../acl`, { - '@google-cloud/storage': StorageMock - }); - - program.printBucketAcl(bucketName, callback); - program.printBucketAclForUser(bucketName, userEmail, callback); - program.addBucketOwner(bucketName, userEmail, callback); - program.removeBucketOwner(bucketName, userEmail, callback); - program.addBucketDefaultOwner(bucketName, userEmail, callback); - program.removeBucketDefaultOwner(bucketName, userEmail, callback); - program.printFileAcl(bucketName, fileName, callback); - program.printFileAclForUser(bucketName, fileName, userEmail, callback); - program.addFileOwner(bucketName, fileName, userEmail, callback); - program.removeFileOwner(bucketName, fileName, userEmail, callback); - - assert.equal(callback.callCount, 10); - assert.equal(callback.alwaysCalledWithExactly(error), true); - }); -}); diff --git a/storage/test/buckets.test.js b/storage/test/buckets.test.js deleted file mode 100644 index 0447aa49e3..0000000000 --- a/storage/test/buckets.test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`storage:buckets`, () => { - it(`should handle errors`, () => { - const bucketName = `foo`; - const error = new Error(`error`); - const callback = sinon.spy(); - const bucketMock = { - delete: sinon.stub().yields(error) - }; - const storageMock = { - bucket: sinon.stub().returns(bucketMock), - getBuckets: sinon.stub().yields(error), - createBucket: sinon.stub().yields(error) - }; - const StorageMock = sinon.stub().returns(storageMock); - const program = proxyquire(`../buckets`, { - '@google-cloud/storage': StorageMock - }); - - program.createBucket(bucketName, callback); - program.deleteBucket(bucketName, callback); - program.listBuckets(callback); - - assert.equal(callback.callCount, 3); - assert.equal(callback.alwaysCalledWithExactly(error), true); - }); -}); diff --git a/storage/test/encryption.test.js b/storage/test/encryption.test.js deleted file mode 100644 index 5463762475..0000000000 --- a/storage/test/encryption.test.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`storage:encryption`, () => { - it(`should handle errors`, () => { - const bucketName = `foo`; - const fileName = `file.txt`; - const key = `keyboard-cat`; - const error = new Error(`error`); - const callback = sinon.spy(); - const fileMock = { - download: sinon.stub().yields(error), - setEncryptionKey: sinon.stub() - }; - const bucketMock = { - file: sinon.stub().returns(fileMock), - upload: sinon.stub().yields(error) - }; - const storageMock = { - bucket: sinon.stub().returns(bucketMock) - }; - const StorageMock = sinon.stub().returns(storageMock); - const program = proxyquire(`../encryption`, { - '@google-cloud/storage': StorageMock - }); - - program.uploadEncryptedFile(bucketName, fileName, fileName, key, callback); - program.downloadEncryptedFile(bucketName, fileName, fileName, key, callback); - - assert.equal(callback.callCount, 2); - assert.equal(callback.alwaysCalledWithExactly(error), true); - }); -}); - diff --git a/storage/test/files.test.js b/storage/test/files.test.js deleted file mode 100644 index b48235f9e4..0000000000 --- a/storage/test/files.test.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`storage:files`, () => { - it(`should handle errors`, () => { - const bucketName = `foo`; - const fileName = `file.txt`; - const error = new Error(`error`); - const callback = sinon.spy(); - const fileMock = { - copy: sinon.stub().yields(error), - delete: sinon.stub().yields(error), - download: sinon.stub().yields(error), - getMetadata: sinon.stub().yields(error), - getSignedUrl: sinon.stub().yields(error), - makePublic: sinon.stub().yields(error), - move: sinon.stub().yields(error) - }; - const bucketMock = { - file: sinon.stub().returns(fileMock), - getFiles: sinon.stub().yields(error), - upload: sinon.stub().yields(error) - }; - const storageMock = { - bucket: sinon.stub().returns(bucketMock) - }; - const StorageMock = sinon.stub().returns(storageMock); - const program = proxyquire(`../files`, { - '@google-cloud/storage': StorageMock - }); - - program.listFiles(bucketName, callback); - program.listFilesByPrefix(bucketName, `public/`, undefined, callback); - program.uploadFile(bucketName, fileName, callback); - program.downloadFile(bucketName, fileName, fileName, callback); - program.deleteFile(bucketName, fileName, callback); - program.getMetadata(bucketName, fileName, callback); - program.generateSignedUrl(bucketName, fileName, callback); - program.makePublic(bucketName, fileName, callback); - program.moveFile(bucketName, fileName, fileName, callback); - program.copyFile(bucketName, fileName, bucketName, fileName, callback); - - assert.equal(callback.callCount, 10); - assert.equal(callback.alwaysCalledWithExactly(error), true); - }); -}); diff --git a/storage/test/quickstart.test.js b/storage/test/quickstart.test.js deleted file mode 100644 index c929f78dca..0000000000 --- a/storage/test/quickstart.test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`storage:quickstart`, () => { - let storageMock, StorageMock; - const error = new Error(`error`); - const expectedBucketName = `my-new-bucket`; - - before(() => { - storageMock = { - createBucket: sinon.stub().yields(error) - }; - StorageMock = sinon.stub().returns(storageMock); - }); - - it(`should handle error`, () => { - proxyquire(`../quickstart`, { - '@google-cloud/storage': StorageMock - }); - - assert.equal(StorageMock.calledOnce, true); - assert.deepEqual(StorageMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); - assert.equal(storageMock.createBucket.calledOnce, true); - assert.deepEqual(storageMock.createBucket.firstCall.args.slice(0, -1), [expectedBucketName]); - assert.equal(console.error.calledOnce, true); - assert.deepEqual(console.error.firstCall.args, [error]); - }); -}); From c6971e48fd4bb61f9237dc47adbc2330c55a6cc8 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Fri, 9 Dec 2016 10:08:01 -0800 Subject: [PATCH 2/3] Update dependencies. --- appengine/analytics/package.json | 2 +- appengine/datastore/package.json | 2 +- appengine/pubsub/package.json | 2 +- appengine/sails/package.json | 2 +- appengine/storage/package.json | 2 +- appengine/websockets/package.json | 2 +- bigquery/package.json | 10 +-- bigquery/system-test/datasets.test.js | 2 +- bigquery/system-test/quickstart.test.js | 2 +- bigquery/system-test/tables.test.js | 2 +- computeengine/package.json | 2 +- datastore/package.json | 4 +- dns/package.json | 4 +- functions/datastore/package.json | 2 +- functions/errorreporting/package.json | 2 +- functions/gcs/package.json | 4 +- functions/log/package.json | 4 +- functions/ocr/app/package.json | 8 +-- functions/pubsub/package.json | 2 +- functions/sendgrid/index.js | 2 +- functions/sendgrid/package.json | 8 +-- functions/sendgrid/test/index.test.js | 2 +- functions/uuid/index.js | 2 +- functions/uuid/package.json | 2 +- language/package.json | 6 +- language/slackbot/package.json | 2 +- language/system-test/analyze.test.js | 2 +- logging/package.json | 8 +-- logging/system-test/logs.test.js | 2 +- logging/system-test/quickstart.test.js | 2 +- logging/system-test/sinks.test.js | 2 +- monitoring/package.json | 2 +- package.json | 4 +- prediction/package.json | 2 +- pubsub/package.json | 6 +- pubsub/system-test/quickstart.test.js | 2 +- pubsub/system-test/subscriptions.test.js | 2 +- pubsub/system-test/topics.test.js | 2 +- resource/package.json | 4 +- scripts/install | 84 ---------------------- scripts/run | 88 ++++++++++++++++++++++++ scripts/uninstall | 87 ----------------------- scripts/updates | 81 ---------------------- speech/package.json | 6 +- storage/package.json | 4 +- storage/system-test/acl.test.js | 2 +- storage/system-test/buckets.test.js | 2 +- storage/system-test/encryption.test.js | 2 +- storage/system-test/files.test.js | 2 +- storage/system-test/quickstart.test.js | 2 +- storage/system-test/transfer.test.js | 2 +- trace/package.json | 2 +- translate/package.json | 4 +- vision/package.json | 4 +- 54 files changed, 166 insertions(+), 330 deletions(-) delete mode 100755 scripts/install create mode 100644 scripts/run delete mode 100755 scripts/uninstall delete mode 100644 scripts/updates diff --git a/appengine/analytics/package.json b/appengine/analytics/package.json index 4eda3694a6..00aefe9248 100644 --- a/appengine/analytics/package.json +++ b/appengine/analytics/package.json @@ -14,6 +14,6 @@ }, "dependencies": { "express": "4.14.0", - "request": "2.78.0" + "request": "2.79.0" } } diff --git a/appengine/datastore/package.json b/appengine/datastore/package.json index e48892708b..e9f4d069dd 100644 --- a/appengine/datastore/package.json +++ b/appengine/datastore/package.json @@ -13,7 +13,7 @@ "test": "cd ..; npm run t -- appengine/analytics/test/*.test.js" }, "dependencies": { - "@google-cloud/datastore": "0.5.0", + "@google-cloud/datastore": "0.6.0", "express": "4.14.0" } } diff --git a/appengine/pubsub/package.json b/appengine/pubsub/package.json index 114ec21dbd..c275e06dc4 100644 --- a/appengine/pubsub/package.json +++ b/appengine/pubsub/package.json @@ -12,7 +12,7 @@ "start": "node app.js" }, "dependencies": { - "@google-cloud/pubsub": "0.3.0", + "@google-cloud/pubsub": "0.7.0", "body-parser": "1.15.2", "express": "4.14.0", "pug": "2.0.0-beta6" diff --git a/appengine/sails/package.json b/appengine/sails/package.json index d3a185cea2..70af592e54 100644 --- a/appengine/sails/package.json +++ b/appengine/sails/package.json @@ -29,6 +29,6 @@ "include-all": "0.1.6", "rc": "1.1.1", "sails": "0.11.2", - "sails-disk": "0.10.0" + "sails-disk": "0.10.10" } } \ No newline at end of file diff --git a/appengine/storage/package.json b/appengine/storage/package.json index 5a3c9bcf24..e74b6bff67 100644 --- a/appengine/storage/package.json +++ b/appengine/storage/package.json @@ -8,7 +8,7 @@ "node": ">=4.3.2" }, "dependencies": { - "@google-cloud/storage": "0.3.0", + "@google-cloud/storage": "0.6.0", "body-parser": "1.15.2", "express": "4.14.0", "multer": "1.2.0", diff --git a/appengine/websockets/package.json b/appengine/websockets/package.json index 24df72f0e5..5094be1da6 100644 --- a/appengine/websockets/package.json +++ b/appengine/websockets/package.json @@ -15,6 +15,6 @@ "express": "4.14.0", "express-ws": "1.0.0-rc.2", "pug": "2.0.0-beta6", - "request": "2.78.0" + "request": "2.79.0" } } diff --git a/bigquery/package.json b/bigquery/package.json index 2ecfa97c1e..e3b74f185f 100644 --- a/bigquery/package.json +++ b/bigquery/package.json @@ -9,13 +9,13 @@ "system-test": "cd ..; npm run st -- bigquery/system-test/*.test.js" }, "dependencies": { - "@google-cloud/bigquery": "0.4.0", - "@google-cloud/storage": "0.4.0", - "async": "2.1.2", - "yargs": "6.3.0" + "@google-cloud/bigquery": "0.6.0", + "@google-cloud/storage": "0.6.0", + "async": "2.1.4", + "yargs": "6.5.0" }, "devDependencies": { - "node-uuid": "^1.4.7" + "uuid": "3.0.1" }, "engines": { "node": ">=4.3.2" diff --git a/bigquery/system-test/datasets.test.js b/bigquery/system-test/datasets.test.js index 1648837bdb..16822ea3b8 100644 --- a/bigquery/system-test/datasets.test.js +++ b/bigquery/system-test/datasets.test.js @@ -16,7 +16,7 @@ 'use strict'; const bigquery = require(`@google-cloud/bigquery`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/bigquery/system-test/quickstart.test.js b/bigquery/system-test/quickstart.test.js index 52172fbef8..85e5b0edac 100644 --- a/bigquery/system-test/quickstart.test.js +++ b/bigquery/system-test/quickstart.test.js @@ -17,7 +17,7 @@ const proxyquire = require(`proxyquire`).noPreserveCache(); const bigquery = proxyquire(`@google-cloud/bigquery`, {})(); -var uuid = require('node-uuid'); +const uuid = require(`uuid`); const expectedDatasetId = `my_new_dataset`; let datasetId = `nodejs-docs-samples-test-${uuid.v4()}`; diff --git a/bigquery/system-test/tables.test.js b/bigquery/system-test/tables.test.js index b8f9c563d5..982b6b2d63 100644 --- a/bigquery/system-test/tables.test.js +++ b/bigquery/system-test/tables.test.js @@ -17,7 +17,7 @@ const bigquery = require(`@google-cloud/bigquery`)(); const storage = require(`@google-cloud/storage`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const utils = require(`../../utils`); const run = utils.run; diff --git a/computeengine/package.json b/computeengine/package.json index 1f86f337c5..f568ba5229 100644 --- a/computeengine/package.json +++ b/computeengine/package.json @@ -9,7 +9,7 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "@google-cloud/compute": "^0.1.1", + "@google-cloud/compute": "0.4.0", "googleapis": "^12.2.0", "nodemailer": "^2.4.1", "nodemailer-smtp-transport": "^2.5.0", diff --git a/datastore/package.json b/datastore/package.json index 837c76e9a5..8d6ce64978 100644 --- a/datastore/package.json +++ b/datastore/package.json @@ -8,8 +8,8 @@ "test": "cd ..; npm run st -- datastore/system-test/*.test.js" }, "dependencies": { - "@google-cloud/datastore": "^0.5.0", - "yargs": "^6.4.0" + "@google-cloud/datastore": "0.6.0", + "yargs": "6.5.0" }, "engines": { "node": ">=4.3.2" diff --git a/dns/package.json b/dns/package.json index 79150fcd78..4162b5bbbe 100644 --- a/dns/package.json +++ b/dns/package.json @@ -9,8 +9,8 @@ "system-test": "cd ..; npm run st -- dns/system-test/*.test.js" }, "dependencies": { - "@google-cloud/dns": "0.2.0", - "yargs": "6.4.0" + "@google-cloud/dns": "0.4.0", + "yargs": "6.5.0" }, "devDependencies": { "uuid": "2.0.3" diff --git a/functions/datastore/package.json b/functions/datastore/package.json index 9ca43d860f..7c17e76bbe 100644 --- a/functions/datastore/package.json +++ b/functions/datastore/package.json @@ -9,6 +9,6 @@ "test": "cd ..; npm run t -- functions/datastore/test/*.test.js" }, "dependencies": { - "@google-cloud/datastore": "^0.5.0" + "@google-cloud/datastore": "0.6.0" } } diff --git a/functions/errorreporting/package.json b/functions/errorreporting/package.json index 298f5e1cfa..e7572f3dc7 100644 --- a/functions/errorreporting/package.json +++ b/functions/errorreporting/package.json @@ -9,6 +9,6 @@ "test": "cd ..; npm run t -- functions/errorreporting/test/*.test.js" }, "dependencies": { - "@google-cloud/logging": "^0.5.0" + "@google-cloud/logging": "0.6.0" } } diff --git a/functions/gcs/package.json b/functions/gcs/package.json index 3d5f945f44..6ed6647988 100644 --- a/functions/gcs/package.json +++ b/functions/gcs/package.json @@ -8,7 +8,7 @@ "scripts": { "test": "cd ..; npm run t -- functions/gcs/test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "^0.4.0", - "request": "^2.78.0" + "@google-cloud/storage": "0.6.0", + "request": "2.79.0" } } diff --git a/functions/log/package.json b/functions/log/package.json index 22f72e1651..68c34222fa 100644 --- a/functions/log/package.json +++ b/functions/log/package.json @@ -9,7 +9,7 @@ "test": "cd ..; npm run t -- functions/log/test/*.test.js" }, "dependencies": { - "@google-cloud/logging": "^0.5.0", - "@google-cloud/monitoring": "^0.1.0" + "@google-cloud/logging": "0.6.0", + "@google-cloud/monitoring": "0.1.3" } } diff --git a/functions/ocr/app/package.json b/functions/ocr/app/package.json index 3ffc5b08e2..1e5ffe15c7 100644 --- a/functions/ocr/app/package.json +++ b/functions/ocr/app/package.json @@ -9,9 +9,9 @@ "test": "cd ..; npm run t -- functions/ocr/app/test/*.test.js" }, "dependencies": { - "@google-cloud/pubsub": "^0.5.0", - "@google-cloud/storage": "^0.4.0", - "@google-cloud/translate": "^0.5.0", - "@google-cloud/vision": "^0.5.0" + "@google-cloud/pubsub": "0.7.0", + "@google-cloud/storage": "0.6.0", + "@google-cloud/translate": "0.6.0", + "@google-cloud/vision": "0.7.0" } } diff --git a/functions/pubsub/package.json b/functions/pubsub/package.json index 5398da1697..a24ee9ebd0 100644 --- a/functions/pubsub/package.json +++ b/functions/pubsub/package.json @@ -9,6 +9,6 @@ "test": "cd ..; npm run t -- functions/pubsub/test/*.test.js" }, "dependencies": { - "@google-cloud/pubsub": "^0.5.0" + "@google-cloud/pubsub": "0.7.0" } } diff --git a/functions/sendgrid/index.js b/functions/sendgrid/index.js index bb79508565..7f51720608 100644 --- a/functions/sendgrid/index.js +++ b/functions/sendgrid/index.js @@ -18,7 +18,7 @@ // [START functions_sendgrid_setup] const sendgrid = require('sendgrid'); const config = require('./config.json'); -const uuid = require('node-uuid'); +const uuid = require('uuid'); // Get a reference to the Cloud Storage component const storage = require('@google-cloud/storage')(); diff --git a/functions/sendgrid/package.json b/functions/sendgrid/package.json index 520b077cf1..ef8549adfa 100644 --- a/functions/sendgrid/package.json +++ b/functions/sendgrid/package.json @@ -9,9 +9,9 @@ "test": "cd ..; npm run t -- functions/sendgrid/test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "^0.4.0", - "@google-cloud/bigquery": "^0.4.0", - "node-uuid": "^1.4.7", - "sendgrid": "^4.7.1" + "@google-cloud/storage": "0.6.0", + "@google-cloud/bigquery": "0.6.0", + "uuid": "3.0.1", + "sendgrid": "4.7.1" } } diff --git a/functions/sendgrid/test/index.test.js b/functions/sendgrid/test/index.test.js index 931ba29447..804c5c5935 100644 --- a/functions/sendgrid/test/index.test.js +++ b/functions/sendgrid/test/index.test.js @@ -90,7 +90,7 @@ function getSample () { '@google-cloud/bigquery': BigQueryMock, '@google-cloud/storage': StorageMock, './config.json': config, - 'node-uuid': uuid + 'uuid': uuid }), mocks: { sendgrid, diff --git a/functions/uuid/index.js b/functions/uuid/index.js index 3d3c5d41c6..355c8f6625 100644 --- a/functions/uuid/index.js +++ b/functions/uuid/index.js @@ -16,7 +16,7 @@ 'use strict'; // [START functions_uuid] -const uuid = require('node-uuid'); +const uuid = require('uuid'); exports.uuid = function (event, callback) { callback(null, uuid.v4()); diff --git a/functions/uuid/package.json b/functions/uuid/package.json index c028f7b95b..9a5f6920fc 100644 --- a/functions/uuid/package.json +++ b/functions/uuid/package.json @@ -9,6 +9,6 @@ "test": "cd ..; npm run t -- functions/uuid/test/*.test.js" }, "dependencies": { - "node-uuid": "^1.4.7" + "uuid": "3.0.1" } } diff --git a/language/package.json b/language/package.json index 30d16f2d7a..f59e676d38 100644 --- a/language/package.json +++ b/language/package.json @@ -8,9 +8,9 @@ "test": "cd ..; npm run st -- language/system-test/*.test.js" }, "dependencies": { - "@google-cloud/language": "^0.6.0", - "@google-cloud/storage": "^0.4.0", - "yargs": "^6.4.0" + "@google-cloud/language": "0.7.0", + "@google-cloud/storage": "0.6.0", + "yargs": "6.5.0" }, "engines": { "node": ">=4.3.2" diff --git a/language/slackbot/package.json b/language/slackbot/package.json index 2f9ab75520..b3f51eccfb 100644 --- a/language/slackbot/package.json +++ b/language/slackbot/package.json @@ -8,7 +8,7 @@ "main": "demo_bot.js", "dependencies": { "botkit": "^0.0.5", - "@google-cloud/language": "^0.6.3", + "@google-cloud/language": "0.7.0", "sqlite3": "^3.1.8" }, "scripts": { diff --git a/language/system-test/analyze.test.js b/language/system-test/analyze.test.js index dc34430e42..f400799a28 100644 --- a/language/system-test/analyze.test.js +++ b/language/system-test/analyze.test.js @@ -15,7 +15,7 @@ 'use strict'; -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const storage = require(`@google-cloud/storage`)(); const run = require(`../../utils`).run; diff --git a/logging/package.json b/logging/package.json index 990db1599c..613a759fbd 100644 --- a/logging/package.json +++ b/logging/package.json @@ -9,14 +9,14 @@ "system-test": "cd ..; npm run st -- logging/system-test/*.test.js" }, "dependencies": { - "@google-cloud/logging": "0.5.1", - "@google-cloud/storage": "0.5.0", + "@google-cloud/logging": "0.6.0", + "@google-cloud/storage": "0.6.0", "express": "4.14.0", "fluent-logger": "2.2.0", - "yargs": "6.4.0" + "yargs": "6.5.0" }, "devDependencies": { - "node-uuid": "1.4.7" + "uuid": "3.0.1" }, "engines": { "node": ">=4.3.2" diff --git a/logging/system-test/logs.test.js b/logging/system-test/logs.test.js index 93a134b5b4..b9669cfe1f 100644 --- a/logging/system-test/logs.test.js +++ b/logging/system-test/logs.test.js @@ -13,7 +13,7 @@ 'use strict'; -var uuid = require('node-uuid'); +var uuid = require('uuid'); var program = require('../logs'); var logName = 'nodejs-docs-samples-test-' + uuid.v4(); diff --git a/logging/system-test/quickstart.test.js b/logging/system-test/quickstart.test.js index d33d99878f..0c47367e65 100644 --- a/logging/system-test/quickstart.test.js +++ b/logging/system-test/quickstart.test.js @@ -17,7 +17,7 @@ const proxyquire = require(`proxyquire`).noPreserveCache(); const logging = proxyquire(`@google-cloud/logging`, {})(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const logName = `nodejs-docs-samples-test-${uuid.v4()}`; diff --git a/logging/system-test/sinks.test.js b/logging/system-test/sinks.test.js index 5a55074bf0..a36915e249 100644 --- a/logging/system-test/sinks.test.js +++ b/logging/system-test/sinks.test.js @@ -15,7 +15,7 @@ var Logging = require('@google-cloud/logging'); var Storage = require('@google-cloud/storage'); -var uuid = require('node-uuid'); +var uuid = require('uuid'); var program = require('../sinks'); var logging = Logging(); diff --git a/monitoring/package.json b/monitoring/package.json index 23f7396580..b682bbbf98 100644 --- a/monitoring/package.json +++ b/monitoring/package.json @@ -10,6 +10,6 @@ }, "dependencies": { "async":"2.1.2", - "googleapis": "14.2.0" + "googleapis": "15.0.0" } } diff --git a/package.json b/package.json index 85a136de07..7143d95e35 100644 --- a/package.json +++ b/package.json @@ -65,14 +65,14 @@ "all-cover": "npm run pretest && nyc --cache npm run all-test && nyc report --reporter=html && nyc report --reporter=lcov" }, "devDependencies": { - "async": "2.1.2", + "async": "2.1.4", "intelli-espower-loader": "1.0.1", "mocha": "3.1.2", "nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#bbbb6035d77671eb053dbe6b6f0e3ff983f79639", "nyc": "9.0.1", "power-assert": "1.4.2", "proxyquire": "1.7.10", - "request": "2.78.0", + "request": "2.79.0", "semistandard": "9.1.0", "shelljs": "0.7.5", "sinon": "1.17.6", diff --git a/prediction/package.json b/prediction/package.json index f622a58395..20c984fad8 100644 --- a/prediction/package.json +++ b/prediction/package.json @@ -9,6 +9,6 @@ "system-test": "cd ..; npm run st -- prediction/system-test/*.test.js" }, "dependencies": { - "googleapis": "14.2.0" + "googleapis": "15.0.0" } } diff --git a/pubsub/package.json b/pubsub/package.json index c71c475b3f..19f1faff64 100644 --- a/pubsub/package.json +++ b/pubsub/package.json @@ -8,11 +8,11 @@ "test": "cd ..; npm run st -- pubsub/system-test/*.test.js" }, "dependencies": { - "@google-cloud/pubsub": "0.5.0", - "yargs": "6.4.0" + "@google-cloud/pubsub": "0.7.0", + "yargs": "6.5.0" }, "devDependencies": { - "node-uuid": "1.4.7" + "uuid": "3.0.1" }, "engines": { "node": ">=4.3.2" diff --git a/pubsub/system-test/quickstart.test.js b/pubsub/system-test/quickstart.test.js index 29bb0d3f37..6f08e9e959 100644 --- a/pubsub/system-test/quickstart.test.js +++ b/pubsub/system-test/quickstart.test.js @@ -17,7 +17,7 @@ const proxyquire = require(`proxyquire`).noPreserveCache(); const pubsub = proxyquire(`@google-cloud/pubsub`, {})(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const topicName = `nodejs-docs-samples-test-${uuid.v4()}`; const projectId = process.env.GCLOUD_PROJECT; diff --git a/pubsub/system-test/subscriptions.test.js b/pubsub/system-test/subscriptions.test.js index d530eb6ba8..6aa9711202 100644 --- a/pubsub/system-test/subscriptions.test.js +++ b/pubsub/system-test/subscriptions.test.js @@ -16,7 +16,7 @@ 'use strict'; const pubsub = require(`@google-cloud/pubsub`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/pubsub/system-test/topics.test.js b/pubsub/system-test/topics.test.js index 5369427b34..4f6a2e62ae 100644 --- a/pubsub/system-test/topics.test.js +++ b/pubsub/system-test/topics.test.js @@ -16,7 +16,7 @@ 'use strict'; const pubsub = require(`@google-cloud/pubsub`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/resource/package.json b/resource/package.json index 52bc552346..0d8b12f338 100644 --- a/resource/package.json +++ b/resource/package.json @@ -9,8 +9,8 @@ "system-test": "cd ..; npm run st -- resource/system-test/*.test.js" }, "dependencies": { - "@google-cloud/resource": "0.3.0", - "yargs": "6.4.0" + "@google-cloud/resource": "0.5.0", + "yargs": "6.5.0" }, "engines": { "node": ">=4.3.2" diff --git a/scripts/install b/scripts/install deleted file mode 100755 index fb1f8c28bb..0000000000 --- a/scripts/install +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env node - -// Copyright 2016, Google, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -var async = require('async'); -var path = require('path'); - -require('shelljs/global'); - -// Install NPM dependencies, in up to 7 directories at a time -var queue = async.queue(function (directory, callback) { - installForDirectory(directory, callback); -}, 7); - -queueDirectories('appengine'); -queue.push('bigquery'); -queue.push('computeengine'); -queue.push('datastore'); -queue.push('debugger'); -queue.push('dns'); -queueDirectories('functions'); -queue.push('functions/ocr/app'); -queue.push('language'); -queue.push('logging'); -queue.push('monitoring'); -queue.push('prediction'); -queue.push('pubsub'); -queue.push('resource'); -queue.push('speech'); -queue.push('storage'); -queue.push('trace'); -queue.push('translate'); -queue.push('vision'); - -/** - * Install NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to install dependencies. - * @param {function} callback The callback function. - */ -function installForDirectory(directory, callback) { - console.log(directory + '...installing dependencies'); - exec('npm install', { - async: true, - cwd: path.join(__dirname, '../', directory) - }, function (err) { - console.log(directory + '...done'); - callback(err); - }); -} - -/** - * Recursively install NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to recursively install dependencies. - */ -function queueDirectories(directory) { - // Move into the directory - cd(directory); - - // List the files in the directory - ls('-dl', '*') - .filter(function (file) { - // Find the directories within the directory - return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test'; - }) - .forEach(function (file) { - queue.push(directory + '/' + file.name); - }); - - // Move out of the directory - cd('..'); -} \ No newline at end of file diff --git a/scripts/run b/scripts/run new file mode 100644 index 0000000000..51f4d2a617 --- /dev/null +++ b/scripts/run @@ -0,0 +1,88 @@ +#!/usr/bin/env node + +/** + * Copyright 2016, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const async = require('async'); +const path = require('path'); + +const command = process.argv.slice(2).shift(); + +require('shelljs/global'); + +// Run the command in up to 7 directories at a time +const queue = async.queue((directory, callback) => { + runForDirectory(directory, callback); +}, 7); + +queueDirectories('appengine'); +queue.push('bigquery'); +queue.push('computeengine'); +queue.push('datastore'); +queue.push('debugger'); +queue.push('dns'); +queueDirectories('functions'); +queue.push('functions/ocr/app'); +queue.push('language'); +queue.push('logging'); +queue.push('monitoring'); +queue.push('prediction'); +queue.push('pubsub'); +queue.push('resource'); +queue.push('speech'); +queue.push('storage'); +queue.push('trace'); +queue.push('translate'); +queue.push('vision'); + +/** + * Run the command in the given directory + * + * @param {string} directory The name of the directory in which to run the + * command. + * @param {function} callback The callback function. + */ +function runForDirectory(directory, callback) { + console.log(`${directory}...running ${command}`); + exec(command, { + async: true, + cwd: path.join(__dirname, '../', directory) + }, function (err) { + console.log(`${directory}...done`); + callback(err); + }); +} + +/** + * Recursively run the command within a single directory. + * + * @param {string} directory The name of the directory in which to recursively + * run the command. + */ +function queueDirectories(directory) { + // Move into the directory + cd(directory); + + // List the files in the directory + ls('-dl', '*') + // Find the directories within the directory + .filter((file) => file.isDirectory() && file.name !== 'test' && file.name !== 'system-test') + .forEach((file) => { + queue.push(path.join(directory, file.name)); + }); + + // Move out of the directory + cd('..'); +} diff --git a/scripts/uninstall b/scripts/uninstall deleted file mode 100755 index 04600d367e..0000000000 --- a/scripts/uninstall +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env node - -// Copyright 2016, Google, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -var async = require('async'); -var path = require('path'); - -require('shelljs/global'); - -// Uninstall NPM dependencies, in up to 7 directories at a time -var queue = async.queue(function (directory, callback) { - uninstallForDirectory(directory, callback); -}, 7); - -queueDirectories('appengine'); -queue.push('bigquery'); -queue.push('computeengine'); -queue.push('datastore'); -queue.push('debugger'); -queue.push('dns'); -queueDirectories('functions'); -queue.push('functions/ocr/app'); -queue.push('language'); -queue.push('logging'); -queue.push('monitoring'); -queue.push('prediction'); -queue.push('pubsub'); -queue.push('resource'); -queue.push('speech'); -queue.push('storage'); -queue.push('trace'); -queue.push('translate'); -queue.push('vision'); - -/** - * Uninstall NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to uninstall dependencies. - * @param {function} callback The callback function. - */ -function uninstallForDirectory(directory, callback) { - // Move into the directory - cd(directory); - - // Uninstall dependencies - console.log(directory + '...uninstalling dependencies'); - rm('-rf', 'node_modules'); - - // Move out of the directory - cd('..'); - console.log(directory + '...done'); - callback(); -} - -/** - * Recursively uninstall NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to recursively uninstall dependencies. - */ -function queueDirectories(directory) { - // Move into the directory - cd(directory); - - // List the files in the directory - ls('-dl', '*') - .filter(function (file) { - // Find the directories within the directory - return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test'; - }) - .forEach(function (file) { - queue.push(directory + '/' + file.name); - }); - - // Move out of the directory - cd('..'); -} \ No newline at end of file diff --git a/scripts/updates b/scripts/updates deleted file mode 100644 index 7957c9f092..0000000000 --- a/scripts/updates +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env node - -// Copyright 2016, Google, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -var async = require('async'); -var path = require('path'); - -require('shelljs/global'); - -// Check NPM dependencies, in up to 7 directories at a time -var queue = async.queue(function (directory, callback) { - checkForDirectory(directory, callback); -}, 1); - -queueDirectories('appengine'); -queue.push('bigquery'); -queue.push('computeengine'); -queue.push('datastore'); -queue.push('debugger'); -queue.push('dns'); -queueDirectories('functions'); -queue.push('functions/ocr/app'); -queue.push('language'); -queue.push('logging'); -queue.push('monitoring'); -queue.push('prediction'); -queue.push('pubsub'); -queue.push('resource'); -queue.push('speech'); -queue.push('storage'); -queue.push('trace'); -queue.push('translate'); -queue.push('vision'); - -/** - * Check NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to check dependencies. - * @param {function} callback The callback function. - */ -function checkForDirectory(directory, callback) { - console.log(directory + '...checking dependencies'); - exec('npm outdated', { - async: true, - cwd: path.join(__dirname, '../', directory) - }, callback); -} - -/** - * Recursively check NPM dependencies within a single directory. - * - * @param {string} directory The name of the directory in which to recursively check dependencies. - */ -function queueDirectories(directory) { - // Move into the directory - cd(directory); - - // List the files in the directory - ls('-dl', '*') - .filter(function (file) { - // Find the directories within the directory - return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test'; - }) - .forEach(function (file) { - queue.push(directory + '/' + file.name); - }); - - // Move out of the directory - cd('..'); -} \ No newline at end of file diff --git a/speech/package.json b/speech/package.json index 4ce70045cb..3ac2236a61 100644 --- a/speech/package.json +++ b/speech/package.json @@ -8,9 +8,9 @@ "test": "cd ..; npm run st -- speech/system-test/*.test.js" }, "dependencies": { - "@google-cloud/speech": "^0.4.0", - "node-record-lpcm16": "^0.1.4", - "yargs": "^6.4.0" + "@google-cloud/speech": "0.5.0", + "node-record-lpcm16": "0.1.4", + "yargs": "6.5.0" }, "engines": { "node": ">=4.3.2" diff --git a/storage/package.json b/storage/package.json index 734f95803b..a6c9f0a923 100644 --- a/storage/package.json +++ b/storage/package.json @@ -9,13 +9,13 @@ "system-test": "cd ..; npm run st -- storage/system-test/*.test.js" }, "dependencies": { - "@google-cloud/storage": "0.5.0", + "@google-cloud/storage": "0.6.0", "googleapis": "15.0.0", "moment": "2.17.1", "yargs": "6.5.0" }, "devDependencies": { - "node-uuid": "1.4.7" + "uuid": "3.0.1" }, "engines": { "node": ">=4.3.2" diff --git a/storage/system-test/acl.test.js b/storage/system-test/acl.test.js index c91cb8d4c4..89bd3de62e 100644 --- a/storage/system-test/acl.test.js +++ b/storage/system-test/acl.test.js @@ -16,7 +16,7 @@ 'use strict'; const storage = require(`@google-cloud/storage`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/storage/system-test/buckets.test.js b/storage/system-test/buckets.test.js index 03d83affc9..a7a80254cb 100644 --- a/storage/system-test/buckets.test.js +++ b/storage/system-test/buckets.test.js @@ -16,7 +16,7 @@ 'use strict'; const storage = require(`@google-cloud/storage`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/storage/system-test/encryption.test.js b/storage/system-test/encryption.test.js index 233912b8ce..43162c7ed5 100644 --- a/storage/system-test/encryption.test.js +++ b/storage/system-test/encryption.test.js @@ -19,7 +19,7 @@ const fs = require('fs'); const path = require('path'); const run = require(`../../utils`).run; const storage = require('@google-cloud/storage')(); -const uuid = require('node-uuid'); +const uuid = require('uuid'); const cwd = path.join(__dirname, `..`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; diff --git a/storage/system-test/files.test.js b/storage/system-test/files.test.js index b59124c41a..ecaecbd5b0 100644 --- a/storage/system-test/files.test.js +++ b/storage/system-test/files.test.js @@ -17,7 +17,7 @@ const fs = require(`fs`); const storage = require(`@google-cloud/storage`)(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const path = require(`path`); const run = require(`../../utils`).run; diff --git a/storage/system-test/quickstart.test.js b/storage/system-test/quickstart.test.js index c7c6925c3e..6f6e74168b 100644 --- a/storage/system-test/quickstart.test.js +++ b/storage/system-test/quickstart.test.js @@ -17,7 +17,7 @@ const proxyquire = require(`proxyquire`).noPreserveCache(); const storage = proxyquire(`@google-cloud/storage`, {})(); -const uuid = require(`node-uuid`); +const uuid = require(`uuid`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const bucket = storage.bucket(bucketName); diff --git a/storage/system-test/transfer.test.js b/storage/system-test/transfer.test.js index ae1d8c081e..2355ce14b1 100644 --- a/storage/system-test/transfer.test.js +++ b/storage/system-test/transfer.test.js @@ -15,7 +15,7 @@ 'use strict'; -var uuid = require('node-uuid'); +var uuid = require('uuid'); var program = require('../transfer'); var Storage = require('@google-cloud/storage'); diff --git a/trace/package.json b/trace/package.json index 88b585f1a8..87d8f4ae8d 100644 --- a/trace/package.json +++ b/trace/package.json @@ -14,6 +14,6 @@ "dependencies": { "@google/cloud-trace": "0.5.10", "express": "4.14.0", - "request": "2.78.0" + "request": "2.79.0" } } diff --git a/translate/package.json b/translate/package.json index ef36037b91..aea880afd9 100644 --- a/translate/package.json +++ b/translate/package.json @@ -8,8 +8,8 @@ "test": "cd ..; npm run st -- translate/system-test/*.test.js" }, "dependencies": { - "@google-cloud/translate": "^0.5.0", - "yargs": "^6.4.0" + "@google-cloud/translate": "0.6.0", + "yargs": "6.5.0" }, "engines": { "node": ">=4.3.2" diff --git a/vision/package.json b/vision/package.json index 313d4eb283..a3043b8145 100644 --- a/vision/package.json +++ b/vision/package.json @@ -9,8 +9,8 @@ "system-test": "cd ..; npm run st -- vision/system-test/*.test.js" }, "dependencies": { - "@google-cloud/vision": "0.5.0", - "async": "2.1.2", + "@google-cloud/vision": "0.7.0", + "async": "2.1.4", "natural": "0.4.0", "redis": "2.6.3" }, From a03f15905653c99256e6cb742457563bc81fe959 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Fri, 9 Dec 2016 10:40:51 -0800 Subject: [PATCH 3/3] Fix some tests. --- pubsub/system-test/topics.test.js | 4 ++-- speech/system-test/recognize.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pubsub/system-test/topics.test.js b/pubsub/system-test/topics.test.js index 4f6a2e62ae..1c154f2939 100644 --- a/pubsub/system-test/topics.test.js +++ b/pubsub/system-test/topics.test.js @@ -69,7 +69,7 @@ describe(`pubsub:topics`, () => { }); it(`should publish a JSON message`, () => { - return pubsub.topic(topicName).subscribe(subscriptionName, { reuseExisting: true }) + return pubsub.topic(topicName).subscribe(subscriptionName) .then((results) => { const subscription = results[0]; run(`${cmd} publish ${topicName} '${JSON.stringify(message)}'`, cwd); @@ -85,7 +85,7 @@ describe(`pubsub:topics`, () => { const topics = require(`../topics`); let subscription; - return pubsub.topic(topicName).subscribe(subscriptionName, { reuseExisting: true }) + return pubsub.topic(topicName).subscribe(subscriptionName) .then((results) => { subscription = results[0]; return topics.publishOrderedMessage(topicName, message.data); diff --git a/speech/system-test/recognize.test.js b/speech/system-test/recognize.test.js index 2653725fd3..8feb6e0167 100644 --- a/speech/system-test/recognize.test.js +++ b/speech/system-test/recognize.test.js @@ -25,11 +25,11 @@ const text = `how old is the Brooklyn Bridge`; describe(`speech:recognize`, () => { it(`should run sync recognize`, () => { - assert.equal(run(`${cmd} sync ${filename}`, cwd), `Transcription: ${text}`); + assert.equal(run(`${cmd} sync ${filename}`, cwd).includes(text), true); }); it(`should run async recognize`, () => { - assert.equal(run(`${cmd} async ${filename}`, cwd), `Transcription: ${text}`); + assert.equal(run(`${cmd} async ${filename}`, cwd).includes(text), true); }); it(`should run streaming recognize`, () => {