@@ -30,6 +30,8 @@ type failedModule struct {
3030 lastError string
3131}
3232
33+ type Decrypter func (* ConfigurationSection ) error
34+
3335type ConfigServer struct {
3436 UnimplementedConfigServiceServer
3537
@@ -38,6 +40,7 @@ type ConfigServer struct {
3840 cache map [PluginType ]* ConfigurationSection
3941 failedModules map [PluginType ]* failedModule
4042 failedMu sync.RWMutex
43+ decrypt Decrypter
4144}
4245
4346func GetConfigServer () * ConfigServer {
@@ -51,6 +54,17 @@ func GetConfigServer() *ConfigServer {
5154 return configServer
5255}
5356
57+ func (s * ConfigServer ) SetDecrypter (d Decrypter ) {
58+ s .decrypt = d
59+ }
60+
61+ func (s * ConfigServer ) runDecrypter (section * ConfigurationSection ) error {
62+ if s .decrypt == nil {
63+ return nil
64+ }
65+ return s .decrypt (section )
66+ }
67+
5468func (s * ConfigServer ) GetModuleGroup (moduleName PluginType ) * ConfigurationSection {
5569 s .mu .RLock ()
5670 defer s .mu .RUnlock ()
@@ -146,7 +160,15 @@ func (s *ConfigServer) NotifyUpdate(moduleName string, section *ConfigurationSec
146160}
147161
148162func (s * ConfigServer ) fetchModuleConfig (backend , moduleName , internalKey string ) (* ConfigurationSection , int , error ) {
149- url := fmt .Sprintf ("%s/api/utm-modules/module-details-decrypted?nameShort=%s&serverId=1" , backend , moduleName )
163+ url := fmt .Sprintf ("%s/api/utm-modules/moduleDetails?nameShort=%s&serverId=1" , backend , moduleName )
164+ // Remove after testing, before release to production
165+ catcher .Info ("fetchModuleConfig: requesting" , map [string ]any {
166+ "process" : "plugin_com.utmstack.modules-config" ,
167+ "module" : moduleName ,
168+ "url" : url ,
169+ "internalKey" : internalKey ,
170+ "internalKeyLen" : len (internalKey ),
171+ })
150172
151173 response , status , err := utils .DoReq [ConfigurationSection ](
152174 url ,
@@ -155,10 +177,54 @@ func (s *ConfigServer) fetchModuleConfig(backend, moduleName, internalKey string
155177 map [string ]string {"Utm-Internal-Key" : internalKey },
156178 true ,
157179 )
180+ // Remove after testing, before release to production
181+ catcher .Info ("fetchModuleConfig: response received" , map [string ]any {
182+ "process" : "plugin_com.utmstack.modules-config" ,
183+ "module" : moduleName ,
184+ "status" : status ,
185+ "err" : fmt .Sprintf ("%v" , err ),
186+ "groupCount" : len (response .ModuleGroups ),
187+ "moduleName" : response .ModuleName ,
188+ })
158189
159190 if err != nil || status != http .StatusOK {
160191 return nil , status , err
161192 }
193+ // Remove after testing, before release to production
194+ for _ , g := range response .ModuleGroups {
195+ for _ , cnf := range g .ModuleGroupConfigurations {
196+ catcher .Info ("fetchModuleConfig: incoming field (pre-decrypt)" , map [string ]any {
197+ "process" : "plugin_com.utmstack.modules-config" ,
198+ "module" : moduleName ,
199+ "groupId" : g .Id ,
200+ "confKey" : cnf .ConfKey ,
201+ "confDataType" : cnf .ConfDataType ,
202+ "valueLen" : len (cnf .ConfValue ),
203+ "confValue" : cnf .ConfValue ,
204+ })
205+ }
206+ }
207+
208+ if err := s .runDecrypter (& response ); err != nil {
209+ return nil , status , catcher .Error ("failed to decrypt module config" , err , map [string ]any {
210+ "process" : "plugin_com.utmstack.modules-config" ,
211+ "module" : moduleName ,
212+ })
213+ }
214+ // Remove after testing, before release to production
215+ for _ , g := range response .ModuleGroups {
216+ for _ , cnf := range g .ModuleGroupConfigurations {
217+ catcher .Info ("fetchModuleConfig: field (post-decrypt)" , map [string ]any {
218+ "process" : "plugin_com.utmstack.modules-config" ,
219+ "module" : moduleName ,
220+ "groupId" : g .Id ,
221+ "confKey" : cnf .ConfKey ,
222+ "confDataType" : cnf .ConfDataType ,
223+ "valueLen" : len (cnf .ConfValue ),
224+ "confValue" : cnf .ConfValue ,
225+ })
226+ }
227+ }
162228
163229 return & response , status , nil
164230}
0 commit comments