E5FF Add read only file plugin by aphralG · Pull Request #1128 · nginx/agent · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5b31494
add auxiliary command server proto
aphralG Jun 11, 2025
c42a042
Merge branch 'main' into add-auxiliary-command-server-proto
aphralG Jun 12, 2025
e07bf64
allow multiple management planes
aphralG Jun 12, 2025
a6b6e52
start of file plugins
aphralG Jun 16, 2025
650a0d9
PR feedback
aphralG Jun 16, 2025
8c422cc
Merge branch 'add-auxiliary-command-server-to-agent-config' into add-…
aphralG Jun 16, 2025
8ef9c26
file plugin
aphralG Jun 16, 2025
a8817ab
file plugin
aphralG Jun 16, 2025
f958507
Merge branch 'main' into add-auxiliary-command-server-proto
aphralG Jun 23, 2025
2487a4d
Merge branch 'add-auxiliary-command-server-proto' into add-auxiliary-…
aphralG Jun 23, 2025
b710855
PR feedback
aphralG Jun 23, 2025
90cd7f9
merge main
aphralG Jun 23, 2025
8ef3c45
refactor file plugin to have read only mode
aphralG Jun 23, 2025
5773b42
clean up
aphralG Jun 23, 2025
fbbe418
merge main
aphralG Jun 27, 2025
1fa09b9
Merge branch 'add-auxiliary-command-server-proto' into add-auxiliary-…
aphralG Jun 27, 2025
8e26d81
PR feedback
aphralG Jun 27, 2025
4091223
Merge branch 'add-auxiliary-command-server-to-agent-config' into add-…
aphralG Jun 27, 2025
f2d1fb2
PR feedback
aphralG Jun 27, 2025
e4423de
Merge branch 'add-auxiliary-command-server-to-agent-config' into add-…
aphralG Jun 27, 2025
6d39669
PR feedback
aphralG Jun 27, 2025
0d86529
PR feedback
aphralG Jun 27, 2025
0a95a38
PR feedback
aphralG Jun 27, 2025
3f39fbf
fix message response
aphralG Jun 27, 2025
08fa4db
Merge branch 'main' into add-auxiliary-command-server-proto
aphralG Jul 1, 2025
44f1e1e
merge main
aphralG Jul 1, 2025
16b08c0
Merge branch 'add-auxiliary-command-server-proto' into add-auxiliary-…
aphralG Jul 1, 2025
845f3dd
fix instance ID
aphralG Jul 1, 2025
bf98852
Merge branch 'add-auxiliary-command-server-to-agent-config' into add-…
aphralG Jul 1, 2025
b728b91
merge main
aphralG Jul 7, 2025
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
25 changes: 6 additions & 19 deletions internal/command/command_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"log/slog"
"sync"

"github.com/nginx/agent/v3/internal/model"

"google.golang.org/protobuf/types/known/timestamppb"

mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
Expand All @@ -25,17 +27,6 @@ var _ bus.Plugin = (*CommandPlugin)(nil)

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6@v6.8.1 -generate
//counterfeiter:generate . commandService
type ServerType int

const (
Command ServerType = iota
Auxiliary
)

var serverType = map[ServerType]string{
Command: "command",
Auxiliary: "auxiliary",
}

type (
commandService interface {
Expand All @@ -55,13 +46,13 @@ type (
conn grpc.GrpcConnectionInterface
commandService commandService
subscribeChannel chan *mpi.ManagementPlaneRequest
commandServerType ServerType
commandServerType model.ServerType
subscribeMutex sync.Mutex
}
)

func NewCommandPlugin(agentConfig *config.Config, grpcConnection grpc.GrpcConnectionInterface,
commandServerType ServerType,
commandServerType model.ServerType,
) *CommandPlugin {
return &CommandPlugin{
config: agentConfig,
Expand Down Expand Up @@ -256,7 +247,7 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
slog.InfoContext(ctx, "Received management plane config upload request")
cp.handleConfigUploadRequest(newCtx, message)
case *mpi.ManagementPlaneRequest_ConfigApplyRequest:
if cp.commandServerType != Command {
if cp.commandServerType != model.Command {
slog.WarnContext(newCtx, "Auxiliary command server can not perform config apply",
"command_server_type", cp.commandServerType.String())
cp.handleInvalidRequest(newCtx, message)
Expand All @@ -269,7 +260,7 @@ func (cp *CommandPlugin) monitorSubscribeChannel(ctx context.Context) {
slog.InfoContext(ctx, "Received management plane health request")
cp.handleHealthRequest(newCtx)
case *mpi.ManagementPlaneRequest_ActionRequest:
if cp.commandServerType != Command {
if cp.commandServerType != model.Command {
slog.WarnContext(newCtx, "Auxiliary command server can not perform api action",
"command_server_type", cp.commandServerType.String())
cp.handleInvalidRequest(newCtx, message)
Expand Down Expand Up @@ -395,7 +386,3 @@ func (cp *CommandPlugin) createDataPlaneResponse(correlationID string, status mp
},
}
}

func (s ServerType) String() string {
return serverType[s]
}
20 changes: 11 additions & 9 deletions internal/command/command_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"testing"
"time"

"github.com/nginx/agent/v3/internal/model"

pkg "github.com/nginx/agent/v3/pkg/config"
"github.com/nginx/agent/v3/pkg/id"

Expand All @@ -32,14 +34,14 @@ import (
)

func TestCommandPlugin_Info(t *testing.T) {
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
info := commandPlugin.Info()

assert.Equal(t, "command", info.Name)
}

func TestCommandPlugin_Subscriptions(t *testing.T) {
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
subscriptions := commandPlugin.Subscriptions()

assert.Equal(
Expand All @@ -60,7 +62,7 @@ func TestCommandPlugin_Init(t *testing.T) {
messagePipe := busfakes.NewFakeMessagePipe()
fakeCommandService := &commandfakes.FakeCommandService{}

commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
err := commandPlugin.Init(ctx, messagePipe)
require.NoError(t, err)

Expand All @@ -79,7 +81,7 @@ func TestCommandPlugin_createConnection(t *testing.T) {
commandService.CreateConnectionReturns(&mpi.CreateConnectionResponse{}, nil)
messagePipe := busfakes.NewFakeMessagePipe()

commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
err := commandPlugin.Init(ctx, messagePipe)
commandPlugin.commandService = commandService
require.NoError(t, err)
Expand Down Expand Up @@ -111,7 +113,7 @@ func TestCommandPlugin_Process(t *testing.T) {
messagePipe := busfakes.NewFakeMessagePipe()
fakeCommandService := &commandfakes.FakeCommandService{}

commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
err := commandPlugin.Init(ctx, messagePipe)
require.NoError(t, err)
defer commandPlugin.Close(ctx)
Expand Down Expand Up @@ -219,7 +221,7 @@ func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {

agentConfig := types.AgentConfig()
agentConfig.Features = test.configFeatures
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
err := commandPlugin.Init(ctx, messagePipe)
require.NoError(tt, err)
defer commandPlugin.Close(ctx)
Expand Down Expand Up @@ -319,7 +321,7 @@ func TestCommandPlugin_FeatureDisabled(t *testing.T) {

agentConfig.Features = test.configFeatures

commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(agentConfig, &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
err := commandPlugin.Init(ctx, messagePipe)
commandPlugin.commandService = fakeCommandService
require.NoError(tt, err)
Expand All @@ -344,7 +346,7 @@ func TestMonitorSubscribeChannel(t *testing.T) {
logBuf := &bytes.Buffer{}
stub.StubLoggerWith(logBuf)

cp := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
cp := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
cp.subscribeCancel = cncl

message := protos.CreateManagementPlaneRequest()
Expand Down Expand Up @@ -383,7 +385,7 @@ func Test_createDataPlaneResponse(t *testing.T) {
Error: "",
},
}
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, Command)
commandPlugin := NewCommandPlugin(types.AgentConfig(), &grpcfakes.FakeGrpcConnectionInterface{}, model.Command)
result := commandPlugin.createDataPlaneResponse(expected.GetMessageMeta().GetCorrelationId(),
expected.GetCommandResponse().GetStatus(),
expected.GetCommandResponse().GetMessage(), expected.GetCommandResponse().GetError())
Expand Down
4 changes: 1 addition & 3 deletions internal/file/file_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"context"
"log/slog"

"github.com/nginx/agent/v3/internal/command"

"github.com/nginx/agent/v3/pkg/files"
"github.com/nginx/agent/v3/pkg/id"

Expand Down Expand Up @@ -64,7 +62,7 @@ func (fp *FilePlugin) Info() *bus.Info {

// nolint: cyclop, revive
func (fp *FilePlugin) Process(ctx context.Context, msg *bus.Message) {
if logger.ServerType(ctx) == command.Command.String() || logger.ServerType(ctx) == "" {
if logger.ServerType(ctx) == model.Command.String() || logger.ServerType(ctx) == "" {
switch msg.Topic {
case bus.ConnectionResetTopic:
fp.handleConnectionReset(ctx, msg)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions internal/file/read_only_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"context"
"log/slog"

"github.com/nginx/agent/v3/internal/command"

"github.com/nginx/agent/v3/pkg/id"

mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
Expand Down Expand Up @@ -62,7 +60,7 @@ func (rp *ReadFilePlugin) Info() *bus.Info {
}

func (rp *ReadFilePlugin) Process(ctx context.Context, msg *bus.Message) {
if logger.ServerType(ctx) == command.Auxiliary.String() || logger.ServerType(ctx) == "" {
if logger.ServerType(ctx) == model.Auxiliary.String() || logger.ServerType(ctx) == "" {
switch msg.Topic {
case bus.ConnectionResetTopic:
rp.handleConnectionReset(ctx, msg)
Expand Down
22 changes: 22 additions & 0 deletions internal/model/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) F5, Inc. 9E79
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.

package model

type ServerType int

const (
Command ServerType = iota
Auxiliary
)

var serverType = map[ServerType]string{
Command: "command",
Auxiliary: "auxiliary",
}

func (s ServerType) String() string {
return serverType[s]
}
6 changes: 4 additions & 2 deletions internal/plugin/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"context"
"log/slog"

"github.com/nginx/agent/v3/internal/model"

pkg "github.com/nginx/agent/v3/pkg/config"

"github.com/nginx/agent/v3/internal/collector"
Expand Down Expand Up @@ -47,7 +49,7 @@ func addCommandAndFilePlugins(ctx context.Context, plugins []bus.Plugin, agentCo
if err != nil {
slog.WarnContext(ctx, "Failed to create gRPC connection for command server", "error", err)
} else {
commandPlugin := command.NewCommandPlugin(agentConfig, grpcConnection, command.Command)
commandPlugin := command.NewCommandPlugin(agentConfig, grpcConnection, model.Command)
plugins = append(plugins, commandPlugin)
filePlugin := file.NewFilePlugin(agentConfig, grpcConnection)
plugins = append(plugins, filePlugin)
Expand All @@ -68,7 +70,7 @@ func addAuxiliaryCommandAndFilePlugins(ctx context.Context, plugins []bus.Plugin
if err != nil {
slog.WarnContext(ctx, "Failed to create gRPC connection for auxiliary command server", "error", err)
} else {
auxCommandPlugin := command.NewCommandPlugin(agentConfig, auxGRPCConnection, command.Auxiliary)
auxCommandPlugin := command.NewCommandPlugin(agentConfig, auxGRPCConnection, model.Auxiliary)
plugins = append(plugins, auxCommandPlugin)
readFilePlugin := file.NewReadFilePlugin(agentConfig, auxGRPCConnection)
plugins = append(plugins, readFilePlugin)
Expand Down
0