@@ -80,11 +80,9 @@ const (
8080 ngtsUploadEndpoint = "v1/tlspk/upload/clusterdata/no"
8181
8282 // ngtsAccessTokenEndpoint matches the CM-SaaS token endpoint
83- // TODO: Confirm that this will match in NGTS
8483 ngtsAccessTokenEndpoint = accessTokenEndpoint
8584
8685 // ngtsRequiredGrantType matches the CM-SaaS required grant type for JWTs
87- // TODO: Confirm JWT structure for NGTS
8886 ngtsRequiredGrantType = requiredGrantType
8987)
9088
@@ -166,30 +164,32 @@ func (c *NGTSServiceAccountCredentials) LoadClientIDIfNeeded() error {
166164 return fmt .Errorf ("credentials are nil" )
167165 }
168166
169- // If ClientID is already set, nothing to do
167+ // If ClientID is already set via helm values / CLI args , nothing to do
170168 if c .ClientID != "" {
169+ klog .V (2 ).Info ("Using clientID from config.clientID helm value" )
171170 return nil
172171 }
173172
173+ // We'd preferably have NGTSServiceAccountCredentials.CredentialPath but we didn't want to make another change
174+ // to existing CLI flags; so we depend on PrivateKeyFile and assume clientID is in the same directory.
175+
174176 // If PrivateKeyFile is not set, we can't determine where to look for the clientID file
175177 if c .PrivateKeyFile == "" {
176- return nil // Will be caught by Validate() later
178+ return nil // This is actually a fatal error but will be caught by Validate() later
177179 }
178180
179181 // Try to load ClientID from a file in the same directory as the private key
180182 clientIDPath := path .Dir (c .PrivateKeyFile ) + "/clientID"
181183 clientIDBytes , err := os .ReadFile (clientIDPath )
182184 if err != nil {
183- // If the file doesn't exist, that's okay - the ClientID might be required to be set directly
184- if os .IsNotExist (err ) {
185- return nil
186- }
187- return fmt .Errorf ("failed to read clientID from %s: %w" , clientIDPath , err )
185+ // If the file doesn't exist, that's okay - we'll let Validate() catch the empty ClientID error later
186+ klog .V (2 ).Info ("Could not read clientID from file" , "path" , clientIDPath , "error" , err )
187+ return nil
188188 }
189189
190190 // Trim whitespace from the clientID
191191 c .ClientID = strings .TrimSpace (string (clientIDBytes ))
192- klog .V (2 ).Info ("Loaded clientID from secret file" , "path" , clientIDPath )
192+ klog .V (2 ).Info ("Loaded clientID from file" , "path" , clientIDPath )
193193
194194 return nil
195195}
@@ -205,7 +205,7 @@ func (c *NGTSServiceAccountCredentials) Validate() error {
205205 }
206206
207207 if c .PrivateKeyFile == "" {
208- return fmt .Errorf ("private_key_file cannot be empty" )
208+ return fmt .Errorf ("NGTS private key file location cannot be empty" )
209209 }
210210
211211 return nil
0 commit comments