-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
rule.go
49 lines (41 loc) · 1.52 KB
/
rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
// Package compliance defines common interfaces and types for Compliance Agent
package compliance
import "fmt"
// Rule defines a rule in a compliance config
type Rule struct {
ID string `yaml:"id"`
Description string `yaml:"description,omitempty"`
Scope RuleScopeList `yaml:"scope,omitempty"`
HostSelector string `yaml:"hostSelector,omitempty"`
ResourceType string `yaml:"resourceType,omitempty"`
Resources []Resource `yaml:"resources,omitempty"`
}
// RuleScope defines scope for applicability of a rule
type RuleScope string
const (
// DockerScope const
DockerScope RuleScope = "docker"
// KubernetesNodeScope const
KubernetesNodeScope RuleScope = "kubernetesNode"
// KubernetesClusterScope const
KubernetesClusterScope RuleScope = "kubernetesCluster"
)
// RuleScopeList is a set of RuleScopes
type RuleScopeList []RuleScope
// Includes returns true if RuleScopeList includes the specified RuleScope value
func (l RuleScopeList) Includes(ruleScope RuleScope) bool {
for _, s := range l {
if s == ruleScope {
return true
}
}
return false
}
// CheckName returns a canonical name of a check for a rule ID and description
func CheckName(ruleID string, description string) string {
return fmt.Sprintf("%s: %s", ruleID, description)
}