Skip to content

Commit 1276e4f

Browse files
authored
Tweak Client (#76)
This works out better with how the servers are initialised for now.
1 parent 929c330 commit 1276e4f

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

charts/identity/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A Helm chart for deploying Unikorn's IdP
44

55
type: application
66

7-
version: v0.2.7
8-
appVersion: v0.2.7
7+
version: v0.2.8
8+
appVersion: v0.2.8
99

1010
icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png

pkg/client/client.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,52 +41,58 @@ var (
4141
ErrFormatError = errors.New("secret incorrectly formatted")
4242
)
4343

44+
type Options struct {
45+
// host is the identity host name.
46+
host string
47+
// caSecretNamespace tells us where to source the CA secret.
48+
caSecretNamespace string
49+
// caSecretName is the root CA secret of the identity endpoint.
50+
caSecretName string
51+
}
52+
53+
// AddFlags adds the options to the CLI flags.
54+
func (o *Options) AddFlags(f *pflag.FlagSet) {
55+
f.StringVar(&o.host, "identity-host", "", "Identity endpoint URL.")
56+
f.StringVar(&o.caSecretNamespace, "identity-ca-secret-namespace", "", "Identity endpoint CA certificate secret namespace.")
57+
f.StringVar(&o.caSecretName, "identity-ca-secret-name", "", "Identity endpoint CA certificate secret.")
58+
}
59+
4460
// Client wraps up the raw OpenAPI client with things to make it useable e.g.
4561
// authorization and TLS.
4662
type Client struct {
4763
// client is a Kubenetes client.
4864
client client.Client
4965
// namespace is the namespace the client is running in.
5066
namespace string
51-
// host is the identity host name.
52-
host string
53-
// caSecretNamespace tells us where to source the CA secret.
54-
caSecretNamespace string
55-
// caSecretName is the root CA secret of the identity endpoint.
56-
caSecretName string
67+
// options allows setting of option from the CLI
68+
options *Options
5769
}
5870

5971
// New creates a new client.
60-
func New(client client.Client, namespace string) *Client {
72+
func New(client client.Client, namespace string, options *Options) *Client {
6173
return &Client{
6274
client: client,
6375
namespace: namespace,
76+
options: options,
6477
}
6578
}
6679

67-
// AddFlags adds the options to the CLI flags.
68-
func (c *Client) AddFlags(f *pflag.FlagSet) {
69-
f.StringVar(&c.host, "identity-host", "", "Identity endpoint URL.")
70-
f.StringVar(&c.caSecretNamespace, "identity-ca-secret-namespace", "", "Identity endpoint CA certificate secret namespace.")
71-
f.StringVar(&c.caSecretName, "identity-ca-secret-name", "", "Identity endpoint CA certificate secret.")
72-
}
73-
7480
// tlsClientConfig abstracts away private TLS CAs or self signed certificates.
7581
func (c *Client) tlsClientConfig(ctx context.Context) (*tls.Config, error) {
76-
if c.caSecretName == "" {
82+
if c.options.caSecretName == "" {
7783
//nolint:nilnil
7884
return nil, nil
7985
}
8086

8187
namespace := c.namespace
8288

83-
if c.caSecretNamespace != "" {
84-
namespace = c.caSecretNamespace
89+
if c.options.caSecretNamespace != "" {
90+
namespace = c.options.caSecretNamespace
8591
}
8692

8793
secret := &corev1.Secret{}
8894

89-
if err := c.client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: c.caSecretName}, secret); err != nil {
95+
if err := c.client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: c.options.caSecretName}, secret); err != nil {
9096
return nil, err
9197
}
9298

@@ -149,7 +155,7 @@ func (c *Client) Client(ctx context.Context) (*openapi.ClientWithResponses, erro
149155
return nil, err
150156
}
151157

152-
client, err := openapi.NewClientWithResponses(c.host, openapi.WithHTTPClient(httpClient), openapi.WithRequestEditorFn(accessTokenInjector))
158+
client, err := openapi.NewClientWithResponses(c.options.host, openapi.WithHTTPClient(httpClient), openapi.WithRequestEditorFn(accessTokenInjector))
153159
if err != nil {
154160
return nil, err
155161
}

0 commit comments

Comments
 (0)