@@ -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
5149func (r * RAGConfigResource ) ResourceVersion () string {
5250 return "1"
5351}
5452
5553func (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
6357func (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
124110func (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
142124func (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- }
0 commit comments