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
@@ -348,12 +348,13 @@ func (b *Server) createInitialOidcAuthMethod(ctx context.Context) (*oidc.AuthMet
|
||||
}
|
||||
|
||||
// Create the auth method
|
||||
oidcRepo, err := oidc.NewRepository(rw, rw, kmsCache)
|
||||
oidcRepo, err := oidc.NewRepository(ctx, rw, rw, kmsCache)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating oidc repo: %w", err)
|
||||
}
|
||||
|
||||
authMethod, err := oidc.NewAuthMethod(
|
||||
ctx,
|
||||
scope.Global.String(),
|
||||
b.DevOidcSetup.clientId,
|
||||
b.DevOidcSetup.clientSecret,
|
||||
@@ -395,6 +396,7 @@ func (b *Server) createInitialOidcAuthMethod(ctx context.Context) (*oidc.AuthMet
|
||||
{
|
||||
createAndLinkAccount := func(loginName, userId, accountId, typ string) error {
|
||||
acct, err := oidc.NewAccount(
|
||||
ctx,
|
||||
b.DevOidcSetup.authMethod.GetPublicId(),
|
||||
loginName,
|
||||
oidc.WithDescription(fmt.Sprintf("Initial %s OIDC account", typ)),
|
||||
|
||||
@@ -145,18 +145,18 @@ func (b *Server) SetupEventing(logger hclog.Logger, serializationLock *sync.Mute
|
||||
const op = "base.(Server).SetupEventing"
|
||||
|
||||
if logger == nil {
|
||||
return berrors.New(berrors.InvalidParameter, op, "missing logger")
|
||||
return berrors.NewDeprecated(berrors.InvalidParameter, op, "missing logger")
|
||||
}
|
||||
if serializationLock == nil {
|
||||
return berrors.New(berrors.InvalidParameter, op, "missing serialization lock")
|
||||
return berrors.NewDeprecated(berrors.InvalidParameter, op, "missing serialization lock")
|
||||
}
|
||||
if serverName == "" {
|
||||
return berrors.New(berrors.InvalidParameter, op, "missing server name")
|
||||
return berrors.NewDeprecated(berrors.InvalidParameter, op, "missing server name")
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
if opts.withEventerConfig != nil {
|
||||
if err := opts.withEventerConfig.Validate(); err != nil {
|
||||
return berrors.Wrap(err, op, berrors.WithMsg("invalid eventer config"))
|
||||
return berrors.WrapDeprecated(err, op, berrors.WithMsg("invalid eventer config"))
|
||||
}
|
||||
}
|
||||
if opts.withEventerConfig == nil {
|
||||
@@ -165,7 +165,7 @@ func (b *Server) SetupEventing(logger hclog.Logger, serializationLock *sync.Mute
|
||||
|
||||
if opts.withEventFlags != nil {
|
||||
if err := opts.withEventFlags.Validate(); err != nil {
|
||||
return berrors.Wrap(err, op, berrors.WithMsg("invalid event flags"))
|
||||
return berrors.WrapDeprecated(err, op, berrors.WithMsg("invalid event flags"))
|
||||
}
|
||||
if opts.withEventFlags.Format != "" {
|
||||
for i := 0; i < len(opts.withEventerConfig.Sinks); i++ {
|
||||
@@ -195,12 +195,12 @@ func (b *Server) SetupEventing(logger hclog.Logger, serializationLock *sync.Mute
|
||||
|
||||
e, err := event.NewEventer(logger, serializationLock, serverName, *opts.withEventerConfig)
|
||||
if err != nil {
|
||||
return berrors.Wrap(err, op, berrors.WithMsg("unable to create eventer"))
|
||||
return berrors.WrapDeprecated(err, op, berrors.WithMsg("unable to create eventer"))
|
||||
}
|
||||
b.Eventer = e
|
||||
|
||||
if err := event.InitSysEventer(logger, serializationLock, serverName, event.WithEventer(e)); err != nil {
|
||||
return berrors.Wrap(err, op, berrors.WithMsg("unable to initialize system eventer"))
|
||||
return berrors.WrapDeprecated(err, op, berrors.WithMsg("unable to initialize system eventer"))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -210,11 +210,11 @@ func (b *Server) SetupEventing(logger hclog.Logger, serializationLock *sync.Mute
|
||||
func (b *Server) AddEventerToContext(ctx context.Context) (context.Context, error) {
|
||||
const op = "base.(Server).AddEventerToContext"
|
||||
if b.Eventer == nil {
|
||||
return nil, berrors.New(berrors.InvalidParameter, op, "missing server eventer")
|
||||
return nil, berrors.NewDeprecated(berrors.InvalidParameter, op, "missing server eventer")
|
||||
}
|
||||
e, err := event.NewEventerContext(ctx, b.Eventer)
|
||||
if err != nil {
|
||||
return nil, berrors.Wrap(err, op, berrors.WithMsg("unable to add eventer to context"))
|
||||
return nil, berrors.WrapDeprecated(err, op, berrors.WithMsg("unable to add eventer to context"))
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ func (c *InitCommand) verifyOplogIsEmpty() error {
|
||||
var empty bool
|
||||
r.Scan(&empty)
|
||||
if !empty {
|
||||
return errors.New(errors.MigrationIntegrity, op, "oplog_entry is not empty")
|
||||
return errors.NewDeprecated(errors.MigrationIntegrity, op, "oplog_entry is not empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -321,6 +321,7 @@ func (c *Command) AutocompleteFlags() complete.Flags {
|
||||
|
||||
func (c *Command) Run(args []string) int {
|
||||
const op = "dev.(Command).Run"
|
||||
ctx := context.TODO()
|
||||
c.CombineLogs = c.flagCombineLogs
|
||||
|
||||
var err error
|
||||
@@ -579,7 +580,7 @@ func (c *Command) Run(args []string) int {
|
||||
}
|
||||
|
||||
var err error
|
||||
c.controller, err = controller.New(conf)
|
||||
c.controller, err = controller.New(ctx, conf)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error initializing controller: %w", err).Error())
|
||||
return base.CommandCliError
|
||||
|
||||
@@ -133,6 +133,7 @@ func (c *Command) AutocompleteFlags() complete.Flags {
|
||||
}
|
||||
|
||||
func (c *Command) Run(args []string) int {
|
||||
ctx := context.TODO()
|
||||
c.CombineLogs = c.flagCombineLogs
|
||||
|
||||
if result := c.ParseFlagsAndConfig(args); result > 0 {
|
||||
@@ -453,7 +454,7 @@ func (c *Command) Run(args []string) int {
|
||||
c.ReleaseLogGate()
|
||||
|
||||
if c.Config.Controller != nil {
|
||||
if err := c.StartController(); err != nil {
|
||||
if err := c.StartController(ctx); err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
return base.CommandCliError
|
||||
}
|
||||
@@ -536,14 +537,14 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
func (c *Command) StartController() error {
|
||||
func (c *Command) StartController(ctx context.Context) error {
|
||||
conf := &controller.Config{
|
||||
RawConfig: c.Config,
|
||||
Server: c.Server,
|
||||
}
|
||||
|
||||
var err error
|
||||
c.controller, err = controller.New(conf)
|
||||
c.controller, err = controller.New(ctx, conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error initializing controller: %w", err)
|
||||
}
|
||||
@@ -735,5 +736,5 @@ func (c *Command) verifyKmsSetup() error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New(errors.MigrationIntegrity, op, "can't find global scoped root key")
|
||||
return errors.NewDeprecated(errors.MigrationIntegrity, op, "can't find global scoped root key")
|
||||
}
|
||||
Reference in new issue
Block a user