-
Notifications
You must be signed in to change notification settings - Fork 13
/
agentfeaturesconfig.go
122 lines (107 loc) · 5.11 KB
/
agentfeaturesconfig.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package config
import (
"github.com/Axway/agent-sdk/pkg/cmd/properties"
)
// AgentFeaturesConfig - Interface to get agent features Config
type AgentFeaturesConfig interface {
ConnectionToCentralEnabled() bool
ProcessSystemSignalsEnabled() bool
VersionCheckerEnabled() bool
PersistCacheEnabled() bool
MarketplaceProvisioningEnabled() bool
GetExternalIDPConfig() ExternalIDPConfig
AgentStatusUpdatesEnabled() bool
}
// AgentFeaturesConfiguration - Structure to hold the agent features config
type AgentFeaturesConfiguration struct {
AgentFeaturesConfig
IConfigValidator
ConnectToCentral bool `config:"connectToCentral"`
ProcessSystemSignals bool `config:"processSystemSignals"`
VersionChecker bool `config:"versionChecker"`
PersistCache bool `config:"persistCache"`
MarketplaceProvisioning bool `config:"marketplaceProvisioning"`
ExternalIDPConfig ExternalIDPConfig `config:"idp"`
AgentStatusUpdates bool `config:"agentStatusUpdates"`
}
// NewAgentFeaturesConfiguration - Creates the default agent features config
func NewAgentFeaturesConfiguration() AgentFeaturesConfig {
return &AgentFeaturesConfiguration{
ConnectToCentral: true,
ProcessSystemSignals: true,
VersionChecker: true,
PersistCache: false,
MarketplaceProvisioning: false,
AgentStatusUpdates: true,
}
}
// ConnectionToCentralEnabled - True if the agent is a standard agent that connects to Central
func (c *AgentFeaturesConfiguration) ConnectionToCentralEnabled() bool {
return c.ConnectToCentral
}
// ProcessSystemSignalsEnabled - True if the agent SDK listens for system signals and manages shutdown
func (c *AgentFeaturesConfiguration) ProcessSystemSignalsEnabled() bool {
return c.ProcessSystemSignals
}
// VersionCheckerEnabled - True if the agent SDK should check for newer versions of the agent.
func (c *AgentFeaturesConfiguration) VersionCheckerEnabled() bool {
return c.VersionChecker
}
// PersistCacheEnabled - True if the agent SDK should use persistence for agent cache.
func (c *AgentFeaturesConfiguration) PersistCacheEnabled() bool {
return c.PersistCache
}
// MarketplaceProvisioningEnabled - True if the agent SDK should handle marketplace subscriptions.
func (c *AgentFeaturesConfiguration) MarketplaceProvisioningEnabled() bool {
return c.MarketplaceProvisioning
}
// GetExternalIDPConfig - returns the config for external IdP providers
func (c *AgentFeaturesConfiguration) GetExternalIDPConfig() ExternalIDPConfig {
return c.ExternalIDPConfig
}
// AgentStatusUpdatesEnabled - True if the agent SDK should manage the status update.
func (c *AgentFeaturesConfiguration) AgentStatusUpdatesEnabled() bool {
return c.AgentStatusUpdates
}
const (
pathConnectToCentral = "agentFeatures.connectToCentral"
pathProcessSystemSignals = "agentFeatures.processSystemSignals"
pathVersionChecker = "agentFeatures.versionChecker"
pathPersistCache = "agentFeatures.persistCache"
pathMarketplaceProvisioning = "agentFeatures.marketplaceProvisioning"
pathAgentStatusUpdates = "agentFeatures.agentStatusUpdates"
)
// ValidateCfg - Validates the config, implementing IConfigInterface
func (c *AgentFeaturesConfiguration) ValidateCfg() (err error) {
if c.ExternalIDPConfig != nil {
return c.ExternalIDPConfig.ValidateCfg()
}
return
}
// AddAgentFeaturesConfigProperties - Adds the command properties needed for Agent Features Config
func AddAgentFeaturesConfigProperties(props properties.Properties) {
props.AddBoolProperty(pathConnectToCentral, true, "Controls whether the agent SDK connects to Central or not")
props.AddBoolProperty(pathProcessSystemSignals, true, "Controls whether the agent SDK processes system signals or not")
props.AddBoolProperty(pathVersionChecker, true, "Controls whether the agent SDK version checker will be enabled or not")
props.AddBoolProperty(pathPersistCache, false, "Controls whether the agent SDK will persist agent cache or not")
props.AddBoolProperty(pathMarketplaceProvisioning, false, "Controls whether the agent should handle Marketplace Subscriptions or not")
props.AddBoolProperty(pathAgentStatusUpdates, true, "Controls whether the agent should manage the status update or not")
addExternalIDPProperties(props)
}
// ParseAgentFeaturesConfig - Parses the AgentFeatures Config values from the command line
func ParseAgentFeaturesConfig(props properties.Properties) (AgentFeaturesConfig, error) {
cfg := &AgentFeaturesConfiguration{
ConnectToCentral: props.BoolPropertyValueOrTrue(pathConnectToCentral),
ProcessSystemSignals: props.BoolPropertyValueOrTrue(pathProcessSystemSignals),
VersionChecker: props.BoolPropertyValueOrTrue(pathVersionChecker),
PersistCache: props.BoolPropertyValueOrTrue(pathPersistCache),
MarketplaceProvisioning: props.BoolPropertyValueOrTrue(pathMarketplaceProvisioning),
AgentStatusUpdates: props.BoolPropertyValueOrTrue(pathAgentStatusUpdates),
}
externalIDPCfg, err := parseExternalIDPConfig(props)
if err != nil {
return nil, err
}
cfg.ExternalIDPConfig = externalIDPCfg
return cfg, nil
}