Skip to content

Commit bf26088

Browse files
authored
Merge pull request #128 from deinstapel/fix/consumer_account
Implement linked account userCredentials for consumer management
2 parents be342e4 + 7676aae commit bf26088

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

controllers/jetstream/consumer.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
5656
remoteClientKey string
5757
remoteRootCA string
5858
accServers []string
59+
accUserCreds string
5960
)
6061
if spec.Account != "" && c.opts.CRDConnect {
6162
// Lookup the account using the REST client.
@@ -92,7 +93,28 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
9293
}
9394
}
9495
}
95-
// FIXME: Add support for UserCredentials for consumer.
96+
// Lookup the UserCredentials.
97+
if acc.Spec.Creds != nil {
98+
secretName := acc.Spec.Creds.Secret.Name
99+
secret, err := c.ki.Secrets(ns).Get(c.ctx, secretName, k8smeta.GetOptions{})
100+
if err != nil {
101+
return err
102+
}
103+
104+
// Write the user credentials to the cache dir.
105+
accDir := filepath.Join(c.cacheDir, ns, spec.Account)
106+
if err := os.MkdirAll(accDir, 0755); err != nil {
107+
return err
108+
}
109+
for k, v := range secret.Data {
110+
if k == acc.Spec.Creds.File {
111+
accUserCreds = filepath.Join(c.cacheDir, ns, spec.Account, k)
112+
if err := os.WriteFile(filepath.Join(accDir, k), v, 0644); err != nil {
113+
return err
114+
}
115+
}
116+
}
117+
}
96118
}
97119

98120
defer func() {
@@ -134,7 +156,9 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
134156
if remoteRootCA != "" {
135157
opts = append(opts, nats.RootCAs(remoteRootCA))
136158
}
137-
159+
if accUserCreds != "" {
160+
opts = append(opts, nats.UserCredentials(accUserCreds))
161+
}
138162
if len(spec.TLS.RootCAs) > 0 {
139163
opts = append(opts, nats.RootCAs(spec.TLS.RootCAs...))
140164
}

0 commit comments

Comments
 (0)