Skip to content

Commit 753ee94

Browse files
committed
feedback
1 parent d065710 commit 753ee94

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

internal/watcher/credentials/credential_watcher_service.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16-
"github.com/nginx/agent/v3/internal/command"
16+
"github.com/nginx/agent/v3/internal/model"
17+
1718
"github.com/nginx/agent/v3/internal/grpc"
1819

1920
"github.com/fsnotify/fsnotify"
@@ -31,21 +32,21 @@ var emptyEvent = fsnotify.Event{
3132
}
3233

3334
type CredentialUpdateMessage struct {
34-
CorrelationID slog.Attr
35-
Conn *grpc.GrpcConnection
36-
SeverType command.ServerType
35+
CorrelationID slog.Attr
36+
GrpcConnection *grpc.GrpcConnection
37+
ServerType model.ServerType
3738
}
3839

3940
type CredentialWatcherService struct {
4041
agentConfig *config.Config
4142
watcher *fsnotify.Watcher
4243
filesBeingWatched *sync.Map
4344
filesChanged *atomic.Bool
44-
serverType command.ServerType
45+
serverType model.ServerType
4546
watcherMutex sync.Mutex
4647
}
4748

48-
func NewCredentialWatcherService(agentConfig *config.Config, serverType command.ServerType) *CredentialWatcherService {
49+
func NewCredentialWatcherService(agentConfig *config.Config, serverType model.ServerType) *CredentialWatcherService {
4950
filesChanged := &atomic.Bool{}
5051
filesChanged.Store(false)
5152

@@ -78,7 +79,7 @@ func (cws *CredentialWatcherService) Watch(ctx context.Context, ch chan<- Creden
7879
cws.watcherMutex.Lock()
7980
commandSever := cws.agentConfig.Command
8081

81-
if cws.serverType == command.Auxiliary {
82+
if cws.serverType == model.Auxiliary {
8283
commandSever = cws.agentConfig.AuxiliaryCommand
8384
}
8485

@@ -172,7 +173,7 @@ func (cws *CredentialWatcherService) checkForUpdates(ctx context.Context, ch cha
172173
defer cws.watcherMutex.Unlock()
173174

174175
commandSever := cws.agentConfig.Command
175-
if cws.serverType == command.Auxiliary {
176+
if cws.serverType == model.Auxiliary {
176177
commandSever = cws.agentConfig.AuxiliaryCommand
177178
}
178179

@@ -185,8 +186,9 @@ func (cws *CredentialWatcherService) checkForUpdates(ctx context.Context, ch cha
185186
}
186187
slog.DebugContext(ctx, "Credential watcher has detected changes")
187188
ch <- CredentialUpdateMessage{
188-
CorrelationID: logger.CorrelationIDAttr(newCtx),
189-
SeverType: cws.serverType, Conn: conn,
189+
CorrelationID: logger.CorrelationIDAttr(newCtx),
190+
ServerType: cws.serverType,
191+
GrpcConnection: conn,
190192
}
191193
cws.filesChanged.Store(false)
192194
}

internal/watcher/credentials/credential_watcher_service_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"testing"
1414
"time"
1515

16-
"github.com/nginx/agent/v3/internal/command"
16+
"github.com/nginx/agent/v3/internal/model"
1717

1818
"github.com/nginx/agent/v3/internal/config"
1919

@@ -24,15 +24,15 @@ import (
2424
)
2525

2626
func TestCredentialWatcherService_TestNewCredentialWatcherService(t *testing.T) {
27-
credentialWatcherService := NewCredentialWatcherService(types.AgentConfig(), command.Command)
27+
credentialWatcherService := NewCredentialWatcherService(types.AgentConfig(), model.Command)
2828

2929
assert.Empty(t, credentialWatcherService.filesBeingWatched)
3030
assert.False(t, credentialWatcherService.filesChanged.Load())
3131
}
3232

3333
func TestCredentialWatcherService_Watch(t *testing.T) {
3434
ctx := context.Background()
35-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
35+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
3636
watcher, err := fsnotify.NewWatcher()
3737
require.NoError(t, err)
3838
cws.watcher = watcher
@@ -63,7 +63,7 @@ func TestCredentialWatcherService_Watch(t *testing.T) {
6363
}
6464

6565
func TestCredentialWatcherService_isWatching(t *testing.T) {
66-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
66+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
6767
assert.False(t, cws.isWatching("test-file"))
6868
cws.filesBeingWatched.Store("test-file", true)
6969
assert.True(t, cws.isWatching("test-file"))
@@ -82,7 +82,7 @@ func TestCredentialWatcherService_isEventSkippable(t *testing.T) {
8282

8383
func TestCredentialWatcherService_addWatcher(t *testing.T) {
8484
ctx := context.Background()
85-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
85+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
8686
watcher, err := fsnotify.NewWatcher()
8787
require.NoError(t, err)
8888
cws.watcher = watcher
@@ -107,7 +107,7 @@ func TestCredentialWatcherService_watchFiles(t *testing.T) {
107107
var files []string
108108

109109
ctx := context.Background()
110-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
110+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
111111
watcher, err := fsnotify.NewWatcher()
112112
require.NoError(t, err)
113113
cws.watcher = watcher
@@ -139,7 +139,7 @@ func TestCredentialWatcherService_watchFiles(t *testing.T) {
139139

140140
func TestCredentialWatcherService_checkForUpdates(t *testing.T) {
141141
ctx := context.Background()
142-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
142+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
143143
watcher, err := fsnotify.NewWatcher()
144144
require.NoError(t, err)
145145
cws.watcher = watcher
@@ -166,7 +166,7 @@ func TestCredentialWatcherService_checkForUpdates(t *testing.T) {
166166

167167
func TestCredentialWatcherService_handleEvent(t *testing.T) {
168168
ctx := context.Background()
169-
cws := NewCredentialWatcherService(types.AgentConfig(), command.Command)
169+
cws := NewCredentialWatcherService(types.AgentConfig(), model.Command)
170170
watcher, err := fsnotify.NewWatcher()
171171
require.NoError(t, err)
172172
cws.watcher = watcher

internal/watcher/watcher_plugin.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"slices"
1212
"sync"
1313

14-
"github.com/nginx/agent/v3/internal/command"
15-
1614
"github.com/nginx/agent/v3/internal/model"
1715

1816
"github.com/nginx/agent/v3/internal/watcher/credentials"
@@ -80,8 +78,8 @@ func NewWatcher(agentConfig *config.Config) *Watcher {
8078
instanceWatcherService: instance.NewInstanceWatcherService(agentConfig),
8179
healthWatcherService: health.NewHealthWatcherService(agentConfig),
8280
fileWatcherService: file.NewFileWatcherService(agentConfig),
83-
commandCredentialWatcherService: credentials.NewCredentialWatcherService(agentConfig, command.Command),
84-
auxiliaryCredentialWatcherService: credentials.NewCredentialWatcherService(agentConfig, command.Auxiliary),
81+
commandCredentialWatcherService: credentials.NewCredentialWatcherService(agentConfig, model.Command),
82+
auxiliaryCredentialWatcherService: credentials.NewCredentialWatcherService(agentConfig, model.Auxiliary),
8583
instanceUpdatesChannel: make(chan instance.InstanceUpdatesMessage),
8684
nginxConfigContextChannel: make(chan instance.NginxConfigContextMessage),
8785
instanceHealthChannel: make(chan health.InstanceHealthMessage),
@@ -262,20 +260,20 @@ func (w *Watcher) monitorWatchers(ctx context.Context) {
262260
slog.DebugContext(ctx, "Received credential update event for command server")
263261
newCtx := context.WithValue(context.WithValue(ctx, logger.CorrelationIDContextKey, message.CorrelationID),
264262
logger.ServerTypeContextKey, slog.Any(logger.ServerTypeKey,
265-
message.SeverType.String()))
263+
message.ServerType.String()))
266264

267265
w.messagePipe.Process(newCtx, &bus.Message{
268-
Topic: bus.ConnectionResetTopic, Data: message.Conn,
266+
Topic: bus.ConnectionResetTopic, Data: message.GrpcConnection,
269267
})
270268

271269
case message := <-w.auxiliaryCredentialUpdatesChannel:
272270
slog.DebugContext(ctx, "Received credential update event for auxiliary command server")
273271
newCtx := context.WithValue(context.WithValue(ctx, logger.CorrelationIDContextKey, message.CorrelationID),
274272
logger.ServerTypeContextKey, slog.Any(logger.ServerTypeKey,
275-
message.SeverType.String()))
273+
message.ServerType.String()))
276274

277275
w.messagePipe.Process(newCtx, &bus.Message{
278-
Topic: bus.ConnectionResetTopic, Data: message.Conn,
276+
Topic: bus.ConnectionResetTopic, Data: message.GrpcConnection,
279277
})
280278
case message := <-w.instanceUpdatesChannel:
281279
newCtx := context.WithValue(ctx, logger.CorrelationIDContextKey, message.CorrelationID)

internal/watcher/watcher_plugin_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/nginx/agent/v3/internal/command"
1413
"github.com/nginx/agent/v3/internal/grpc"
1514

16-
model2 "github.com/nginx/agent/v3/internal/model"
15+
"github.com/nginx/agent/v3/internal/model"
1716

1817
"github.com/nginx/agent/v3/internal/watcher/credentials"
1918

@@ -28,7 +27,7 @@ import (
2827
"github.com/nginx/agent/v3/internal/bus"
2928
"github.com/nginx/agent/v3/internal/logger"
3029
"github.com/nginx/agent/v3/pkg/id"
31-
"github.com/nginx/agent/v3/test/model"
30+
testModel "github.com/nginx/agent/v3/test/model"
3231
"github.com/nginx/agent/v3/test/protos"
3332
"github.com/nginx/agent/v3/test/types"
3433
"github.com/stretchr/testify/assert"
@@ -70,7 +69,7 @@ func TestWatcher_Init(t *testing.T) {
7069

7170
nginxConfigContextMessage := instance.NginxConfigContextMessage{
7271
CorrelationID: logger.GenerateCorrelationID(),
73-
NginxConfigContext: model.ConfigContext(),
72+
NginxConfigContext: testModel.ConfigContext(),
7473
}
7574

7675
instanceHealthMessage := health.InstanceHealthMessage{
@@ -79,9 +78,9 @@ func TestWatcher_Init(t *testing.T) {
7978
}
8079

8180
credentialUpdateMessage := credentials.CredentialUpdateMessage{
82-
CorrelationID: logger.GenerateCorrelationID(),
83-
SeverType: command.Command,
84-
Conn: &grpc.GrpcConnection{},
81+
CorrelationID: logger.GenerateCorrelationID(),
82+
ServerType: model.Command,
83+
GrpcConnection: &grpc.GrpcConnection{},
8584
}
8685

8786
watcherPlugin.instanceUpdatesChannel <- instanceUpdatesMessage
@@ -170,8 +169,8 @@ func TestWatcher_Process_ConfigApplySuccessfulTopic(t *testing.T) {
170169
ctx := context.Background()
171170
data := protos.NginxOssInstance([]string{})
172171

173-
response := &model2.ConfigApplySuccess{
174-
ConfigContext: &model2.NginxConfigContext{
172+
response := &model.ConfigApplySuccess{
173+
ConfigContext: &model.NginxConfigContext{
175174
InstanceID: data.GetInstanceMeta().GetInstanceId(),
176175
},
177176
DataPlaneResponse: &mpi.DataPlaneResponse{

0 commit comments

Comments
 (0)