Skip to content
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

OnCommand is ignored for when AcceptsCommands not set #189

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions client/internal/receivedprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ func newReceivedProcessor(
func (r *receivedProcessor) ProcessReceivedMessage(ctx context.Context, msg *protobufs.ServerToAgent) {
if r.callbacks != nil {
if msg.Command != nil {
r.rcvCommand(msg.Command)
// If a command message exists, other messages will be ignored
return
if r.hasCapability(protobufs.AgentCapabilities_AgentCapabilities_AcceptsRestartCommand) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be useful to add a comment that says when any new command capabilities are added they need to be checked here. I am not sure what's the best way to ensure we don't forget to do it, but a comment may help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added note

r.rcvCommand(msg.Command)
// If a command message exists, other messages will be ignored
return
} else {
r.logger.Debugf("Ignoring Command, agent does not have AcceptsCommands capability")
}
}

scheduled, err := r.rcvFlags(ctx, protobufs.ServerToAgentFlags(msg.Flags))
Expand Down
6 changes: 4 additions & 2 deletions client/internal/wsreceiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func TestServerToAgentCommand(t *testing.T) {
remoteConfigStatus: &protobufs.RemoteConfigStatus{},
}
sender := WSSender{}
receiver := NewWSReceiver(TestLogger{t}, callbacks, nil, &sender, &clientSyncedState, nil, 0)
capabilities := protobufs.AgentCapabilities_AgentCapabilities_AcceptsRestartCommand
receiver := NewWSReceiver(TestLogger{t}, callbacks, nil, &sender, &clientSyncedState, nil, capabilities)
receiver.processor.ProcessReceivedMessage(context.Background(), &protobufs.ServerToAgent{
Command: test.command,
})
Expand All @@ -100,7 +101,8 @@ func TestServerToAgentCommandExclusive(t *testing.T) {
},
}
clientSyncedState := ClientSyncedState{}
receiver := NewWSReceiver(TestLogger{t}, callbacks, nil, nil, &clientSyncedState, nil, 0)
capabilities := protobufs.AgentCapabilities_AgentCapabilities_AcceptsRestartCommand
receiver := NewWSReceiver(TestLogger{t}, callbacks, nil, nil, &clientSyncedState, nil, capabilities)
receiver.processor.ProcessReceivedMessage(context.Background(), &protobufs.ServerToAgent{
Command: &protobufs.ServerToAgentCommand{
Type: protobufs.CommandType_CommandType_Restart,
Expand Down