Skip to content

Commit

Permalink
chore: clean up imports and names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidby-influx committed Dec 21, 2023
1 parent 0591cfc commit 1ca654b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
42 changes: 21 additions & 21 deletions authorization/error.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
package authorization

import (
"errors"
errors2 "errors"
"fmt"

errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
)

var (
// ErrInvalidAuthID is used when the Authorization's ID cannot be encoded
ErrInvalidAuthID = &errors2.Error{
Code: errors2.EInvalid,
ErrInvalidAuthID = &errors.Error{
Code: errors.EInvalid,
Msg: "authorization ID is invalid",
}

// ErrAuthNotFound is used when the specified auth cannot be found
ErrAuthNotFound = &errors2.Error{
Code: errors2.ENotFound,
ErrAuthNotFound = &errors.Error{
Code: errors.ENotFound,
Msg: "authorization not found",
}

// NotUniqueIDError occurs when attempting to create an Authorization with an ID that already belongs to another one
NotUniqueIDError = &errors2.Error{
Code: errors2.EConflict,
NotUniqueIDError = &errors.Error{
Code: errors.EConflict,
Msg: "ID already exists",
}

// ErrFailureGeneratingID occurs ony when the random number generator
// cannot generate an ID in MaxIDGenerationN times.
ErrFailureGeneratingID = &errors2.Error{
Code: errors2.EInternal,
ErrFailureGeneratingID = &errors.Error{
Code: errors.EInternal,
Msg: "unable to generate valid id",
}

// ErrTokenAlreadyExistsError is used when attempting to create an authorization
// with a token that already exists
ErrTokenAlreadyExistsError = &errors2.Error{
Code: errors2.EConflict,
ErrTokenAlreadyExistsError = &errors.Error{
Code: errors.EConflict,
Msg: "token already exists",
}
)

// ErrInvalidAuthIDError is used when a service was provided an invalid ID.
func ErrInvalidAuthIDError(err error) *errors2.Error {
return &errors2.Error{
Code: errors2.EInvalid,
func ErrInvalidAuthIDError(err error) *errors.Error {
return &errors.Error{
Code: errors.EInvalid,
Msg: "auth id provided is invalid",
Err: err,
}
}

// UnexpectedAuthIndexError is used when the error comes from an internal system.
func UnexpectedAuthIndexError(err error) *errors2.Error {
var e *errors2.Error
if !errors.As(err, &e) {
e = &errors2.Error{
func UnexpectedAuthIndexError(err error) *errors.Error {
var e *errors.Error
if !errors2.As(err, &e) {
e = &errors.Error{
Msg: fmt.Sprintf("unexpected error retrieving auth index; Err: %v", err),
Code: errors2.EInternal,
Code: errors.EInternal,
Err: err,
}
}
if e.Code == "" {
e.Code = errors2.EInternal
e.Code = errors.EInternal
}
return e
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/apache/arrow/go/v7 v7.0.1
github.com/benbjohnson/clock v0.0.0-20161215174838-7dc76406b6d3
github.com/benbjohnson/tmpl v1.0.0
github.com/boltdb/bolt v1.3.1
github.com/buger/jsonparser v1.1.1
github.com/cespare/xxhash v1.1.0
github.com/davecgh/go-spew v1.1.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bonitoo-io/go-sql-bigquery v0.3.4-1.4.0 h1:MaVh0h9+KaMnJcoDvvIGp+O3fefdWm+8MBUX6ELTJTM=
github.com/bonitoo-io/go-sql-bigquery v0.3.4-1.4.0/go.mod h1:J4Y6YJm0qTWB9aFziB7cPeSyc6dOZFyJdteSeybVpXQ=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
Expand Down
22 changes: 11 additions & 11 deletions query/control/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/influxdata/flux/lang"
"github.com/influxdata/flux/memory"
"github.com/influxdata/flux/runtime"
errors2 "github.com/influxdata/influxdb/v2/kit/errors"
errors3 "github.com/influxdata/influxdb/v2/kit/platform/errors"
errors3 "github.com/influxdata/influxdb/v2/kit/errors"
errors2 "github.com/influxdata/influxdb/v2/kit/platform/errors"
"github.com/influxdata/influxdb/v2/kit/prom"
"github.com/influxdata/influxdb/v2/kit/tracing"
influxlogger "github.com/influxdata/influxdb/v2/logger"
Expand Down Expand Up @@ -184,7 +184,7 @@ type QueryID uint64
func New(config Config, logger *zap.Logger) (*Controller, error) {
c, err := config.complete(logger)
if err != nil {
return nil, errors2.Wrap(err, "invalid controller config")
return nil, errors3.Wrap(err, "invalid controller config")
}
metricLabelKeys := append(c.MetricLabelKeys, orgLabel)
if logger == nil {
Expand Down Expand Up @@ -1113,20 +1113,20 @@ func handleFluxError(err error) error {
}
werr := handleFluxError(ferr.Err)

code := errors3.EInternal
code := errors2.EInternal
switch ferr.Code {
case codes.Inherit:
// If we are inheriting the error code, influxdb doesn't
// have an equivalent of this so we need to retrieve
// the error code from the wrapped error which has already
// been translated to an influxdb error (if possible).
if werr != nil {
code = errors3.ErrorCode(werr)
code = errors2.ErrorCode(werr)
}
case codes.NotFound:
code = errors3.ENotFound
code = errors2.ENotFound
case codes.Invalid:
code = errors3.EInvalid
code = errors2.EInvalid
// These don't really map correctly, but we want
// them to show up as 4XX so until influxdb error
// codes are updated for more types of failures,
Expand All @@ -1137,16 +1137,16 @@ func handleFluxError(err error) error {
codes.Aborted,
codes.OutOfRange,
codes.Unimplemented:
code = errors3.EInvalid
code = errors2.EInvalid
case codes.PermissionDenied:
code = errors3.EForbidden
code = errors2.EForbidden
case codes.Unauthenticated:
code = errors3.EUnauthorized
code = errors2.EUnauthorized
default:
// Everything else is treated as an internal error
// which is set above.
}
return &errors3.Error{
return &errors2.Error{
Code: code,
Msg: ferr.Msg,
Err: werr,
Expand Down

0 comments on commit 1ca654b

Please sign in to comment.