diff --git a/pkg/cmd/discovery/discoveryCmd.go b/pkg/cmd/discovery/discoveryCmd.go deleted file mode 100644 index 3c935f5..0000000 --- a/pkg/cmd/discovery/discoveryCmd.go +++ /dev/null @@ -1,88 +0,0 @@ -package discovery - -import ( - "time" - - corecmd "github.com/Axway/agent-sdk/pkg/cmd" - corecfg "github.com/Axway/agent-sdk/pkg/config" - "github.com/Axway/agent-sdk/pkg/util/log" - config "github.com/Axway/agents-kong/pkg/config/discovery" - "github.com/Axway/agents-kong/pkg/gateway" -) - -var DiscoveryCmd corecmd.AgentRootCmd -var agentConfig config.AgentConfig - -func init() { - // Create new root command with callbacks to initialize the agent config and command execution. - // The first parameter identifies the name of the yaml file that agent will look for to load the config - DiscoveryCmd = corecmd.NewRootCmd( - "kong_discovery_agent", - "Kong Discovery Agent", - initConfig, - run, - corecfg.DiscoveryAgent, - ) - - // Get the root command properties and bind the config property in YAML definition - rootProps := DiscoveryCmd.GetProperties() - rootProps.AddStringProperty("kong.token", "", "Token to authenticate with Kong Gateway") - rootProps.AddStringProperty("kong.adminEndpoint", "", "The Kong admin endpoint") - rootProps.AddStringProperty("kong.proxyEndpoint", "", "The Kong proxy endpoint") - rootProps.AddIntProperty("kong.proxyEndpointProtocols.http", 80, "The Kong proxy http port") - rootProps.AddIntProperty("kong.proxyEndpointProtocols.https", 443, "The Kong proxy https port") -} - -// Callback that agent will call to process the execution -func run() error { - var err error - stopChan := make(chan struct{}) - - gatewayClient, err := gateway.NewClient(agentConfig) - if err != nil { - return err - } - - go func() { - for { - err = gatewayClient.DiscoverAPIs() - if err != nil { - log.Errorf("error in processing: %v", err) - stopChan <- struct{}{} - } - log.Infof("next poll in %s", agentConfig.CentralCfg.GetPollInterval()) - time.Sleep(agentConfig.CentralCfg.GetPollInterval()) - } - }() - - <-stopChan - log.Info("Received signal to stop processing") - - return err -} - -// Callback that agent will call to initialize the config. CentralConfig is parsed by Agent SDK -// and passed to the callback allowing the agent code to access the central config -func initConfig(centralConfig corecfg.CentralConfig) (interface{}, error) { - rootProps := DiscoveryCmd.GetProperties() - - // Parse the config from bound properties and setup gateway config - gatewayConfig := &config.KongGatewayConfig{ - AdminEndpoint: rootProps.StringPropertyValue("kong.adminEndpoint"), - Token: rootProps.StringPropertyValue("kong.token"), - ProxyEndpoint: rootProps.StringPropertyValue("kong.proxyEndpoint"), - ProxyHttpPort: rootProps.IntPropertyValue("kong.proxyEndpointProtocols.http"), - ProxyHttpsPort: rootProps.IntPropertyValue("kong.proxyEndpointProtocols.https"), - SpecDownloadPaths: rootProps.StringSlicePropertyValue("kong.specDownloadPaths"), - } - - agentConfig = config.AgentConfig{ - CentralCfg: centralConfig, - KongGatewayCfg: gatewayConfig, - } - return agentConfig, nil -} - -func GetAgentConfig() config.AgentConfig { - return agentConfig -} diff --git a/pkg/cmd/traceability/traceabilityCmd.go b/pkg/cmd/traceability/traceabilityCmd.go deleted file mode 100644 index 0ca8e64..0000000 --- a/pkg/cmd/traceability/traceabilityCmd.go +++ /dev/null @@ -1,63 +0,0 @@ -package traceability - -import ( - corecmd "github.com/Axway/agent-sdk/pkg/cmd" - corecfg "github.com/Axway/agent-sdk/pkg/config" - "github.com/Axway/agents-kong/pkg/beater" - config "github.com/Axway/agents-kong/pkg/config/traceability" - libcmd "github.com/elastic/beats/v7/libbeat/cmd" - "github.com/elastic/beats/v7/libbeat/cmd/instance" -) - -var TraceCmd corecmd.AgentRootCmd -var beatCmd *libcmd.BeatsRootCmd - -func init() { - name := "kong_traceability_agent" - settings := instance.Settings{ - Name: name, - HasDashboards: true, - } - - beatCmd = libcmd.GenRootCmdWithSettings(beater.New, settings) - cmd := beatCmd.Command - // Wrap the beat command with the agent command processor with callbacks to initialize the agent config and command execution. - // The first parameter identifies the name of the yaml file that agent will look for to load the config - TraceCmd = corecmd.NewCmd( - &cmd, - name, - "Kong Traceability Agent", - initConfig, - run, - corecfg.TraceabilityAgent, - ) - - rootProps := TraceCmd.GetProperties() - rootProps.AddStringProperty("http_log_plugin_config.path", "/requestlogs", "Path on which the HTTP Log plugin sends request logs") - rootProps.AddIntProperty("http_log_plugin_config.port", 9000, "Port that listens for request logs from HTTP Log plugin") -} - -func run() error { - return beatCmd.Execute() -} - -// Callback that agent will call to initialize the config. CentralConfig is parsed by Agent SDK -// and passed to the callback allowing the agent code to access the central config -func initConfig(centralConfig corecfg.CentralConfig) (interface{}, error) { - - rootProps := TraceCmd.GetProperties() - - httpLogPluginConfig := &config.HttpLogPluginConfig{ - Port: rootProps.IntPropertyValue("http_log_plugin_config.port"), - Path: rootProps.StringPropertyValue("http_log_plugin_config.path"), - } - - agentConfig := &config.AgentConfig{ - CentralCfg: centralConfig, - HttpLogPluginConfig: httpLogPluginConfig, - } - - config.SetAgentConfig(agentConfig) - - return agentConfig, nil -}