Skip to content

Commit

Permalink
fix: fix public types that have multiple ref names
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Oct 16, 2024
1 parent 9ced758 commit c5294da
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apiclient/types/oauthapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OAuthAppType string

type OAuthApp struct {
OAuthAppManifest
OAuthAppExternalStatus
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
}

type OAuthAppManifest struct {
Expand Down
2 changes: 1 addition & 1 deletion apiclient/types/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
type Webhook struct {
Metadata
WebhookManifest
WebhookExternalStatus
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
LastSuccessfulRunCompleted *Time `json:"lastSuccessfulRunCompleted,omitempty"`
}

Expand Down
2 changes: 0 additions & 2 deletions apiclient/types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func convertWebhook(webhook v1.Webhook, urlPrefix string) *types.Webhook {
links = []string{"invoke", fmt.Sprintf("%s/webhooks/%s", urlPrefix, webhook.Status.External.RefName)}
}

manifest := webhook.Spec.WebhookManifest
manifest.RefName = webhook.Status.External.RefName
wh := &types.Webhook{
Metadata: MetadataFrom(&webhook, links...),
WebhookManifest: webhook.Spec.WebhookManifest,
WebhookExternalStatus: webhook.Status.External,
WebhookManifest: manifest,
RefNameAssigned: webhook.Status.External.RefNameAssigned,
LastSuccessfulRunCompleted: v1.NewTime(webhook.Status.LastSuccessfulRunCompleted),
}

Expand Down
15 changes: 8 additions & 7 deletions pkg/gateway/server/oauth_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (s *Server) createOAuthApp(apiContext api.Context) error {

// updateOAuthApp updates an existing OAuth app registration in the database (admin only).
func (s *Server) updateOAuthApp(apiContext api.Context) error {
appManifest := new(types2.OAuthAppManifest)
if err := apiContext.Read(appManifest); err != nil {
var appManifest types2.OAuthAppManifest
if err := apiContext.Read(&appManifest); err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("invalid OAuth app: %s", err))
}

Expand All @@ -135,13 +135,13 @@ func (s *Server) updateOAuthApp(apiContext api.Context) error {
return err
}

merged := types.MergeOAuthAppManifests(&originalApp.Spec.Manifest, appManifest)
if err := types.ValidateAndSetDefaultsOAuthAppManifest(merged); err != nil {
merged := types.MergeOAuthAppManifests(originalApp.Spec.Manifest, appManifest)
if err := types.ValidateAndSetDefaultsOAuthAppManifest(&merged); err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("invalid OAuth app: %s", err))
}

// Update the app.
originalApp.Spec.Manifest = *merged
originalApp.Spec.Manifest = merged
if err := apiContext.Update(&originalApp); err != nil {
return err
}
Expand Down Expand Up @@ -512,9 +512,10 @@ func convertOAuthAppRegistrationToOAuthApp(app v1.OAuthApp, baseURL string) type
links = append(links, "refreshURL", refreshURL)
}
appManifest.Metadata = handlers.MetadataFrom(&app, links...)
appManifest.RefName = app.Status.External.RefName
return types2.OAuthApp{
OAuthAppManifest: appManifest,
OAuthAppExternalStatus: app.Status.External,
OAuthAppManifest: appManifest,
RefNameAssigned: app.Status.External.RefNameAssigned,
}
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/gateway/types/oauth_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func ValidateAndSetDefaultsOAuthAppManifest(r *types.OAuthAppManifest) error {
return errors.Join(errs...)
}

func MergeOAuthAppManifests(r, other *types.OAuthAppManifest) *types.OAuthAppManifest {
retVal := *r
func MergeOAuthAppManifests(r, other types.OAuthAppManifest) types.OAuthAppManifest {
retVal := r

if other.RefName != "" {
retVal.RefName = other.RefName
Expand All @@ -167,8 +167,11 @@ func MergeOAuthAppManifests(r, other *types.OAuthAppManifest) *types.OAuthAppMan
if other.TenantID != "" {
retVal.TenantID = other.TenantID
}
if other.Name != "" {
retVal.Name = other.Name
}

return &retVal
return retVal
}

// OAuthTokenResponse represents a response from the /token endpoint on an OAuth server.
Expand Down
20 changes: 10 additions & 10 deletions pkg/storage/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5294da

Please sign in to comment.