Skip to content

Commit

Permalink
Add --no_decrypt and --no_encrypt flags to disable encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed May 16, 2024
1 parent 95cecb3 commit 93df5ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
21 changes: 16 additions & 5 deletions cmd/flag/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

type EncryptionFlagValues struct {
Encryption bool
NoEncryption bool
IgnoreMeta bool
Mode commons.EncryptionMode
modeInput string
Expand All @@ -19,6 +20,7 @@ type EncryptionFlagValues struct {

type DecryptionFlagValues struct {
Decryption bool
NoDecryption bool
IgnoreMeta bool
Key string
PrivateKeyPath string
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions cmd/subcmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/subcmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/subcmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 93df5ad

Please sign in to comment.