@@ -56,6 +56,7 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
56
56
remoteClientKey string
57
57
remoteRootCA string
58
58
accServers []string
59
+ accUserCreds string
59
60
)
60
61
if spec .Account != "" && c .opts .CRDConnect {
61
62
// Lookup the account using the REST client.
@@ -92,7 +93,28 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
92
93
}
93
94
}
94
95
}
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
+ }
96
118
}
97
119
98
120
defer func () {
@@ -134,7 +156,9 @@ func (c *Controller) processConsumerObject(cns *apis.Consumer, jsmc jsmClient) (
134
156
if remoteRootCA != "" {
135
157
opts = append (opts , nats .RootCAs (remoteRootCA ))
136
158
}
137
-
159
+ if accUserCreds != "" {
160
+ opts = append (opts , nats .UserCredentials (accUserCreds ))
161
+ }
138
162
if len (spec .TLS .RootCAs ) > 0 {
139
163
opts = append (opts , nats .RootCAs (spec .TLS .RootCAs ... ))
140
164
}
0 commit comments