Skip to content

Commit 2719035

Browse files
committed
addressing review comments
1 parent e9bb34e commit 2719035

2 files changed

Lines changed: 13 additions & 47 deletions

File tree

server/internal/orchestrator/swarm/rag_config_resource.go

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,14 @@ type RAGConfigResource struct {
4444
DatabaseName string `json:"database_name"`
4545
DatabaseHost string `json:"database_host"`
4646
DatabasePort int `json:"database_port"`
47-
Username string `json:"username"`
48-
Password string `json:"password"`
4947
}
5048

5149
func (r *RAGConfigResource) ResourceVersion() string {
5250
return "1"
5351
}
5452

5553
func (r *RAGConfigResource) DiffIgnore() []string {
56-
return []string{
57-
// Credentials are populated at runtime from ServiceUserRole.
58-
"/username",
59-
"/password",
60-
}
54+
return nil
6155
}
6256

6357
func (r *RAGConfigResource) Identifier() resource.Identifier {
@@ -91,10 +85,6 @@ func (r *RAGConfigResource) Refresh(ctx context.Context, rc *resource.Context) e
9185
return fmt.Errorf("failed to get service data dir path: %w", err)
9286
}
9387

94-
if err := r.populateCredentials(rc); err != nil {
95-
return err
96-
}
97-
9888
_, err = readResourceFile(fs, filepath.Join(dirPath, ragConfigFilename))
9989
if err != nil {
10090
return fmt.Errorf("failed to read RAG config: %w", err)
@@ -114,11 +104,7 @@ func (r *RAGConfigResource) Create(ctx context.Context, rc *resource.Context) er
114104
return fmt.Errorf("failed to get service data dir path: %w", err)
115105
}
116106

117-
if err := r.populateCredentials(rc); err != nil {
118-
return err
119-
}
120-
121-
return r.writeConfigFile(fs, dirPath)
107+
return r.writeConfigFile(fs, dirPath, rc)
122108
}
123109

124110
func (r *RAGConfigResource) Update(ctx context.Context, rc *resource.Context) error {
@@ -132,26 +118,27 @@ func (r *RAGConfigResource) Update(ctx context.Context, rc *resource.Context) er
132118
return fmt.Errorf("failed to get service data dir path: %w", err)
133119
}
134120

135-
if err := r.populateCredentials(rc); err != nil {
136-
return err
137-
}
138-
139-
return r.writeConfigFile(fs, dirPath)
121+
return r.writeConfigFile(fs, dirPath, rc)
140122
}
141123

142124
func (r *RAGConfigResource) Delete(ctx context.Context, rc *resource.Context) error {
143125
// Cleanup is handled by the parent DirResource deletion.
144126
return nil
145127
}
146128

147-
func (r *RAGConfigResource) writeConfigFile(fs afero.Fs, dirPath string) error {
129+
func (r *RAGConfigResource) writeConfigFile(fs afero.Fs, dirPath string, rc *resource.Context) error {
130+
userRole, err := resource.FromContext[*ServiceUserRole](rc, ServiceUserRoleIdentifier(r.ServiceID, ServiceUserRoleRO))
131+
if err != nil {
132+
return fmt.Errorf("failed to get RAG service user role from state: %w", err)
133+
}
134+
148135
content, err := GenerateRAGConfig(&RAGConfigParams{
149136
Config: r.Config,
150137
DatabaseName: r.DatabaseName,
151138
DatabaseHost: r.DatabaseHost,
152139
DatabasePort: r.DatabasePort,
153-
Username: r.Username,
154-
Password: r.Password,
140+
Username: userRole.Username,
141+
Password: userRole.Password,
155142
KeysDir: ragKeysContainerDir,
156143
})
157144
if err != nil {
@@ -168,15 +155,3 @@ func (r *RAGConfigResource) writeConfigFile(fs afero.Fs, dirPath string) error {
168155

169156
return nil
170157
}
171-
172-
// populateCredentials fetches username and password from the ServiceUserRole
173-
// resource in the current reconciliation context.
174-
func (r *RAGConfigResource) populateCredentials(rc *resource.Context) error {
175-
userRole, err := resource.FromContext[*ServiceUserRole](rc, ServiceUserRoleIdentifier(r.ServiceID, ServiceUserRoleRO))
176-
if err != nil {
177-
return fmt.Errorf("failed to get RAG service user role from state: %w", err)
178-
}
179-
r.Username = userRole.Username
180-
r.Password = userRole.Password
181-
return nil
182-
}

server/internal/orchestrator/swarm/rag_config_resource_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,8 @@ func TestRAGConfigResource_Executor(t *testing.T) {
4646
func TestRAGConfigResource_DiffIgnore(t *testing.T) {
4747
r := &RAGConfigResource{}
4848
ignored := r.DiffIgnore()
49-
want := map[string]bool{
50-
"/username": true,
51-
"/password": true,
52-
}
53-
if len(ignored) != len(want) {
54-
t.Errorf("DiffIgnore() length = %d, want %d", len(ignored), len(want))
55-
}
56-
for _, path := range ignored {
57-
if !want[path] {
58-
t.Errorf("unexpected path in DiffIgnore(): %q", path)
59-
}
49+
if len(ignored) != 0 {
50+
t.Errorf("DiffIgnore() = %v, want empty", ignored)
6051
}
6152
}
6253

0 commit comments

Comments
 (0)