diff --git a/cmd/flag/encryption.go b/cmd/flag/encryption.go index 37a39c7..dc58feb 100644 --- a/cmd/flag/encryption.go +++ b/cmd/flag/encryption.go @@ -9,6 +9,7 @@ import ( type EncryptionFlagValues struct { Encryption bool + NoEncryption bool IgnoreMeta bool Mode commons.EncryptionMode modeInput string @@ -19,6 +20,7 @@ type EncryptionFlagValues struct { type DecryptionFlagValues struct { Decryption bool + NoDecryption bool IgnoreMeta bool Key string PrivateKeyPath string @@ -32,35 +34,44 @@ var ( func SetEncryptionFlags(command *cobra.Command) { command.Flags().BoolVar(&encryptionFlagValues.Encryption, "encrypt", false, "Encrypt files") + command.Flags().BoolVar(&encryptionFlagValues.NoEncryption, "no_encrypt", false, "Disable encryption forcefully") command.Flags().BoolVar(&encryptionFlagValues.IgnoreMeta, "ignore_meta", false, "Ignore encryption config via metadata") command.Flags().StringVar(&encryptionFlagValues.modeInput, "encrypt_mode", "ssh", "Encryption mode ('winscp', 'pgp', or 'ssh')") command.Flags().StringVar(&encryptionFlagValues.Key, "encrypt_key", "", "Encryption key for 'winscp' and 'pgp' mode") command.Flags().StringVar(&encryptionFlagValues.PublicPrivateKeyPath, "encrypt_pub_key", commons.GetDefaultPublicKeyPath(), "Encryption public (or private) key for 'ssh' mode") command.Flags().StringVar(&encryptionFlagValues.TempPath, "encrypt_temp", os.TempDir(), "Specify temp directory path for encrypting files") - } func SetDecryptionFlags(command *cobra.Command) { command.Flags().BoolVar(&decryptionFlagValues.Decryption, "decrypt", false, "Decrypt files") + command.Flags().BoolVar(&decryptionFlagValues.NoDecryption, "no_decrypt", false, "Disable decryption forcefully") command.Flags().BoolVar(&decryptionFlagValues.IgnoreMeta, "ignore_meta", false, "Ignore decryption config via metadata") command.Flags().StringVar(&decryptionFlagValues.Key, "decrypt_key", "", "Decryption key for 'winscp' and 'pgp' mode") command.Flags().StringVar(&decryptionFlagValues.PrivateKeyPath, "decrypt_priv_key", commons.GetDefaultPrivateKeyPath(), "Decryption private key for 'ssh' mode") command.Flags().StringVar(&decryptionFlagValues.TempPath, "decrypt_temp", os.TempDir(), "Specify temp directory path for decrypting files") } -func GetEncryptionFlagValues() *EncryptionFlagValues { +func GetEncryptionFlagValues(command *cobra.Command) *EncryptionFlagValues { encryptionFlagValues.Mode = commons.GetEncryptionMode(encryptionFlagValues.modeInput) - if len(encryptionFlagValues.Key) > 0 { + if command.Flags().Changed("encrypt_key") && len(encryptionFlagValues.Key) > 0 { encryptionFlagValues.Encryption = true } + if encryptionFlagValues.NoEncryption { + encryptionFlagValues.Encryption = false + } + return &encryptionFlagValues } -func GetDecryptionFlagValues() *DecryptionFlagValues { - if len(decryptionFlagValues.Key) > 0 { +func GetDecryptionFlagValues(command *cobra.Command) *DecryptionFlagValues { + if command.Flags().Changed("decrypt_key") && len(decryptionFlagValues.Key) > 0 { decryptionFlagValues.Decryption = true } + if decryptionFlagValues.NoDecryption { + decryptionFlagValues.Decryption = false + } + return &decryptionFlagValues } diff --git a/cmd/subcmd/get.go b/cmd/subcmd/get.go index 2276d51..0d8f057 100644 --- a/cmd/subcmd/get.go +++ b/cmd/subcmd/get.go @@ -74,7 +74,7 @@ func processGetCommand(command *cobra.Command, args []string) error { differentialTransferFlagValues := flag.GetDifferentialTransferFlagValues() noRootFlagValues := flag.GetNoRootFlagValues() syncFlagValues := flag.GetSyncFlagValues() - decryptionFlagValues := flag.GetDecryptionFlagValues() + decryptionFlagValues := flag.GetDecryptionFlagValues(command) postTransferFlagValues := flag.GetPostTransferFlagValues() maxConnectionNum := parallelTransferFlagValues.ThreadNumber + 2 // 2 for metadata op @@ -197,7 +197,7 @@ func getOne(parallelJobManager *commons.ParallelJobManager, inputPathMap map[str } // load encryption config from meta - if !decryptionFlagValues.IgnoreMeta { + if !decryptionFlagValues.NoDecryption && !decryptionFlagValues.IgnoreMeta { sourceDir := sourcePath if !sourceEntry.IsDir() { sourceDir = commons.GetDir(sourcePath) diff --git a/cmd/subcmd/ls.go b/cmd/subcmd/ls.go index 4c5de09..77b2ee4 100644 --- a/cmd/subcmd/ls.go +++ b/cmd/subcmd/ls.go @@ -67,7 +67,7 @@ func processLsCommand(command *cobra.Command, args []string) error { ticketAccessFlagValues := flag.GetTicketAccessFlagValues() listFlagValues := flag.GetListFlagValues() - decryptionFlagValues := flag.GetDecryptionFlagValues() + decryptionFlagValues := flag.GetDecryptionFlagValues(command) appConfig := commons.GetConfig() @@ -126,7 +126,7 @@ func listOne(fs *irodsclient_fs.FileSystem, sourcePath string, listFlagValues *f } // load encryption config from meta - if !decryptionFlagValues.IgnoreMeta { + if !decryptionFlagValues.NoDecryption && !decryptionFlagValues.IgnoreMeta { sourceDir := sourcePath if !sourceEntry.IsDir() { sourceDir = commons.GetDir(sourcePath) diff --git a/cmd/subcmd/put.go b/cmd/subcmd/put.go index cdf3a22..8cdf750 100644 --- a/cmd/subcmd/put.go +++ b/cmd/subcmd/put.go @@ -73,7 +73,7 @@ func processPutCommand(command *cobra.Command, args []string) error { differentialTransferFlagValues := flag.GetDifferentialTransferFlagValues() noRootFlagValues := flag.GetNoRootFlagValues() syncFlagValues := flag.GetSyncFlagValues() - encryptionFlagValues := flag.GetEncryptionFlagValues() + encryptionFlagValues := flag.GetEncryptionFlagValues(command) postTransferFlagValues := flag.GetPostTransferFlagValues() maxConnectionNum := parallelTransferFlagValues.ThreadNumber + 2 // 2 for metadata op @@ -200,7 +200,7 @@ func putOne(parallelJobManager *commons.ParallelJobManager, inputPathMap map[str } // load encryption config from meta - if !encryptionFlagValues.IgnoreMeta { + if !encryptionFlagValues.NoEncryption && !encryptionFlagValues.IgnoreMeta { targetDir := targetPath targetEntry, err := filesystem.Stat(targetPath) if err != nil {