Skip to content

Commit

Permalink
optimize: safe.String and Encryption logic
Browse files Browse the repository at this point in the history
Signed-off-by: 孙林耀 <sunlinyao@vip.qq.com>
  • Loading branch information
MicroOps-cn committed May 8, 2024
1 parent e51338f commit 0a575f6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions safe/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (e *String) getSecret() string {
}

func (e *String) String() string {
if e.value == "" {
return ""
}
if !strings.HasPrefix(e.value, ciphertextPrefix) {
if secret := e.getSecret(); secret != "" {
if value, err := Encrypt([]byte(e.value), e.secret, nil); err == nil {
Expand Down Expand Up @@ -99,6 +102,9 @@ func (e *String) UnmarshalYAML(value *yaml.Node) (err error) {
}

func (e String) UnsafeString() (string, error) {
if e.value == "" {
return "", nil
}
if strings.HasPrefix(e.value, ciphertextPrefix) {
fmt.Println(e.getSecret(), e.value)
if secret := e.getSecret(); secret != "" {
Expand Down

0 comments on commit 0a575f6

Please sign in to comment.