Skip to content

Commit

Permalink
fix: contain entire auth header in ProviderConfig (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariatsji authored Dec 5, 2024
1 parent 564dd10 commit f8a8b0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions internal/controller/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package group

import (
"context"
"encoding/base64"
"fmt"

"github.com/pkg/errors"
Expand Down Expand Up @@ -52,9 +51,9 @@ const (
type NoOpService struct{}

var (
newCloudianService = func(providerConfig *apisv1alpha1.ProviderConfig, authHeader []byte) (*cloudian.Client, error) {
newCloudianService = func(providerConfig *apisv1alpha1.ProviderConfig, authHeader string) (*cloudian.Client, error) {
// FIXME: Don't require InsecureSkipVerify
return cloudian.NewClient(providerConfig.Spec.Endpoint, true, base64.StdEncoding.EncodeToString(authHeader)), nil
return cloudian.NewClient(providerConfig.Spec.Endpoint, true, authHeader), nil
}
)

Expand Down Expand Up @@ -91,7 +90,7 @@ func Setup(mgr ctrl.Manager, o controller.Options) error {
type connector struct {
kube client.Client
usage resource.Tracker
newServiceFn func(providerConfig *apisv1alpha1.ProviderConfig, authHeader []byte) (*cloudian.Client, error)
newServiceFn func(providerConfig *apisv1alpha1.ProviderConfig, authHeader string) (*cloudian.Client, error)
}

// Connect typically produces an ExternalClient by:
Expand Down Expand Up @@ -120,7 +119,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errGetCreds)
}

svc, err := c.newServiceFn(pc, authHeader)
svc, err := c.newServiceFn(pc, string(authHeader))
if err != nil {
return nil, errors.Wrap(err, errNewClient)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/sdk/cloudian/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Client struct {
baseURL string
httpClient *http.Client
token string
authHeader string
}

type Group struct {
Expand All @@ -41,13 +41,13 @@ type User struct {

var ErrNotFound = errors.New("not found")

func NewClient(baseUrl string, tlsInsecureSkipVerify bool, tokenBase64 string) *Client {
func NewClient(baseUrl string, tlsInsecureSkipVerify bool, authHeader string) *Client {
return &Client{
baseURL: baseUrl,
httpClient: &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: tlsInsecureSkipVerify}, // nolint:gosec
}},
token: tokenBase64,
authHeader: authHeader,
}
}

Expand Down Expand Up @@ -258,7 +258,7 @@ func (client Client) newRequest(ctx context.Context, url string, method string,
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Basic "+client.token)
req.Header.Set("Authorization", client.authHeader)

return req, nil
}

0 comments on commit f8a8b0d

Please sign in to comment.