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
@@ -21,48 +21,48 @@ import (
|
||||
func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt ...Option) (*AuthMethod, error) {
|
||||
const op = "oidc.(Repository).CreateAuthMethod"
|
||||
if am == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing auth method")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing auth method")
|
||||
}
|
||||
if am.PublicId != "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "public id must be empty")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "public id must be empty")
|
||||
}
|
||||
if am.Version != 0 {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "version must be empty")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "version must be empty")
|
||||
}
|
||||
if err := am.validate(op); err != nil {
|
||||
if err := am.validate(ctx, op); err != nil {
|
||||
return nil, err // validate properly sets the op to the caller, the code and the msg, so just return it.
|
||||
}
|
||||
|
||||
opts := getOpts(opt...)
|
||||
am.PublicId = opts.withPublicId
|
||||
if am.PublicId == "" {
|
||||
id, err := newAuthMethodId()
|
||||
id, err := newAuthMethodId(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
am.PublicId = id
|
||||
} else {
|
||||
if !strings.HasPrefix(am.PublicId, AuthMethodPrefix+"_") {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "wrong auth method id prefix")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "wrong auth method id prefix")
|
||||
}
|
||||
}
|
||||
|
||||
vo, err := am.convertValueObjects()
|
||||
vo, err := am.convertValueObjects(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
oplogWrapper, err := r.kms.GetWrapper(ctx, am.ScopeId, kms.KeyPurposeOplog)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to get oplog wrapper"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to get oplog wrapper"))
|
||||
}
|
||||
|
||||
databaseWrapper, err := r.kms.GetWrapper(context.Background(), am.ScopeId, kms.KeyPurposeDatabase)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to get database wrapper"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to get database wrapper"))
|
||||
}
|
||||
if err := am.encrypt(ctx, databaseWrapper); err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
var returnedAuthMethod *AuthMethod
|
||||
@@ -74,7 +74,7 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt .
|
||||
msgs := make([]*oplog.Message, 0, 5)
|
||||
ticket, err := w.GetTicket(am)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op, errors.WithMsg("unable to get ticket"))
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket"))
|
||||
}
|
||||
|
||||
returnedAuthMethod = am.Clone()
|
||||
@@ -121,13 +121,13 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt .
|
||||
}
|
||||
metadata := am.oplog(oplog.OpType_OP_TYPE_CREATE)
|
||||
if err := w.WriteOplogEntryWith(ctx, oplogWrapper, ticket, metadata, msgs); err != nil {
|
||||
return errors.Wrap(err, op, errors.WithMsg("unable to write oplog"))
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to write oplog"))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return returnedAuthMethod, nil
|
||||
}
|
||||
Reference in new issue
Block a user