Skip to content

Commit a43cb53

Browse files
committed
address PR feedback
1 parent 1b2b029 commit a43cb53

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

internal/grpc/grpc.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ func GetDialOptions(agentConfig *config.Config, resourceID string) []grpc.DialOp
221221
func 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

240239
func 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

internal/grpc/grpc_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ func Test_validateTokenFile(t *testing.T) {
405405
}
406406
}
407407

408-
got, err := validateTokenFile(tt.path)
408+
got, err := retrieveTokenFile(tt.path)
409409
if err != nil {
410410
if err.Error() != tt.wantErrMsg {
411-
t.Errorf("validateTokenFile() error = %v, wantErr %v", err, tt.wantErrMsg)
411+
t.Errorf("retrieveTokenFile() error = %v, wantErr %v", err, tt.wantErrMsg)
412412
}
413413
}
414-
assert.Equalf(t, tt.want, got, "validateTokenFile(%v)", tt.path)
414+
assert.Equalf(t, tt.want, got, "retrieveTokenFile(%v)", tt.path)
415415
})
416416
}
417417
}

0 commit comments

Comments
 (0)