Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring Storage samples up to standard. #386

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"check": "yarn check --strict-semver --integrity",
"lint": "samples lint",
"generate": "node ./scripts/generate",
"pretest": "npm run lint && ./scripts/clean",
"pretest": "npm run lint && node ./scripts/clean coverage",
"unit-test": "ava --verbose -T 30s functions/**/test/**/*.test.js",
"unit-cover": "nyc --cache npm test && nyc report --reporter=html",
"system-test": "ava --verbose -T 30s vision/system-test/**/*.test.js",
Expand All @@ -55,6 +55,7 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.13",
"@google-cloud/storage": "1.1.0",
"ava": "0.19.1",
"nyc": "10.3.2",
"shelljs": "0.7.7"
Expand Down
33 changes: 32 additions & 1 deletion scripts/clean
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,35 @@

require('shelljs/global');

rm('-rf', 'coverage');
const storage = require('@google-cloud/storage')();

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}$/;

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

buckets
.filter((bucket) => NAME_REG_EXP.test(bucket.name))
.forEach((bucket) => {
promise = promise.then(() => {
return bucket.deleteFiles()
.then(() => bucket.deleteFiles(), console.error)
.then(() => {
console.log(`Deleting ${bucket.name}`);
return bucket.delete();
}, console.error)
.catch(console.error);
});
});
})
.catch((err) => {
console.error('ERROR:', err);
});
}
4 changes: 2 additions & 2 deletions storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ __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.
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:
Expand Down
Loading