-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlobStorageCommand.js
More file actions
75 lines (67 loc) · 3.27 KB
/
Copy pathBlobStorageCommand.js
File metadata and controls
75 lines (67 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const AzureBlobStorageHandler = require("./AzureBlobStorageHandler.js");
function addBlobStorageCommandOptions(program, azureConfig, fileList, debug=false) {
let azureHandler = new AzureBlobStorageHandler(azureConfig, fileList)
// create a blob storage container
program
.command('create-container')
.description('Creates container in blob storage')
.option('-n, --name <name>', 'The name of the container')
.option('-d, --debug <debug>', 'Enable debug response')
.action(async (options, _) => {
await azureHandler.createContainerInBlobStorage(options.name, options.debug); // some hocus-pocus
})
// delete a blob storage container
program
.command('delete-container')
.description('Deletes container from the blob storage')
.option('-n, --name <name>', 'The name of the container')
.option('-d, --debug <debug>', 'Enable debug response')
.action(async (options, _) => {
await azureHandler.deleteContainerInBlobStorage(options.name, options.debug);
})
// download file from blob storage
program
.command('download')
.description('Downloads files from the blob storage. Drop -f to download all files mentioned in config file list')
.option('-n, --name <name>', 'name of the container')
.option('-b, --blob <blob>', 'name of blob')
.option('-f, --file <file>', 'file to download')
.option('-o, --output <output>', 'path to store downloaded report(s)')
.option('-d, --debug <debug>', 'Enable debug response')
.action(async(options, _) => {
if (!options.output) {
// set download path to present directory
options.output = ".";
}
if (!options.file) {
await azureHandler.downloadAllReportsFromBlobStorage(options.name, options.blob, options.output, options.debug);
} else {
console.log(`Downloaded ${options.name} to ${options.blob}`);
await azureHandler.downloadReportFromBlobStorage(options.name, options.blob, options.file, options.output, options.debug);
}
})
// upload file to blob storage
program
.command('upload')
.description('Uploads file to the blob storage at the provided path within the container')
.option('-n, --name <name>', 'The name of the container')
.option('-f, --file <file>', 'path of file to upload')
.option('-b, --blob <blob>', 'name of blob to upload to')
.option('-d, --debug <debug>', 'Enable debug response')
.action(async (options, _) => {
await azureHandler.uploadFileToBlobStorage(options.name, options.file, options.blob, options.debug)
})
// list storage entities
program
.command('list')
.description('Lists all blobs in the container')
.option('-n, --name <name>', 'The name of the container')
.option('-p, --prefix <prefix>', 'The prefix/folder of the blob')
.option('-d, --debug <debug>', 'Enable debug response')
.action(async (options, _) => {
await azureHandler.listAzureEntities(options.name, options.prefix, options.debug)
})
}
module.exports = {
addBlobStorageCommandOptions
}