Skip to content

Commit

Permalink
Move storage samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Sep 21, 2017
1 parent 7cd93ef commit 4ba9dda
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 2,564 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ deployment:
- node scripts/build "resource"
- node scripts/build "spanner"
- node scripts/build "speech"
- node scripts/build "storage"
- node scripts/build "storage-transfer"
- node scripts/build "trace"
- node scripts/build "translate"
# TODO: This build times out. Does video need more than 10 minutes?
Expand Down
5 changes: 2 additions & 3 deletions scripts/clean
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ const args = process.argv.slice(2);
if (!args.length || args[0] === 'coverage') {
rm('-rf', 'coverage');
} else if (args[0] === 'buckets') {
const NAME_REG_EXP = /^nodejs-docs-samples-test-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/;
const NAME_REG_EXP_2 = /^docs-samples-gae-test-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/;
const NAME_REG_EXP = /^docs-samples-gae-test-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/;

storage
.getBuckets()
.then(([buckets]) => {
let promise = Promise.resolve();

buckets
.filter((bucket) => NAME_REG_EXP.test(bucket.name) || NAME_REG_EXP_2.test(bucket.name))
.filter((bucket) => NAME_REG_EXP.test(bucket.name))
.forEach((bucket) => {
promise = promise.then(() => {
return bucket.deleteFiles()
Expand Down
68 changes: 68 additions & 0 deletions storage-transfer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud Storage Transfer API Node.js Samples

[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-storage-transfer.svg)]()

## Table of Contents

* [Setup](#setup)
* [Samples](#samples)
* [Storage Transfer API](#storage-transfer-api)
* [Running the tests](#running-the-tests)

## Setup

1. Read [Prerequisites][prereq] and [How to run a sample][run] first.
1. Install dependencies:

With **npm**:

npm install

With **yarn**:

yarn install

[prereq]: ../README.md#prerequisites
[run]: ../README.md#how-to-run-a-sample

## Samples

### Storage Transfer API

View the [documentation][transfer_0_docs] or the [source code][transfer_0_code].

__Usage:__ `node transfer.js --help`

```
Commands:
jobs <cmd> [args] Run a job command.
operations <cmd> [args] Run an operation command.
Options:
--help Show help [boolean]
Examples:
node transfer.js jobs --help Show job commands.
node transfer.js operations --help Show operations commands.
For more information, see https://cloud.google.com/storage/transfer
```

[transfer_0_docs]: https://cloud.google.com/storage/transfer
[transfer_0_code]: transfer.js

## Running the tests

1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables.

1. Run the tests:

With **npm**:

npm test

With **yarn**:

yarn test
48 changes: 48 additions & 0 deletions storage-transfer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "nodejs-docs-samples-storage-transfer",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": ">=4"
},
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"unit-test": "samples test run --cmd ava -- -T 20s --verbose test/*.test.js",
"system-test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js",
"test": "npm run unit-test && npm run system-test"
},
"dependencies": {
"googleapis": "21.3.0",
"moment": "2.18.1",
"safe-buffer": "5.1.1",
"yargs": "9.0.1"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.22.0",
"proxyquire": "1.8.0",
"sinon": "3.3.0",
"uuid": "3.1.0"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true,
"product": "storage",
"samples": [
{
"id": "transfer",
"name": "Storage Transfer API",
"file": "transfer.js",
"docs_link": "https://cloud.google.com/storage/transfer",
"usage": "node transfer.js --help"
}
]
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
251 changes: 4 additions & 247 deletions storage/README.md
Original file line number Diff line number Diff line change
@@ -1,248 +1,5 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
Samples for the [Google Cloud Storage Node.js Client][client] have moved to
[github.com/googleapis/nodejs-storage: samples/][samples].

# Google Cloud Storage Node.js Samples

[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-storage.svg)]()

[Cloud Storage](https://cloud.google.com/storage/docs) allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

## Table of Contents

* [Setup](#setup)
* [Samples](#samples)
* [ACL (Access Control Lists)](#acl-access-control-lists)
* [Buckets](#buckets)
* [Encryption](#encryption)
* [Files](#files)
* [Storage Transfer API](#storage-transfer-api)
* [Requester Pays samples](#requester-pays-samples)
* [Running the tests](#running-the-tests)

## Setup

1. Read [Prerequisites][prereq] and [How to run a sample][run] first.
1. Install dependencies:

With **npm**:

npm install

With **yarn**:

yarn install

[prereq]: ../README.md#prerequisites
[run]: ../README.md#how-to-run-a-sample

## Samples

### ACL (Access Control Lists)

View the [documentation][acl_0_docs] or the [source code][acl_0_code].

__Usage:__ `node acl.js --help`

```
Commands:
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:
--help Show help [boolean]
Examples:
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
```

[acl_0_docs]: https://cloud.google.com/storage/docs/access-control/create-manage-lists
[acl_0_code]: acl.js

### Buckets

View the [documentation][buckets_1_docs] or the [source code][buckets_1_code].

__Usage:__ `node buckets.js --help`

```
Commands:
create <bucket> Creates a new bucket.
list Lists all buckets in the current project.
delete <bucket> Deletes a bucket.
Options:
--help Show help [boolean]
Examples:
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
```

[buckets_1_docs]: https://cloud.google.com/storage/docs
[buckets_1_code]: buckets.js

### Encryption

View the [documentation][encryption_2_docs] or the [source code][encryption_2_code].

__Usage:__ `node encryption.js --help`

```
Commands:
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]
Examples:
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.js download my-bucket file_encrypted.txt Decrypts and downloads
./file.txt QxhqaZEqBGVTW55HhQw9Q= "gs://my-bucket/file_encrypted.txt" to "./file.txt".
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
```

[encryption_2_docs]: https://cloud.google.com/storage/docs
[encryption_2_code]: encryption.js

### Files

View the [documentation][files_3_docs] or the [source code][files_3_code].

__Usage:__ `node files.js --help`

```
Commands:
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]
Examples:
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_3_docs]: https://cloud.google.com/storage/docs
[files_3_code]: files.js

### Storage Transfer API

View the [documentation][transfer_4_docs] or the [source code][transfer_4_code].

__Usage:__ `node transfer.js --help`

```
Commands:
jobs <cmd> [args] Run a job command.
operations <cmd> [args] Run an operation command.
Options:
--help Show help [boolean]
Examples:
node transfer.js jobs --help Show job commands.
node transfer.js operations --help Show operations commands.
For more information, see https://cloud.google.com/storage/transfer
```

[transfer_4_docs]: https://cloud.google.com/storage/transfer
[transfer_4_code]: transfer.js

### Requester Pays samples

View the [documentation][requesterPays_5_docs] or the [source code][requesterPays_5_code].

__Usage:__ `node requesterPays.js --help`

```
Commands:
enable <bucket> Enables requester-pays requests on a bucket.
disable <bucket> Disables requester-pays requests on a bucket.
get-status <bucket> Determines whether requester-pays requests are enabled on a
bucket.
download <bucketName> <srcFileName> <destFileName> Downloads a file from a bucket using requester-pays requests.
Options:
--help Show help [boolean]
Examples:
node requesterPays.js enable my-bucket Enables requester-pays requests on a bucket named
"my-bucket".
node requesterPays.js disable my-bucket Disables requester-pays requests on a bucket named
"my-bucket".
node requesterPays.js get-status my-bucket Determines whether requester-pays requests are enabled
for a bucket named "my-bucket".
node requesterPays.js download my-bucket file.txt ./file.txt Downloads "gs://my-bucket/file.txt" to "./file.txt"
using requester-pays requests.
For more information, see https://cloud.google.com/storage/docs
```

[requesterPays_5_docs]: https://cloud.google.com/storage/docs
[requesterPays_5_code]: requesterPays.js

## Running the tests

1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables.

1. Run the tests:

With **npm**:

npm test

With **yarn**:

yarn test
[client]: https://github.com/googleapis/nodejs-storage
[samples]: https://github.com/googleapis/nodejs-storage/tree/master/samples
Loading

0 comments on commit 4ba9dda

Please sign in to comment.