-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
83 lines (70 loc) · 3.21 KB
/
config.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package runtime
import (
"encoding/json"
"github.com/mitchellh/copystructure"
"github.com/open-policy-agent/opa/bundle"
"github.com/open-policy-agent/opa/keys"
bundleplugin "github.com/open-policy-agent/opa/plugins/bundle"
"github.com/open-policy-agent/opa/plugins/discovery"
"github.com/open-policy-agent/opa/plugins/logs"
"github.com/open-policy-agent/opa/plugins/status"
"github.com/open-policy-agent/opa/topdown/cache"
)
type Config struct {
LocalBundles LocalBundlesConfig `json:"local_bundles"`
InstanceID string `json:"instance_id"`
PluginsErrorLimit int `json:"plugins_error_limit"`
GracefulShutdownPeriodSeconds int `json:"graceful_shutdown_period_seconds"`
MaxPluginWaitTimeSeconds int `json:"max_plugin_wait_time_seconds"`
Flags Flags `json:"flags"`
Config OPAConfig `json:"config"`
}
type Flags struct {
EnableStatusPlugin bool `json:"enable_status_plugin"`
}
func (c *Config) rawOPAConfig() ([]byte, error) {
return json.Marshal(c.Config)
}
type LocalBundlesConfig struct {
Watch bool `json:"watch"`
LocalPolicyImage string `json:"local_policy_image"`
FileStoreRoot string `json:"file_store_root"`
Paths []string `json:"paths"`
Ignore []string `json:"ignore"`
SkipVerification bool `json:"skip_verification"`
VerificationConfig *bundle.VerificationConfig `json:"verification_config"`
}
type OPAConfig struct {
Services map[string]interface{} `json:"services,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Discovery *discovery.Config `json:"discovery,omitempty"`
Bundles map[string]*bundleplugin.Source `json:"bundles,omitempty"`
DecisionLogs *logs.Config `json:"decision_logs,omitempty"`
Status *status.Config `json:"status,omitempty"`
Plugins map[string]interface{} `json:"plugins,omitempty"`
Keys map[string]*keys.Config `json:"keys,omitempty"`
DefaultDecision *string `json:"default_decision,omitempty"`
DefaultAuthorizationDecision *string `json:"default_authorization_decision,omitempty"`
Caching *cache.Config `json:"caching,omitempty"`
PersistenceDirectory *string `json:"persistence_directory,omitempty"`
}
func (c *OPAConfig) ServicesCopy() map[string]interface{} {
if c.Services == nil {
return nil
}
servicesCopy, err := copystructure.Copy(c.Services)
if err != nil {
panic(err)
}
return servicesCopy.(map[string]interface{})
}
func (c *OPAConfig) DiscoveryCopy() *discovery.Config {
if c.Discovery == nil {
return nil
}
discoveryCopy, err := copystructure.Copy(c.Discovery)
if err != nil {
panic(err)
}
return discoveryCopy.(*discovery.Config)
}