-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add token path to Agent config Command block #958
base: v3
Are you sure you want to change the base?
Conversation
internal/grpc/grpc.go
Outdated
) | ||
} else { | ||
if err != nil { | ||
slog.Error("Unable to add transport credentials to gRPC dial options", "error", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error log is misleading since we are adding the default transport credentials. Maybe it should be Unable to get transport credentials from agent configuration, adding default transport credentials to gRPC dial options
internal/grpc/grpc.go
Outdated
) | ||
} else { | ||
if err != nil { | ||
slog.Error("Unable to add transport credentials to gRPC dial options", "error", err) | ||
slog.Debug("Adding default transport credentials to gRPC dial options") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove the debug log
internal/grpc/grpc.go
Outdated
return opts | ||
} | ||
|
||
func validateTokenFile(path string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func validateTokenFile(path string) (string, error) { | |
func retrieveTokenFromFile(path string) (string, error) { |
might be a better description for what the function is doing
internal/grpc/grpc.go
Outdated
} | ||
|
||
func addPerRPCCredentials(agentConfig *config.Config, resourceID string, opts []grpc.DialOption) []grpc.DialOption { | ||
key := agentConfig.Command.Auth.Token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key := agentConfig.Command.Auth.Token | |
token := agentConfig.Command.Auth.Token |
would token
be a better name for this variable?
internal/grpc/grpc.go
Outdated
return "", errors.New("token file path is empty") | ||
} | ||
|
||
slog.Debug("Reading dataplane key from file", "path", path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Debug("Reading dataplane key from file", "path", path) | |
slog.Debug("Reading token from file", "path", path) |
Should be consistent is our naming. I think referring to it as token is better than dataplane key
internal/grpc/grpc.go
Outdated
return opts | ||
} | ||
|
||
func validateTokenFile(path string) (string, error) { | ||
if path == "" { | ||
slog.Error("Token file path is empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are return the error then there is no need to also log it here since it will be logged by the function calling it
internal/grpc/grpc.go
Outdated
|
||
if keyVal == "" { | ||
slog.Error("failed to load token, please check agent configuration") | ||
return "", errors.New("failed to load token, please check agent configuration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", errors.New("failed to load token, please check agent configuration") | |
return "", errors.New("failed to retrieve token, token file is empty") |
internal/grpc/grpc.go
Outdated
slog.Error("Unable to read token from file", "error", err) | ||
return "", err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Error("Unable to read token from file", "error", err) | |
return "", err | |
return "", fmt.Errorf("unable to read token from file %w", err) |
} | ||
} | ||
|
||
func Test_getTransportCredentials(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if the struct array is needed since there is only one test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really needed, but I was going to leave it there in case of expansion in the future.
* modify alpine package name: nginx-agent-3.0.0_1234 -> nginx-agent-3.0.0.1234 * protoc-gen update
* update config defaults and format
Proposed changes
Allow the data plane key to be loaded from a file by adding a new configuration option
token-path
under the Command section of the agent config file. Also refactored some code to create new functionsaddTransportCredentials
andvalidateTokenFile
which are used when creating the gRPC credentials.token
andtoken-path
are set:token-path
will take prioritytoken
field will be used as a fallback when thetoken-path
file does not exist or is inaccessibleChecklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)