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
@@ -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)
|
||||
|
||||
@@ -45,13 +45,13 @@ func GetListingScopeIds(
|
||||
// Validation
|
||||
switch {
|
||||
case typ == resource.Unknown:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "unknown resource")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "unknown resource")
|
||||
case repoFn == nil:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "nil iam repo")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "nil iam repo")
|
||||
case rootScopeId == "":
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "missing root scope id")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing root scope id")
|
||||
case authResults.Scope == nil:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "nil scope in auth results")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "nil scope in auth results")
|
||||
}
|
||||
|
||||
// Base case: if not recursive, return the scope we were given and the
|
||||
@@ -103,7 +103,7 @@ func GetListingScopeIds(
|
||||
}
|
||||
case 1:
|
||||
if aSet[0] != action.List {
|
||||
return nil, nil, errors.New(errors.Internal, op, "unexpected action in set")
|
||||
return nil, nil, errors.New(ctx, errors.Internal, op, "unexpected action in set")
|
||||
}
|
||||
if scopeInfoMap[scpId] == nil {
|
||||
scopeInfo := &scopes.ScopeInfo{
|
||||
@@ -119,7 +119,7 @@ func GetListingScopeIds(
|
||||
globalHasList = true
|
||||
}
|
||||
default:
|
||||
return nil, nil, errors.New(errors.Internal, op, "unexpected number of actions back in set")
|
||||
return nil, nil, errors.New(ctx, errors.Internal, op, "unexpected number of actions back in set")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ type Controller struct {
|
||||
kms *kms.Kms
|
||||
}
|
||||
|
||||
func New(conf *Config) (*Controller, error) {
|
||||
func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
c := &Controller{
|
||||
conf: conf,
|
||||
logger: conf.Logger.Named("controller"),
|
||||
@@ -143,7 +143,7 @@ func New(conf *Config) (*Controller, error) {
|
||||
return servers.NewRepository(dbase, dbase, c.kms)
|
||||
}
|
||||
c.OidcRepoFn = func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(dbase, dbase, c.kms)
|
||||
return oidc.NewRepository(ctx, dbase, dbase, c.kms)
|
||||
}
|
||||
c.PasswordAuthRepoFn = func() (*password.Repository, error) {
|
||||
return password.NewRepository(dbase, dbase, c.kms)
|
||||
|
||||
@@ -104,10 +104,10 @@ type Service struct {
|
||||
func NewService(pwRepo common.PasswordAuthRepoFactory, oidcRepo common.OidcAuthRepoFactory) (Service, error) {
|
||||
const op = "accounts.NewService"
|
||||
if pwRepo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing password repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing password repository")
|
||||
}
|
||||
if oidcRepo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing oidc repository provided")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing oidc repository provided")
|
||||
}
|
||||
return Service{pwRepoFn: pwRepo, oidcRepoFn: oidcRepo}, nil
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (s Service) GetAccount(ctx context.Context, req *pbs.GetAccountRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -234,7 +234,7 @@ func (s Service) CreateAccount(ctx context.Context, req *pbs.CreateAccountReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -273,7 +273,7 @@ func (s Service) UpdateAccount(ctx context.Context, req *pbs.UpdateAccountReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -328,7 +328,7 @@ func (s Service) ChangePassword(ctx context.Context, req *pbs.ChangePasswordRequ
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -367,7 +367,7 @@ func (s Service) SetPassword(ctx context.Context, req *pbs.SetPasswordRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -435,7 +435,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []st
|
||||
func (s Service) createPwInRepo(ctx context.Context, am auth.AuthMethod, item *pb.Account) (*password.Account, error) {
|
||||
const op = "accounts.(Service).createPwInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing item")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
pwAttrs := &pb.PasswordAccountAttributes{}
|
||||
if err := handlers.StructToProto(item.GetAttributes(), pwAttrs); err != nil {
|
||||
@@ -464,7 +464,7 @@ func (s Service) createPwInRepo(ctx context.Context, am auth.AuthMethod, item *p
|
||||
}
|
||||
out, err := repo.CreateAccount(ctx, am.GetScopeId(), a, createOpts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
|
||||
@@ -475,7 +475,7 @@ func (s Service) createPwInRepo(ctx context.Context, am auth.AuthMethod, item *p
|
||||
func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item *pb.Account) (*oidc.Account, error) {
|
||||
const op = "accounts.(Service).createOidcInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing item")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var opts []oidc.Option
|
||||
if item.GetName() != nil {
|
||||
@@ -492,11 +492,11 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
if attrs.GetIssuer() != "" {
|
||||
u, err := url.Parse(attrs.GetIssuer())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to parse issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to parse issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
opts = append(opts, oidc.WithIssuer(u))
|
||||
}
|
||||
a, err := oidc.NewAccount(am.GetPublicId(), attrs.GetSubject(), opts...)
|
||||
a, err := oidc.NewAccount(ctx, am.GetPublicId(), attrs.GetSubject(), opts...)
|
||||
if err != nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to build account for creation: %v.", err)
|
||||
}
|
||||
@@ -507,7 +507,7 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
|
||||
out, err := repo.CreateAccount(ctx, am.GetScopeId(), a)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create account"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create account"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
|
||||
@@ -518,14 +518,14 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.Account) (auth.Account, error) {
|
||||
const op = "accounts.(Service).createInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing item")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var out auth.Account
|
||||
switch auth.SubtypeFromId(am.GetPublicId()) {
|
||||
case password.Subtype:
|
||||
am, err := s.createPwInRepo(ctx, am, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
|
||||
@@ -534,7 +534,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
|
||||
case oidc.Subtype:
|
||||
am, err := s.createOidcInRepo(ctx, am, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create account but no error returned from repository.")
|
||||
@@ -560,7 +560,7 @@ func (s Service) updatePwInRepo(ctx context.Context, scopeId, authMethId, id str
|
||||
}
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateAccount(ctx, scopeId, u, version, dbMask)
|
||||
if err != nil {
|
||||
@@ -569,7 +569,7 @@ func (s Service) updatePwInRepo(ctx context.Context, scopeId, authMethId, id str
|
||||
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
|
||||
map[string]string{"attributes.login_name": "Length too short."})
|
||||
}
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Account %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -580,7 +580,7 @@ func (s Service) updatePwInRepo(ctx context.Context, scopeId, authMethId, id str
|
||||
func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string, mask []string, item *pb.Account) (*oidc.Account, error) {
|
||||
const op = "accounts.(Service).updateOidcInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil account.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil account.")
|
||||
}
|
||||
u := oidc.AllocAccount()
|
||||
u.PublicId = id
|
||||
@@ -599,11 +599,11 @@ func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string,
|
||||
}
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateAccount(ctx, scopeId, u, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update account"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update account"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Account %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -618,7 +618,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
|
||||
case password.Subtype:
|
||||
a, err := s.updatePwInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if a == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update account but no error returned from repository.")
|
||||
@@ -627,7 +627,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
|
||||
case oidc.Subtype:
|
||||
a, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if a == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update account but no error returned from repository.")
|
||||
@@ -659,7 +659,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -672,11 +672,11 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
|
||||
case password.Subtype:
|
||||
pwRepo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
pwl, err := pwRepo.ListAccounts(ctx, authMethodId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, a := range pwl {
|
||||
outUl = append(outUl, a)
|
||||
@@ -684,11 +684,11 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
|
||||
case oidc.Subtype:
|
||||
oidcRepo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
oidcl, err := oidcRepo.ListAccounts(ctx, authMethodId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, a := range oidcl {
|
||||
outUl = append(outUl, a)
|
||||
@@ -701,7 +701,7 @@ func (s Service) changePasswordInRepo(ctx context.Context, scopeId, id string, v
|
||||
const op = "account.(Service).changePasswordInRepo"
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.ChangePassword(ctx, scopeId, id, currentPassword, newPassword, version)
|
||||
if err != nil {
|
||||
@@ -715,7 +715,7 @@ func (s Service) changePasswordInRepo(ctx context.Context, scopeId, id string, v
|
||||
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
|
||||
map[string]string{"new_password": "New password equal to current password."})
|
||||
}
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.PermissionDenied, "Failed to change password.")
|
||||
@@ -728,7 +728,7 @@ func (s Service) setPasswordInRepo(ctx context.Context, scopeId, id string, vers
|
||||
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.SetPassword(ctx, scopeId, id, pw, version)
|
||||
if err != nil {
|
||||
@@ -739,7 +739,7 @@ func (s Service) setPasswordInRepo(ctx context.Context, scopeId, id string, vers
|
||||
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
|
||||
map[string]string{"password": "Password is too short."})
|
||||
}
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -889,20 +889,20 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
|
||||
m := make(map[string]interface{})
|
||||
var err error
|
||||
if err = json.Unmarshal([]byte(s), &m); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("error unmarshaling stored token claims"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error unmarshaling stored token claims"))
|
||||
}
|
||||
if attrs.TokenClaims, err = structpb.NewStruct(m); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("error converting stored token claims to protobuf struct"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error converting stored token claims to protobuf struct"))
|
||||
}
|
||||
}
|
||||
if s := i.GetUserinfoClaims(); s != "" {
|
||||
m := make(map[string]interface{})
|
||||
var err error
|
||||
if err = json.Unmarshal([]byte(s), &m); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("error unmarshaling stored userinfo claims"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error unmarshaling stored userinfo claims"))
|
||||
}
|
||||
if attrs.UserinfoClaims, err = structpb.NewStruct(m); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("error converting stored userinfo claims to protobuf struct"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error converting stored userinfo claims to protobuf struct"))
|
||||
}
|
||||
}
|
||||
st, err := handlers.ProtoToStruct(attrs)
|
||||
@@ -917,7 +917,7 @@ func toProto(ctx context.Context, in auth.Account, opt ...handlers.Option) (*pb.
|
||||
func toStoragePwAccount(amId string, item *pb.Account) (*password.Account, error) {
|
||||
const op = "accounts.toStoragePwAccount"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil account.")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "nil account.")
|
||||
}
|
||||
var opts []password.Option
|
||||
if item.GetName() != nil {
|
||||
@@ -951,7 +951,7 @@ func toStoragePwAccount(amId string, item *pb.Account) (*password.Account, error
|
||||
func validateGetRequest(req *pbs.GetAccountRequest) error {
|
||||
const op = "accounts.validateGetRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
|
||||
}
|
||||
@@ -959,7 +959,7 @@ func validateGetRequest(req *pbs.GetAccountRequest) error {
|
||||
func validateCreateRequest(req *pbs.CreateAccountRequest) error {
|
||||
const op = "accounts.validateCreateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -1014,7 +1014,7 @@ func validateCreateRequest(req *pbs.CreateAccountRequest) error {
|
||||
func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
|
||||
const op = "accounts.validateUpdateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -1055,7 +1055,7 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
|
||||
func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
|
||||
const op = "accounts.validateDeleteRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
|
||||
}
|
||||
@@ -1063,7 +1063,7 @@ func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
|
||||
func validateListRequest(req *pbs.ListAccountsRequest) error {
|
||||
const op = "accounts.validateListRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), password.AuthMethodPrefix, oidc.AuthMethodPrefix) {
|
||||
@@ -1081,7 +1081,7 @@ func validateListRequest(req *pbs.ListAccountsRequest) error {
|
||||
func validateChangePasswordRequest(req *pbs.ChangePasswordRequest) error {
|
||||
const op = "accounts.validateChangePasswordRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
|
||||
@@ -1105,7 +1105,7 @@ func validateChangePasswordRequest(req *pbs.ChangePasswordRequest) error {
|
||||
func validateSetPasswordRequest(req *pbs.SetPasswordRequest) error {
|
||||
const op = "accounts.validateSetPasswordRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
|
||||
|
||||
@@ -55,6 +55,7 @@ var (
|
||||
)
|
||||
|
||||
func TestNewService(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -63,7 +64,7 @@ func TestNewService(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
@@ -114,7 +115,7 @@ func TestGet(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -244,6 +245,7 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListPassword(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -252,7 +254,7 @@ func TestListPassword(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
@@ -386,7 +388,7 @@ func TestListOidc(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -539,7 +541,7 @@ func TestDelete(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -625,6 +627,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete_twice(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -634,7 +637,7 @@ func TestDelete_twice(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
@@ -657,6 +660,7 @@ func TestDelete_twice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreatePassword(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -665,7 +669,7 @@ func TestCreatePassword(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
@@ -867,7 +871,7 @@ func TestCreateOidc(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -1071,6 +1075,7 @@ func TestCreateOidc(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdatePassword(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -1079,7 +1084,7 @@ func TestUpdatePassword(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
@@ -1460,7 +1465,7 @@ func TestUpdateOidc(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -1834,6 +1839,7 @@ func TestUpdateOidc(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetPassword(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -1842,7 +1848,7 @@ func TestSetPassword(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
@@ -1972,6 +1978,7 @@ func TestSetPassword(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangePassword(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -1980,7 +1987,7 @@ func TestChangePassword(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kms)
|
||||
|
||||
@@ -82,16 +82,16 @@ type Service struct {
|
||||
func NewService(kms *kms.Kms, pwRepoFn common.PasswordAuthRepoFactory, oidcRepoFn common.OidcAuthRepoFactory, iamRepoFn common.IamRepoFactory, atRepoFn common.AuthTokenRepoFactory, opt ...handlers.Option) (Service, error) {
|
||||
const op = "authmethods.NewService"
|
||||
if kms == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing kms")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing kms")
|
||||
}
|
||||
if pwRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing password repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing password repository")
|
||||
}
|
||||
if oidcRepoFn == nil {
|
||||
return Service{}, fmt.Errorf("nil oidc repository provided")
|
||||
}
|
||||
if iamRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
if atRepoFn == nil {
|
||||
return Service{}, fmt.Errorf("nil auth token repository provided")
|
||||
@@ -205,7 +205,7 @@ func (s Service) GetAuthMethod(ctx context.Context, req *pbs.GetAuthMethodReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -236,7 +236,7 @@ func (s Service) GetAuthMethod(ctx context.Context, req *pbs.GetAuthMethodReques
|
||||
func (s Service) CreateAuthMethod(ctx context.Context, req *pbs.CreateAuthMethodRequest) (*pbs.CreateAuthMethodResponse, error) {
|
||||
const op = "authmethods.(Service).CreateAuthMethod"
|
||||
|
||||
if err := validateCreateRequest(req); err != nil {
|
||||
if err := validateCreateRequest(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authResults := s.authResult(ctx, req.GetItem().GetScopeId(), action.Create)
|
||||
@@ -250,7 +250,7 @@ func (s Service) CreateAuthMethod(ctx context.Context, req *pbs.CreateAuthMethod
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -281,7 +281,7 @@ func (s Service) CreateAuthMethod(ctx context.Context, req *pbs.CreateAuthMethod
|
||||
func (s Service) UpdateAuthMethod(ctx context.Context, req *pbs.UpdateAuthMethodRequest) (*pbs.UpdateAuthMethodResponse, error) {
|
||||
const op = "authmethods.(Service).UpdateAuthMethod"
|
||||
|
||||
if err := validateUpdateRequest(req); err != nil {
|
||||
if err := validateUpdateRequest(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authResults := s.authResult(ctx, req.GetId(), action.Update)
|
||||
@@ -300,7 +300,7 @@ func (s Service) UpdateAuthMethod(ctx context.Context, req *pbs.UpdateAuthMethod
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -354,7 +354,7 @@ func (s Service) ChangeState(ctx context.Context, req *pbs.ChangeStateRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -427,7 +427,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
case oidc.Subtype:
|
||||
return s.authenticateOidc(ctx, req, &authResults)
|
||||
}
|
||||
return nil, errors.New(errors.Internal, op, "Invalid auth method subtype not caught in validation function.")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "Invalid auth method subtype not caught in validation function.")
|
||||
}
|
||||
|
||||
// Deprecated: use Authenticate
|
||||
@@ -491,18 +491,18 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResult
|
||||
const op = "authmethods.(Service).listFromRepo"
|
||||
reqCtx, ok := requests.RequestContextFromCtx(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
var outUl []auth.AuthMethod
|
||||
|
||||
oidcRepo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
ol, err := oidcRepo.ListAuthMethods(ctx, scopeIds, oidc.WithUnauthenticatedUser(reqCtx.UserId == requestauth.AnonymousUserId))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, item := range ol {
|
||||
outUl = append(outUl, item)
|
||||
@@ -510,11 +510,11 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResult
|
||||
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
pl, err := repo.ListAuthMethods(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, item := range pl {
|
||||
outUl = append(outUl, item)
|
||||
@@ -529,7 +529,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
|
||||
case password.Subtype:
|
||||
am, err := s.createPwInRepo(ctx, scopeId, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create auth method but no error returned from repository.")
|
||||
@@ -538,7 +538,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Auth
|
||||
case oidc.Subtype:
|
||||
am, err := s.createOidcInRepo(ctx, scopeId, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create auth method but no error returned from repository.")
|
||||
@@ -558,7 +558,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
|
||||
case password.Subtype:
|
||||
pam, err := s.updatePwInRepo(ctx, scopeId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, op)
|
||||
return nil, false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if pam == nil {
|
||||
return nil, false, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update auth method but no error returned from repository.")
|
||||
@@ -568,7 +568,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
|
||||
case oidc.Subtype:
|
||||
oam, dr, err := s.updateOidcInRepo(ctx, scopeId, req)
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, op)
|
||||
return nil, false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if oam == nil {
|
||||
return nil, false, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update auth method but no error returned from repository.")
|
||||
@@ -588,14 +588,14 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
case password.Subtype:
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
rows, dErr = repo.DeleteAuthMethod(ctx, scopeId, id)
|
||||
|
||||
case oidc.Subtype:
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
rows, dErr = repo.DeleteAuthMethod(ctx, id)
|
||||
}
|
||||
@@ -604,7 +604,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if errors.IsNotFoundError(dErr) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(dErr, op, errors.WithMsg("unable to delete auth method"))
|
||||
return false, errors.Wrap(ctx, dErr, op, errors.WithMsg("unable to delete auth method"))
|
||||
}
|
||||
|
||||
return rows > 0, nil
|
||||
@@ -622,7 +622,7 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
|
||||
|
||||
attrs := &pbs.OidcChangeStateAttributes{}
|
||||
if err := handlers.StructToProto(req.GetAttributes(), attrs); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to parse attributes"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to parse attributes"))
|
||||
}
|
||||
|
||||
var opts []oidc.Option
|
||||
@@ -639,7 +639,7 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
|
||||
case publicState:
|
||||
am, err = repo.MakePublic(ctx, req.GetId(), req.GetVersion(), opts...)
|
||||
default:
|
||||
err = errors.New(errors.InvalidParameter, op, fmt.Sprintf("unrecognized state %q", attrs.GetState()))
|
||||
err = errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("unrecognized state %q", attrs.GetState()))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -648,7 +648,7 @@ func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequ
|
||||
return am, nil
|
||||
}
|
||||
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Given auth method type does not support changing state")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Given auth method type does not support changing state")
|
||||
}
|
||||
|
||||
func (s Service) authResult(ctx context.Context, id string, a action.Type) requestauth.VerifyResults {
|
||||
@@ -710,7 +710,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) reque
|
||||
}
|
||||
authMeth = am
|
||||
default:
|
||||
res.Error = errors.New(errors.InvalidPublicId, op, "unrecognized auth method type")
|
||||
res.Error = errors.New(ctx, errors.InvalidPublicId, op, "unrecognized auth method type")
|
||||
return res
|
||||
}
|
||||
parentId = authMeth.GetScopeId()
|
||||
@@ -843,15 +843,15 @@ func toAuthTokenProto(t *authtoken.AuthToken) *pba.AuthToken {
|
||||
func validateGetRequest(req *pbs.GetAuthMethodRequest) error {
|
||||
const op = "authmethod.validateGetRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, password.AuthMethodPrefix, oidc.AuthMethodPrefix)
|
||||
}
|
||||
|
||||
func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
|
||||
func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest) error {
|
||||
const op = "authmethod.validateCreateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -917,7 +917,7 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
|
||||
}
|
||||
}
|
||||
if len(attrs.GetIdpCaCerts()) > 0 {
|
||||
if _, err := oidc.ParseCertificates(attrs.GetIdpCaCerts()...); err != nil {
|
||||
if _, err := oidc.ParseCertificates(ctx, attrs.GetIdpCaCerts()...); err != nil {
|
||||
badFields[idpCaCertsField] = fmt.Sprintf("Cannot parse CA certificates. %v", err.Error())
|
||||
}
|
||||
}
|
||||
@@ -930,7 +930,7 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
|
||||
}
|
||||
}
|
||||
if len(attrs.GetAccountClaimMaps()) > 0 {
|
||||
acm, err := oidc.ParseAccountClaimMaps(attrs.GetAccountClaimMaps()...)
|
||||
acm, err := oidc.ParseAccountClaimMaps(ctx, attrs.GetAccountClaimMaps()...)
|
||||
if err != nil {
|
||||
badFields[accountClaimMapsField] = fmt.Sprintf("Contains invalid map %q", err.Error())
|
||||
}
|
||||
@@ -950,10 +950,10 @@ func validateCreateRequest(req *pbs.CreateAuthMethodRequest) error {
|
||||
})
|
||||
}
|
||||
|
||||
func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest) error {
|
||||
const op = "authmethod.validateUpdateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "missing request")
|
||||
}
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -1038,7 +1038,7 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
}
|
||||
}
|
||||
if len(attrs.GetIdpCaCerts()) > 0 {
|
||||
if _, err := oidc.ParseCertificates(attrs.GetIdpCaCerts()...); err != nil {
|
||||
if _, err := oidc.ParseCertificates(ctx, attrs.GetIdpCaCerts()...); err != nil {
|
||||
badFields[idpCaCertsField] = fmt.Sprintf("Cannot parse CA certificates. %v", err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1051,7 +1051,7 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
}
|
||||
}
|
||||
if len(attrs.GetAccountClaimMaps()) > 0 {
|
||||
acm, err := oidc.ParseAccountClaimMaps(attrs.GetAccountClaimMaps()...)
|
||||
acm, err := oidc.ParseAccountClaimMaps(ctx, attrs.GetAccountClaimMaps()...)
|
||||
if err != nil {
|
||||
badFields[accountClaimMapsField] = fmt.Sprintf("Contains invalid map %q", err.Error())
|
||||
} else {
|
||||
@@ -1062,7 +1062,7 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
}
|
||||
foundTo[m.To] = true
|
||||
|
||||
to, err := oidc.ConvertToAccountToClaim(m.To)
|
||||
to, err := oidc.ConvertToAccountToClaim(ctx, m.To)
|
||||
if err != nil {
|
||||
badFields[accountClaimMapsField] = fmt.Sprintf("%s=%s contains invalid map %q", m.From, m.To, err.Error())
|
||||
break
|
||||
@@ -1084,7 +1084,7 @@ func validateUpdateRequest(req *pbs.UpdateAuthMethodRequest) error {
|
||||
func validateDeleteRequest(req *pbs.DeleteAuthMethodRequest) error {
|
||||
const op = "authmethod.validateDeleteRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, password.AuthMethodPrefix, oidc.AuthMethodPrefix)
|
||||
}
|
||||
@@ -1092,7 +1092,7 @@ func validateDeleteRequest(req *pbs.DeleteAuthMethodRequest) error {
|
||||
func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
|
||||
const op = "authmethod.validateListRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetScopeId()), scope.Org.Prefix()) &&
|
||||
@@ -1111,7 +1111,7 @@ func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
|
||||
func validateChangeStateRequest(req *pbs.ChangeStateRequest) error {
|
||||
const op = "authmethod.validateChangeStateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
if st := auth.SubtypeFromId(req.GetId()); st != oidc.Subtype {
|
||||
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", oidc.Subtype.String())
|
||||
@@ -1139,7 +1139,7 @@ func validateChangeStateRequest(req *pbs.ChangeStateRequest) error {
|
||||
func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
const op = "authmethod.validateAuthenticateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
|
||||
badFields := make(map[string]string)
|
||||
@@ -1166,7 +1166,7 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
func validateAuthenticateLoginRequest(req *pbs.AuthenticateLoginRequest) error {
|
||||
const op = "authmethod.validateAuthenticateLoginRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "Missing request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
badFields := make(map[string]string)
|
||||
if strings.TrimSpace(req.GetAuthMethodId()) == "" {
|
||||
@@ -1201,16 +1201,16 @@ func (s Service) ConvertInternalAuthTokenToApiAuthToken(ctx context.Context, tok
|
||||
return nil, err
|
||||
}
|
||||
if tok == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing auth token.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing auth token.")
|
||||
}
|
||||
if tok.Token == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Empty token.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Empty token.")
|
||||
}
|
||||
if tok.GetPublicId() == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Empty token public ID.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Empty token public ID.")
|
||||
}
|
||||
if tok.GetScopeId() == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Empty token, scope ID.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Empty token, scope ID.")
|
||||
}
|
||||
token, err := authtoken.EncryptToken(ctx, s.kms, tok.GetScopeId(), tok.GetPublicId(), tok.GetToken())
|
||||
if err != nil {
|
||||
@@ -1239,19 +1239,19 @@ func (s Service) ConvertInternalAuthTokenToApiAuthToken(ctx context.Context, tok
|
||||
func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.AuthenticateRequest, authResults *requestauth.VerifyResults, tok *pba.AuthToken) (*pbs.AuthenticateResponse, error) {
|
||||
const op = "authmethod.convertToAuthenticateResponse"
|
||||
if req == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Missing request.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing request.")
|
||||
}
|
||||
if authResults == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Missing auth results.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results.")
|
||||
}
|
||||
if authResults.Scope == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Missing auth results scope.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results scope.")
|
||||
}
|
||||
if authResults.Scope.Id == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Missing auth results scope ID.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth results scope ID.")
|
||||
}
|
||||
if tok == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Missing auth token.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Missing auth token.")
|
||||
}
|
||||
res := &perms.Resource{
|
||||
ScopeId: authResults.Scope.Id,
|
||||
|
||||
@@ -67,6 +67,7 @@ var authorizedCollectionActions = map[string]*structpb.ListValue{
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -75,7 +76,7 @@ func TestGet(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -204,6 +205,7 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -212,7 +214,7 @@ func TestList(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -385,6 +387,7 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -393,7 +396,7 @@ func TestDelete(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -461,6 +464,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete_twice(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
@@ -470,7 +474,7 @@ func TestDelete_twice(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
@@ -497,6 +501,7 @@ func TestDelete_twice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -508,7 +513,7 @@ func TestCreate(t *testing.T) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
atRepoFn := func() (*authtoken.Repository, error) {
|
||||
return authtoken.NewRepository(rw, rw, kms)
|
||||
|
||||
@@ -91,7 +91,7 @@ func (o oidcState) String() string {
|
||||
// createOidcInRepo creates an oidc auth method in a repo and returns the result.
|
||||
// This method should never return a nil AuthMethod without returning an error.
|
||||
func (s Service) createOidcInRepo(ctx context.Context, scopeId string, item *pb.AuthMethod) (*oidc.AuthMethod, error) {
|
||||
u, _, _, err := toStorageOidcAuthMethod(scopeId, item)
|
||||
u, _, _, err := toStorageOidcAuthMethod(ctx, scopeId, item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (s Service) createOidcInRepo(ctx context.Context, scopeId string, item *pb.
|
||||
|
||||
func (s Service) updateOidcInRepo(ctx context.Context, scopeId string, req *pbs.UpdateAuthMethodRequest) (*oidc.AuthMethod, bool, error) {
|
||||
item := req.GetItem()
|
||||
u, dryRun, forced, err := toStorageOidcAuthMethod(scopeId, item)
|
||||
u, dryRun, forced, err := toStorageOidcAuthMethod(ctx, scopeId, item)
|
||||
if err != nil {
|
||||
return nil, dryRun, err
|
||||
}
|
||||
@@ -145,10 +145,10 @@ func (s Service) updateOidcInRepo(ctx context.Context, scopeId string, req *pbs.
|
||||
func (s Service) authenticateOidc(ctx context.Context, req *pbs.AuthenticateRequest, authResults *auth.VerifyResults) (*pbs.AuthenticateResponse, error) {
|
||||
const op = "authmethod_service.(Service).authenticateOidc"
|
||||
if req == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil request.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil request.")
|
||||
}
|
||||
if authResults == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil auth results.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil auth results.")
|
||||
}
|
||||
switch req.GetCommand() {
|
||||
case startCommand:
|
||||
@@ -165,13 +165,13 @@ func (s Service) authenticateOidc(ctx context.Context, req *pbs.AuthenticateRequ
|
||||
func (s Service) authenticateOidcStart(ctx context.Context, req *pbs.AuthenticateRequest) (*pbs.AuthenticateResponse, error) {
|
||||
const op = "authmethod_service.(Service).authenticateOidcStart"
|
||||
if req == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil request.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil request.")
|
||||
}
|
||||
|
||||
var opts []oidc.Option
|
||||
attrs := new(pbs.OidcStartAttributes)
|
||||
if err := handlers.StructToProto(req.GetAttributes(), attrs); err != nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Error parsing request attributes.", errors.WithWrap(err))
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Error parsing request attributes.", errors.WithWrap(err))
|
||||
}
|
||||
if attrs.GetCachedRoundtripPayload() != "" {
|
||||
opts = append(opts, oidc.WithRoundtripPayload(attrs.GetCachedRoundtripPayload()))
|
||||
@@ -182,7 +182,7 @@ func (s Service) authenticateOidcStart(ctx context.Context, req *pbs.Authenticat
|
||||
// this event.WriteError(...) may cause a dup error to be emitted...
|
||||
// it should be removed if that's the case.
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error starting the oidc authentication flow"))
|
||||
return nil, errors.New(errors.Internal, op, "Error generating parameters for starting the OIDC flow. See the controller's log for more information.")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "Error generating parameters for starting the OIDC flow. See the controller's log for more information.")
|
||||
}
|
||||
|
||||
respAttrs := &pb.OidcAuthMethodAuthenticateStartResponse{
|
||||
@@ -191,7 +191,7 @@ func (s Service) authenticateOidcStart(ctx context.Context, req *pbs.Authenticat
|
||||
}
|
||||
resp := &pbs.AuthenticateResponse{Command: req.GetCommand()}
|
||||
if resp.Attributes, err = handlers.ProtoToStruct(respAttrs); err != nil {
|
||||
return nil, errors.New(errors.Internal, op, "Error marshaling parameters.", errors.WithWrap(err))
|
||||
return nil, errors.New(ctx, errors.Internal, op, "Error marshaling parameters.", errors.WithWrap(err))
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -208,22 +208,22 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
// in the redirect URL once we start looking at the url used for this
|
||||
// request instead of requiring the API URL to be set on the auth method.
|
||||
if req == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil request.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil request.")
|
||||
}
|
||||
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
am, err := repo.LookupAuthMethod(ctx, req.GetAuthMethodId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, errors.New(errors.RecordNotFound, op, fmt.Sprintf("Auth method %s not found.", req.GetAuthMethodId()))
|
||||
return nil, errors.New(ctx, errors.RecordNotFound, op, fmt.Sprintf("Auth method %s not found.", req.GetAuthMethodId()))
|
||||
}
|
||||
if am.GetApiUrl() == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Auth method doesn't have API URL defined.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Auth method doesn't have API URL defined.")
|
||||
}
|
||||
|
||||
errRedirectBase := fmt.Sprintf(oidc.AuthenticationErrorsEndpoint, am.GetApiUrl())
|
||||
@@ -232,7 +232,7 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
pbErr := handlers.ToApiError(err)
|
||||
out, err := handlers.JSONMarshaler().Marshal(pbErr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to marshal the error for callback"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to marshal the error for callback"))
|
||||
}
|
||||
u.Add("error", string(out))
|
||||
errRedirect := fmt.Sprintf("%s?%s", errRedirectBase, u.Encode())
|
||||
@@ -240,7 +240,7 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
FinalRedirectUrl: errRedirect,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("failed creating error redirect response"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("failed creating error redirect response"))
|
||||
}
|
||||
return &pbs.AuthenticateResponse{Command: callbackCommand, Attributes: respAttrs}, nil
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
|
||||
var finalRedirectUrl string
|
||||
if attrs.GetError() != "" {
|
||||
err := errors.Wrap(fmt.Errorf("Error: %q, Details: %q", attrs.GetError(), attrs.GetErrorDescription()), op, errors.WithCode(errors.OidcProviderCallbackError))
|
||||
err := errors.Wrap(ctx, fmt.Errorf("Error: %q, Details: %q", attrs.GetError(), attrs.GetErrorDescription()), op, errors.WithCode(errors.OidcProviderCallbackError))
|
||||
return errResponse(err)
|
||||
}
|
||||
finalRedirectUrl, err = oidc.Callback(
|
||||
@@ -265,14 +265,14 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
attrs.GetState(),
|
||||
attrs.GetCode())
|
||||
if err != nil {
|
||||
return errResponse(errors.New(errors.InvalidParameter, op, "Callback validation failed.", errors.WithWrap(err)))
|
||||
return errResponse(errors.New(ctx, errors.InvalidParameter, op, "Callback validation failed.", errors.WithWrap(err)))
|
||||
}
|
||||
|
||||
respAttrs, err := handlers.ProtoToStruct(&pb.OidcAuthMethodAuthenticateCallbackResponse{
|
||||
FinalRedirectUrl: finalRedirectUrl,
|
||||
})
|
||||
if err != nil {
|
||||
return errResponse(errors.New(errors.Internal, op, "Error marshaling parameters after successful callback", errors.WithWrap(err)))
|
||||
return errResponse(errors.New(ctx, errors.Internal, op, "Error marshaling parameters after successful callback", errors.WithWrap(err)))
|
||||
}
|
||||
|
||||
return &pbs.AuthenticateResponse{Command: req.GetCommand(), Attributes: respAttrs}, nil
|
||||
@@ -281,35 +281,35 @@ func (s Service) authenticateOidcCallback(ctx context.Context, req *pbs.Authenti
|
||||
func (s Service) authenticateOidcToken(ctx context.Context, req *pbs.AuthenticateRequest, authResults *auth.VerifyResults) (*pbs.AuthenticateResponse, error) {
|
||||
const op = "authmethod_service.(Service).authenticateOidcToken"
|
||||
if req == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil request.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil request.")
|
||||
}
|
||||
if authResults == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil auth results.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil auth results.")
|
||||
}
|
||||
if req.GetAttributes() == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Nil request attributes.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Nil request attributes.")
|
||||
}
|
||||
|
||||
attrs := new(pb.OidcAuthMethodAuthenticateTokenRequest)
|
||||
if err := handlers.StructToProto(req.GetAttributes(), attrs); err != nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Error parsing request attributes.", errors.WithWrap(err))
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Error parsing request attributes.", errors.WithWrap(err))
|
||||
}
|
||||
if attrs.TokenId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "Empty token ID in request attributes.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "Empty token ID in request attributes.")
|
||||
}
|
||||
|
||||
token, err := oidc.TokenRequest(ctx, s.kms, s.atRepoFn, req.GetAuthMethodId(), attrs.TokenId)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Match(errors.T(errors.Forbidden), err):
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Forbidden."))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Forbidden."))
|
||||
case errors.Match(errors.T(errors.AuthAttemptExpired), err):
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Forbidden."))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Forbidden."))
|
||||
default:
|
||||
// this event.WriteError(...) may cause a dup error to be emitted...
|
||||
// it should be removed if that's the case.
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error generating parameters for token request"))
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Error generating parameters for token request. See the controller's log for more information."))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Error generating parameters for token request. See the controller's log for more information."))
|
||||
}
|
||||
}
|
||||
if token == nil {
|
||||
@@ -317,7 +317,7 @@ func (s Service) authenticateOidcToken(ctx context.Context, req *pbs.Authenticat
|
||||
statusField: "unknown",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.New(errors.Internal, op, "Error generating response attributes.", errors.WithWrap(err))
|
||||
return nil, errors.New(ctx, errors.Internal, op, "Error generating response attributes.", errors.WithWrap(err))
|
||||
}
|
||||
return &pbs.AuthenticateResponse{
|
||||
Command: req.Command,
|
||||
@@ -330,7 +330,7 @@ func (s Service) authenticateOidcToken(ctx context.Context, req *pbs.Authenticat
|
||||
token,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.New(errors.Internal, op, "Error converting response to proper format.", errors.WithWrap(err))
|
||||
return nil, errors.New(ctx, errors.Internal, op, "Error converting response to proper format.", errors.WithWrap(err))
|
||||
}
|
||||
return s.convertToAuthenticateResponse(ctx, req, authResults, responseToken)
|
||||
}
|
||||
@@ -404,10 +404,10 @@ func validateAuthenticateOidcRequest(req *pbs.AuthenticateRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func toStorageOidcAuthMethod(scopeId string, in *pb.AuthMethod) (out *oidc.AuthMethod, dryRun, forced bool, err error) {
|
||||
func toStorageOidcAuthMethod(ctx context.Context, scopeId string, in *pb.AuthMethod) (out *oidc.AuthMethod, dryRun, forced bool, err error) {
|
||||
const op = "authmethod_service.toStorageOidcAuthMethod"
|
||||
if in == nil {
|
||||
return nil, false, false, errors.New(errors.InvalidParameter, op, "nil auth method.")
|
||||
return nil, false, false, errors.NewDeprecated(errors.InvalidParameter, op, "nil auth method.")
|
||||
}
|
||||
attrs := &pb.OidcAuthMethodAttributes{}
|
||||
if err := handlers.StructToProto(in.GetAttributes(), attrs); err != nil {
|
||||
@@ -431,14 +431,14 @@ func toStorageOidcAuthMethod(scopeId string, in *pb.AuthMethod) (out *oidc.AuthM
|
||||
iss = strings.SplitN(iss, ".well-known/", 2)[0]
|
||||
issuer, err := url.Parse(iss)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(err, op, errors.WithMsg("cannot parse issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
return nil, false, false, errors.WrapDeprecated(err, op, errors.WithMsg("cannot parse issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
opts = append(opts, oidc.WithIssuer(issuer))
|
||||
}
|
||||
if apiUrl := strings.TrimSpace(attrs.GetApiUrlPrefix().GetValue()); apiUrl != "" {
|
||||
apiU, err := url.Parse(apiUrl)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(err, op, errors.WithMsg("cannot parse api_url_prefix"), errors.WithCode(errors.InvalidParameter))
|
||||
return nil, false, false, errors.WrapDeprecated(err, op, errors.WithMsg("cannot parse api_url_prefix"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
opts = append(opts, oidc.WithApiUrl(apiU))
|
||||
}
|
||||
@@ -463,7 +463,7 @@ func toStorageOidcAuthMethod(scopeId string, in *pb.AuthMethod) (out *oidc.AuthM
|
||||
}
|
||||
|
||||
if len(attrs.GetIdpCaCerts()) > 0 {
|
||||
certs, err := oidc.ParseCertificates(attrs.GetIdpCaCerts()...)
|
||||
certs, err := oidc.ParseCertificates(ctx, attrs.GetIdpCaCerts()...)
|
||||
if err != nil {
|
||||
return nil, false, false, err
|
||||
}
|
||||
@@ -477,26 +477,26 @@ func toStorageOidcAuthMethod(scopeId string, in *pb.AuthMethod) (out *oidc.AuthM
|
||||
if len(attrs.GetAccountClaimMaps()) > 0 {
|
||||
claimsMap := make(map[string]oidc.AccountToClaim, len(attrs.GetAccountClaimMaps()))
|
||||
for _, v := range attrs.GetAccountClaimMaps() {
|
||||
acm, err := oidc.ParseAccountClaimMaps(v)
|
||||
acm, err := oidc.ParseAccountClaimMaps(ctx, v)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(err, op)
|
||||
return nil, false, false, errors.WrapDeprecated(err, op)
|
||||
}
|
||||
if len(acm) > 1 {
|
||||
return nil, false, false, errors.New(errors.InvalidParameter, op, fmt.Sprintf("unable to parse account claim map %s", v))
|
||||
return nil, false, false, errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("unable to parse account claim map %s", v))
|
||||
}
|
||||
var m oidc.ClaimMap
|
||||
for _, m = range acm {
|
||||
}
|
||||
to, err := oidc.ConvertToAccountToClaim(m.To)
|
||||
to, err := oidc.ConvertToAccountToClaim(ctx, m.To)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(err, op)
|
||||
return nil, false, false, errors.WrapDeprecated(err, op)
|
||||
}
|
||||
claimsMap[m.From] = to
|
||||
}
|
||||
opts = append(opts, oidc.WithAccountClaimMap(claimsMap))
|
||||
}
|
||||
|
||||
u, err := oidc.NewAuthMethod(scopeId, clientId, clientSecret, opts...)
|
||||
u, err := oidc.NewAuthMethod(ctx, scopeId, clientId, clientSecret, opts...)
|
||||
if err != nil {
|
||||
return nil, false, false, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to build auth method: %v.", err)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ type setup struct {
|
||||
|
||||
func getSetup(t *testing.T) setup {
|
||||
t.Helper()
|
||||
ctx := context.TODO()
|
||||
require := require.New(t)
|
||||
var ret setup
|
||||
var err error
|
||||
@@ -84,7 +85,7 @@ func getSetup(t *testing.T) setup {
|
||||
return ret.iamRepo, nil
|
||||
}
|
||||
ret.oidcRepoFn = func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(ret.rw, ret.rw, ret.kmsCache)
|
||||
return oidc.NewRepository(ctx, ret.rw, ret.rw, ret.kmsCache)
|
||||
}
|
||||
ret.pwRepoFn = func() (*password.Repository, error) {
|
||||
return password.NewRepository(ret.rw, ret.rw, ret.kmsCache)
|
||||
@@ -102,7 +103,7 @@ func getSetup(t *testing.T) setup {
|
||||
|
||||
ret.testProvider = capoidc.StartTestProvider(t)
|
||||
_, _, ret.testProviderAlg, _ = ret.testProvider.SigningKeys()
|
||||
ret.testProviderCaCert, err = oidc.ParseCertificates(ret.testProvider.CACert())
|
||||
ret.testProviderCaCert, err = oidc.ParseCertificates(ctx, ret.testProvider.CACert())
|
||||
require.NoError(err)
|
||||
|
||||
ret.testController = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
@@ -132,6 +133,7 @@ func getSetup(t *testing.T) setup {
|
||||
}
|
||||
|
||||
func TestList_FilterNonPublic(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -140,7 +142,7 @@ func TestList_FilterNonPublic(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -234,6 +236,7 @@ func TestList_FilterNonPublic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate_OIDC(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -242,7 +245,7 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
@@ -1120,6 +1123,7 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate_OIDCDryRun(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -1128,7 +1132,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -1146,7 +1150,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
|
||||
tp.SetClientCreds(tpClientId, tpClientSecret)
|
||||
_, _, tpAlg, _ := tp.SigningKeys()
|
||||
|
||||
tpCert, err := oidc.ParseCertificates(tp.CACert())
|
||||
tpCert, err := oidc.ParseCertificates(ctx, tp.CACert())
|
||||
require.NoError(t, err)
|
||||
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), o.PublicId, kms.KeyPurposeDatabase)
|
||||
require.NoError(t, err)
|
||||
@@ -1294,6 +1298,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangeState_OIDC(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -1302,7 +1307,7 @@ func TestChangeState_OIDC(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kmsCache)
|
||||
@@ -1323,7 +1328,7 @@ func TestChangeState_OIDC(t *testing.T) {
|
||||
tpClientSecret := "her-dog's-name"
|
||||
tp.SetClientCreds(tpClientId, tpClientSecret)
|
||||
_, _, tpAlg, _ := tp.SigningKeys()
|
||||
tpCert, err := oidc.ParseCertificates(tp.CACert())
|
||||
tpCert, err := oidc.ParseCertificates(ctx, tp.CACert())
|
||||
require.NoError(t, err)
|
||||
|
||||
incompleteAm := oidc.TestAuthMethod(t, conn, databaseWrapper, o.PublicId, "inactive", "client id", "secret",
|
||||
|
||||
@@ -174,7 +174,7 @@ func validateAuthenticatePasswordRequest(req *pbs.AuthenticateRequest) error {
|
||||
func toStoragePwAuthMethod(scopeId string, item *pb.AuthMethod) (*password.AuthMethod, error) {
|
||||
const op = "authmethod_service.toStoragePwAuthMethod"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil auth method.")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "nil auth method.")
|
||||
}
|
||||
var opts []password.Option
|
||||
if item.GetName() != nil {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func TestUpdate_Password(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -40,7 +41,7 @@ func TestUpdate_Password(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
@@ -447,6 +448,7 @@ func TestUpdate_Password(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthenticate_Password(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -457,7 +459,7 @@ func TestAuthenticate_Password(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
@@ -616,6 +618,7 @@ func TestAuthenticate_Password(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthenticateLogin_Password(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
@@ -626,7 +629,7 @@ func TestAuthenticateLogin_Password(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
@@ -784,6 +787,7 @@ func TestAuthenticateLogin_Password(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthenticate_AuthAccountConnectedToIamUser_Password(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
@@ -795,7 +799,7 @@ func TestAuthenticate_AuthAccountConnectedToIamUser_Password(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kms)
|
||||
return oidc.NewRepository(ctx, rw, rw, kms)
|
||||
}
|
||||
pwRepoFn := func() (*password.Repository, error) {
|
||||
return password.NewRepository(rw, rw, kms)
|
||||
|
||||
@@ -51,10 +51,10 @@ type Service struct {
|
||||
func NewService(repo common.AuthTokenRepoFactory, iamRepoFn common.IamRepoFactory) (Service, error) {
|
||||
const op = "authtoken.NewService"
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing auth token repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing auth token repository")
|
||||
}
|
||||
if iamRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repo, iamRepoFn: iamRepoFn}, nil
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (s Service) GetAuthToken(ctx context.Context, req *pbs.GetAuthTokenRequest)
|
||||
var ok bool
|
||||
outputFields, ok = requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,14 +229,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*authtoken.AuthTok
|
||||
const op = "authtokens.(Service).getFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
at, err := repo.LookupAuthToken(ctx, id)
|
||||
if err != nil && !errors.IsNotFoundError(err) {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if at == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("AuthToken %q not found", id))
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("AuthToken %q not found", id))
|
||||
}
|
||||
return at, nil
|
||||
}
|
||||
@@ -245,14 +245,14 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
const op = "authtokens.(Service).deleteFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
rows, err := repo.DeleteAuthToken(ctx, id)
|
||||
if err != nil {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete user"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete user"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
+24
-24
@@ -70,10 +70,10 @@ type Service struct {
|
||||
func NewService(repo common.VaultCredentialRepoFactory, iamRepo common.IamRepoFactory) (Service, error) {
|
||||
const op = "credentiallibraries.NewService"
|
||||
if iamRepo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
}
|
||||
return Service{iamRepoFn: iamRepo, repoFn: repo}, nil
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func (s Service) GetCredentialLibrary(ctx context.Context, req *pbs.GetCredentia
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -193,7 +193,7 @@ func (s Service) CreateCredentialLibrary(ctx context.Context, req *pbs.CreateCre
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -234,7 +234,7 @@ func (s Service) UpdateCredentialLibrary(ctx context.Context, req *pbs.UpdateCre
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -274,11 +274,11 @@ func (s Service) listFromRepo(ctx context.Context, storeId string) ([]*vault.Cre
|
||||
const op = "credentiallibraries.(Service).listFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
csl, err := repo.ListCredentialLibraries(ctx, storeId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return csl, nil
|
||||
}
|
||||
@@ -287,14 +287,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Library
|
||||
const op = "credentiallibraries.(Service).getFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
cs, err := repo.LookupCredentialLibrary(ctx, id)
|
||||
if err != nil && !errors.IsNotFoundError(err) {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if cs == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("credential library %q not found", id))
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("credential library %q not found", id))
|
||||
}
|
||||
return cs, err
|
||||
}
|
||||
@@ -303,15 +303,15 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Cred
|
||||
const op = "credentiallibraries.(Service).createInRepo"
|
||||
cl, err := toStorageVaultLibrary(item.GetCredentialStoreId(), item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateCredentialLibrary(ctx, scopeId, cl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create credential library"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create credential library"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create credential library but no error returned from repository.")
|
||||
@@ -323,7 +323,7 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
const op = "credentiallibraries.(Service).updateInRepo"
|
||||
cl, err := toStorageVaultLibrary(item.GetCredentialStoreId(), item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
cl.PublicId = id
|
||||
|
||||
@@ -333,11 +333,11 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateCredentialLibrary(ctx, projId, cl, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update credential library"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update credential library"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Credential Library %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -356,7 +356,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete credential library"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete credential library"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -391,13 +391,13 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
}
|
||||
parentId = cl.GetStoreId()
|
||||
default:
|
||||
res.Error = errors.New(errors.InvalidParameter, op, "unrecognized credential library subtype from id")
|
||||
res.Error = errors.New(ctx, errors.InvalidParameter, op, "unrecognized credential library subtype from id")
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
if parentId == "" {
|
||||
res.Error = errors.New(errors.RecordNotFound, op, "unable to find credential store for provided library")
|
||||
res.Error = errors.New(ctx, errors.RecordNotFound, op, "unable to find credential store for provided library")
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(cs.GetScopeId()))
|
||||
default:
|
||||
res.Error = errors.New(errors.InvalidParameter, op, "unrecognized credential store subtype from id")
|
||||
res.Error = errors.New(ctx, errors.InvalidParameter, op, "unrecognized credential store subtype from id")
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ func toProto(in credential.Library, opt ...handlers.Option) (*pb.CredentialLibra
|
||||
case vault.Subtype:
|
||||
vaultIn, ok := in.(*vault.CredentialLibrary)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "unable to cast to vault credential library")
|
||||
return nil, errors.NewDeprecated(errors.Internal, op, "unable to cast to vault credential library")
|
||||
}
|
||||
attrs := &pb.VaultCredentialLibraryAttributes{
|
||||
Path: wrapperspb.String(vaultIn.GetVaultPath()),
|
||||
@@ -482,7 +482,7 @@ func toProto(in credential.Library, opt ...handlers.Option) (*pb.CredentialLibra
|
||||
var err error
|
||||
out.Attributes, err = handlers.ProtoToStruct(attrs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("failed to convert resource from storage to api"))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("failed to convert resource from storage to api"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,7 +501,7 @@ func toStorageVaultLibrary(storeId string, in *pb.CredentialLibrary) (out *vault
|
||||
|
||||
attrs := &pb.VaultCredentialLibraryAttributes{}
|
||||
if err := handlers.StructToProto(in.GetAttributes(), attrs); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to parse the attributes"))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("unable to parse the attributes"))
|
||||
}
|
||||
|
||||
if attrs.GetHttpMethod() != nil {
|
||||
@@ -513,7 +513,7 @@ func toStorageVaultLibrary(storeId string, in *pb.CredentialLibrary) (out *vault
|
||||
|
||||
cs, err := vault.NewCredentialLibrary(storeId, attrs.GetPath().GetValue(), opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to build credential library"))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("unable to build credential library"))
|
||||
}
|
||||
return cs, err
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ type Service struct {
|
||||
func NewService(repo common.VaultCredentialRepoFactory, iamRepo common.IamRepoFactory) (Service, error) {
|
||||
const op = "credentialstores.NewService"
|
||||
if iamRepo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
}
|
||||
return Service{iamRepoFn: iamRepo, repoFn: repo}, nil
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func (s Service) GetCredentialStore(ctx context.Context, req *pbs.GetCredentialS
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -234,7 +234,7 @@ func (s Service) CreateCredentialStore(ctx context.Context, req *pbs.CreateCrede
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -282,7 +282,7 @@ func (s Service) UpdateCredentialStore(ctx context.Context, req *pbs.UpdateCrede
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -329,11 +329,11 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]*vault.
|
||||
const op = "credentialstores.(Service).listFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
csl, err := repo.ListCredentialStores(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return csl, nil
|
||||
}
|
||||
@@ -342,14 +342,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (credential.Store,
|
||||
const op = "credentialstores.(Service).getFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
cs, err := repo.LookupCredentialStore(ctx, id)
|
||||
if err != nil && !errors.IsNotFoundError(err) {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if cs == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("credential store %q not found", id))
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("credential store %q not found", id))
|
||||
}
|
||||
return cs, err
|
||||
}
|
||||
@@ -358,15 +358,15 @@ func (s Service) createInRepo(ctx context.Context, projId string, item *pb.Crede
|
||||
const op = "credentialstores.(Service).createInRepo"
|
||||
cs, err := toStorageVaultStore(projId, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateCredentialStore(ctx, cs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create credential store"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create credential store"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create credential store but no error returned from repository.")
|
||||
@@ -378,7 +378,7 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
const op = "credentialstores.(Service).updateInRepo"
|
||||
cs, err := toStorageVaultStore(projId, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
cs.PublicId = id
|
||||
|
||||
@@ -388,11 +388,11 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateCredentialStore(ctx, cs, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update credential store"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update credential store"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Credential Store %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -411,7 +411,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete credential store"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete credential store"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -505,7 +505,7 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
|
||||
case vault.Subtype:
|
||||
vaultIn, ok := in.(*vault.CredentialStore)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "unable to cast to vault credential store")
|
||||
return nil, errors.NewDeprecated(errors.Internal, op, "unable to cast to vault credential store")
|
||||
}
|
||||
attrs := &pb.VaultCredentialStoreAttributes{
|
||||
Address: wrapperspb.String(vaultIn.GetVaultAddress()),
|
||||
@@ -534,7 +534,7 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
|
||||
|
||||
var err error
|
||||
if out.Attributes, err = handlers.ProtoToStruct(attrs); err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.WrapDeprecated(err, op)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,7 +553,7 @@ func toStorageVaultStore(scopeId string, in *pb.CredentialStore) (out *vault.Cre
|
||||
|
||||
attrs := &pb.VaultCredentialStoreAttributes{}
|
||||
if err := handlers.StructToProto(in.GetAttributes(), attrs); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to parse the attributes"))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("unable to parse the attributes"))
|
||||
}
|
||||
if attrs.GetTlsServerName() != nil {
|
||||
opts = append(opts, vault.WithTlsServerName(attrs.GetTlsServerName().GetValue()))
|
||||
@@ -572,7 +572,7 @@ func toStorageVaultStore(scopeId string, in *pb.CredentialStore) (out *vault.Cre
|
||||
}
|
||||
pemCerts, pemPk, err := extractClientCertAndPk(attrs.GetClientCertificate().GetValue(), attrs.GetClientCertificateKey().GetValue())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.WrapDeprecated(err, op)
|
||||
}
|
||||
if len(pemCerts) != 0 {
|
||||
var cert []byte
|
||||
@@ -585,14 +585,14 @@ func toStorageVaultStore(scopeId string, in *pb.CredentialStore) (out *vault.Cre
|
||||
}
|
||||
cc, err := vault.NewClientCertificate(cert, pk)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.WrapDeprecated(err, op)
|
||||
}
|
||||
opts = append(opts, vault.WithClientCert(cc))
|
||||
}
|
||||
|
||||
cs, err := vault.NewCredentialStore(scopeId, attrs.GetAddress().GetValue(), []byte(attrs.GetToken().GetValue()), opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to build credential store for creation"))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("unable to build credential store for creation"))
|
||||
}
|
||||
return cs, err
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func extractClientCertAndPk(cert, pk string) ([]*pem.Block, *pem.Block, error) {
|
||||
const op = "credentialstores.extractClientCertAndPk"
|
||||
pks, err := decodePemBlocks(pk)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("failed to parse client certificate private key"))
|
||||
return nil, nil, errors.WrapDeprecated(err, op, errors.WithMsg("failed to parse client certificate private key"))
|
||||
}
|
||||
var pkPem *pem.Block
|
||||
switch len(pks) {
|
||||
@@ -24,12 +24,12 @@ func extractClientCertAndPk(cert, pk string) ([]*pem.Block, *pem.Block, error) {
|
||||
case 1:
|
||||
pkPem = pks[0]
|
||||
default:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "private key payload contained multiple pem blocks")
|
||||
return nil, nil, errors.NewDeprecated(errors.InvalidParameter, op, "private key payload contained multiple pem blocks")
|
||||
}
|
||||
|
||||
bs, err := decodePemBlocks(cert)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("failed to parse client certificate into pem blocks"))
|
||||
return nil, nil, errors.WrapDeprecated(err, op, errors.WithMsg("failed to parse client certificate into pem blocks"))
|
||||
}
|
||||
pkIdx := -1
|
||||
for i, b := range bs {
|
||||
@@ -38,9 +38,9 @@ func extractClientCertAndPk(cert, pk string) ([]*pem.Block, *pem.Block, error) {
|
||||
case pkPem == nil:
|
||||
pkIdx, pkPem = i, b
|
||||
case pkIdx < 0:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "client certificate contains a private key when one was also provided separately")
|
||||
return nil, nil, errors.NewDeprecated(errors.InvalidParameter, op, "client certificate contains a private key when one was also provided separately")
|
||||
default:
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("second primary key found at %d after previous one found at %d", i, pkIdx))
|
||||
return nil, nil, errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("second primary key found at %d after previous one found at %d", i, pkIdx))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func decodePemBlocks(input string) ([]*pem.Block, error) {
|
||||
ret = append(ret, p)
|
||||
}
|
||||
if len(cpIn) > 0 {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "not all data parseable by pem block")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "not all data parseable by pem block")
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db invalid public id",
|
||||
err: errors.E(errors.WithCode(errors.InvalidPublicId)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.InvalidPublicId)),
|
||||
expected: apiError{
|
||||
status: http.StatusInternalServerError,
|
||||
inner: &pb.Error{
|
||||
@@ -118,7 +118,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db invalid parameter",
|
||||
err: errors.E(errors.WithCode(errors.InvalidParameter)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.InvalidParameter)),
|
||||
expected: apiError{
|
||||
status: http.StatusInternalServerError,
|
||||
inner: &pb.Error{
|
||||
@@ -129,7 +129,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db invalid field mask",
|
||||
err: errors.E(errors.WithCode(errors.InvalidFieldMask)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.InvalidFieldMask)),
|
||||
expected: apiError{
|
||||
status: http.StatusBadRequest,
|
||||
inner: &pb.Error{
|
||||
@@ -141,7 +141,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db empty field mask",
|
||||
err: errors.E(errors.WithCode(errors.EmptyFieldMask)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.EmptyFieldMask)),
|
||||
expected: apiError{
|
||||
status: http.StatusBadRequest,
|
||||
inner: &pb.Error{
|
||||
@@ -153,7 +153,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db not unqiue",
|
||||
err: errors.E(errors.WithCode(errors.NotUnique)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.NotUnique)),
|
||||
expected: apiError{
|
||||
status: http.StatusBadRequest,
|
||||
inner: &pb.Error{
|
||||
@@ -164,7 +164,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db record not found",
|
||||
err: errors.E(errors.WithCode(errors.RecordNotFound)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.RecordNotFound)),
|
||||
expected: apiError{
|
||||
status: http.StatusNotFound,
|
||||
inner: &pb.Error{
|
||||
@@ -175,7 +175,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error Db multiple records",
|
||||
err: errors.E(errors.WithCode(errors.MultipleRecords)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.MultipleRecords)),
|
||||
expected: apiError{
|
||||
status: http.StatusInternalServerError,
|
||||
inner: &pb.Error{
|
||||
@@ -186,7 +186,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Domain error account already associated",
|
||||
err: errors.E(errors.WithCode(errors.AccountAlreadyAssociated)),
|
||||
err: errors.E(ctx, errors.WithCode(errors.AccountAlreadyAssociated)),
|
||||
expected: apiError{
|
||||
status: http.StatusBadRequest,
|
||||
inner: &pb.Error{
|
||||
@@ -197,7 +197,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Wrapped domain error",
|
||||
err: errors.E(errors.WithCode(errors.InvalidAddress), errors.WithMsg("test msg"), errors.WithWrap(errors.E(errors.WithCode(errors.NotNull), errors.WithMsg("inner msg")))),
|
||||
err: errors.E(ctx, errors.WithCode(errors.InvalidAddress), errors.WithMsg("test msg"), errors.WithWrap(errors.E(ctx, errors.WithCode(errors.NotNull), errors.WithMsg("inner msg")))),
|
||||
expected: apiError{
|
||||
status: http.StatusInternalServerError,
|
||||
inner: &pb.Error{
|
||||
@@ -208,7 +208,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Forbidden domain error",
|
||||
err: errors.E(errors.WithCode(errors.Forbidden), errors.WithMsg("test msg")),
|
||||
err: errors.E(ctx, errors.WithCode(errors.Forbidden), errors.WithMsg("test msg")),
|
||||
expected: apiError{
|
||||
status: http.StatusForbidden,
|
||||
inner: &pb.Error{
|
||||
@@ -219,7 +219,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Wrapped forbidden domain error",
|
||||
err: fmt.Errorf("got error: %w", errors.E(errors.WithCode(errors.Forbidden), errors.WithMsg("test msg"))),
|
||||
err: fmt.Errorf("got error: %w", errors.E(ctx, errors.WithCode(errors.Forbidden), errors.WithMsg("test msg"))),
|
||||
expected: apiError{
|
||||
status: http.StatusForbidden,
|
||||
inner: &pb.Error{
|
||||
|
||||
@@ -25,7 +25,7 @@ func NewFilter(f string) (*Filter, error) {
|
||||
}
|
||||
e, err := bexpr.CreateEvaluator(f, bexpr.WithTagName("json"), bexpr.WithHookFn(filter.WellKnownTypeFilterHook))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("couldn't build filter"), errors.WithCode(errors.InvalidParameter))
|
||||
return nil, errors.WrapDeprecated(err, op, errors.WithMsg("couldn't build filter"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
return &Filter{eval: e}, nil
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ type Service struct {
|
||||
func NewService(repo common.IamRepoFactory) (Service, error) {
|
||||
const op = "groups.NewService"
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repo}, nil
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (s Service) GetGroup(ctx context.Context, req *pbs.GetGroupRequest) (*pbs.G
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -202,7 +202,7 @@ func (s Service) CreateGroup(ctx context.Context, req *pbs.CreateGroupRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -240,7 +240,7 @@ func (s Service) UpdateGroup(ctx context.Context, req *pbs.UpdateGroupRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -294,7 +294,7 @@ func (s Service) AddGroupMembers(ctx context.Context, req *pbs.AddGroupMembersRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -332,7 +332,7 @@ func (s Service) SetGroupMembers(ctx context.Context, req *pbs.SetGroupMembersRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -370,7 +370,7 @@ func (s Service) RemoveGroupMembers(ctx context.Context, req *pbs.RemoveGroupMem
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -394,14 +394,14 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*iam.Group, []*iam
|
||||
const op = "groups.(Service).getFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
g, m, err := repo.LookupGroup(ctx, id)
|
||||
if err != nil && !errors.IsNotFoundError(err) {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if g == nil {
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("group %q not found", id))
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("group %q not found", id))
|
||||
}
|
||||
return g, m, err
|
||||
}
|
||||
@@ -421,11 +421,11 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Grou
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateGroup(ctx, u)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create group but no error returned from repository.")
|
||||
@@ -454,11 +454,11 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []st
|
||||
}
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, m, rowsUpdated, err := repo.UpdateGroup(ctx, g, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil, handlers.NotFoundErrorf("Group %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -477,7 +477,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete group"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete group"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -486,11 +486,11 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]*iam.Gr
|
||||
const op = "groups.(Service).listFromRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
gl, err := repo.ListGroups(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return gl, nil
|
||||
}
|
||||
@@ -499,7 +499,7 @@ func (s Service) addMembersInRepo(ctx context.Context, groupId string, userIds [
|
||||
const op = "groups.(Service).addMembersInRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, err = repo.AddGroupMembers(ctx, groupId, version, strutil.RemoveDuplicates(userIds, false))
|
||||
if err != nil {
|
||||
@@ -508,7 +508,7 @@ func (s Service) addMembersInRepo(ctx context.Context, groupId string, userIds [
|
||||
}
|
||||
out, m, err := repo.LookupGroup(ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up group after adding memebers"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up group after adding memebers"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup group after adding member to it.")
|
||||
@@ -520,7 +520,7 @@ func (s Service) setMembersInRepo(ctx context.Context, groupId string, userIds [
|
||||
const op = "groups.(Service).setMembersInRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, _, err = repo.SetGroupMembers(ctx, groupId, version, strutil.RemoveDuplicates(userIds, false))
|
||||
if err != nil {
|
||||
@@ -529,7 +529,7 @@ func (s Service) setMembersInRepo(ctx context.Context, groupId string, userIds [
|
||||
}
|
||||
out, m, err := repo.LookupGroup(ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up group after setting members"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up group after setting members"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup group after setting members for it.")
|
||||
@@ -541,7 +541,7 @@ func (s Service) removeMembersInRepo(ctx context.Context, groupId string, userId
|
||||
const op = "groups.(Service).removeMembersInRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, err = repo.DeleteGroupMembers(ctx, groupId, version, strutil.RemoveDuplicates(userIds, false))
|
||||
if err != nil {
|
||||
@@ -550,7 +550,7 @@ func (s Service) removeMembersInRepo(ctx context.Context, groupId string, userId
|
||||
}
|
||||
out, m, err := repo.LookupGroup(ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up group after removing members"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up group after removing members"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup group after removing members from it.")
|
||||
|
||||
@@ -72,10 +72,10 @@ var _ pbs.HostCatalogServiceServer = Service{}
|
||||
func NewService(repoFn common.StaticRepoFactory, iamRepoFn common.IamRepoFactory) (Service, error) {
|
||||
const op = "host_catalogs.NewService"
|
||||
if repoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing static repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing static repository")
|
||||
}
|
||||
if iamRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{staticRepoFn: repoFn, iamRepoFn: iamRepoFn}, nil
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (s Service) GetHostCatalog(ctx context.Context, req *pbs.GetHostCatalogRequ
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -223,7 +223,7 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -271,7 +271,7 @@ func (s Service) UpdateHostCatalog(ctx context.Context, req *pbs.UpdateHostCatal
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -352,15 +352,15 @@ func (s Service) createInRepo(ctx context.Context, projId string, item *pb.HostC
|
||||
}
|
||||
h, err := static.NewHostCatalog(projId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to build host catalog for creation"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to build host catalog for creation"))
|
||||
}
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateCatalog(ctx, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create host catalog"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host catalog"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host catalog but no error returned from repository.")
|
||||
@@ -380,7 +380,7 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
version := item.GetVersion()
|
||||
h, err := static.NewHostCatalog(projId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to build host catalog for update"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to build host catalog for update"))
|
||||
}
|
||||
h.PublicId = id
|
||||
dbMask := maskManager.Translate(mask)
|
||||
@@ -389,11 +389,11 @@ func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []str
|
||||
}
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateCatalog(ctx, h, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update host catalog"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host catalog"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -405,11 +405,11 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
const op = "host_catalogs.(Service).deleteFromRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
rows, err := repo.DeleteCatalog(ctx, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete host"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ var _ pbs.HostSetServiceServer = Service{}
|
||||
func NewService(repoFn common.StaticRepoFactory) (Service, error) {
|
||||
const op = "host_sets.NewService"
|
||||
if repoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing static repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing static repository")
|
||||
}
|
||||
return Service{staticRepoFn: repoFn}, nil
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func (s Service) GetHostSet(ctx context.Context, req *pbs.GetHostSetRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -183,7 +183,7 @@ func (s Service) CreateHostSet(ctx context.Context, req *pbs.CreateHostSetReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -224,7 +224,7 @@ func (s Service) UpdateHostSet(ctx context.Context, req *pbs.UpdateHostSetReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -278,7 +278,7 @@ func (s Service) AddHostSetHosts(ctx context.Context, req *pbs.AddHostSetHostsRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -315,7 +315,7 @@ func (s Service) SetHostSetHosts(ctx context.Context, req *pbs.SetHostSetHostsRe
|
||||
}
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -353,7 +353,7 @@ func (s Service) RemoveHostSetHosts(ctx context.Context, req *pbs.RemoveHostSetH
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -399,7 +399,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
}
|
||||
h, err := static.NewHostSet(catalogId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Unable to build host set for creation"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for creation"))
|
||||
}
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
@@ -407,7 +407,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
}
|
||||
out, err := repo.CreateSet(ctx, scopeId, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create host set"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
|
||||
@@ -426,7 +426,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
}
|
||||
h, err := static.NewHostSet(catalogId, opts...)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("Unable to build host set for update"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for update"))
|
||||
}
|
||||
h.PublicId = id
|
||||
dbMask := maskManager.Translate(mask)
|
||||
@@ -439,7 +439,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
}
|
||||
out, m, rowsUpdated, err := repo.UpdateSet(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to update host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host set"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil, handlers.NotFoundErrorf("Host Set %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -455,7 +455,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
}
|
||||
rows, err := repo.DeleteSet(ctx, scopeId, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete host"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -480,11 +480,11 @@ func (s Service) addInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
}
|
||||
_, err = repo.AddSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("Unable to add hosts to host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to add hosts to host set"))
|
||||
}
|
||||
out, m, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up host set after adding hosts"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up host set after adding hosts"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup host set after adding hosts to it.")
|
||||
@@ -496,16 +496,16 @@ func (s Service) setInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
const op = "host_sets.(Service).setInRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, _, err = repo.SetSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("Unable to set hosts in host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to set hosts in host set"))
|
||||
}
|
||||
|
||||
out, m, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up host set after setting hosts"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up host set after setting hosts"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup host set after setting hosts for it.")
|
||||
@@ -517,15 +517,15 @@ func (s Service) removeInRepo(ctx context.Context, scopeId, setId string, hostId
|
||||
const op = "host_sets.(Service).removeInRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, err = repo.DeleteSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("Unable to remove hosts from host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to remove hosts from host set"))
|
||||
}
|
||||
out, m, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up host set"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup host set after removing hosts from it.")
|
||||
|
||||
@@ -65,7 +65,7 @@ var _ pbs.HostServiceServer = Service{}
|
||||
func NewService(repoFn common.StaticRepoFactory) (Service, error) {
|
||||
const op = "hosts.NewService"
|
||||
if repoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing static repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing static repository")
|
||||
}
|
||||
return Service{staticRepoFn: repoFn}, nil
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (s Service) GetHost(ctx context.Context, req *pbs.GetHostRequest) (*pbs.Get
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -182,7 +182,7 @@ func (s Service) CreateHost(ctx context.Context, req *pbs.CreateHostRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -223,7 +223,7 @@ func (s Service) UpdateHost(ctx context.Context, req *pbs.UpdateHostRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -292,16 +292,16 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
}
|
||||
h, err := static.NewHost(catalogId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Unable to build host for creation"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host for creation"))
|
||||
}
|
||||
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateHost(ctx, scopeId, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Unable to create host"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to create host"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host but no error returned from repository.")
|
||||
@@ -327,7 +327,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
}
|
||||
h, err := static.NewHost(catalogId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("Unable to build host for update"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host for update"))
|
||||
}
|
||||
h.PublicId = id
|
||||
dbMask := maskManager.Translate(mask)
|
||||
@@ -340,7 +340,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateHost(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update host"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Host %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -356,7 +356,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
}
|
||||
rows, err := repo.DeleteHost(ctx, scopeId, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete host"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ type Service struct {
|
||||
func NewService(oidcRepo common.OidcAuthRepoFactory) (Service, error) {
|
||||
const op = "managed_groups.NewService"
|
||||
if oidcRepo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing oidc repository provided")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing oidc repository provided")
|
||||
}
|
||||
return Service{oidcRepoFn: oidcRepo}, nil
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func (s Service) GetManagedGroup(ctx context.Context, req *pbs.GetManagedGroupRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -197,7 +197,7 @@ func (s Service) CreateManagedGroup(ctx context.Context, req *pbs.CreateManagedG
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -236,7 +236,7 @@ func (s Service) UpdateManagedGroup(ctx context.Context, req *pbs.UpdateManagedG
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -308,7 +308,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (auth.ManagedGroup,
|
||||
func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item *pb.ManagedGroup) (*oidc.ManagedGroup, error) {
|
||||
const op = "managed_groups.(Service).createOidcInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing item")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var opts []oidc.Option
|
||||
if item.GetName() != nil {
|
||||
@@ -322,7 +322,7 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
return nil, handlers.InvalidArgumentErrorf("Error in provided request.",
|
||||
map[string]string{"attributes": "Attribute fields do not match the expected format."})
|
||||
}
|
||||
mg, err := oidc.NewManagedGroup(am.GetPublicId(), attrs.GetFilter(), opts...)
|
||||
mg, err := oidc.NewManagedGroup(ctx, am.GetPublicId(), attrs.GetFilter(), opts...)
|
||||
if err != nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to build user for creation: %v.", err)
|
||||
}
|
||||
@@ -333,7 +333,7 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
|
||||
out, err := repo.CreateManagedGroup(ctx, am.GetScopeId(), mg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create managed group"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create managed group"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create managed group but no error returned from repository.")
|
||||
@@ -344,14 +344,14 @@ func (s Service) createOidcInRepo(ctx context.Context, am auth.AuthMethod, item
|
||||
func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.ManagedGroup) (auth.ManagedGroup, error) {
|
||||
const op = "managed_groups.(Service).createInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing item")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var out auth.ManagedGroup
|
||||
switch auth.SubtypeFromId(am.GetPublicId()) {
|
||||
case oidc.Subtype:
|
||||
am, err := s.createOidcInRepo(ctx, am, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if am == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create managed group but no error returned from repository.")
|
||||
@@ -364,7 +364,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
|
||||
func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string, mask []string, item *pb.ManagedGroup) (*oidc.ManagedGroup, error) {
|
||||
const op = "managed_groups.(Service).updateOidcInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil managed group.")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil managed group.")
|
||||
}
|
||||
mg := oidc.AllocManagedGroup()
|
||||
mg.PublicId = id
|
||||
@@ -392,11 +392,11 @@ func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string,
|
||||
}
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateManagedGroup(ctx, scopeId, mg, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update managed group"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update managed group"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Managed Group %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -411,7 +411,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string,
|
||||
case oidc.Subtype:
|
||||
mg, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if mg == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to update managed group but no error returned from repository.")
|
||||
@@ -437,7 +437,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op)
|
||||
return false, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -450,11 +450,11 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
|
||||
case oidc.Subtype:
|
||||
oidcRepo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
oidcl, err := oidcRepo.ListManagedGroups(ctx, authMethodId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, a := range oidcl {
|
||||
outUl = append(outUl, a)
|
||||
@@ -491,7 +491,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
parentId = acct.GetAuthMethodId()
|
||||
default:
|
||||
res.Error = errors.New(errors.InvalidPublicId, op, "unrecognized managed group subtype")
|
||||
res.Error = errors.New(ctx, errors.InvalidPublicId, op, "unrecognized managed group subtype")
|
||||
return nil, res
|
||||
}
|
||||
opts = append(opts, requestauth.WithId(id))
|
||||
@@ -512,7 +512,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
authMeth = am
|
||||
opts = append(opts, requestauth.WithScopeId(am.GetScopeId()))
|
||||
default:
|
||||
res.Error = errors.New(errors.InvalidPublicId, op, "unrecognized auth method subtype")
|
||||
res.Error = errors.New(ctx, errors.InvalidPublicId, op, "unrecognized auth method subtype")
|
||||
return nil, res
|
||||
}
|
||||
opts = append(opts, requestauth.WithPin(parentId))
|
||||
@@ -585,7 +585,7 @@ func toProto(ctx context.Context, in auth.ManagedGroup, opt ...handlers.Option)
|
||||
func validateGetRequest(req *pbs.GetManagedGroupRequest) error {
|
||||
const op = "managed_groups.validateGetRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
|
||||
}
|
||||
@@ -593,7 +593,7 @@ func validateGetRequest(req *pbs.GetManagedGroupRequest) error {
|
||||
func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
|
||||
const op = "managed_groups.validateCreateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -626,7 +626,7 @@ func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
|
||||
func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
|
||||
const op = "managed_groups.validateUpdateRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
@@ -658,7 +658,7 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
|
||||
func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
|
||||
const op = "managed_groups.validateDeleteRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
|
||||
}
|
||||
@@ -666,7 +666,7 @@ func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
|
||||
func validateListRequest(req *pbs.ListManagedGroupsRequest) error {
|
||||
const op = "managed_groups.validateListRequest"
|
||||
if req == nil {
|
||||
return errors.New(errors.InvalidParameter, op, "nil request")
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
|
||||
}
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), oidc.AuthMethodPrefix) {
|
||||
|
||||
@@ -45,12 +45,13 @@ var oidcAuthorizedActions = []string{
|
||||
}
|
||||
|
||||
func TestNewService(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
@@ -86,7 +87,7 @@ func TestGet(t *testing.T) {
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -187,7 +188,7 @@ func TestListOidc(t *testing.T) {
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -335,7 +336,7 @@ func TestDelete(t *testing.T) {
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -399,6 +400,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete_twice(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrap := db.TestWrapper(t)
|
||||
@@ -406,7 +408,7 @@ func TestDelete_twice(t *testing.T) {
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -444,7 +446,7 @@ func TestCreateOidc(t *testing.T) {
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
@@ -629,7 +631,7 @@ func TestUpdateOidc(t *testing.T) {
|
||||
wrap := db.TestWrapper(t)
|
||||
kmsCache := kms.TestKms(t, conn, wrap)
|
||||
oidcRepoFn := func() (*oidc.Repository, error) {
|
||||
return oidc.NewRepository(rw, rw, kmsCache)
|
||||
return oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
}
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
return iam.NewRepository(rw, rw, kmsCache)
|
||||
|
||||
@@ -37,7 +37,7 @@ func NewMaskManager(dest MaskDestination, src MaskSource) (MaskManager, error) {
|
||||
for k, v := range srcToDest {
|
||||
ov, ok := destToSrc[v]
|
||||
if !ok || ov != k {
|
||||
return nil, errors.New(errors.Encode, op, fmt.Sprintf("mapping src field %q maps to %q, dest %q maps to %q", k, v, v, ov))
|
||||
return nil, errors.NewDeprecated(errors.Encode, op, fmt.Sprintf("mapping src field %q maps to %q, dest %q maps to %q", k, v, v, ov))
|
||||
}
|
||||
result[k] = v
|
||||
}
|
||||
@@ -45,12 +45,12 @@ func NewMaskManager(dest MaskDestination, src MaskSource) (MaskManager, error) {
|
||||
// Now check to make sure there aren't any dangling dest mappings.
|
||||
for k, v := range destToSrc {
|
||||
if ov, ok := srcToDest[v]; !ok || ov != k {
|
||||
return nil, errors.New(errors.Encode, op, fmt.Sprintf("mapping src field %q maps to %q, dest %q maps to %q", k, v, v, ov))
|
||||
return nil, errors.NewDeprecated(errors.Encode, op, fmt.Sprintf("mapping src field %q maps to %q, dest %q maps to %q", k, v, v, ov))
|
||||
}
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "mask mapping generated is zero")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "mask mapping generated is zero")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -67,7 +67,7 @@ func mapFromProto(ps []protoreflect.ProtoMessage) (map[string]string, error) {
|
||||
opts := f.Options().(*descriptorpb.FieldOptions)
|
||||
if nameMap := proto.GetExtension(opts, pb.E_MaskMapping).(*pb.MaskMapping); !proto.Equal(nameMap, &pb.MaskMapping{}) && nameMap != nil {
|
||||
if _, ok := mapping[nameMap.GetThis()]; ok {
|
||||
return nil, errors.New(errors.InvalidParameter, op, fmt.Sprintf("duplicate mapping from field %q with the mapping key %q", f.Name(), nameMap.GetThis()))
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("duplicate mapping from field %q with the mapping key %q", f.Name(), nameMap.GetThis()))
|
||||
}
|
||||
mapping[nameMap.GetThis()] = nameMap.GetThat()
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ type Service struct {
|
||||
func NewService(repo common.IamRepoFactory) (Service, error) {
|
||||
const op = "roles.NewService"
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repo}, nil
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (s Service) GetRole(ctx context.Context, req *pbs.GetRoleRequest) (*pbs.Get
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -206,7 +206,7 @@ func (s Service) CreateRole(ctx context.Context, req *pbs.CreateRoleRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -244,7 +244,7 @@ func (s Service) UpdateRole(ctx context.Context, req *pbs.UpdateRoleRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -298,7 +298,7 @@ func (s Service) AddRolePrincipals(ctx context.Context, req *pbs.AddRolePrincipa
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -336,7 +336,7 @@ func (s Service) SetRolePrincipals(ctx context.Context, req *pbs.SetRolePrincipa
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -374,7 +374,7 @@ func (s Service) RemoveRolePrincipals(ctx context.Context, req *pbs.RemoveRolePr
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -412,7 +412,7 @@ func (s Service) AddRoleGrants(ctx context.Context, req *pbs.AddRoleGrantsReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -450,7 +450,7 @@ func (s Service) SetRoleGrants(ctx context.Context, req *pbs.SetRoleGrantsReques
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -488,7 +488,7 @@ func (s Service) RemoveRoleGrants(ctx context.Context, req *pbs.RemoveRoleGrants
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -548,7 +548,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.Role
|
||||
}
|
||||
out, err := repo.CreateRole(ctx, u)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create role but no error returned from repository.")
|
||||
@@ -585,7 +585,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []st
|
||||
}
|
||||
out, pr, gr, rowsUpdated, err := repo.UpdateRole(ctx, u, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op)
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil, nil, handlers.NotFoundErrorf("Role %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -604,7 +604,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete role"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete role"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -634,7 +634,7 @@ func (s Service) addPrinciplesInRepo(ctx context.Context, roleId string, princip
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up role after adding principals"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up role after adding principals"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after adding principals to it.")
|
||||
@@ -655,7 +655,7 @@ func (s Service) setPrinciplesInRepo(ctx context.Context, roleId string, princip
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up role after setting principals"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up role after setting principals"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after setting principals for it.")
|
||||
@@ -676,7 +676,7 @@ func (s Service) removePrinciplesInRepo(ctx context.Context, roleId string, prin
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up role after removing principals"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up role after removing principals"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after removing principals from it.")
|
||||
@@ -697,7 +697,7 @@ func (s Service) addGrantsInRepo(ctx context.Context, roleId string, grants []st
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up role after adding grants"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up role after adding grants"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after adding grants to it.")
|
||||
@@ -722,7 +722,7 @@ func (s Service) setGrantsInRepo(ctx context.Context, roleId string, grants []st
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up role after setting grants"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up role after setting grants"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after setting grants on it.")
|
||||
@@ -743,7 +743,7 @@ func (s Service) removeGrantsInRepo(ctx context.Context, roleId string, grants [
|
||||
}
|
||||
out, pr, roleGrants, err := repo.LookupRole(ctx, roleId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("uable to look up role after removing grant"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("uable to look up role after removing grant"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup role after removing grants from it.")
|
||||
|
||||
@@ -102,7 +102,7 @@ type Service struct {
|
||||
func NewService(repo common.IamRepoFactory) (Service, error) {
|
||||
const op = "scopes.(Service).NewService"
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repo}, nil
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func (s Service) GetScope(ctx context.Context, req *pbs.GetScopeRequest) (*pbs.G
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -263,7 +263,7 @@ func (s Service) CreateScope(ctx context.Context, req *pbs.CreateScopeRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -308,7 +308,7 @@ func (s Service) UpdateScope(ctx context.Context, req *pbs.UpdateScopeRequest) (
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -397,7 +397,7 @@ func (s Service) createInRepo(ctx context.Context, authResults auth.VerifyResult
|
||||
}
|
||||
out, err := repo.CreateScope(ctx, iamScope, authResults.UserId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create scope"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create scope"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create scope but no error returned from repository.")
|
||||
@@ -457,7 +457,7 @@ func (s Service) updateInRepo(ctx context.Context, parentScope *pb.ScopeInfo, sc
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateScope(ctx, iamScope, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update project"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update project"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, handlers.NotFoundErrorf("Scope %q doesn't exist or incorrect version provided.", scopeId)
|
||||
@@ -473,7 +473,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId string) (bool, erro
|
||||
}
|
||||
rows, err := repo.DeleteScope(ctx, scopeId)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete scope"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete scope"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ type Service struct {
|
||||
func NewService(repoFn common.SessionRepoFactory, iamRepoFn common.IamRepoFactory) (Service, error) {
|
||||
const op = "sessions.NewService"
|
||||
if repoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing session repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing session repository")
|
||||
}
|
||||
if iamRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repoFn, iamRepoFn: iamRepoFn}, nil
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (s Service) GetSession(ctx context.Context, req *pbs.GetSessionRequest) (*p
|
||||
var ok bool
|
||||
outputFields, ok = requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ func (s Service) CancelSession(ctx context.Context, req *pbs.CancelSessionReques
|
||||
var ok bool
|
||||
outputFields, ok = requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ func (s Service) cancelInRepo(ctx context.Context, id string, version uint32) (*
|
||||
}
|
||||
out, err := repo.CancelSession(ctx, id, version)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to update session"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update session"))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -106,22 +106,22 @@ func NewService(
|
||||
vaultCredRepoFn common.VaultCredentialRepoFactory) (Service, error) {
|
||||
const op = "targets.NewService"
|
||||
if repoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing target repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing target repository")
|
||||
}
|
||||
if iamRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
if serversRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing servers repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing servers repository")
|
||||
}
|
||||
if sessionRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing session repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing session repository")
|
||||
}
|
||||
if staticHostRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing static host repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing static host repository")
|
||||
}
|
||||
if vaultCredRepoFn == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing vault credential repository")
|
||||
}
|
||||
return Service{
|
||||
repoFn: repoFn,
|
||||
@@ -228,7 +228,7 @@ func (s Service) GetTarget(ctx context.Context, req *pbs.GetTargetRequest) (*pbs
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -266,7 +266,7 @@ func (s Service) CreateTarget(ctx context.Context, req *pbs.CreateTargetRequest)
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -304,7 +304,7 @@ func (s Service) UpdateTarget(ctx context.Context, req *pbs.UpdateTargetRequest)
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -358,7 +358,7 @@ func (s Service) AddTargetHostSets(ctx context.Context, req *pbs.AddTargetHostSe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -396,7 +396,7 @@ func (s Service) SetTargetHostSets(ctx context.Context, req *pbs.SetTargetHostSe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -434,7 +434,7 @@ func (s Service) RemoveTargetHostSets(ctx context.Context, req *pbs.RemoveTarget
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -472,7 +472,7 @@ func (s Service) AddTargetCredentialLibraries(ctx context.Context, req *pbs.AddT
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -510,7 +510,7 @@ func (s Service) SetTargetCredentialLibraries(ctx context.Context, req *pbs.SetT
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -548,7 +548,7 @@ func (s Service) RemoveTargetCredentialLibraries(ctx context.Context, req *pbs.R
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -586,7 +586,7 @@ func (s Service) AddTargetCredentialSources(ctx context.Context, req *pbs.AddTar
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -624,7 +624,7 @@ func (s Service) SetTargetCredentialSources(ctx context.Context, req *pbs.SetTar
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -662,7 +662,7 @@ func (s Service) RemoveTargetCredentialSources(ctx context.Context, req *pbs.Rem
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -885,7 +885,7 @@ HostSetIterationLoop:
|
||||
case static.Subtype:
|
||||
h, err := staticHostRepo.LookupHost(ctx, chosenId.hostId)
|
||||
if err != nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "errors looking up host")
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "errors looking up host")
|
||||
}
|
||||
endpointHost = h.Address
|
||||
if endpointHost == "" {
|
||||
@@ -941,11 +941,11 @@ HostSetIterationLoop:
|
||||
if len(reqs) > 0 {
|
||||
credRepo, err := s.vaultCredRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
cs, err = credRepo.Issue(ctx, sess.GetPublicId(), reqs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -956,7 +956,7 @@ HostSetIterationLoop:
|
||||
// TODO: Access the json directly from the vault response instead of re-marshalling it.
|
||||
jSecret, err := json.Marshal(secret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("marshalling secret to json"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("marshalling secret to json"))
|
||||
}
|
||||
var sSecret *structpb.Struct
|
||||
switch secret.(type) {
|
||||
@@ -969,11 +969,11 @@ HostSetIterationLoop:
|
||||
// decoder with UseNumber here.
|
||||
var dSecret map[string]interface{}
|
||||
if err := json.Unmarshal(jSecret, &dSecret); err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("decoding json for proto marshaling"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("decoding json for proto marshaling"))
|
||||
}
|
||||
sSecret, err = structpb.NewStruct(dSecret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("creating proto struct for secret"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("creating proto struct for secret"))
|
||||
}
|
||||
}
|
||||
creds = append(creds, &pb.SessionCredential{
|
||||
@@ -1076,7 +1076,7 @@ func (s Service) createInRepo(ctx context.Context, item *pb.Target) (target.Targ
|
||||
}
|
||||
out, hs, cl, err := repo.CreateTcpTarget(ctx, u)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to create target"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create target"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create target but no error returned from repository.")
|
||||
@@ -1125,7 +1125,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []st
|
||||
}
|
||||
out, hs, cl, rowsUpdated, err := repo.UpdateTcpTarget(ctx, u, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to update target"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update target"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil, nil, handlers.NotFoundErrorf("Target %q not found or incorrect version provided.", id)
|
||||
@@ -1144,7 +1144,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete target"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete target"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -1191,7 +1191,7 @@ func (s Service) setSetsInRepo(ctx context.Context, targetId string, hostSetIds
|
||||
|
||||
out, hs, cl, err := repo.LookupTarget(ctx, targetId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up target after setting host sets"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up target after setting host sets"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup target after setting host sets for it.")
|
||||
@@ -1212,7 +1212,7 @@ func (s Service) removeSetsInRepo(ctx context.Context, targetId string, hostSetI
|
||||
}
|
||||
out, hs, cl, err := repo.LookupTarget(ctx, targetId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up target after removing host sets"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up target after removing host sets"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup target after removing host sets from it.")
|
||||
@@ -1250,7 +1250,7 @@ func (s Service) setCredentialSourcesInRepo(ctx context.Context, targetId string
|
||||
|
||||
out, hs, credSources, err := repo.LookupTarget(ctx, targetId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up target after setting credential sources"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up target after setting credential sources"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup target after setting credential sources for it.")
|
||||
@@ -1271,7 +1271,7 @@ func (s Service) removeCredentialSourcesInRepo(ctx context.Context, targetId str
|
||||
}
|
||||
out, hs, credSources, err := repo.LookupTarget(ctx, targetId)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up target after removing credential sources"))
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up target after removing credential sources"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup target after removing credential sources from it.")
|
||||
@@ -1414,7 +1414,7 @@ func toProto(ctx context.Context, in target.Target, m []*target.TargetSet, credS
|
||||
case credential.IngressPurpose, credential.EgressPurpose:
|
||||
// TODO: When we support other purposes add them to different fields here.
|
||||
default:
|
||||
return nil, errors.New(errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1429,7 +1429,7 @@ func toProto(ctx context.Context, in target.Target, m []*target.TargetSet, credS
|
||||
case credential.IngressPurpose, credential.EgressPurpose:
|
||||
// TODO: When we support other purposes add them to different fields here.
|
||||
default:
|
||||
return nil, errors.New(errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ type Service struct {
|
||||
func NewService(repo common.IamRepoFactory) (Service, error) {
|
||||
const op = "users.NewService"
|
||||
if repo == nil {
|
||||
return Service{}, errors.New(errors.InvalidParameter, op, "missing iam repository")
|
||||
return Service{}, errors.NewDeprecated(errors.InvalidParameter, op, "missing iam repository")
|
||||
}
|
||||
return Service{repoFn: repo}, nil
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func (s Service) GetUser(ctx context.Context, req *pbs.GetUserRequest) (*pbs.Get
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -204,7 +204,7 @@ func (s Service) CreateUser(ctx context.Context, req *pbs.CreateUserRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -241,7 +241,7 @@ func (s Service) UpdateUser(ctx context.Context, req *pbs.UpdateUserRequest) (*p
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -295,7 +295,7 @@ func (s Service) AddUserAccounts(ctx context.Context, req *pbs.AddUserAccountsRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -333,7 +333,7 @@ func (s Service) SetUserAccounts(ctx context.Context, req *pbs.SetUserAccountsRe
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -371,7 +371,7 @@ func (s Service) RemoveUserAccounts(ctx context.Context, req *pbs.RemoveUserAcco
|
||||
|
||||
outputFields, ok := requests.OutputFields(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New(errors.Internal, op, "no request context found")
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
@@ -428,7 +428,7 @@ func (s Service) createInRepo(ctx context.Context, orgId string, item *pb.User)
|
||||
}
|
||||
out, err := repo.CreateUser(ctx, u)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op, errors.WithMsg("unable to create user"))
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create user"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create user but no error returned from repository.")
|
||||
@@ -461,7 +461,7 @@ func (s Service) updateInRepo(ctx context.Context, orgId, id string, mask []stri
|
||||
}
|
||||
out, accts, rowsUpdated, err := repo.UpdateUser(ctx, u, version, dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to update user"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update user"))
|
||||
}
|
||||
if rowsUpdated == 0 {
|
||||
return nil, nil, handlers.NotFoundErrorf("User %q doesn't exist or incorrect version provided.", id)
|
||||
@@ -480,7 +480,7 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
|
||||
if errors.IsNotFoundError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, op, errors.WithMsg("unable to delete user"))
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete user"))
|
||||
}
|
||||
return rows > 0, nil
|
||||
}
|
||||
@@ -509,7 +509,7 @@ func (s Service) addInRepo(ctx context.Context, userId string, accountIds []stri
|
||||
}
|
||||
out, accts, err := repo.LookupUser(ctx, userId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up user after adding accounts"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up user after adding accounts"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup user after adding accounts to it.")
|
||||
@@ -529,7 +529,7 @@ func (s Service) setInRepo(ctx context.Context, userId string, accountIds []stri
|
||||
}
|
||||
out, accts, err := repo.LookupUser(ctx, userId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up user after setting accounts"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up user after setting accounts"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup user after setting accounts for it.")
|
||||
@@ -549,7 +549,7 @@ func (s Service) removeInRepo(ctx context.Context, userId string, accountIds []s
|
||||
}
|
||||
out, accts, err := repo.LookupUser(ctx, userId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, op, errors.WithMsg("unable to look up user after removing accounts"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to look up user after removing accounts"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to lookup user after removing accounts from it.")
|
||||
|
||||
@@ -44,11 +44,11 @@ func newSessionCleanupJob(
|
||||
const op = "controller.newNewSessionCleanupJob"
|
||||
switch {
|
||||
case logger == nil:
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing logger")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing logger")
|
||||
case sessionRepoFn == nil:
|
||||
return nil, errors.New(errors.InvalidParameter, op, "missing sessionRepoFn")
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing sessionRepoFn")
|
||||
case gracePeriod < session.DeadWorkerConnCloseMinGrace:
|
||||
return nil, errors.New(
|
||||
return nil, errors.NewDeprecated(
|
||||
errors.InvalidParameter, op, fmt.Sprintf("invalid gracePeriod, must be greater than %d", session.DeadWorkerConnCloseMinGrace))
|
||||
}
|
||||
|
||||
@@ -92,13 +92,13 @@ func (j *sessionCleanupJob) Run(ctx context.Context) error {
|
||||
// Load repos.
|
||||
sessionRepo, err := j.sessionRepoFn()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op, errors.WithMsg("error getting session repo"))
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error getting session repo"))
|
||||
}
|
||||
|
||||
// Run the atomic dead worker cleanup job.
|
||||
results, err := sessionRepo.CloseConnectionsForDeadWorkers(ctx, j.gracePeriod)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op)
|
||||
return errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
if len(results) < 1 {
|
||||
|
||||
@@ -141,11 +141,13 @@ func TestSessionCleanupJob(t *testing.T) {
|
||||
|
||||
func TestSessionCleanupJobNewJobErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.TODO()
|
||||
const op = "controller.newNewSessionCleanupJob"
|
||||
require := require.New(t)
|
||||
|
||||
job, err := newSessionCleanupJob(nil, nil, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
errors.WithOp(op),
|
||||
errors.WithMsg("missing logger"),
|
||||
@@ -154,6 +156,7 @@ func TestSessionCleanupJobNewJobErr(t *testing.T) {
|
||||
|
||||
job, err = newSessionCleanupJob(hclog.New(nil), nil, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
errors.WithOp(op),
|
||||
errors.WithMsg("missing sessionRepoFn"),
|
||||
@@ -162,6 +165,7 @@ func TestSessionCleanupJobNewJobErr(t *testing.T) {
|
||||
|
||||
job, err = newSessionCleanupJob(hclog.New(nil), func() (*session.Repository, error) { return nil, nil }, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
errors.WithOp(op),
|
||||
errors.WithMsg(fmt.Sprintf("invalid gracePeriod, must be greater than %d", session.DeadWorkerConnCloseMinGrace)),
|
||||
|
||||
@@ -589,7 +589,7 @@ func NewTestController(t *testing.T, opts *TestControllerOpts) *TestController {
|
||||
DisableAuthorizationFailures: opts.DisableAuthorizationFailures,
|
||||
}
|
||||
|
||||
tc.c, err = New(conf)
|
||||
tc.c, err = New(ctx, conf)
|
||||
if err != nil {
|
||||
tc.Shutdown()
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in new issue
Block a user