Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth/oidc): OIDC authentication method support #1197

Merged
merged 17 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ func As[E error](err error) (e E, _ bool) {
return e, errors.As(err, &e)
}

// AsMatch is the same as As but it returns just a boolean to represent
// whether or not the wrapped type matches the type parameter.
func AsMatch[E error](err error) (match bool) {
_, match = As[E](err)
return
}

// New creates a new error with errors.New
func New(s string) error {
return errors.New(s)
}

// NewErrorf is a generic utility for formatting a string into a target error type E.
func NewErrorf[E StringError](format string, args ...any) error {
return E(fmt.Sprintf(format, args...))
}

// ErrNotFound represents a not found error
type ErrNotFound string

// ErrNotFoundf creates an ErrNotFound using a custom format
func ErrNotFoundf(format string, args ...interface{}) error {
return ErrNotFound(fmt.Sprintf(format, args...))
}

func (e ErrNotFound) Error() string {
return fmt.Sprintf("%s not found", string(e))
}

// ErrInvalid represents an invalid error
type ErrInvalid string

// ErrInvalidf creates an ErrInvalid using a custom format
func ErrInvalidf(format string, args ...interface{}) error {
return ErrInvalid(fmt.Sprintf(format, args...))
}

func (e ErrInvalid) Error() string {
return string(e)
}
Expand Down Expand Up @@ -66,3 +68,18 @@ func InvalidFieldError(field, reason string) error {
func EmptyFieldError(field string) error {
return InvalidFieldError(field, "must not be empty")
}

// ErrUnauthenticated is returned when an operation is attempted by an unauthenticated
// client in an authenticated context.
type ErrUnauthenticated string

// Error() returns the underlying string of the error.
func (e ErrUnauthenticated) Error() string {
return string(e)
}

// StringError is any error that also happens to have an underlying type of string.
type StringError interface {
error
~string
}
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Masterminds/squirrel v1.5.3
github.com/XSAM/otelsql v0.17.0
github.com/blang/semver/v4 v4.0.0
github.com/coreos/go-oidc/v3 v3.4.0
github.com/docker/go-connections v0.4.0
github.com/fatih/color v1.13.0
github.com/go-chi/chi/v5 v5.0.8-0.20220103191336-b750c805b4ee
Expand All @@ -21,11 +22,11 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0
github.com/hashicorp/cap v0.2.0
github.com/lib/pq v1.10.7
github.com/mattn/go-sqlite3 v1.14.16
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/phyber/negroni-gzip v1.0.0
github.com/prometheus/client_golang v1.14.0
github.com/santhosh-tekuri/jsonschema/v5 v5.1.1
github.com/spf13/cobra v1.6.1
Expand All @@ -44,6 +45,7 @@ require (
go.opentelemetry.io/otel/trace v1.11.2
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95
golang.org/x/net v0.2.0
golang.org/x/sync v0.1.0
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -77,7 +79,10 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
Expand Down Expand Up @@ -111,7 +116,6 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/urfave/negroni v1.0.1-0.20200608235619-7de0dfc1ff79 // indirect
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand All @@ -120,11 +124,13 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading