Skip to content

Commit

Permalink
Simplify Storage samples and their tests. (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry authored Oct 3, 2016
1 parent db124bc commit 3d4bb4d
Show file tree
Hide file tree
Showing 19 changed files with 1,388 additions and 2,485 deletions.
20 changes: 10 additions & 10 deletions pubsub/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function listTopics (callback) {
return;
}

console.log(`Topics:`);
console.log('Topics:');
topics.forEach((topic) => console.log(topic.name));
callback();
});
Expand Down Expand Up @@ -257,7 +257,7 @@ function testTopicPermissions (topicName, callback) {

// The command-line program
const cli = require(`yargs`);
const makeHandler = require(`../utils`).makeHandler;
const noop = require(`../utils`).noop;

const program = module.exports = {
listTopics: listTopics,
Expand All @@ -277,30 +277,30 @@ const program = module.exports = {
cli
.demand(1)
.command(`list`, `Lists all topics in the current project.`, {}, (options) => {
program.listTopics(makeHandler(false));
program.listTopics(noop);
})
.command(`create <topicName>`, `Creates a new topic.`, {}, (options) => {
program.createTopic(options.topicName, makeHandler(false));
program.createTopic(options.topicName, noop);
})
.command(`delete <topicName>`, `Deletes the a topic.`, {}, (options) => {
program.deleteTopic(options.topicName, makeHandler(false));
.command(`delete <topicName>`, `Deletes a topic.`, {}, (options) => {
program.deleteTopic(options.topicName, noop);
})
.command(`publish <topicName> <message>`, `Publishes a message.`, {}, (options) => {
try {
options.message = JSON.parse(options.message);
} catch (err) {
// Ignore error
}
program.publishMessage(options.topicName, options.message, makeHandler(false));
program.publishMessage(options.topicName, options.message, noop);
})
.command(`get-policy <topicName>`, `Gets the IAM policy for a topic.`, {}, (options) => {
program.getTopicPolicy(options.topicName, makeHandler(false));
program.getTopicPolicy(options.topicName, noop);
})
.command(`set-policy <topicName>`, `Sets the IAM policy for a topic.`, {}, (options) => {
program.setTopicPolicy(options.topicName, makeHandler(false));
program.setTopicPolicy(options.topicName, noop);
})
.command(`test-permissions <topicName>`, `Tests the permissions for a topic.`, {}, (options) => {
program.testTopicPermissions(options.topicName, makeHandler(false));
program.testTopicPermissions(options.topicName, noop);
})
.example(`node $0 list`, `Lists all topics in the current project.`)
.example(`node $0 create greetings`, `Creates a new topic named "greetings".`)
Expand Down
124 changes: 68 additions & 56 deletions storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,38 @@ __Usage:__ `node acl --help`

```
Commands:
add <entity> <role> Add access controls on a bucket or file.
get [entity] Get access controls on a bucket or file.
delete <entity> Delete access controls from a bucket or file.
print-bucket-acl <bucketName> Prints the ACL for a bucket.
print-bucket-acl-for-user <bucketName> <userEmail> Prints a user's ACL for a bucket.
add-bucket-owner <bucketName> <userEmail> Adds a user as an owner of a bucket.
remove-bucket-owner <bucketName> <userEmail> Removes a user from the ACL of a bucket.
add-bucket-default-owner <bucketName> <userEmail> Adds a user as an owner in the default ACL of a bucket.
remove-bucket-default-owner <bucketName> <userEmail> Removes a user from the default ACL of a bucket.
print-file-acl <bucketName> <fileName> Prints the ACL for a file.
print-file-acl-for-user <bucketName> <fileName> <userEmail> Prints a user's ACL for a file.
add-file-owner <bucketName> <fileName> <userEmail> Adds a user as an owner of a file.
remove-file-owner <bucketName> <fileName> <userEmail> Removes a user from the ACL of a file.
Options:
--bucket, -b The target storage bucket. [string] [required]
--default, -d Whether to set default access
controls. Only valid when setting
access controls on a bucket. [boolean]
--file, -f The target file. [string]
--help Show help [boolean]
--help Show help [boolean]
Examples:
node acl add user-bob@domain.com OWNER -b mybucket Add OWNER access controls for
"user-bob@domain.com" to "mybucket".
node acl add viewers-2256 WRITER -b mybucket -d Add default WRITER access controls to
"mybucket" for "viewers-2256".
node acl get editors-1234 -b mybucket Get access controls for "editors-1234" in
"mybucket".
node acl delete -b mybucket -f file.txt Delete all access controls for all entities
from "file.txt" in "mybucket".
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".
For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists
```
Expand All @@ -73,17 +84,17 @@ __Usage:__ `node buckets --help`

```
Commands:
create <bucket> Create a new bucket with the given name.
list List all buckets in the authenticated project.
delete <bucket> Delete the specified bucket.
create <bucket> Creates a new bucket.
list Lists all buckets in the current project.
delete <bucket> Deletes a bucket.
Options:
--help Show help [boolean]
--help Show help [boolean]
Examples:
node buckets create my-bucket Create a new bucket named "my-bucket".
node buckets list List all buckets in the authenticated project.
node buckets delete my-bucket Delete "my-bucket".
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".
For more information, see https://cloud.google.com/storage/docs
```
Expand All @@ -99,21 +110,21 @@ __Usage:__ `node encryption --help`

```
Commands:
generate-encryption-key Generate a sample encryption key.
upload <bucket> <srcFile> <destFile> <key> Upload an encrypted file to a bucket.
download <bucket> <srcFile> <destFile> <key> Download an encrypted file from a bucket.
rotate <bucket> <file> <oldkey> <newKey> Rotate encryption keys for a file.
generate-encryption-key Generate a sample encryption key.
upload <bucketName> <srcFileName> <destFileName> <key> Encrypts and uploads a file.
download <bucketName> <srcFileName> <destFileName> <key> Decrypts and downloads a file.
rotate <bucketName> <fileName> <oldkey> <newKey> Rotates encryption keys for a file.
Options:
--help Show help [boolean]
--help Show help [boolean]
Examples:
node encryption generate-encryption-key Generate a sample encryption key.
node encryption upload my-bucket resources/test.txt Upload "resources/test.txt" to
node encryption 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 Download "gs://my-bucket/file_encrypted.txt" to
./file.txt QxhqaZEqBGVTW55HhQw9Q= "./file.txt".
node encryption rotate my-bucket file_encrypted.txt Rotate encryptiong keys for
node encryption 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
QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q= "gs://my-bucket/file_encrypted.txt".
For more information, see https://cloud.google.com/storage/docs
Expand All @@ -130,33 +141,34 @@ __Usage:__ `node files --help`

```
Commands:
list <bucket> [options] List files in a bucket, optionally filtering
by a prefix.
upload <bucket> <srcFile> Upload a local file to a bucket.
download <bucket> <srcFile> <destFile> Download a file from a bucket.
delete <bucket> <file> Delete a file from a bucket.
getMetadata <bucket> <file> Get metadata for a file in a bucket.
makePublic <bucket> <file> Make a file public in a bucket.
move <bucket> <srcFile> <destFile> Rename a file in a bucket.
copy <srcBucket> <srcFile> <destBucket> <destFile> Copy a file in a bucket to another bucket.
list <bucketName> [prefix] [delimiter] Lists files in a bucket, optionally filtering by a
prefix.
upload <bucketName> <srcFileName> Uploads a local file to a bucket.
download <bucketName> <srcFileName> <destFileName> Downloads a file from a bucket.
delete <bucketName> <fileName> Deletes a file from a bucket.
get-metadata <bucketName> <fileName> Gets the metadata for a file.
make-public <bucketName> <fileName> Makes a file public.
generate-signed-url <bucketName> <fileName> Generates a signed URL for a file.
move <bucketName> <srcFileName> <destFileName> Moves a file to a new location within the same bucket,
i.e. rename the file.
copy <srcBucketName> <srcFileName> <destBucketName> Copies a file in a bucket to another bucket.
<destFileName>
Options:
--help Show help [boolean]
--help Show help [boolean]
Examples:
node files list my-bucket List files in "my-bucket".
node files list my-bucket -p public/ List files in "my-bucket" filtered by prefix
"public/".
node files upload my-bucket ./file.txt Upload "./file.txt" to "my-bucket".
node files download my-bucket file.txt ./file.txt Download "gs://my-bucket/file.txt" to
"./file.txt".
node files delete my-bucket file.txt Delete "gs://my-bucket/file.txt".
node files getMetadata my-bucket file.txt Get metadata for "gs://my-bucket/file.txt".
node files makePublic my-bucket file.txt Make "gs://my-bucket/file.txt" public.
node files move my-bucket file.txt file2.txt Rename "gs://my-bucket/file.txt" to
"gs://my-bucket/file2.txt".
node files copy my-bucket file.txt my-other-bucket Copy "gs://my-bucket/file.txt" to
file.txt "gs://my-other-bucket/file.txt".
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".
For more information, see https://cloud.google.com/storage/docs
```
Expand Down
Loading

0 comments on commit 3d4bb4d

Please sign in to comment.