Skip to content

Commit 412aac3

Browse files
askyrieSongZhen0704
authored andcommitted
feat: custom policy and field disabled
1 parent 28072f2 commit 412aac3

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

server/controller/trisolaris/common/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ const (
129129
)
130130

131131
const (
132+
CONFIG_KEY_FIELDS = "fields"
133+
CONFIG_KEY_CONST_FIELDS = "const_fields"
134+
CONFIG_KEY_COMPOUND_FIELDS = "compound_fields"
132135
CONFIG_KEY_BIZ_PROTOCOL_POLICIES = "biz_protocol_policies"
133136
CONFIG_KEY_BIZ_FIELD_DICTIONARIES = "biz_field.dictionaries"
134137
CONFIG_KEY_BIZ_FIELD_POLICIES = "biz_field.policies"

server/controller/trisolaris/metadata/custom_app_config.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)