@@ -266,6 +266,58 @@ func (c *CustomAppConfig) GetCustomAppConfigByte(teamID, agentGroupID int) []byt
266266 log .Error (errMessage , logger .NewORGPrefix (c .orgID ))
267267 return []byte ("# " + errMessage )
268268 }
269+ if policyYaml .Exists ("enabled" ) && ! policyYaml .Bool ("enabled" ) {
270+ log .Debugf ("policy (%s) is not enabled, skip it" , p .Name , logger .NewORGPrefix (c .orgID ))
271+ continue
272+ }
273+
274+ // fields
275+ policyFieldYamls := []map [string ]interface {}{}
276+ for _ , field := range policyYaml .Slices (common .CONFIG_KEY_FIELDS ) {
277+ if field .Exists ("enabled" ) && ! field .Bool ("enabled" ) {
278+ log .Debugf ("field (%s) in policy (%s) is not enabled, skip it" , field .String ("name" ), p .Name , logger .NewORGPrefix (c .orgID ))
279+ continue
280+ }
281+ policyFieldYamls = append (policyFieldYamls , field .Raw ())
282+ }
283+ err = policyYaml .Set (common .CONFIG_KEY_FIELDS , policyFieldYamls )
284+ if err != nil {
285+ errMessage := fmt .Sprintf ("set fields for policy (%s) failed: %s" , p .Name , err .Error ())
286+ log .Error (errMessage , logger .NewORGPrefix (c .orgID ))
287+ return []byte ("# " + errMessage )
288+ }
289+
290+ // const fields
291+ policyConstFieldYamls := []map [string ]interface {}{}
292+ for _ , field := range policyYaml .Slices (common .CONFIG_KEY_CONST_FIELDS ) {
293+ if field .Exists ("enabled" ) && ! field .Bool ("enabled" ) {
294+ log .Debugf ("const field (%s) in policy (%s) is not enabled, skip it" , field .String ("name" ), p .Name , logger .NewORGPrefix (c .orgID ))
295+ continue
296+ }
297+ policyConstFieldYamls = append (policyConstFieldYamls , field .Raw ())
298+ }
299+ err = policyYaml .Set (common .CONFIG_KEY_CONST_FIELDS , policyConstFieldYamls )
300+ if err != nil {
301+ errMessage := fmt .Sprintf ("set const fields for policy (%s) failed: %s" , p .Name , err .Error ())
302+ log .Error (errMessage , logger .NewORGPrefix (c .orgID ))
303+ return []byte ("# " + errMessage )
304+ }
305+
306+ // compound fields
307+ policyCompoundFieldYamls := []map [string ]interface {}{}
308+ for _ , field := range policyYaml .Slices (common .CONFIG_KEY_COMPOUND_FIELDS ) {
309+ if field .Exists ("enabled" ) && ! field .Bool ("enabled" ) {
310+ log .Debugf ("compound field (%s) in policy (%s) is not enabled, skip it" , field .String ("name" ), p .Name , logger .NewORGPrefix (c .orgID ))
311+ continue
312+ }
313+ policyCompoundFieldYamls = append (policyCompoundFieldYamls , field .Raw ())
314+ }
315+ err = policyYaml .Set (common .CONFIG_KEY_COMPOUND_FIELDS , policyCompoundFieldYamls )
316+ if err != nil {
317+ errMessage := fmt .Sprintf ("set compound fields for policy (%s) failed: %s" , p .Name , err .Error ())
318+ log .Error (errMessage , logger .NewORGPrefix (c .orgID ))
319+ return []byte ("# " + errMessage )
320+ }
269321 policyYamls = append (policyYamls , policyYaml .Raw ())
270322 }
271323 err := k .Set (common .CONFIG_KEY_BIZ_FIELD_POLICIES , policyYamls )
0 commit comments