Skip to content

Commit

Permalink
Share Errors (#69)
Browse files Browse the repository at this point in the history
Ensure consistency across services.
  • Loading branch information
spjmurray authored Jun 5, 2024
1 parent f550abe commit 74e4623
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 609 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/unikorn-cloud/core v0.1.41
github.com/unikorn-cloud/core v0.1.43
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/unikorn-cloud/core v0.1.41 h1:hjiGB8lZkLR3306BlR/jy6Bx2uvecm0W8YFE2GrdVDY=
github.com/unikorn-cloud/core v0.1.41/go.mod h1:cP39UQN7aSmsfjQuSMsworI4oBIwx4oA4u20CbPpfZw=
github.com/unikorn-cloud/core v0.1.43 h1:QszxVqWaZXIzSlf0qkHa5m8cRnjKGvHjM8iUk0Y3U9A=
github.com/unikorn-cloud/core v0.1.43/go.mod h1:cP39UQN7aSmsfjQuSMsworI4oBIwx4oA4u20CbPpfZw=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/groups/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func New(client client.Client, namespace string) *Client {

func convert(in *unikornv1.Group) *openapi.GroupRead {
out := &openapi.GroupRead{
Metadata: conversion.OrganizationScopedResourceReadMetadata(in, coreopenapi.Provisioned),
Metadata: conversion.OrganizationScopedResourceReadMetadata(in, coreopenapi.ResourceProvisioningStatusProvisioned),
Spec: openapi.GroupSpec{
Roles: in.Spec.Roles,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/oauth2providers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func convert(permissions *rbac.Permissions, in *unikornv1.OAuth2Provider) *opena
t := openapi.Oauth2ProviderType(*in.Spec.Type)

out := &openapi.Oauth2ProviderRead{
Metadata: conversion.OrganizationScopedResourceReadMetadata(in, coreopenapi.Provisioned),
Metadata: conversion.OrganizationScopedResourceReadMetadata(in, coreopenapi.ResourceProvisioningStatusProvisioned),
Spec: openapi.Oauth2ProviderSpec{
Type: &t,
ClientID: in.Spec.ClientID,
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/organizations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func convertOrganizationType(in *unikornv1.Organization) openapi.OrganizationTyp
}

func convert(in *unikornv1.Organization) *openapi.OrganizationRead {
provisioningStatus := coreopenapi.Unknown
provisioningStatus := coreopenapi.ResourceProvisioningStatusUnknown

if condition, err := in.StatusConditionRead(unikornv1core.ConditionAvailable); err == nil {
provisioningStatus = conversion.ConvertStatusCondition(condition)
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/projects/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func New(client client.Client, namespace string) *Client {
}

func convert(in *unikornv1.Project) *openapi.ProjectRead {
provisioningStatus := coreopenapi.Unknown
provisioningStatus := coreopenapi.ResourceProvisioningStatusUnknown

if condition, err := in.StatusConditionRead(unikornv1core.ConditionAvailable); err == nil {
provisioningStatus = conversion.ConvertStatusCondition(condition)
Expand Down
3 changes: 2 additions & 1 deletion pkg/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"golang.org/x/oauth2"

"github.com/unikorn-cloud/core/pkg/authorization/userinfo"
coreopenapi "github.com/unikorn-cloud/core/pkg/openapi"
"github.com/unikorn-cloud/core/pkg/server/errors"
unikornv1 "github.com/unikorn-cloud/identity/pkg/apis/unikorn/v1alpha1"
"github.com/unikorn-cloud/identity/pkg/jose"
Expand Down Expand Up @@ -969,7 +970,7 @@ func (a *Authenticator) Token(w http.ResponseWriter, r *http.Request) (*openapi.
if err != nil {
var rerr *oauth2.RetrieveError

if goerrors.As(err, &rerr) && rerr.ErrorCode == string(openapi.InvalidGrant) {
if goerrors.As(err, &rerr) && rerr.ErrorCode == string(coreopenapi.InvalidGrant) {
return nil, errors.OAuth2InvalidGrant("provider refresh token has expired").WithError(err)
}

Expand Down
Loading

0 comments on commit 74e4623

Please sign in to comment.