-
Notifications
You must be signed in to change notification settings - Fork 188
feat(encrypt): Support both encrypted and unencrypted passwords for the upstream and downstream database #633
Changes from 2 commits
bc8bac5
d84aece
53ebb15
438169f
eb8f7e1
bf05b56
8912fac
b011dee
9f7ad8d
7b70831
07eabac
34778da
bde723b
870c528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ const ( | |
|
||
// EncryptCmdName is special command | ||
EncryptCmdName = "encrypt" | ||
// DecryptCmdName is special command | ||
DecryptCmdName = "decrypt" | ||
) | ||
|
||
// NewConfig creates a new base config for dmctl. | ||
|
@@ -47,6 +49,7 @@ func NewConfig() *Config { | |
fs.StringVar(&cfg.MasterAddr, "master-addr", "", "master API server addr") | ||
fs.StringVar(&cfg.RPCTimeoutStr, "rpc-timeout", defaultRPCTimeout, fmt.Sprintf("rpc timeout, default is %s", defaultRPCTimeout)) | ||
fs.StringVar(&cfg.encrypt, EncryptCmdName, "", "encrypt plaintext to ciphertext") | ||
fs.StringVar(&cfg.decrypt, DecryptCmdName, "", "decrypt ciphertext to plaintext") | ||
|
||
return cfg | ||
} | ||
|
@@ -64,6 +67,7 @@ type Config struct { | |
|
||
printVersion bool | ||
encrypt string // string need to be encrypted | ||
decrypt string // string need to be decrypted | ||
} | ||
|
||
func (c *Config) String() string { | ||
|
@@ -87,14 +91,23 @@ func (c *Config) Parse(arguments []string) (finish bool, err error) { | |
} | ||
|
||
if len(c.encrypt) > 0 { | ||
ciphertext, err1 := utils.Encrypt(c.encrypt) | ||
if err1 != nil { | ||
return true, err1 | ||
ciphertext, err := utils.Encrypt(c.encrypt) | ||
if err != nil { | ||
return true, err | ||
} | ||
fmt.Println(ciphertext) | ||
return true, nil | ||
} | ||
|
||
if len(c.decrypt) > 0 { | ||
plaintext, err := utils.Decrypt(c.decrypt) | ||
if err != nil { | ||
return true, err | ||
} | ||
fmt.Println(plaintext) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line should be deleted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we are shouldn't delete these lines, because the |
||
return true, nil | ||
} | ||
|
||
// Load config file if specified. | ||
if c.ConfigFile != "" { | ||
err = c.configFromFile(c.ConfigFile) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,13 @@ func Decrypt(ciphertextB64 string) (string, error) { | |
} | ||
return string(plaintext), nil | ||
} | ||
|
||
|
||
// DecryptOrPlaintext tries to decrypt base64 encoded ciphertext to plaintext or return plaintext | ||
func DecryptOrPlaintext(ciphertextB64 string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems that dosen't need to return error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, i have cleaned the extra |
||
plaintext, err := Decrypt(ciphertextB64) | ||
if err != nil { | ||
return ciphertextB64, nil | ||
} | ||
return plaintext, nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another new line is needed here (with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename
err1
toerr
will report some warning bymake check
.