Skip to content

Commit ffe2476

Browse files
authored
All Storage samples are now up to standard. (#182)
* All Storage samples are now up to standard. * Address comments * Address comments * Remove .only * Fixed links
1 parent e4958b0 commit ffe2476

17 files changed

+1324
-1309
lines changed

CONTRIBUTING.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,65 @@ accept your pull requests.
2727
1. Fork the desired repo, develop and test your code changes.
2828
1. Ensure that your code adheres to the existing style in the sample to which you are contributing. Refer to the
2929
[Google Cloud Platform Samples Style Guide](https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
30-
recommended coding standards for this organization. You can run `npm run jshint` to match our JavaScript coding standards.
30+
recommended coding standards for this organization. You can run `npm run jshint` to match our JavaScript coding standards.
3131
1. Ensure that your code has an appropriate set of unit tests which all pass.
3232
1. Submit a pull request!
33+
34+
## Sample template
35+
36+
```
37+
<LICENSE_HEADER>
38+
39+
// [START all]
40+
// [START setup]
41+
// By default, the client will authenticate using the service account file
42+
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
43+
// the project specified by the GCLOUD_PROJECT environment variable. See
44+
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
45+
var <API_CLIENT> = require('@google-cloud/<API>');
46+
47+
// Instantiate a <API> client
48+
var <CLIENT> = <API_CLIENT>();
49+
// [END setup]
50+
51+
// [START <REGION_TAG_NAME>]
52+
/**
53+
* <DESCRIPTION>
54+
*
55+
* @param {<TYPE>} <NAME> <DESCRIPTION>.
56+
* @param {function} cb The callback function.
57+
*/
58+
function <METHOD_NAME> (<ARGUMENTS>, callback) {
59+
// <SETUP>
60+
61+
// <RUN SAMPLE CODE>
62+
63+
// Inside callback: console.log(<MESSAGE>)
64+
}
65+
// [END <REGION_TAG_NAME>]
66+
67+
// The command-line program
68+
var cli = require('yargs');
69+
70+
var program = module.exports = {
71+
<METHOD_NAME>: <METHOD_NAME>,
72+
main: function (args) {
73+
// Run the command-line program
74+
cli.help().strict().parse(args).argv;
75+
}
76+
};
77+
78+
cli
79+
.demand(1)
80+
.command('<COMMAND> <ARGS>', '<DESCRIPTION>.', {}, function (options) {
81+
program.<METHOD_NAME>(options, console.log);
82+
})
83+
.example('node $0 <COMMAND> <ARGS>', '<DESCRIPTION>.')
84+
.wrap(100)
85+
.recommendCommands()
86+
.epilogue('For more information, see <DOCS_LINK>');
87+
88+
if (module === require.main) {
89+
program.main(process.argv.slice(2));
90+
}
91+
```

storage/README.md

+114-71
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ Commands:
4242
delete <entity> Delete access controls from a bucket or file.
4343
4444
Options:
45-
--bucket, -b The target storage bucket. [string] [required]
46-
--default, -d Whether to set default access controls. Only valid when setting access controls on
47-
a bucket. [boolean]
48-
--file, -f The target file. [string]
49-
--help Show help [boolean]
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]
5051
5152
Examples:
5253
node acl add [email protected] OWNER -b mybucket Add OWNER access controls for
@@ -71,19 +72,20 @@ View the [documentation][buckets_docs] or the [source code][buckets_code].
7172
__Usage:__ `node buckets --help`
7273

7374
```
74-
Usage: node buckets COMMAND [ARGS...]
75-
7675
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.
7779
78-
create BUCKET_NAME
79-
list
80-
delete BUCKET_NAME
80+
Options:
81+
--help Show help [boolean]
8182
8283
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".
8387
84-
node buckets create my-bucket
85-
node buckets list
86-
node buckets delete my-bucket
88+
For more information, see https://cloud.google.com/storage/docs
8789
```
8890

8991
[buckets_docs]: https://cloud.google.com/storage/docs
@@ -96,21 +98,25 @@ View the [documentation][encryption_docs] or the [source code][encryption_code].
9698
__Usage:__ `node encryption --help`
9799

98100
```
99-
Usage: node encryption COMMAND [ARGS...]
100-
101101
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.
102106
103-
generate-encryption-key
104-
upload BUCKET_NAME SRC_FILE_NAME DEST_FILE_NAME KEY
105-
download BUCKET_NAME SRC_FILE_NAME DEST_FILE_NAME KEY
106-
rotate BUCKET_NAME FILE_NAME OLD_KEY NEW_KEY
107+
Options:
108+
--help Show help [boolean]
107109
108110
Examples:
109-
110-
node encryption generate-encryption-key
111-
node encryption upload my-bucket resources/test.txt file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q=
112-
node encryption download my-bucket file_encrypted.txt ./file.txt QxhqaZEqBGVTW55HhQw9Q=
113-
node encryption rotate my-bucket file_encrypted.txt QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q=
111+
node encryption generate-encryption-key Generate a sample encryption key.
112+
node encryption upload my-bucket resources/test.txt Upload "resources/test.txt" to
113+
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
117+
QxhqaZEqBGVTW55HhQw9Q= SxafpsdfSDFS89sds9Q= "gs://my-bucket/file_encrypted.txt".
118+
119+
For more information, see https://cloud.google.com/storage/docs
114120
```
115121

116122
[encryption_docs]: https://cloud.google.com/storage/docs
@@ -123,32 +129,36 @@ View the [documentation][files_docs] or the [source code][files_code].
123129
__Usage:__ `node files --help`
124130

125131
```
126-
Usage: node files COMMAND [ARGS...]
127-
128132
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.
129142
130-
list BUCKET_NAME
131-
listByPrefix BUCKET_NAME PREFIX [DELIMITER]
132-
upload BUCKET_NAME FILE_NAME
133-
download BUCKET_NAME SRC_FILE_NAME DEST_FILE_NAME
134-
delete BUCKET_NAME FILE_NAME
135-
getMetadata BUCKET_NAME FILE_NAME
136-
makePublic BUCKET_NAME FILE_NAME
137-
move BUCKET_NAME SRC_FILE_NAME DEST_FILE_NAME
138-
copy BUCKET_NAME SRC_FILE_NAME DEST_BUCKET_NAME DEST_FILE_NAME
143+
Options:
144+
--help Show help [boolean]
139145
140146
Examples:
141-
142-
list my-bucket
143-
listByPrefix my-bucket /some-folder
144-
listByPrefix my-bucket /some-folder -
145-
upload my-bucket ./file.txt
146-
download my-bucket file.txt ./file.txt
147-
delete my-bucket file.txt
148-
getMetadata my-bucket file.txt
149-
makePublic my-bucket file.txt
150-
move my-bucket file.txt file2.txt
151-
copy my-bucket file.txt my-other-bucket file.txt
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".
160+
161+
For more information, see https://cloud.google.com/storage/docs
152162
```
153163

154164
[files_docs]: https://cloud.google.com/storage/docs
@@ -161,41 +171,74 @@ View the [documentation][storagetransfer_docs] or the [source code][storagetrans
161171
__Usage:__ `node transfer --help`
162172

163173
```
164-
Usage: node encryption RESOURCE COMMAND [ARGS...]
174+
Commands:
175+
jobs <cmd> [args] Run a job command.
176+
operations <cmd> [args] Run an operation command.
165177
166-
Resources:
178+
Options:
179+
--help Show help [boolean]
167180
168-
jobs
181+
Examples:
182+
node transfer jobs --help Show job commands.
183+
node transfer operations --help Show operations commands.
169184
170-
Commands:
185+
For more information, see https://cloud.google.com/storage/transfer
186+
```
171187

172-
create SRC_BUCKET_NAME DEST_BUCKET_NAME DATE TIME [DESCRIPTION]
173-
get JOB_NAME
174-
list
175-
set JOB_NAME FIELD VALUE
188+
__Usage:__ `node transfer jobs --help`
176189

177-
operations
190+
```
191+
transfer jobs <cmd> [args]
178192
179-
Commands:
193+
Commands:
194+
create <srcBucket> <destBucket> <time> <date> Create a transfer job.
195+
[description]
196+
get <job> Get a transfer job.
197+
list List transfer jobs.
198+
set <job> <field> <value> Change the status, description or transferSpec
199+
of a transfer job.
180200
181-
list [JOB_NAME]
182-
get TRANSFER_NAME
183-
pause TRANSFER_NAME
184-
resume TRANSFER_NAME
201+
Options:
202+
--help Show help [boolean]
185203
186204
Examples:
205+
node transfer jobs create my-bucket Create a transfer job.
206+
my-other-bucket 2016/08/12 16:30 "Move my files"
207+
node transfer jobs get Get a transfer job.
208+
transferJobs/123456789012345678
209+
node transfer jobs list List transfer jobs.
210+
node transfer jobs set Update the description for a transfer job.
211+
transferJobs/123456789012345678 description "My
212+
new description"
213+
node transfer jobs set Disable a transfer job.
214+
transferJobs/123456789012345678 status DISABLED
215+
```
216+
217+
__Usage:__ `node transfer operations --help`
218+
219+
```
220+
transfer operations <cmd> [args]
221+
222+
Commands:
223+
list [job] List transfer operations, optionally filtering by a job name.
224+
get <operation> Get a transfer operation.
225+
pause <operation> Pause a transfer operation.
226+
resume <operation> Resume a transfer operation.
187227
188-
node transfer jobs create my-bucket my-other-bucket 2016/08/12 16:30 "Move my files"
189-
node transfer jobs get transferJobs/123456789012345678
190-
node transfer jobs list
191-
node transfer jobs set transferJobs/123456789012345678 description "My new description"
192-
node transfer jobs set transferJobs/123456789012345678 status DISABLED
193-
node transfer operations list
194-
node transfer operations list transferJobs/123456789012345678
195-
node transfer operations get transferOperations/123456789012345678
196-
node transfer operations pause transferOperations/123456789012345678
197-
node transfer operations resume transferOperations/123456789012345678
228+
Options:
229+
--help Show help [boolean]
230+
231+
Examples:
232+
node transfer operations list List all transfer operations.
233+
node transfer operations list List all transfer operations for a specific
234+
transferJobs/123456789012345678 job.
235+
node transfer operations get Get a transfer operation.
236+
transferOperations/123456789012345678
237+
node transfer operations pause Pause a transfer operation.
238+
transferOperations/123456789012345678
239+
node transfer operations resume Resume a transfer operation.
240+
transferOperations/123456789012345678
198241
```
199242

200-
[storagetransfer_docs]: https://cloud.google.com/storage/docs
243+
[storagetransfer_docs]: https://cloud.google.com/storage/transfer
201244
[storagetransfer_code]: transfer.js

storage/acl.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ function addAccessControl (options, callback) {
4141
// Reference the specified storage bucket
4242
var bucket = storage.bucket(options.bucket);
4343
// Reference the bucket's acl resource
44-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.add
44+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
4545
var acl = bucket.acl;
4646

4747
if (options.file) {
4848
// Optionally target a file's acl resource
49-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/file?method=acl.add
49+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/file
5050
acl = bucket.file(options.file).acl;
5151
} else if (options.default) {
5252
// Optionally add "default" access controls to the bucket
53-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.default.add
53+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
5454
acl = acl.default;
5555
}
5656

@@ -86,16 +86,16 @@ function getAccessControl (options, callback) {
8686
// Reference the specified storage bucket
8787
var bucket = storage.bucket(options.bucket);
8888
// Reference the bucket's acl resource
89-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.get
89+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
9090
var acl = bucket.acl;
9191

9292
if (options.file) {
9393
// Optionally target a file's acl resource
94-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/file?method=acl.get
94+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/file
9595
acl = bucket.file(options.file).acl;
9696
} else if (options.default) {
9797
// Optionally get "default" access controls for the bucket
98-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.default.get
98+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
9999
acl = acl.default;
100100
}
101101

@@ -133,16 +133,16 @@ function deleteAccessControl (options, callback) {
133133
// Reference the specified storage bucket
134134
var bucket = storage.bucket(options.bucket);
135135
// Reference the bucket's acl resource
136-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.delete
136+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
137137
var acl = bucket.acl;
138138

139139
if (options.file) {
140140
// Optionally target a file's acl resource
141-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/file?method=acl.delete
141+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/file
142142
acl = bucket.file(options.file).acl;
143143
} else if (options.default) {
144144
// Optionally delete "default" access controls from the bucket
145-
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/storage/bucket?method=acl.default.delete
145+
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/storage/latest/storage/bucket
146146
acl = acl.default;
147147
}
148148

@@ -173,6 +173,7 @@ var program = module.exports = {
173173
};
174174

175175
cli
176+
.demand(1)
176177
.command('add <entity> <role>', 'Add access controls on a bucket or file.', {}, function (options) {
177178
program.addAccessControl(options, console.log);
178179
})

0 commit comments

Comments
 (0)