|
1 |
| -package cmd |
2 |
| - |
3 |
| -import ( |
4 |
| - "fmt" |
5 |
| - |
6 |
| - "github.com/spf13/cobra" |
7 |
| -) |
8 |
| - |
9 |
| -// storeCmd represents the store command |
10 |
| -var storeCmd = &cobra.Command{ |
11 |
| - Use: "store", |
12 |
| - Short: "Command to upload data to storj V3 network.", |
13 |
| - Long: `Command to connect and transfer ALL tables from a desired Zenko instance to given Storj Bucket.`, |
14 |
| - Run: zenkoStore, |
15 |
| -} |
16 |
| - |
17 |
| -func init() { |
18 |
| - |
19 |
| - // Setup the store command with its flags. |
20 |
| - rootCmd.AddCommand(storeCmd) |
21 |
| - var defaultZenkoFile string |
22 |
| - var defaultStorjFile string |
23 |
| - storeCmd.Flags().BoolP("accesskey", "a", false, "Connect to storj using access key(default connection method is by using API Key).") |
24 |
| - storeCmd.Flags().BoolP("share", "s", false, "For generating share access of the uploaded backup file.") |
25 |
| - storeCmd.Flags().StringVarP(&defaultZenkoFile, "zenko", "z", "./config/zenko_property.json", "full filepath contaning Zenko configuration.") |
26 |
| - storeCmd.Flags().StringVarP(&defaultStorjFile, "storj", "u", "./config/storj_config.json", "full filepath contaning storj V3 configuration.") |
27 |
| -} |
28 |
| - |
29 |
| -func zenkoStore(cmd *cobra.Command, args []string) { |
30 |
| - |
31 |
| - // Process arguments from the CLI. |
32 |
| - zenkoConfigfilePath, _ := cmd.Flags().GetString("zenko") |
33 |
| - fullFileNameStorj, _ := cmd.Flags().GetString("storj") |
34 |
| - useAccessKey, _ := cmd.Flags().GetBool("accesskey") |
35 |
| - useAccessShare, _ := cmd.Flags().GetBool("share") |
36 |
| - |
37 |
| - // Read Zenko instance's configurations from an external file and create an Zenko configuration object. |
38 |
| - configZenko := LoadZenkoProperty(zenkoConfigfilePath) |
39 |
| - |
40 |
| - // Read storj network configurations from and external file and create a storj configuration object. |
41 |
| - storjConfig := LoadStorjConfiguration(fullFileNameStorj) |
42 |
| - |
43 |
| - // Connect to storj network using the specified credentials. |
44 |
| - access, project := ConnectToStorj(fullFileNameStorj, storjConfig, useAccessKey) |
45 |
| - |
46 |
| - // Establish connection with Zenko and get io.Reader implementor. |
47 |
| - zenkoReader := ConnectToZenko(configZenko) |
48 |
| - |
49 |
| - // Fetch all file names and their corresponding Reader Object for upload |
50 |
| - uploadPathNames, zenkoObjectReaders := GetFileAndObjectNames(zenkoReader) |
51 |
| - |
52 |
| - fmt.Printf("\nInitiating back-up.\n") |
53 |
| - // Fetch all backup files from Zenko instance and simultaneously store them into desired Storj bucket. |
54 |
| - for i := 0; i < len(uploadPathNames); i++ { |
55 |
| - UploadData(project, storjConfig, uploadPathNames[i], zenkoObjectReaders[i]) |
56 |
| - } |
57 |
| - fmt.Printf("\nBack-up complete.\n\n") |
58 |
| - |
59 |
| - // Create restricted shareable serialized access if share is provided as argument. |
60 |
| - if useAccessShare { |
61 |
| - ShareAccess(access, storjConfig) |
62 |
| - } |
63 |
| -} |
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
| 8 | + |
| 9 | +// storeCmd represents the store command |
| 10 | +var storeCmd = &cobra.Command{ |
| 11 | + Use: "store", |
| 12 | + Short: "Command to upload data to storj V3 network.", |
| 13 | + Long: `Command to connect and transfer ALL tables from a desired Zenko instance to given Storj Bucket.`, |
| 14 | + Run: zenkoStore, |
| 15 | +} |
| 16 | + |
| 17 | +func init() { |
| 18 | + |
| 19 | + // Setup the store command with its flags. |
| 20 | + rootCmd.AddCommand(storeCmd) |
| 21 | + var defaultZenkoFile string |
| 22 | + var defaultStorjFile string |
| 23 | + storeCmd.Flags().BoolP("accesskey", "a", false, "Connect to storj using access key(default connection method is by using API Key).") |
| 24 | + storeCmd.Flags().BoolP("share", "s", false, "For generating share access of the uploaded backup file.") |
| 25 | + storeCmd.Flags().StringVarP(&defaultZenkoFile, "zenko", "z", "./config/zenko_property.json", "full filepath contaning Zenko configuration.") |
| 26 | + storeCmd.Flags().StringVarP(&defaultStorjFile, "storj", "u", "./config/storj_config.json", "full filepath contaning storj V3 configuration.") |
| 27 | +} |
| 28 | + |
| 29 | +func zenkoStore(cmd *cobra.Command, args []string) { |
| 30 | + |
| 31 | + // Process arguments from the CLI. |
| 32 | + zenkoConfigfilePath, _ := cmd.Flags().GetString("zenko") |
| 33 | + fullFileNameStorj, _ := cmd.Flags().GetString("storj") |
| 34 | + useAccessKey, _ := cmd.Flags().GetBool("accesskey") |
| 35 | + useAccessShare, _ := cmd.Flags().GetBool("share") |
| 36 | + |
| 37 | + // Read Zenko instance's configurations from an external file and create an Zenko configuration object. |
| 38 | + configZenko := LoadZenkoProperty(zenkoConfigfilePath) |
| 39 | + |
| 40 | + // Read storj network configurations from and external file and create a storj configuration object. |
| 41 | + storjConfig := LoadStorjConfiguration(fullFileNameStorj) |
| 42 | + |
| 43 | + // Connect to storj network using the specified credentials. |
| 44 | + access, project := ConnectToStorj(fullFileNameStorj, storjConfig, useAccessKey) |
| 45 | + |
| 46 | + // Establish connection with Zenko and get io.Reader implementor. |
| 47 | + zenkoReader := ConnectToZenko(configZenko) |
| 48 | + |
| 49 | + // Fetch all file names and their corresponding Reader Object for upload |
| 50 | + uploadPathNames, zenkoObjectReaders := GetFileAndObjectNames(zenkoReader) |
| 51 | + |
| 52 | + fmt.Printf("\nInitiating back-up.\n") |
| 53 | + // Fetch all backup files from Zenko instance and simultaneously store them into desired Storj bucket. |
| 54 | + for i := 0; i < len(uploadPathNames); i++ { |
| 55 | + UploadData(project, storjConfig, uploadPathNames[i], zenkoObjectReaders[i]) |
| 56 | + } |
| 57 | + fmt.Printf("\nBack-up complete.\n\n") |
| 58 | + |
| 59 | + // Create restricted shareable serialized access if share is provided as argument. |
| 60 | + if useAccessShare { |
| 61 | + ShareAccess(access, storjConfig) |
| 62 | + } |
| 63 | +} |
0 commit comments