-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PMM-7 Don't panic in case of path to encryption file doesn't exist. #3307
base: v3
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -27,7 +27,6 @@ import ( | |
|
||
"github.com/google/tink/go/tink" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"github.com/tink-crypto/tink-go/aead" | ||
"github.com/tink-crypto/tink-go/insecurecleartextkeyset" | ||
"github.com/tink-crypto/tink-go/keyset" | ||
|
@@ -40,7 +39,7 @@ var ( | |
// ErrEncryptionNotInitialized is error in case of encryption is not initialized. | ||
ErrEncryptionNotInitialized = errors.New("encryption is not initialized") | ||
// DefaultEncryption is the default implementation of encryption. | ||
DefaultEncryption = New() | ||
DefaultEncryption, _ = New() | ||
defaultEncryptionMtx sync.Mutex | ||
) | ||
|
||
|
@@ -72,7 +71,7 @@ type QueryValues struct { | |
} | ||
|
||
// New creates an encryption; if key on path doesn't exist, it will be generated. | ||
func New() *Encryption { | ||
func New() (*Encryption, error) { | ||
e := &Encryption{} | ||
e.Path = encryptionKeyPath() | ||
|
||
|
@@ -81,21 +80,22 @@ func New() *Encryption { | |
case os.IsNotExist(err): | ||
err = e.generateKey() | ||
if err != nil { | ||
logrus.Panicf("Encryption: %v", err) | ||
return nil, err | ||
} | ||
|
||
case err != nil: | ||
logrus.Panicf("Encryption: %v", err) | ||
return nil, err | ||
default: | ||
e.Key = string(bytes) | ||
} | ||
|
||
primitive, err := e.getPrimitive() | ||
if err != nil { | ||
logrus.Panicf("Encryption: %v", err) | ||
return nil, err | ||
} | ||
e.Primitive = primitive | ||
|
||
return e | ||
return e, nil | ||
} | ||
|
||
// RotateEncryptionKey is a wrapper around DefaultEncryption.RotateEncryptionKey. | ||
|
@@ -106,8 +106,11 @@ func RotateEncryptionKey() error { | |
} | ||
|
||
defaultEncryptionMtx.Lock() | ||
DefaultEncryption = New() | ||
defaultEncryptionMtx.Unlock() | ||
defer defaultEncryptionMtx.Unlock() | ||
DefaultEncryption, err = New() | ||
if err != 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. Would 'return err' suffice? 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. do you think we need to panic? it will be returned by stack to main 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. Pardon me, I believed
was an equivalent of Is it not? 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. oh, good point |
||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
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.
Is it make sense to continue if PMM is not able to generate encryption key?
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.
We can't run tests locally because of this panic
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.
I see. Ok