github.com/Axway/agent-sdk@v1.1.101/pkg/config/agentfeaturesconfig.go (about) 1 package config 2 3 import ( 4 "github.com/Axway/agent-sdk/pkg/cmd/properties" 5 ) 6 7 // AgentFeaturesConfig - Interface to get agent features Config 8 type AgentFeaturesConfig interface { 9 ConnectionToCentralEnabled() bool 10 ProcessSystemSignalsEnabled() bool 11 VersionCheckerEnabled() bool 12 PersistCacheEnabled() bool 13 GetExternalIDPConfig() ExternalIDPConfig 14 AgentStatusUpdatesEnabled() bool 15 SetPersistentCache(enable bool) 16 } 17 18 // AgentFeaturesConfiguration - Structure to hold the agent features config 19 type AgentFeaturesConfiguration struct { 20 AgentFeaturesConfig 21 IConfigValidator 22 ConnectToCentral bool `config:"connectToCentral"` 23 ProcessSystemSignals bool `config:"processSystemSignals"` 24 VersionChecker bool `config:"versionChecker"` 25 PersistCache bool `config:"persistCache"` 26 ExternalIDPConfig ExternalIDPConfig `config:"idp"` 27 AgentStatusUpdates bool `config:"agentStatusUpdates"` 28 } 29 30 // NewAgentFeaturesConfiguration - Creates the default agent features config 31 func NewAgentFeaturesConfiguration() AgentFeaturesConfig { 32 return &AgentFeaturesConfiguration{ 33 ConnectToCentral: true, 34 ProcessSystemSignals: true, 35 VersionChecker: true, 36 PersistCache: true, 37 AgentStatusUpdates: true, 38 } 39 } 40 41 func (c *AgentFeaturesConfiguration) SetPersistentCache(enable bool) { 42 c.PersistCache = enable 43 } 44 45 // ConnectionToCentralEnabled - True if the agent is a standard agent that connects to Central 46 func (c *AgentFeaturesConfiguration) ConnectionToCentralEnabled() bool { 47 return c.ConnectToCentral 48 } 49 50 // ProcessSystemSignalsEnabled - True if the agent SDK listens for system signals and manages shutdown 51 func (c *AgentFeaturesConfiguration) ProcessSystemSignalsEnabled() bool { 52 return c.ProcessSystemSignals 53 } 54 55 // VersionCheckerEnabled - True if the agent SDK should check for newer versions of the agent. 56 func (c *AgentFeaturesConfiguration) VersionCheckerEnabled() bool { 57 return c.VersionChecker 58 } 59 60 // PersistCacheEnabled - True if the agent SDK should use persistence for agent cache. 61 func (c *AgentFeaturesConfiguration) PersistCacheEnabled() bool { 62 return c.PersistCache 63 } 64 65 // GetExternalIDPConfig - returns the config for external IdP providers 66 func (c *AgentFeaturesConfiguration) GetExternalIDPConfig() ExternalIDPConfig { 67 return c.ExternalIDPConfig 68 } 69 70 // AgentStatusUpdatesEnabled - True if the agent SDK should manage the status update. 71 func (c *AgentFeaturesConfiguration) AgentStatusUpdatesEnabled() bool { 72 return c.AgentStatusUpdates 73 } 74 75 const ( 76 pathConnectToCentral = "agentFeatures.connectToCentral" 77 pathProcessSystemSignals = "agentFeatures.processSystemSignals" 78 pathVersionChecker = "agentFeatures.versionChecker" 79 pathPersistCache = "agentFeatures.persistCache" 80 pathAgentStatusUpdates = "agentFeatures.agentStatusUpdates" 81 ) 82 83 // ValidateCfg - Validates the config, implementing IConfigInterface 84 func (c *AgentFeaturesConfiguration) ValidateCfg() (err error) { 85 if c.ExternalIDPConfig != nil { 86 return c.ExternalIDPConfig.ValidateCfg() 87 } 88 return 89 } 90 91 // AddAgentFeaturesConfigProperties - Adds the command properties needed for Agent Features Config 92 func AddAgentFeaturesConfigProperties(props properties.Properties) { 93 props.AddBoolProperty(pathConnectToCentral, true, "Controls whether the agent SDK connects to Central or not") 94 props.AddBoolProperty(pathProcessSystemSignals, true, "Controls whether the agent SDK processes system signals or not") 95 props.AddBoolProperty(pathVersionChecker, true, "Controls whether the agent SDK version checker will be enabled or not") 96 props.AddBoolProperty(pathPersistCache, true, "Controls whether the agent SDK will persist agent cache or not") 97 props.AddBoolProperty(pathAgentStatusUpdates, true, "Controls whether the agent should manage the status update or not") 98 addExternalIDPProperties(props) 99 } 100 101 // ParseAgentFeaturesConfig - Parses the AgentFeatures Config values from the command line 102 func ParseAgentFeaturesConfig(props properties.Properties) (AgentFeaturesConfig, error) { 103 cfg := &AgentFeaturesConfiguration{ 104 ConnectToCentral: props.BoolPropertyValueOrTrue(pathConnectToCentral), 105 ProcessSystemSignals: props.BoolPropertyValueOrTrue(pathProcessSystemSignals), 106 VersionChecker: props.BoolPropertyValueOrTrue(pathVersionChecker), 107 PersistCache: props.BoolPropertyValueOrTrue(pathPersistCache), 108 AgentStatusUpdates: props.BoolPropertyValueOrTrue(pathAgentStatusUpdates), 109 } 110 externalIDPCfg, err := parseExternalIDPConfig(props) 111 if err != nil { 112 return nil, err 113 } 114 cfg.ExternalIDPConfig = externalIDPCfg 115 return cfg, nil 116 }