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:
s-christoffandJim authored and GitHub committed 2021-07-29 20:52:56 -04:00
1 parent 02ff2db66e
commit 6b78108ecf
227 files changed
+3945 -3736

No files matched your search

+10 -10
View File
@@ -197,17 +197,17 @@ func Verify(ctx context.Context, opt ...Option) (ret VerifyResults) {
default:
iamRepo, err := v.iamRepoFn()
if err != nil {
ret.Error = errors.Wrap(err, op, errors.WithMsg("failed to get iam repo"))
ret.Error = errors.Wrap(ctx, err, op, errors.WithMsg("failed to get iam repo"))
return
}
scp, err := iamRepo.LookupScope(v.ctx, ret.Scope.Id)
if err != nil {
ret.Error = errors.Wrap(err, op)
ret.Error = errors.Wrap(ctx, err, op)
return
}
if scp == nil {
ret.Error = errors.New(errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", ret.Scope.Id))
ret.Error = errors.New(ctx, errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", ret.Scope.Id))
return
}
ret.Scope = &scopes.ScopeInfo{
@@ -421,7 +421,7 @@ func (v *verifier) decryptToken(ctx context.Context) {
func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLResults, userId string, scopeInfo *scopes.ScopeInfo, retAcl perms.ACL, retErr error) {
const op = "auth.(verifier).performAuthCheck"
// Ensure we return an error by default if we forget to set this somewhere
retErr = errors.New(errors.Unknown, op, "default auth error")
retErr = errors.NewDeprecated(errors.Unknown, op, "default auth error", errors.WithoutEvent())
// Make the linter happy
_ = retErr
scopeInfo = new(scopes.ScopeInfo)
@@ -445,7 +445,7 @@ func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLRes
}
tokenRepo, err := v.authTokenRepoFn()
if err != nil {
retErr = errors.Wrap(err, op)
retErr = errors.WrapDeprecated(err, op)
return
}
at, err := tokenRepo.ValidateToken(v.ctx, v.requestInfo.PublicId, v.requestInfo.Token)
@@ -468,7 +468,7 @@ func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLRes
iamRepo, err := v.iamRepoFn()
if err != nil {
retErr = errors.Wrap(err, op, errors.WithMsg("failed to get iam repo"))
retErr = errors.WrapDeprecated(err, op, errors.WithMsg("failed to get iam repo"))
return
}
@@ -487,11 +487,11 @@ func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLRes
default:
scp, err := iamRepo.LookupScope(v.ctx, v.res.ScopeId)
if err != nil {
retErr = errors.Wrap(err, op)
retErr = errors.WrapDeprecated(err, op)
return
}
if scp == nil {
retErr = errors.New(errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", v.res.ScopeId))
retErr = errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprint("non-existent scope $q", v.res.ScopeId))
return
}
scopeInfo = &scopes.ScopeInfo{
@@ -518,7 +518,7 @@ func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLRes
// u_anon and u_auth)
grantTuples, err = iamRepo.GrantsForUser(v.ctx, userId)
if err != nil {
retErr = errors.Wrap(err, op)
retErr = errors.WrapDeprecated(err, op)
return
}
parsedGrants = make([]perms.Grant, 0, len(grantTuples))
@@ -533,7 +533,7 @@ func (v verifier) performAuthCheck(ctx context.Context) (aclResults perms.ACLRes
perms.WithAccountId(accountId),
perms.WithSkipFinalValidation(true))
if err != nil {
retErr = errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("failed to parse grant %#v", pair.Grant)))
retErr = errors.WrapDeprecated(err, op, errors.WithMsg(fmt.Sprintf("failed to parse grant %#v", pair.Grant)))
return
}
parsedGrants = append(parsedGrants, parsed)