Skip to content

Commit 3d4bb4d

Browse files
authored
Simplify Storage samples and their tests. (GoogleCloudPlatform#225)
1 parent db124bc commit 3d4bb4d

19 files changed

+1388
-2485
lines changed

pubsub/topics.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function listTopics (callback) {
3737
return;
3838
}
3939

40-
console.log(`Topics:`);
40+
console.log('Topics:');
4141
topics.forEach((topic) => console.log(topic.name));
4242
callback();
4343
});
@@ -257,7 +257,7 @@ function testTopicPermissions (topicName, callback) {
257257

258258
// The command-line program
259259
const cli = require(`yargs`);
260-
const makeHandler = require(`../utils`).makeHandler;
260+
const noop = require(`../utils`).noop;
261261

262262
const program = module.exports = {
263263
listTopics: listTopics,
@@ -277,30 +277,30 @@ const program = module.exports = {
277277
cli
278278
.demand(1)
279279
.command(`list`, `Lists all topics in the current project.`, {}, (options) => {
280-
program.listTopics(makeHandler(false));
280+
program.listTopics(noop);
281281
})
282282
.command(`create <topicName>`, `Creates a new topic.`, {}, (options) => {
283-
program.createTopic(options.topicName, makeHandler(false));
283+
program.createTopic(options.topicName, noop);
284284
})
285-
.command(`delete <topicName>`, `Deletes the a topic.`, {}, (options) => {
286-
program.deleteTopic(options.topicName, makeHandler(false));
285+
.command(`delete <topicName>`, `Deletes a topic.`, {}, (options) => {
286+
program.deleteTopic(options.topicName, noop);
287287
})
288288
.command(`publish <topicName> <message>`, `Publishes a message.`, {}, (options) => {
289289
try {
290290
options.message = JSON.parse(options.message);
291291
} catch (err) {
292292
// Ignore error
293293
}
294-
program.publishMessage(options.topicName, options.message, makeHandler(false));
294+
program.publishMessage(options.topicName, options.message, noop);
295295
})
296296
.command(`get-policy <topicName>`, `Gets the IAM policy for a topic.`, {}, (options) => {
297-
program.getTopicPolicy(options.topicName, makeHandler(false));
297+
program.getTopicPolicy(options.topicName, noop);
298298
})
299299
.command(`set-policy <topicName>`, `Sets the IAM policy for a topic.`, {}, (options) => {
300-
program.setTopicPolicy(options.topicName, makeHandler(false));
300+
program.setTopicPolicy(options.topicName, noop);
301301
})
302302
.command(`test-permissions <topicName>`, `Tests the permissions for a topic.`, {}, (options) => {
303-
program.testTopicPermissions(options.topicName, makeHandler(false));
303+
program.testTopicPermissions(options.topicName, noop);
304304
})
305305
.example(`node $0 list`, `Lists all topics in the current project.`)
306306
.example(`node $0 create greetings`, `Creates a new topic named "greetings".`)

storage/README.md

+68-56
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,38 @@ __Usage:__ `node acl --help`
3737

3838
```
3939
Commands:
40-
add <entity> <role> Add access controls on a bucket or file.
41-
get [entity] Get access controls on a bucket or file.
42-
delete <entity> Delete access controls from a bucket or file.
40+
print-bucket-acl <bucketName> Prints the ACL for a bucket.
41+
print-bucket-acl-for-user <bucketName> <userEmail> Prints a user's ACL for a bucket.
42+
add-bucket-owner <bucketName> <userEmail> Adds a user as an owner of a bucket.
43+
remove-bucket-owner <bucketName> <userEmail> Removes a user from the ACL of a bucket.
44+
add-bucket-default-owner <bucketName> <userEmail> Adds a user as an owner in the default ACL of a bucket.
45+
remove-bucket-default-owner <bucketName> <userEmail> Removes a user from the default ACL of a bucket.
46+
print-file-acl <bucketName> <fileName> Prints the ACL for a file.
47+
print-file-acl-for-user <bucketName> <fileName> <userEmail> Prints a user's ACL for a file.
48+
add-file-owner <bucketName> <fileName> <userEmail> Adds a user as an owner of a file.
49+
remove-file-owner <bucketName> <fileName> <userEmail> Removes a user from the ACL of a file.
4350
4451
Options:
45-
--bucket, -b The target storage bucket. [string] [required]
46-
--default, -d Whether to set default access
47-
controls. Only valid when setting
48-
access controls on a bucket. [boolean]
49-
--file, -f The target file. [string]
50-
--help Show help [boolean]
52+
--help Show help [boolean]
5153
5254
Examples:
53-
node acl add [email protected] OWNER -b mybucket Add OWNER access controls for
54-
"[email protected]" to "mybucket".
55-
node acl add viewers-2256 WRITER -b mybucket -d Add default WRITER access controls to
56-
"mybucket" for "viewers-2256".
57-
node acl get editors-1234 -b mybucket Get access controls for "editors-1234" in
58-
"mybucket".
59-
node acl delete -b mybucket -f file.txt Delete all access controls for all entities
60-
from "file.txt" in "mybucket".
55+
node acl print-bucket-acl my-bucket Prints the ACL for a bucket named "my-bucket".
56+
node acl print-bucket-acl-for-user my-bucket [email protected] Prints a user's ACL for a bucket named "my-bucket".
57+
node acl add-bucket-owner my-bucket [email protected] Adds "[email protected]" as an owner of a bucket named
58+
"my-bucket".
59+
node acl remove-bucket-owner my-bucket [email protected] Removes "[email protected]" from the ACL of a bucket named
60+
"my-bucket".
61+
node acl add-bucket-default-owner my-bucket [email protected] Adds "[email protected]" as an owner in the default ACL of
62+
a bucket named "my-bucket".
63+
node acl remove-bucket-default-owner my-bucket Removes "[email protected]" from the default ACL of a
64+
[email protected] bucket named "my-bucket".
65+
node acl print-file-acl my-bucket file.txt Prints the ACL for a file named "file.txt".
66+
node acl print-file-acl-for-user my-bucket file.txt Prints a user's ACL for a file named "file.txt".
67+
68+
node acl add-file-owner my-bucket file.txt [email protected] Adds "[email protected]" as an owner of a file named
69+
"file.txt".
70+
node acl remove-file-owner my-bucket file.txt Removes "[email protected]" from the ACL of a file named
71+
[email protected] "file.txt".
6172
6273
For more information, see https://cloud.google.com/storage/docs/access-control/create-manage-lists
6374
```
@@ -73,17 +84,17 @@ __Usage:__ `node buckets --help`
7384

7485
```
7586
Commands:
76-
create <bucket> Create a new bucket with the given name.
77-
list List all buckets in the authenticated project.
78-
delete <bucket> Delete the specified bucket.
87+
create <bucket> Creates a new bucket.
88+
list Lists all buckets in the current project.
89+
delete <bucket> Deletes a bucket.
7990
8091
Options:
81-
--help Show help [boolean]
92+
--help Show help [boolean]
8293
8394
Examples:
84-
node buckets create my-bucket Create a new bucket named "my-bucket".
85-
node buckets list List all buckets in the authenticated project.
86-
node buckets delete my-bucket Delete "my-bucket".
95+
node buckets create my-bucket Creates a new bucket named "my-bucket".
96+
node buckets list Lists all buckets in the current project.
97+
node buckets delete my-bucket Deletes a bucket named "my-bucket".
8798
8899
For more information, see https://cloud.google.com/storage/docs
89100
```
@@ -99,21 +110,21 @@ __Usage:__ `node encryption --help`
99110

100111
```
101112
Commands:
102-
generate-encryption-key Generate a sample encryption key.
103-
upload <bucket> <srcFile> <destFile> <key> Upload an encrypted file to a bucket.
104-
download <bucket> <srcFile> <destFile> <key> Download an encrypted file from a bucket.
105-
rotate <bucket> <file> <oldkey> <newKey> Rotate encryption keys for a file.
113+
generate-encryption-key Generate a sample encryption key.
114+
upload <bucketName> <srcFileName> <destFileName> <key> Encrypts and uploads a file.
115+
download <bucketName> <srcFileName> <destFileName> <key> Decrypts and downloads a file.
116+
rotate <bucketName> <fileName> <oldkey> <newKey> Rotates encryption keys for a file.
106117
107118
Options:
108-
--help Show help [boolean]
119+
--help Show help [boolean]
109120
110121
Examples:
111122
node encryption generate-encryption-key Generate a sample encryption key.
112-
node encryption upload my-bucket resources/test.txt Upload "resources/test.txt" to
123+
node encryption upload my-bucket ./resources/test.txt Encrypts and uploads "resources/test.txt" to
113124
file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt".
114-
node encryption download my-bucket file_encrypted.txt Download "gs://my-bucket/file_encrypted.txt" to
115-
./file.txt QxhqaZEqBGVTW55HhQw9Q= "./file.txt".
116-
node encryption rotate my-bucket file_encrypted.txt Rotate encryptiong keys for
125+
node encryption download my-bucket file_encrypted.txt Decrypts and downloads
126+
./file.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt" to "./file.txt".
127+
node encryption rotate my-bucket file_encrypted.txt Rotates encryptiong keys for
117128
QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q= "gs://my-bucket/file_encrypted.txt".
118129
119130
For more information, see https://cloud.google.com/storage/docs
@@ -130,33 +141,34 @@ __Usage:__ `node files --help`
130141

131142
```
132143
Commands:
133-
list <bucket> [options] List files in a bucket, optionally filtering
134-
by a prefix.
135-
upload <bucket> <srcFile> Upload a local file to a bucket.
136-
download <bucket> <srcFile> <destFile> Download a file from a bucket.
137-
delete <bucket> <file> Delete a file from a bucket.
138-
getMetadata <bucket> <file> Get metadata for a file in a bucket.
139-
makePublic <bucket> <file> Make a file public in a bucket.
140-
move <bucket> <srcFile> <destFile> Rename a file in a bucket.
141-
copy <srcBucket> <srcFile> <destBucket> <destFile> Copy a file in a bucket to another bucket.
144+
list <bucketName> [prefix] [delimiter] Lists files in a bucket, optionally filtering by a
145+
prefix.
146+
upload <bucketName> <srcFileName> Uploads a local file to a bucket.
147+
download <bucketName> <srcFileName> <destFileName> Downloads a file from a bucket.
148+
delete <bucketName> <fileName> Deletes a file from a bucket.
149+
get-metadata <bucketName> <fileName> Gets the metadata for a file.
150+
make-public <bucketName> <fileName> Makes a file public.
151+
generate-signed-url <bucketName> <fileName> Generates a signed URL for a file.
152+
move <bucketName> <srcFileName> <destFileName> Moves a file to a new location within the same bucket,
153+
i.e. rename the file.
154+
copy <srcBucketName> <srcFileName> <destBucketName> Copies a file in a bucket to another bucket.
155+
<destFileName>
142156
143157
Options:
144-
--help Show help [boolean]
158+
--help Show help [boolean]
145159
146160
Examples:
147-
node files list my-bucket List files in "my-bucket".
148-
node files list my-bucket -p public/ List files in "my-bucket" filtered by prefix
149-
"public/".
150-
node files upload my-bucket ./file.txt Upload "./file.txt" to "my-bucket".
151-
node files download my-bucket file.txt ./file.txt Download "gs://my-bucket/file.txt" to
152-
"./file.txt".
153-
node files delete my-bucket file.txt Delete "gs://my-bucket/file.txt".
154-
node files getMetadata my-bucket file.txt Get metadata for "gs://my-bucket/file.txt".
155-
node files makePublic my-bucket file.txt Make "gs://my-bucket/file.txt" public.
156-
node files move my-bucket file.txt file2.txt Rename "gs://my-bucket/file.txt" to
157-
"gs://my-bucket/file2.txt".
158-
node files copy my-bucket file.txt my-other-bucket Copy "gs://my-bucket/file.txt" to
159-
file.txt "gs://my-other-bucket/file.txt".
161+
node files list my-bucket Lists files in "my-bucket".
162+
node files list my-bucket public/ Lists files in "my-bucket" filtered by prefix "public/".
163+
node files upload my-bucket ./file.txt Uploads "./file.txt" to "my-bucket".
164+
node files download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt".
165+
node files delete my-bucket file.txt Deletes "gs://my-bucket/file.txt".
166+
node files get-metadata my-bucket file.txt Gets the metadata for "gs://my-bucket/file.txt".
167+
node files make-public my-bucket file.txt Makes "gs://my-bucket/file.txt" public.
168+
node files move my-bucket file.txt file2.txt Renames "gs://my-bucket/file.txt" to
169+
"gs://my-bucket/file2.txt".
170+
node files copy my-bucket file.txt my-other-bucket file.txt Copies "gs://my-bucket/file.txt" to
171+
"gs://my-other-bucket/file.txt".
160172
161173
For more information, see https://cloud.google.com/storage/docs
162174
```

0 commit comments

Comments
 (0)