add: metadata encoding error propagation
This commit is contained in:
parent
1bd0d394b0
commit
8029224178
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ory/hydra-maester/hydra"
|
||||
"github.com/pkg/errors"
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
@ -186,8 +187,11 @@ func init() {
|
||||
}
|
||||
|
||||
// ToOAuth2ClientJSON converts an OAuth2Client into a OAuth2ClientJSON object that represents an OAuth2 client digestible by ORY Hydra
|
||||
func (c *OAuth2Client) ToOAuth2ClientJSON() *hydra.OAuth2ClientJSON {
|
||||
meta, _ := json.Marshal(c.Spec.Metadata)
|
||||
func (c *OAuth2Client) ToOAuth2ClientJSON() (*hydra.OAuth2ClientJSON, error) {
|
||||
meta, err := json.Marshal(c.Spec.Metadata)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "unable to encode `metadata` property value to json")
|
||||
}
|
||||
|
||||
return &hydra.OAuth2ClientJSON{
|
||||
ClientName: c.Spec.ClientName,
|
||||
@ -201,7 +205,7 @@ func (c *OAuth2Client) ToOAuth2ClientJSON() *hydra.OAuth2ClientJSON {
|
||||
Owner: fmt.Sprintf("%s/%s", c.Name, c.Namespace),
|
||||
TokenEndpointAuthMethod: string(c.Spec.TokenEndpointAuthMethod),
|
||||
Metadata: meta,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func responseToStringSlice(rt []ResponseType) []string {
|
||||
|
@ -205,8 +205,13 @@ func (r *OAuth2ClientReconciler) registerOAuth2Client(ctx context.Context, c *hy
|
||||
return err
|
||||
}
|
||||
|
||||
oauth2client, err := c.ToOAuth2ClientJSON()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if credentials != nil {
|
||||
if _, err := hydra.PostOAuth2Client(c.ToOAuth2ClientJSON().WithCredentials(credentials)); err != nil {
|
||||
if _, err := hydra.PostOAuth2Client(oauth2client.WithCredentials(credentials)); err != nil {
|
||||
if updateErr := r.updateReconciliationStatusError(ctx, c, hydrav1alpha1.StatusRegistrationFailed, err); updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
@ -214,7 +219,7 @@ func (r *OAuth2ClientReconciler) registerOAuth2Client(ctx context.Context, c *hy
|
||||
return r.ensureEmptyStatusError(ctx, c)
|
||||
}
|
||||
|
||||
created, err := hydra.PostOAuth2Client(c.ToOAuth2ClientJSON())
|
||||
created, err := hydra.PostOAuth2Client(oauth2client)
|
||||
if err != nil {
|
||||
if updateErr := r.updateReconciliationStatusError(ctx, c, hydrav1alpha1.StatusRegistrationFailed, err); updateErr != nil {
|
||||
return updateErr
|
||||
@ -257,7 +262,12 @@ func (r *OAuth2ClientReconciler) updateRegisteredOAuth2Client(ctx context.Contex
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := hydra.PutOAuth2Client(c.ToOAuth2ClientJSON().WithCredentials(credentials)); err != nil {
|
||||
oauth2client, err := c.ToOAuth2ClientJSON()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := hydra.PutOAuth2Client(oauth2client.WithCredentials(credentials)); err != nil {
|
||||
if updateErr := r.updateReconciliationStatusError(ctx, c, hydrav1alpha1.StatusUpdateFailed, err); updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user