Update primary error functions to take a context, deprecate old functions (#1358)
* add new error funcs which take a ctx and deprecate existing funcs * use context where available when writing error events * remove circular internal/errors pkg dep * suppress some chatty errors using errors.WithoutEvent() * convert auth oidc funcs to take context where needed to write events Co-authored-by: Jim <jlambert@hashicorp.com>
This commit is contained in:
1 parent
02ff2db66e
commit
6b78108ecf
227 files changed
+3945
-3736
No files matched your search
@@ -25,13 +25,13 @@ type DatabaseKeyVersion struct {
|
||||
func NewDatabaseKeyVersion(databaseKeyId string, key []byte, rootKeyVersionId string, _ ...Option) (*DatabaseKeyVersion, error) {
|
||||
const op = "kms.NewDatabaseKeyVersion"
|
||||
if databaseKeyId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing database key id")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing database key id")
|
||||
}
|
||||
if len(key) == 0 {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing key")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing key")
|
||||
}
|
||||
if rootKeyVersionId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing root key version id")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing root key version id")
|
||||
}
|
||||
|
||||
k := &DatabaseKeyVersion{
|
||||
@@ -64,21 +64,21 @@ func (k *DatabaseKeyVersion) Clone() interface{} {
|
||||
func (k *DatabaseKeyVersion) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, opt ...db.Option) error {
|
||||
const op = "kms.(DatabaseKeyVersion).VetForWrite"
|
||||
if k.PrivateId == "" {
|
||||
return errors.New(errors.InvalidParameter, op, "missing private id")
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing private id")
|
||||
}
|
||||
switch opType {
|
||||
case db.CreateOp:
|
||||
if k.CtKey == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "missing key")
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing key")
|
||||
}
|
||||
if k.DatabaseKeyId == "" {
|
||||
return errors.New(errors.InvalidParameter, op, "missing database key id")
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing database key id")
|
||||
}
|
||||
if k.RootKeyVersionId == "" {
|
||||
return errors.New(errors.InvalidParameter, op, "missing root key version id")
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing root key version id")
|
||||
}
|
||||
case db.UpdateOp:
|
||||
return errors.New(errors.InvalidParameter, op, "key is immutable")
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "key is immutable")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func (k *DatabaseKeyVersion) Encrypt(ctx context.Context, cipher wrapping.Wrappe
|
||||
// structwrapping doesn't support embedding, so we'll pass in the
|
||||
// store.DatabaseKeyVersion directly
|
||||
if err := structwrapping.WrapStruct(ctx, cipher, k.DatabaseKeyVersion, nil); err != nil {
|
||||
return errors.Wrap(err, op, errors.WithCode(errors.Encrypt))
|
||||
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Encrypt))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (k *DatabaseKeyVersion) Decrypt(ctx context.Context, cipher wrapping.Wrappe
|
||||
// structwrapping doesn't support embedding, so we'll pass in the
|
||||
// store.DatabaseKeyVersion directly
|
||||
if err := structwrapping.UnwrapStruct(ctx, cipher, k.DatabaseKeyVersion, nil); err != nil {
|
||||
return errors.Wrap(err, op, errors.WithCode(errors.Decrypt))
|
||||
return errors.Wrap(ctx, err, op, errors.WithCode(errors.Decrypt))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user