refactor: update to the latest version of kubebuilder and add support for hydra v2 (#127)
This commit is contained in:
@ -56,7 +56,6 @@ func New(spec hydrav1alpha1.OAuth2ClientSpec, tlsTrustStore string, insecureSkip
|
||||
}
|
||||
|
||||
func (c *InternalClient) GetOAuth2Client(id string) (*OAuth2ClientJSON, bool, error) {
|
||||
|
||||
var jsonClient *OAuth2ClientJSON
|
||||
|
||||
req, err := c.newRequest(http.MethodGet, id, nil)
|
||||
@ -80,7 +79,6 @@ func (c *InternalClient) GetOAuth2Client(id string) (*OAuth2ClientJSON, bool, er
|
||||
}
|
||||
|
||||
func (c *InternalClient) ListOAuth2Client() ([]*OAuth2ClientJSON, error) {
|
||||
|
||||
var jsonClientList []*OAuth2ClientJSON
|
||||
|
||||
req, err := c.newRequest(http.MethodGet, "", nil)
|
||||
@ -102,7 +100,6 @@ func (c *InternalClient) ListOAuth2Client() ([]*OAuth2ClientJSON, error) {
|
||||
}
|
||||
|
||||
func (c *InternalClient) PostOAuth2Client(o *OAuth2ClientJSON) (*OAuth2ClientJSON, error) {
|
||||
|
||||
var jsonClient *OAuth2ClientJSON
|
||||
|
||||
req, err := c.newRequest(http.MethodPost, "", o)
|
||||
@ -126,7 +123,6 @@ func (c *InternalClient) PostOAuth2Client(o *OAuth2ClientJSON) (*OAuth2ClientJSO
|
||||
}
|
||||
|
||||
func (c *InternalClient) PutOAuth2Client(o *OAuth2ClientJSON) (*OAuth2ClientJSON, error) {
|
||||
|
||||
var jsonClient *OAuth2ClientJSON
|
||||
|
||||
req, err := c.newRequest(http.MethodPut, *o.ClientID, o)
|
||||
@ -147,7 +143,6 @@ func (c *InternalClient) PutOAuth2Client(o *OAuth2ClientJSON) (*OAuth2ClientJSON
|
||||
}
|
||||
|
||||
func (c *InternalClient) DeleteOAuth2Client(id string) error {
|
||||
|
||||
req, err := c.newRequest(http.MethodDelete, id, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -170,7 +165,6 @@ func (c *InternalClient) DeleteOAuth2Client(id string) error {
|
||||
}
|
||||
|
||||
func (c *InternalClient) newRequest(method, relativePath string, body interface{}) (*http.Request, error) {
|
||||
|
||||
var buf io.ReadWriter
|
||||
if body != nil {
|
||||
buf = new(bytes.Buffer)
|
||||
|
@ -13,10 +13,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/ory/hydra-maester/hydra"
|
||||
)
|
||||
@ -53,7 +52,7 @@ var testOAuthJSONPost = &hydra.OAuth2ClientJSON{
|
||||
}
|
||||
|
||||
var testOAuthJSONPut = &hydra.OAuth2ClientJSON{
|
||||
ClientID: pointer.StringPtr("test-id-3"),
|
||||
ClientID: ptr.To("test-id-3"),
|
||||
Scope: "yet,another,scope",
|
||||
GrantTypes: []string{"type3"},
|
||||
Owner: "test-name-3",
|
||||
@ -218,7 +217,7 @@ func TestCRUD(t *testing.T) {
|
||||
if newWithMetadata {
|
||||
assert.NotNil(o.Metadata)
|
||||
assert.True(len(o.Metadata) > 0)
|
||||
for key, _ := range o.Metadata {
|
||||
for key := range o.Metadata {
|
||||
assert.Equal(o.Metadata[key], expected.Metadata[key])
|
||||
}
|
||||
} else {
|
||||
|
@ -7,8 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/utils/pointer"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
hydrav1alpha1 "github.com/ory/hydra-maester/api/v1alpha1"
|
||||
)
|
||||
@ -39,9 +38,9 @@ type Oauth2ClientCredentials struct {
|
||||
}
|
||||
|
||||
func (oj *OAuth2ClientJSON) WithCredentials(credentials *Oauth2ClientCredentials) *OAuth2ClientJSON {
|
||||
oj.ClientID = pointer.StringPtr(string(credentials.ID))
|
||||
oj.ClientID = ptr.To(string(credentials.ID))
|
||||
if credentials.Password != nil {
|
||||
oj.Secret = pointer.StringPtr(string(credentials.Password))
|
||||
oj.Secret = ptr.To(string(credentials.Password))
|
||||
}
|
||||
return oj
|
||||
}
|
||||
@ -50,7 +49,7 @@ func (oj *OAuth2ClientJSON) WithCredentials(credentials *Oauth2ClientCredentials
|
||||
func FromOAuth2Client(c *hydrav1alpha1.OAuth2Client) (*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 nil, fmt.Errorf("unable to encode `metadata` property value to json: %w", err)
|
||||
}
|
||||
|
||||
return &OAuth2ClientJSON{
|
||||
|
Reference in New Issue
Block a user