Skip to content

Commit

Permalink
Bring Storage samples up to standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed May 11, 2017
1 parent ebf7a3d commit 28aed1c
Show file tree
Hide file tree
Showing 16 changed files with 1,080 additions and 369 deletions.
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

0 comments on commit 28aed1c

Please sign in to comment.