@@ -221,8 +221,7 @@ func GetDialOptions(agentConfig *config.Config, resourceID string) []grpc.DialOp
221221func addTransportCredentials (agentConfig * config.Config , opts []grpc.DialOption ) ([]grpc.DialOption , bool ) {
222222 transportCredentials , err := getTransportCredentials (agentConfig )
223223 if err != nil {
224- slog .Error ("Unable to add transport credentials to gRPC dial options" , "error" , err )
225- slog .Debug ("Adding default transport credentials to gRPC dial options" )
224+ slog .Error ("Unable to get transport credentials from agent configuration, adding default transport credentials to gRPC dial options" , "error" , err )
226225 opts = append (opts ,
227226 grpc .WithTransportCredentials (defaultCredentials ),
228227 )
@@ -238,11 +237,11 @@ func addTransportCredentials(agentConfig *config.Config, opts []grpc.DialOption)
238237}
239238
240239func addPerRPCCredentials (agentConfig * config.Config , resourceID string , opts []grpc.DialOption ) []grpc.DialOption {
241- key := agentConfig .Command .Auth .Token
240+ token := agentConfig .Command .Auth .Token
242241
243242 if agentConfig .Command .Auth .TokenPath != "" {
244243 var err error
245- key , err = validateTokenFile (agentConfig .Command .Auth .TokenPath )
244+ token , err = retrieveTokenFile (agentConfig .Command .Auth .TokenPath )
246245 if err != nil {
247246 slog .Error ("Unable to add token to gRPC dial options, token will be empty" , "error" , err )
248247 }
@@ -252,17 +251,16 @@ func addPerRPCCredentials(agentConfig *config.Config, resourceID string, opts []
252251 opts = append (opts ,
253252 grpc .WithPerRPCCredentials (
254253 & PerRPCCredentials {
255- Token : key ,
254+ Token : token ,
256255 ID : resourceID ,
257256 }),
258257 )
259258
260259 return opts
261260}
262261
263- func validateTokenFile (path string ) (string , error ) {
262+ func retrieveTokenFile (path string ) (string , error ) {
264263 if path == "" {
265- slog .Error ("Token file path is empty" )
266264 return "" , errors .New ("token file path is empty" )
267265 }
268266
@@ -279,8 +277,7 @@ func validateTokenFile(path string) (string, error) {
279277 keyVal = string (keyBytes )
280278
281279 if keyVal == "" {
282- slog .Error ("failed to load token, please check agent configuration" )
283- return "" , errors .New ("failed to load token, please check agent configuration" )
280+ return "" , errors .New ("failed to retrieve token, token file is empty" )
284281 }
285282
286283 return keyVal , nil
0 commit comments