From 64e3fd8755a6c6850f5cc99c66f2a6a873f4b15f Mon Sep 17 00:00:00 2001 From: Xabier Arbulu Insausti Date: Thu, 24 Nov 2022 17:43:50 +0100 Subject: [PATCH] Restructure project folders structure (#147) * Restructure project folders structure * Move some util function to their respective files * Move back discovery and factsengine to internal --- cmd/config.go | 6 +- cmd/config_test.go | 4 +- cmd/facts.go | 28 +++-- cmd/start.go | 6 +- internal/{ => agent}/agent.go | 29 ++++- internal/{ => agent}/agent_test.go | 2 +- internal/{ => agent}/config.go | 40 +++++-- internal/{ => agent}/heartbeat.go | 2 +- internal/{ => core}/cloud/aws.go | 0 internal/{ => core}/cloud/aws_dto.go | 0 internal/{ => core}/cloud/aws_dto_test.go | 0 internal/{ => core}/cloud/aws_test.go | 2 +- internal/{ => core}/cloud/azure.go | 0 internal/{ => core}/cloud/azure_test.go | 2 +- internal/{ => core}/cloud/client.go | 0 internal/{ => core}/cloud/gcp.go | 0 internal/{ => core}/cloud/gcp_dto.go | 0 internal/{ => core}/cloud/gcp_dto_test.go | 0 internal/{ => core}/cloud/gcp_test.go | 2 +- internal/{ => core}/cloud/metadata.go | 2 +- internal/{ => core}/cloud/metadata_test.go | 4 +- internal/{ => core}/cloud/mocks/HTTPClient.go | 0 internal/{ => core}/cluster/cib/data.go | 0 internal/{ => core}/cluster/cib/parser.go | 0 .../{ => core}/cluster/cib/parser_test.go | 0 internal/{ => core}/cluster/cluster.go | 8 +- internal/{ => core}/cluster/cluster_test.go | 4 +- internal/{ => core}/cluster/crmmon/data.go | 0 internal/{ => core}/cluster/crmmon/parser.go | 0 .../{ => core}/cluster/crmmon/parser_test.go | 0 internal/{ => core}/cluster/sbd.go | 2 +- internal/{ => core}/cluster/sbd_test.go | 2 +- internal/{ => core}/hosts/discovered_host.go | 0 internal/{ => core}/sapsystem/sapcontrol.go | 2 +- .../sapcontrolapi/mocks/WebService.go | 2 +- .../mocks/WebServiceConnector.go | 2 +- .../sapsystem/sapcontrolapi/webservice.go | 0 internal/{ => core}/sapsystem/sapinstance.go | 4 +- internal/{ => core}/sapsystem/sapsystem.go | 4 +- .../{ => core}/sapsystem/sapsystem_test.go | 8 +- .../{ => core}/subscription/subscription.go | 2 +- .../subscription/subscription_test.go | 2 +- internal/discovery/cloud.go | 4 +- internal/discovery/cluster.go | 2 +- internal/discovery/host.go | 2 +- .../discovery/mocks/discovered_cloud_mock.go | 2 +- .../mocks/discovered_cluster_mock.go | 4 +- .../discovery/mocks/discovered_host_mock.go | 2 +- .../mocks/discovered_sap_system_mock.go | 2 +- .../mocks/discovered_subscription_mock.go | 2 +- internal/discovery/sapsystem.go | 6 +- internal/discovery/subscription.go | 4 +- .../factsengine_integration_test.go | 2 +- .../factsengine/gatherers/_todo/cibadmin.go | 2 +- .../gatherers/_todo/cibadmin_test.go | 4 +- .../factsengine/gatherers/_todo/crmmon.go | 2 +- .../gatherers/_todo/crmmon_test.go | 4 +- .../gatherers/_todo/verifypassword.go | 2 +- .../gatherers/_todo/verifypassword_test.go | 4 +- internal/factsengine/gatherers/_todo/xml.go | 2 +- .../factsengine/gatherers/corosynccmapctl.go | 4 +- .../gatherers/corosynccmapctl_test.go | 4 +- .../factsengine/gatherers/corosyncconf.go | 2 +- .../gatherers/corosyncconf_test.go | 2 +- internal/factsengine/gatherers/gatherer.go | 2 +- internal/factsengine/gatherers/hostsfile.go | 2 +- .../factsengine/gatherers/hostsfile_test.go | 2 +- .../gatherers/mocks/FactGatherer.go | 2 +- .../factsengine/gatherers/packageversion.go | 4 +- .../gatherers/packageversion_test.go | 4 +- internal/factsengine/gatherers/rcp_plugin.go | 2 +- internal/factsengine/gatherers/sbd.go | 4 +- internal/factsengine/gatherers/sbd_test.go | 2 +- internal/factsengine/gatherers/systemd.go | 2 +- .../factsengine/gatherers/systemd_test.go | 2 +- internal/factsengine/gathering.go | 2 +- internal/factsengine/gathering_test.go | 2 +- internal/factsengine/mapper.go | 2 +- internal/factsengine/mapper_test.go | 2 +- internal/factsengine/policy.go | 2 +- internal/factsengine/policy_test.go | 2 +- internal/utils/prettify.go | 22 ---- internal/utils/utils.go | 101 ------------------ .../factsengine/entities/fact_value.go | 0 .../factsengine/entities/fact_value_test.go | 2 +- .../factsengine/entities/facts_gathered.go | 0 .../entities/facts_gathering_requested.go | 0 .../factsengine/plugininterface/interface.go | 2 +- .../factsengine/plugininterface/rpc.go | 2 +- {internal => pkg}/utils/commandexecutor.go | 0 .../utils/mocks/CommandExecutor.go | 0 pkg/utils/utils.go | 32 ++++++ plugin_examples/dummy.go | 4 +- 93 files changed, 205 insertions(+), 235 deletions(-) rename internal/{ => agent}/agent.go (88%) rename internal/{ => agent}/agent_test.go (97%) rename internal/{ => agent}/config.go (68%) rename internal/{ => agent}/heartbeat.go (77%) rename internal/{ => core}/cloud/aws.go (100%) rename internal/{ => core}/cloud/aws_dto.go (100%) rename internal/{ => core}/cloud/aws_dto_test.go (100%) rename internal/{ => core}/cloud/aws_test.go (96%) rename internal/{ => core}/cloud/azure.go (100%) rename internal/{ => core}/cloud/azure_test.go (98%) rename internal/{ => core}/cloud/client.go (100%) rename internal/{ => core}/cloud/gcp.go (100%) rename internal/{ => core}/cloud/gcp_dto.go (100%) rename internal/{ => core}/cloud/gcp_dto_test.go (100%) rename internal/{ => core}/cloud/gcp_test.go (96%) rename internal/{ => core}/cloud/metadata.go (99%) rename internal/{ => core}/cloud/metadata_test.go (98%) rename internal/{ => core}/cloud/mocks/HTTPClient.go (100%) rename internal/{ => core}/cluster/cib/data.go (100%) rename internal/{ => core}/cluster/cib/parser.go (100%) rename internal/{ => core}/cluster/cib/parser_test.go (100%) rename internal/{ => core}/cluster/cluster.go (94%) rename internal/{ => core}/cluster/cluster_test.go (97%) rename internal/{ => core}/cluster/crmmon/data.go (100%) rename internal/{ => core}/cluster/crmmon/parser.go (100%) rename internal/{ => core}/cluster/crmmon/parser_test.go (100%) rename internal/{ => core}/cluster/sbd.go (99%) rename internal/{ => core}/cluster/sbd_test.go (99%) rename internal/{ => core}/hosts/discovered_host.go (100%) rename internal/{ => core}/sapsystem/sapcontrol.go (92%) rename internal/{ => core}/sapsystem/sapcontrolapi/mocks/WebService.go (96%) rename internal/{ => core}/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go (92%) rename internal/{ => core}/sapsystem/sapcontrolapi/webservice.go (100%) rename internal/{ => core}/sapsystem/sapinstance.go (97%) rename internal/{ => core}/sapsystem/sapsystem.go (98%) rename internal/{ => core}/sapsystem/sapsystem_test.go (98%) rename internal/{ => core}/subscription/subscription.go (95%) rename internal/{ => core}/subscription/subscription_test.go (97%) delete mode 100644 internal/utils/prettify.go delete mode 100644 internal/utils/utils.go rename {internal => pkg}/factsengine/entities/fact_value.go (100%) rename {internal => pkg}/factsengine/entities/fact_value_test.go (98%) rename {internal => pkg}/factsengine/entities/facts_gathered.go (100%) rename {internal => pkg}/factsengine/entities/facts_gathering_requested.go (100%) rename {internal => pkg}/factsengine/plugininterface/interface.go (93%) rename {internal => pkg}/factsengine/plugininterface/rpc.go (88%) rename {internal => pkg}/utils/commandexecutor.go (100%) rename {internal => pkg}/utils/mocks/CommandExecutor.go (100%) create mode 100644 pkg/utils/utils.go diff --git a/cmd/config.go b/cmd/config.go index 28e3e44c..b29969e4 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/viper" - "github.com/trento-project/agent/internal" + "github.com/trento-project/agent/internal/agent" "github.com/trento-project/agent/internal/discovery" "github.com/trento-project/agent/internal/discovery/collector" ) @@ -20,7 +20,7 @@ func validatePeriod(durationFlag string, minValue time.Duration) error { return nil } -func LoadConfig() (*internal.Config, error) { +func LoadConfig() (*agent.Config, error) { minPeriodValues := map[string]time.Duration{ "cluster-discovery-period": discovery.ClusterDiscoveryMinPeriod, "sapsystem-discovery-period": discovery.SAPDiscoveryMinPeriod, @@ -71,7 +71,7 @@ func LoadConfig() (*internal.Config, error) { DiscoveriesPeriodsConfig: discoveryPeriodsConfig, } - return &internal.Config{ + return &agent.Config{ InstanceName: hostname, DiscoveriesConfig: discoveriesConfig, // Feature flag to enable the facts engine diff --git a/cmd/config_test.go b/cmd/config_test.go index f04f45bf..b3d4433d 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal" + "github.com/trento-project/agent/internal/agent" "github.com/trento-project/agent/internal/discovery" "github.com/trento-project/agent/internal/discovery/collector" ) @@ -46,7 +46,7 @@ func (suite *AgentCmdTestSuite) SetupTest() { func (suite *AgentCmdTestSuite) TearDownTest() { _ = suite.cmd.Execute() - expectedConfig := &internal.Config{ + expectedConfig := &agent.Config{ InstanceName: "some-hostname", DiscoveriesConfig: &discovery.DiscoveriesConfig{ SSHAddress: "some-ssh-address", diff --git a/cmd/facts.go b/cmd/facts.go index f2ffeb5b..3c94575e 100644 --- a/cmd/facts.go +++ b/cmd/facts.go @@ -1,16 +1,18 @@ package cmd import ( + "bytes" + "encoding/json" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" - "github.com/trento-project/agent/internal" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/internal/agent" "github.com/trento-project/agent/internal/factsengine/gatherers" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/factsengine/entities" ) func NewFactsCmd() *cobra.Command { @@ -38,7 +40,7 @@ func NewFactsGatherCmd() *cobra.Command { } }) - return internal.InitConfig("agent") + return agent.InitConfig("agent") }, } @@ -65,7 +67,7 @@ func NewFactsListCmd() *cobra.Command { } }) - return internal.InitConfig("agent") + return agent.InitConfig("agent") }, } @@ -114,7 +116,7 @@ func gather(*cobra.Command, []string) { cleanupAndFatal(err) } - result, err := utils.PrettifyInterfaceToJSON(value[0]) + result, err := prettifyInterfaceToJSON(value[0]) if err != nil { cleanupAndFatal(err) } @@ -159,3 +161,17 @@ func list(*cobra.Command, []string) { log.Printf(g) } } + +func prettifyInterfaceToJSON(data interface{}) (string, error) { + jsonResult, err := json.Marshal(data) + if err != nil { + return "", errors.Wrap(err, "Error building the response") + } + + var prettyJSON bytes.Buffer + if err := json.Indent(&prettyJSON, jsonResult, "", " "); err != nil { + return "", errors.Wrap(err, "Error indenting the json data") + } + + return prettyJSON.String(), nil +} diff --git a/cmd/start.go b/cmd/start.go index 2f786aa0..c04cb0fe 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" - "github.com/trento-project/agent/internal" + "github.com/trento-project/agent/internal/agent" ) func NewStartCmd() *cobra.Command { @@ -36,7 +36,7 @@ func NewStartCmd() *cobra.Command { } }) - return internal.InitConfig("agent") + return agent.InitConfig("agent") }, } @@ -136,7 +136,7 @@ func start(*cobra.Command, []string) { log.Fatal("Failed to create the agent configuration: ", err) } - a, err := internal.NewAgent(config) + a, err := agent.NewAgent(config) if err != nil { log.Fatal("Failed to create the agent: ", err) } diff --git a/internal/agent.go b/internal/agent/agent.go similarity index 88% rename from internal/agent.go rename to internal/agent/agent.go index 728646a8..4ddc44bd 100644 --- a/internal/agent.go +++ b/internal/agent/agent.go @@ -1,9 +1,10 @@ -package internal +package agent import ( "context" "fmt" "strings" + "time" "github.com/google/uuid" "github.com/pkg/errors" @@ -15,7 +16,6 @@ import ( "github.com/trento-project/agent/internal/discovery/collector" "github.com/trento-project/agent/internal/factsengine" "github.com/trento-project/agent/internal/factsengine/gatherers" - "github.com/trento-project/agent/internal/utils" ) const machineIDPath = "/etc/machine-id" @@ -156,7 +156,7 @@ func (a *Agent) startDiscoverTicker(ctx context.Context, d discovery.Discovery) } log.Infof("%s discovery tick output: %s", d.GetID(), result) } - utils.Repeat(ctx, d.GetID(), tick, d.GetInterval()) + repeat(ctx, d.GetID(), tick, d.GetInterval()) } @@ -168,5 +168,26 @@ func (a *Agent) startHeartbeatTicker(ctx context.Context) { } } - utils.Repeat(ctx, "agent.heartbeat", tick, HeartbeatInterval) + repeat(ctx, "agent.heartbeat", tick, HeartbeatInterval) +} + +// Repeat executes a function at a given interval. +// the first tick runs immediately +func repeat(ctx context.Context, operation string, tick func(), interval time.Duration) { + tick() + + ticker := time.NewTicker(interval) + msg := fmt.Sprintf("Next execution for operation %s in %s", operation, interval) + log.Debugf(msg) + + defer ticker.Stop() + for { + select { + case <-ticker.C: + tick() + log.Debugf(msg) + case <-ctx.Done(): + return + } + } } diff --git a/internal/agent_test.go b/internal/agent/agent_test.go similarity index 97% rename from internal/agent_test.go rename to internal/agent/agent_test.go index d446e229..d204e268 100644 --- a/internal/agent_test.go +++ b/internal/agent/agent_test.go @@ -1,4 +1,4 @@ -package internal +package agent import ( "testing" diff --git a/internal/config.go b/internal/agent/config.go similarity index 68% rename from internal/config.go rename to internal/agent/config.go index de5468f8..9b82c8e2 100644 --- a/internal/config.go +++ b/internal/agent/config.go @@ -1,16 +1,15 @@ -package internal +package agent import ( "os" "path" "strings" + "github.com/hashicorp/go-hclog" + "github.com/mitchellh/go-homedir" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - - "github.com/mitchellh/go-homedir" "github.com/spf13/viper" - "github.com/trento-project/agent/internal/utils" ) // InitConfig intializes the config for the application @@ -24,11 +23,11 @@ import ( // /usr/etc/trento/${context}.yaml // $HOME/.config/trento/${context}.yaml func InitConfig(configName string) error { - BindEnv() + bindEnv() viper.SetConfigType("yaml") - utils.SetLogLevel(viper.GetString("log-level")) - utils.SetLogFormatter("2006-01-02 15:04:05") + setLogLevel(viper.GetString("log-level")) + setLogFormatter("2006-01-02 15:04:05") cfgFile := viper.GetString("config") if cfgFile != "" { @@ -73,8 +72,33 @@ func InitConfig(configName string) error { return nil } -func BindEnv() { +func bindEnv() { viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) viper.SetEnvPrefix("TRENTO") viper.AutomaticEnv() // read in environment variables that match } + +func setLogLevel(level string) { + switch level { + case "error": + log.SetLevel(log.ErrorLevel) + case "warn": + log.SetLevel(log.WarnLevel) + case "info": + log.SetLevel(log.InfoLevel) + case "debug": + log.SetLevel(log.DebugLevel) + default: + log.Warnln("Unrecognized minimum log level; using 'info' as default") + log.SetLevel(log.InfoLevel) + } + hclog.DefaultOptions.Level = hclog.LevelFromString(level) +} + +func setLogFormatter(timestampFormat string) { + customFormatter := new(log.TextFormatter) + customFormatter.TimestampFormat = timestampFormat + log.SetFormatter(customFormatter) + customFormatter.FullTimestamp = true + hclog.DefaultOptions.TimeFormat = timestampFormat +} diff --git a/internal/heartbeat.go b/internal/agent/heartbeat.go similarity index 77% rename from internal/heartbeat.go rename to internal/agent/heartbeat.go index cb8dd736..dcd2c745 100644 --- a/internal/heartbeat.go +++ b/internal/agent/heartbeat.go @@ -1,4 +1,4 @@ -package internal +package agent import "time" diff --git a/internal/cloud/aws.go b/internal/core/cloud/aws.go similarity index 100% rename from internal/cloud/aws.go rename to internal/core/cloud/aws.go diff --git a/internal/cloud/aws_dto.go b/internal/core/cloud/aws_dto.go similarity index 100% rename from internal/cloud/aws_dto.go rename to internal/core/cloud/aws_dto.go diff --git a/internal/cloud/aws_dto_test.go b/internal/core/cloud/aws_dto_test.go similarity index 100% rename from internal/cloud/aws_dto_test.go rename to internal/core/cloud/aws_dto_test.go diff --git a/internal/cloud/aws_test.go b/internal/core/cloud/aws_test.go similarity index 96% rename from internal/cloud/aws_test.go rename to internal/core/cloud/aws_test.go index 09977fb2..ae8d31af 100644 --- a/internal/cloud/aws_test.go +++ b/internal/core/cloud/aws_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/cloud/mocks" + "github.com/trento-project/agent/internal/core/cloud/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/cloud/azure.go b/internal/core/cloud/azure.go similarity index 100% rename from internal/cloud/azure.go rename to internal/core/cloud/azure.go diff --git a/internal/cloud/azure_test.go b/internal/core/cloud/azure_test.go similarity index 98% rename from internal/cloud/azure_test.go rename to internal/core/cloud/azure_test.go index 7c538112..bcc94757 100644 --- a/internal/cloud/azure_test.go +++ b/internal/core/cloud/azure_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/cloud/mocks" + "github.com/trento-project/agent/internal/core/cloud/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/cloud/client.go b/internal/core/cloud/client.go similarity index 100% rename from internal/cloud/client.go rename to internal/core/cloud/client.go diff --git a/internal/cloud/gcp.go b/internal/core/cloud/gcp.go similarity index 100% rename from internal/cloud/gcp.go rename to internal/core/cloud/gcp.go diff --git a/internal/cloud/gcp_dto.go b/internal/core/cloud/gcp_dto.go similarity index 100% rename from internal/cloud/gcp_dto.go rename to internal/core/cloud/gcp_dto.go diff --git a/internal/cloud/gcp_dto_test.go b/internal/core/cloud/gcp_dto_test.go similarity index 100% rename from internal/cloud/gcp_dto_test.go rename to internal/core/cloud/gcp_dto_test.go diff --git a/internal/cloud/gcp_test.go b/internal/core/cloud/gcp_test.go similarity index 96% rename from internal/cloud/gcp_test.go rename to internal/core/cloud/gcp_test.go index f9fed680..0986e702 100644 --- a/internal/cloud/gcp_test.go +++ b/internal/core/cloud/gcp_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/cloud/mocks" + "github.com/trento-project/agent/internal/core/cloud/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/cloud/metadata.go b/internal/core/cloud/metadata.go similarity index 99% rename from internal/cloud/metadata.go rename to internal/core/cloud/metadata.go index 5a203c9a..ba7e9225 100644 --- a/internal/cloud/metadata.go +++ b/internal/core/cloud/metadata.go @@ -5,7 +5,7 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) const ( diff --git a/internal/cloud/metadata_test.go b/internal/core/cloud/metadata_test.go similarity index 98% rename from internal/cloud/metadata_test.go rename to internal/core/cloud/metadata_test.go index d01ef624..ccaa632b 100644 --- a/internal/cloud/metadata_test.go +++ b/internal/core/cloud/metadata_test.go @@ -9,8 +9,8 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/cloud/mocks" - utilsMocks "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/internal/core/cloud/mocks" + utilsMocks "github.com/trento-project/agent/pkg/utils/mocks" ) type CloudMetadataTestSuite struct { diff --git a/internal/cloud/mocks/HTTPClient.go b/internal/core/cloud/mocks/HTTPClient.go similarity index 100% rename from internal/cloud/mocks/HTTPClient.go rename to internal/core/cloud/mocks/HTTPClient.go diff --git a/internal/cluster/cib/data.go b/internal/core/cluster/cib/data.go similarity index 100% rename from internal/cluster/cib/data.go rename to internal/core/cluster/cib/data.go diff --git a/internal/cluster/cib/parser.go b/internal/core/cluster/cib/parser.go similarity index 100% rename from internal/cluster/cib/parser.go rename to internal/core/cluster/cib/parser.go diff --git a/internal/cluster/cib/parser_test.go b/internal/core/cluster/cib/parser_test.go similarity index 100% rename from internal/cluster/cib/parser_test.go rename to internal/core/cluster/cib/parser_test.go diff --git a/internal/cluster/cluster.go b/internal/core/cluster/cluster.go similarity index 94% rename from internal/cluster/cluster.go rename to internal/core/cluster/cluster.go index fb6c0f7e..af7db189 100644 --- a/internal/cluster/cluster.go +++ b/internal/core/cluster/cluster.go @@ -12,10 +12,10 @@ import ( // Now we mantain our own fork "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/cloud" - "github.com/trento-project/agent/internal/cluster/cib" - "github.com/trento-project/agent/internal/cluster/crmmon" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/internal/core/cloud" + "github.com/trento-project/agent/internal/core/cluster/cib" + "github.com/trento-project/agent/internal/core/cluster/crmmon" + "github.com/trento-project/agent/pkg/utils" ) const ( diff --git a/internal/cluster/cluster_test.go b/internal/core/cluster/cluster_test.go similarity index 97% rename from internal/cluster/cluster_test.go rename to internal/core/cluster/cluster_test.go index 8d88018f..61d40bcf 100644 --- a/internal/cluster/cluster_test.go +++ b/internal/core/cluster/cluster_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/cluster/cib" - "github.com/trento-project/agent/internal/cluster/crmmon" + "github.com/trento-project/agent/internal/core/cluster/cib" + "github.com/trento-project/agent/internal/core/cluster/crmmon" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/cluster/crmmon/data.go b/internal/core/cluster/crmmon/data.go similarity index 100% rename from internal/cluster/crmmon/data.go rename to internal/core/cluster/crmmon/data.go diff --git a/internal/cluster/crmmon/parser.go b/internal/core/cluster/crmmon/parser.go similarity index 100% rename from internal/cluster/crmmon/parser.go rename to internal/core/cluster/crmmon/parser.go diff --git a/internal/cluster/crmmon/parser_test.go b/internal/core/cluster/crmmon/parser_test.go similarity index 100% rename from internal/cluster/crmmon/parser_test.go rename to internal/core/cluster/crmmon/parser_test.go diff --git a/internal/cluster/sbd.go b/internal/core/cluster/sbd.go similarity index 99% rename from internal/cluster/sbd.go rename to internal/core/cluster/sbd.go index 5f4bb76e..046615a4 100644 --- a/internal/cluster/sbd.go +++ b/internal/core/cluster/sbd.go @@ -11,7 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/pkg/errors" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) const ( diff --git a/internal/cluster/sbd_test.go b/internal/core/cluster/sbd_test.go similarity index 99% rename from internal/cluster/sbd_test.go rename to internal/core/cluster/sbd_test.go index fbe7c087..2dfe7ffc 100644 --- a/internal/cluster/sbd_test.go +++ b/internal/core/cluster/sbd_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/pkg/utils/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/hosts/discovered_host.go b/internal/core/hosts/discovered_host.go similarity index 100% rename from internal/hosts/discovered_host.go rename to internal/core/hosts/discovered_host.go diff --git a/internal/sapsystem/sapcontrol.go b/internal/core/sapsystem/sapcontrol.go similarity index 92% rename from internal/sapsystem/sapcontrol.go rename to internal/core/sapsystem/sapcontrol.go index 2eba4275..938c6de1 100644 --- a/internal/sapsystem/sapcontrol.go +++ b/internal/core/sapsystem/sapcontrol.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/pkg/errors" - sapcontrol "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" + sapcontrol "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" ) type SAPControl struct { diff --git a/internal/sapsystem/sapcontrolapi/mocks/WebService.go b/internal/core/sapsystem/sapcontrolapi/mocks/WebService.go similarity index 96% rename from internal/sapsystem/sapcontrolapi/mocks/WebService.go rename to internal/core/sapsystem/sapcontrolapi/mocks/WebService.go index 2d1e6a8e..99af1ce5 100644 --- a/internal/sapsystem/sapcontrolapi/mocks/WebService.go +++ b/internal/core/sapsystem/sapcontrolapi/mocks/WebService.go @@ -4,7 +4,7 @@ package mocks import ( mock "github.com/stretchr/testify/mock" - sapcontrolapi "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" + sapcontrolapi "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" ) // WebService is an autogenerated mock type for the WebService type diff --git a/internal/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go b/internal/core/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go similarity index 92% rename from internal/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go rename to internal/core/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go index 90c1d4a8..1223d686 100644 --- a/internal/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go +++ b/internal/core/sapsystem/sapcontrolapi/mocks/WebServiceConnector.go @@ -4,7 +4,7 @@ package mocks import ( mock "github.com/stretchr/testify/mock" - sapcontrolapi "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" + sapcontrolapi "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" ) // WebServiceConnector is an autogenerated mock type for the WebServiceConnector type diff --git a/internal/sapsystem/sapcontrolapi/webservice.go b/internal/core/sapsystem/sapcontrolapi/webservice.go similarity index 100% rename from internal/sapsystem/sapcontrolapi/webservice.go rename to internal/core/sapsystem/sapcontrolapi/webservice.go diff --git a/internal/sapsystem/sapinstance.go b/internal/core/sapsystem/sapinstance.go similarity index 97% rename from internal/sapsystem/sapinstance.go rename to internal/core/sapsystem/sapinstance.go index 8c919bc8..498fe203 100644 --- a/internal/sapsystem/sapinstance.go +++ b/internal/core/sapsystem/sapinstance.go @@ -9,8 +9,8 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" + "github.com/trento-project/agent/pkg/utils" ) var ( diff --git a/internal/sapsystem/sapsystem.go b/internal/core/sapsystem/sapsystem.go similarity index 98% rename from internal/sapsystem/sapsystem.go rename to internal/core/sapsystem/sapsystem.go index c84a5da8..c5c325cf 100644 --- a/internal/sapsystem/sapsystem.go +++ b/internal/core/sapsystem/sapsystem.go @@ -15,8 +15,8 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/afero" - "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" + "github.com/trento-project/agent/pkg/utils" ) type SystemType int diff --git a/internal/sapsystem/sapsystem_test.go b/internal/core/sapsystem/sapsystem_test.go similarity index 98% rename from internal/sapsystem/sapsystem_test.go rename to internal/core/sapsystem/sapsystem_test.go index 8a7a1c9d..27e028fe 100644 --- a/internal/sapsystem/sapsystem_test.go +++ b/internal/core/sapsystem/sapsystem_test.go @@ -9,10 +9,10 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" - sapcontrol "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" - sapControlMocks "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi/mocks" - utilsMocks "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" + sapcontrol "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" + sapControlMocks "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi/mocks" + utilsMocks "github.com/trento-project/agent/pkg/utils/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/subscription/subscription.go b/internal/core/subscription/subscription.go similarity index 95% rename from internal/subscription/subscription.go rename to internal/core/subscription/subscription.go index 0e1cd705..97d7e0e9 100644 --- a/internal/subscription/subscription.go +++ b/internal/core/subscription/subscription.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) type Subscriptions []*Subscription diff --git a/internal/subscription/subscription_test.go b/internal/core/subscription/subscription_test.go similarity index 97% rename from internal/subscription/subscription_test.go rename to internal/core/subscription/subscription_test.go index 57265118..614e56e8 100644 --- a/internal/subscription/subscription_test.go +++ b/internal/core/subscription/subscription_test.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/pkg/utils/mocks" ) type SubscriptionTestSuite struct { diff --git a/internal/discovery/cloud.go b/internal/discovery/cloud.go index 91f14c88..05d8bcb5 100644 --- a/internal/discovery/cloud.go +++ b/internal/discovery/cloud.go @@ -5,9 +5,9 @@ import ( "time" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/cloud" + "github.com/trento-project/agent/internal/core/cloud" "github.com/trento-project/agent/internal/discovery/collector" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) const CloudDiscoveryID string = "cloud_discovery" diff --git a/internal/discovery/cluster.go b/internal/discovery/cluster.go index ad2d38bc..0f398443 100644 --- a/internal/discovery/cluster.go +++ b/internal/discovery/cluster.go @@ -5,7 +5,7 @@ import ( "time" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/cluster" + "github.com/trento-project/agent/internal/core/cluster" "github.com/trento-project/agent/internal/discovery/collector" ) diff --git a/internal/discovery/host.go b/internal/discovery/host.go index d62ab758..a8c1c2f5 100644 --- a/internal/discovery/host.go +++ b/internal/discovery/host.go @@ -10,8 +10,8 @@ import ( "github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/mem" log "github.com/sirupsen/logrus" + "github.com/trento-project/agent/internal/core/hosts" "github.com/trento-project/agent/internal/discovery/collector" - "github.com/trento-project/agent/internal/hosts" "github.com/trento-project/agent/version" ) diff --git a/internal/discovery/mocks/discovered_cloud_mock.go b/internal/discovery/mocks/discovered_cloud_mock.go index f648167b..f9cbacce 100644 --- a/internal/discovery/mocks/discovered_cloud_mock.go +++ b/internal/discovery/mocks/discovered_cloud_mock.go @@ -5,7 +5,7 @@ import ( "io" "os" - "github.com/trento-project/agent/internal/cloud" + "github.com/trento-project/agent/internal/core/cloud" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/discovery/mocks/discovered_cluster_mock.go b/internal/discovery/mocks/discovered_cluster_mock.go index 8b9062b5..d8140038 100644 --- a/internal/discovery/mocks/discovered_cluster_mock.go +++ b/internal/discovery/mocks/discovered_cluster_mock.go @@ -1,8 +1,8 @@ package mocks import ( - "github.com/trento-project/agent/internal/cloud" - "github.com/trento-project/agent/internal/cluster" + "github.com/trento-project/agent/internal/core/cloud" + "github.com/trento-project/agent/internal/core/cluster" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/discovery/mocks/discovered_host_mock.go b/internal/discovery/mocks/discovered_host_mock.go index ae56211e..daee2d33 100644 --- a/internal/discovery/mocks/discovered_host_mock.go +++ b/internal/discovery/mocks/discovered_host_mock.go @@ -1,6 +1,6 @@ package mocks -import "github.com/trento-project/agent/internal/hosts" +import "github.com/trento-project/agent/internal/core/hosts" func NewDiscoveredHostMock() hosts.DiscoveredHost { return hosts.DiscoveredHost{ diff --git a/internal/discovery/mocks/discovered_sap_system_mock.go b/internal/discovery/mocks/discovered_sap_system_mock.go index a8348e9d..ee902637 100644 --- a/internal/discovery/mocks/discovered_sap_system_mock.go +++ b/internal/discovery/mocks/discovered_sap_system_mock.go @@ -5,7 +5,7 @@ import ( "io" "os" - "github.com/trento-project/agent/internal/sapsystem" + "github.com/trento-project/agent/internal/core/sapsystem" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/discovery/mocks/discovered_subscription_mock.go b/internal/discovery/mocks/discovered_subscription_mock.go index a8d943de..bcfee6ba 100644 --- a/internal/discovery/mocks/discovered_subscription_mock.go +++ b/internal/discovery/mocks/discovered_subscription_mock.go @@ -5,7 +5,7 @@ import ( "io" "os" - "github.com/trento-project/agent/internal/subscription" + "github.com/trento-project/agent/internal/core/subscription" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/discovery/sapsystem.go b/internal/discovery/sapsystem.go index e890f5f4..8178f95a 100644 --- a/internal/discovery/sapsystem.go +++ b/internal/discovery/sapsystem.go @@ -5,10 +5,10 @@ import ( "time" log "github.com/sirupsen/logrus" + "github.com/trento-project/agent/internal/core/sapsystem" + "github.com/trento-project/agent/internal/core/sapsystem/sapcontrolapi" "github.com/trento-project/agent/internal/discovery/collector" - "github.com/trento-project/agent/internal/sapsystem" - "github.com/trento-project/agent/internal/sapsystem/sapcontrolapi" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) const SAPDiscoveryID string = "sap_system_discovery" diff --git a/internal/discovery/subscription.go b/internal/discovery/subscription.go index 75b7ec31..4f129a06 100644 --- a/internal/discovery/subscription.go +++ b/internal/discovery/subscription.go @@ -5,9 +5,9 @@ import ( "time" log "github.com/sirupsen/logrus" + "github.com/trento-project/agent/internal/core/subscription" "github.com/trento-project/agent/internal/discovery/collector" - "github.com/trento-project/agent/internal/subscription" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/utils" ) const SubscriptionDiscoveryID string = "subscription_discovery" diff --git a/internal/factsengine/factsengine_integration_test.go b/internal/factsengine/factsengine_integration_test.go index 67b25a93..8874801f 100644 --- a/internal/factsengine/factsengine_integration_test.go +++ b/internal/factsengine/factsengine_integration_test.go @@ -10,8 +10,8 @@ import ( "google.golang.org/protobuf/types/known/structpb" "github.com/trento-project/agent/internal/factsengine/adapters" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/contracts/go/pkg/events" ) diff --git a/internal/factsengine/gatherers/_todo/cibadmin.go b/internal/factsengine/gatherers/_todo/cibadmin.go index 1604ebdb..b3dba72a 100644 --- a/internal/factsengine/gatherers/_todo/cibadmin.go +++ b/internal/factsengine/gatherers/_todo/cibadmin.go @@ -2,7 +2,7 @@ package gatherers import ( log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/_todo/cibadmin_test.go b/internal/factsengine/gatherers/_todo/cibadmin_test.go index 1cf4172b..153f3469 100644 --- a/internal/factsengine/gatherers/_todo/cibadmin_test.go +++ b/internal/factsengine/gatherers/_todo/cibadmin_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" - mocks "github.com/trento-project/agent/internal/factsengine/gatherers/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" + mocks "github.com/trento-project/agent/pkg/factsengine/gatherers/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/_todo/crmmon.go b/internal/factsengine/gatherers/_todo/crmmon.go index c50a4d43..9dad356f 100644 --- a/internal/factsengine/gatherers/_todo/crmmon.go +++ b/internal/factsengine/gatherers/_todo/crmmon.go @@ -2,7 +2,7 @@ package gatherers import ( log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/_todo/crmmon_test.go b/internal/factsengine/gatherers/_todo/crmmon_test.go index d9ca6115..d16a588d 100644 --- a/internal/factsengine/gatherers/_todo/crmmon_test.go +++ b/internal/factsengine/gatherers/_todo/crmmon_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" - mocks "github.com/trento-project/agent/internal/factsengine/gatherers/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" + mocks "github.com/trento-project/agent/pkg/factsengine/gatherers/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/_todo/verifypassword.go b/internal/factsengine/gatherers/_todo/verifypassword.go index 4fdc72cb..9221b3df 100644 --- a/internal/factsengine/gatherers/_todo/verifypassword.go +++ b/internal/factsengine/gatherers/_todo/verifypassword.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" crypt "github.com/tredoe/osutil/user/crypt" sha512crypt "github.com/tredoe/osutil/user/crypt/sha512_crypt" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/_todo/verifypassword_test.go b/internal/factsengine/gatherers/_todo/verifypassword_test.go index aa9df6fb..d6ce8804 100644 --- a/internal/factsengine/gatherers/_todo/verifypassword_test.go +++ b/internal/factsengine/gatherers/_todo/verifypassword_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" - mocks "github.com/trento-project/agent/internal/factsengine/gatherers/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" + mocks "github.com/trento-project/agent/pkg/factsengine/gatherers/mocks" ) type PasswordTestSuite struct { diff --git a/internal/factsengine/gatherers/_todo/xml.go b/internal/factsengine/gatherers/_todo/xml.go index b6de5bc1..112c3260 100644 --- a/internal/factsengine/gatherers/_todo/xml.go +++ b/internal/factsengine/gatherers/_todo/xml.go @@ -4,7 +4,7 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" xmlpath "gopkg.in/xmlpath.v2" ) diff --git a/internal/factsengine/gatherers/corosynccmapctl.go b/internal/factsengine/gatherers/corosynccmapctl.go index d6b5545a..4a0c8652 100644 --- a/internal/factsengine/gatherers/corosynccmapctl.go +++ b/internal/factsengine/gatherers/corosynccmapctl.go @@ -4,8 +4,8 @@ import ( "fmt" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/factsengine/entities" + "github.com/trento-project/agent/pkg/utils" ) const ( diff --git a/internal/factsengine/gatherers/corosynccmapctl_test.go b/internal/factsengine/gatherers/corosynccmapctl_test.go index 9fef5210..de20ca48 100644 --- a/internal/factsengine/gatherers/corosynccmapctl_test.go +++ b/internal/factsengine/gatherers/corosynccmapctl_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" - utilsMocks "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" + utilsMocks "github.com/trento-project/agent/pkg/utils/mocks" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/corosyncconf.go b/internal/factsengine/gatherers/corosyncconf.go index ec6a48ae..71d75ff5 100644 --- a/internal/factsengine/gatherers/corosyncconf.go +++ b/internal/factsengine/gatherers/corosyncconf.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/corosyncconf_test.go b/internal/factsengine/gatherers/corosyncconf_test.go index c314dea2..0c91a1de 100644 --- a/internal/factsengine/gatherers/corosyncconf_test.go +++ b/internal/factsengine/gatherers/corosyncconf_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/gatherer.go b/internal/factsengine/gatherers/gatherer.go index 30922fa3..7479f59f 100644 --- a/internal/factsengine/gatherers/gatherer.go +++ b/internal/factsengine/gatherers/gatherer.go @@ -1,7 +1,7 @@ package gatherers import ( - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) type FactGatherer interface { diff --git a/internal/factsengine/gatherers/hostsfile.go b/internal/factsengine/gatherers/hostsfile.go index 6ce89390..e74b5b1f 100644 --- a/internal/factsengine/gatherers/hostsfile.go +++ b/internal/factsengine/gatherers/hostsfile.go @@ -8,7 +8,7 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/hostsfile_test.go b/internal/factsengine/gatherers/hostsfile_test.go index 328a763c..f4664203 100644 --- a/internal/factsengine/gatherers/hostsfile_test.go +++ b/internal/factsengine/gatherers/hostsfile_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/mocks/FactGatherer.go b/internal/factsengine/gatherers/mocks/FactGatherer.go index 6694c7c8..8efcf5da 100644 --- a/internal/factsengine/gatherers/mocks/FactGatherer.go +++ b/internal/factsengine/gatherers/mocks/FactGatherer.go @@ -3,7 +3,7 @@ package mocks import ( - entities "github.com/trento-project/agent/internal/factsengine/entities" + entities "github.com/trento-project/agent/pkg/factsengine/entities" mock "github.com/stretchr/testify/mock" ) diff --git a/internal/factsengine/gatherers/packageversion.go b/internal/factsengine/gatherers/packageversion.go index b3811eab..496b97e8 100644 --- a/internal/factsengine/gatherers/packageversion.go +++ b/internal/factsengine/gatherers/packageversion.go @@ -2,8 +2,8 @@ package gatherers import ( log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" - "github.com/trento-project/agent/internal/utils" + "github.com/trento-project/agent/pkg/factsengine/entities" + "github.com/trento-project/agent/pkg/utils" ) const ( diff --git a/internal/factsengine/gatherers/packageversion_test.go b/internal/factsengine/gatherers/packageversion_test.go index c248d99c..ad852417 100644 --- a/internal/factsengine/gatherers/packageversion_test.go +++ b/internal/factsengine/gatherers/packageversion_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" - utilsMocks "github.com/trento-project/agent/internal/utils/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" + utilsMocks "github.com/trento-project/agent/pkg/utils/mocks" ) type PackageVersionTestSuite struct { diff --git a/internal/factsengine/gatherers/rcp_plugin.go b/internal/factsengine/gatherers/rcp_plugin.go index 3f2d9c09..a4e9af4e 100644 --- a/internal/factsengine/gatherers/rcp_plugin.go +++ b/internal/factsengine/gatherers/rcp_plugin.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" goplugin "github.com/hashicorp/go-plugin" - "github.com/trento-project/agent/internal/factsengine/plugininterface" + "github.com/trento-project/agent/pkg/factsengine/plugininterface" ) type RPCPluginLoader struct{} diff --git a/internal/factsengine/gatherers/sbd.go b/internal/factsengine/gatherers/sbd.go index 1fe4890f..e3457d5e 100644 --- a/internal/factsengine/gatherers/sbd.go +++ b/internal/factsengine/gatherers/sbd.go @@ -2,8 +2,8 @@ package gatherers import ( log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/cluster" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/internal/core/cluster" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/sbd_test.go b/internal/factsengine/gatherers/sbd_test.go index 1cf6d8af..da4f1026 100644 --- a/internal/factsengine/gatherers/sbd_test.go +++ b/internal/factsengine/gatherers/sbd_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/agent/test/helpers" ) diff --git a/internal/factsengine/gatherers/systemd.go b/internal/factsengine/gatherers/systemd.go index 36e17e0f..a6ab89da 100644 --- a/internal/factsengine/gatherers/systemd.go +++ b/internal/factsengine/gatherers/systemd.go @@ -6,7 +6,7 @@ import ( "github.com/coreos/go-systemd/v22/dbus" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) const ( diff --git a/internal/factsengine/gatherers/systemd_test.go b/internal/factsengine/gatherers/systemd_test.go index 68989f68..0d0d8654 100644 --- a/internal/factsengine/gatherers/systemd_test.go +++ b/internal/factsengine/gatherers/systemd_test.go @@ -7,8 +7,8 @@ import ( "github.com/coreos/go-systemd/v22/dbus" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" mocks "github.com/trento-project/agent/internal/factsengine/gatherers/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" ) diff --git a/internal/factsengine/gathering.go b/internal/factsengine/gathering.go index 0c2ecff7..a3113617 100644 --- a/internal/factsengine/gathering.go +++ b/internal/factsengine/gathering.go @@ -3,8 +3,8 @@ package factsengine import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" + "github.com/trento-project/agent/pkg/factsengine/entities" "golang.org/x/sync/errgroup" ) diff --git a/internal/factsengine/gathering_test.go b/internal/factsengine/gathering_test.go index 6ab6203b..c0adfe27 100644 --- a/internal/factsengine/gathering_test.go +++ b/internal/factsengine/gathering_test.go @@ -6,9 +6,9 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" "github.com/trento-project/agent/internal/factsengine/gatherers" "github.com/trento-project/agent/internal/factsengine/gatherers/mocks" + "github.com/trento-project/agent/pkg/factsengine/entities" ) type GatheringTestSuite struct { diff --git a/internal/factsengine/mapper.go b/internal/factsengine/mapper.go index 2946512f..6aa23a36 100644 --- a/internal/factsengine/mapper.go +++ b/internal/factsengine/mapper.go @@ -4,7 +4,7 @@ package factsengine import ( "github.com/google/uuid" "github.com/pkg/errors" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/contracts/go/pkg/events" "google.golang.org/protobuf/types/known/structpb" ) diff --git a/internal/factsengine/mapper_test.go b/internal/factsengine/mapper_test.go index 84a9243c..56b31378 100644 --- a/internal/factsengine/mapper_test.go +++ b/internal/factsengine/mapper_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/suite" "google.golang.org/protobuf/types/known/structpb" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/contracts/go/pkg/events" ) diff --git a/internal/factsengine/policy.go b/internal/factsengine/policy.go index 77526764..be4e49c6 100644 --- a/internal/factsengine/policy.go +++ b/internal/factsengine/policy.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/contracts/go/pkg/events" ) diff --git a/internal/factsengine/policy_test.go b/internal/factsengine/policy_test.go index c8ac1a86..4fa421ab 100644 --- a/internal/factsengine/policy_test.go +++ b/internal/factsengine/policy_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" "github.com/trento-project/agent/internal/factsengine/adapters/mocks" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" "github.com/trento-project/contracts/go/pkg/events" "google.golang.org/protobuf/types/known/structpb" ) diff --git a/internal/utils/prettify.go b/internal/utils/prettify.go deleted file mode 100644 index ab7a5751..00000000 --- a/internal/utils/prettify.go +++ /dev/null @@ -1,22 +0,0 @@ -package utils - -import ( - "bytes" - "encoding/json" - - "github.com/pkg/errors" -) - -func PrettifyInterfaceToJSON(data interface{}) (string, error) { - jsonResult, err := json.Marshal(data) - if err != nil { - return "", errors.Wrap(err, "Error building the response") - } - - var prettyJSON bytes.Buffer - if err := json.Indent(&prettyJSON, jsonResult, "", " "); err != nil { - return "", errors.Wrap(err, "Error indenting the json data") - } - - return prettyJSON.String(), nil -} diff --git a/internal/utils/utils.go b/internal/utils/utils.go deleted file mode 100644 index 790f17a2..00000000 --- a/internal/utils/utils.go +++ /dev/null @@ -1,101 +0,0 @@ -package utils - -import ( - "context" - "fmt" - "hash/crc32" - "regexp" - "strings" - "time" - - "github.com/hashicorp/go-hclog" - log "github.com/sirupsen/logrus" -) - -func SetLogLevel(level string) { - switch level { - case "error": - log.SetLevel(log.ErrorLevel) - case "warn": - log.SetLevel(log.WarnLevel) - case "info": - log.SetLevel(log.InfoLevel) - case "debug": - log.SetLevel(log.DebugLevel) - default: - log.Warnln("Unrecognized minimum log level; using 'info' as default") - log.SetLevel(log.InfoLevel) - } - hclog.DefaultOptions.Level = hclog.LevelFromString(level) -} - -func SetLogFormatter(timestampFormat string) { - customFormatter := new(log.TextFormatter) - customFormatter.TimestampFormat = timestampFormat - log.SetFormatter(customFormatter) - customFormatter.FullTimestamp = true - hclog.DefaultOptions.TimeFormat = timestampFormat -} - -func Contains(s []string, str string) bool { - for _, v := range s { - if v == str { - return true - } - } - - return false -} - -func CRC32hash(input []byte) int { - crc32Table := crc32.MakeTable(crc32.IEEE) - return int(crc32.Checksum(input, crc32Table)) - -} - -// Repeat executes a function at a given interval. -// the first tick runs immediately -func Repeat(ctx context.Context, operation string, tick func(), interval time.Duration) { - tick() - - ticker := time.NewTicker(interval) - msg := fmt.Sprintf("Next execution for operation %s in %s", operation, interval) - log.Debugf(msg) - - defer ticker.Stop() - for { - select { - case <-ticker.C: - tick() - log.Debugf(msg) - case <-ctx.Done(): - return - } - } -} - -// FindMatches finds regular expression matches in a key/value based -// text (ini files, for example), and returns a map with them. -// If the matched key has spaces, they will be replaced with underscores -// If the same keys is found multiple times, the entry of the map will -// have a list as value with all of the matched values -// The pattern must have 2 groups. For example: `(.+)=(.*)` -func FindMatches(pattern string, text []byte) map[string]interface{} { - configMap := make(map[string]interface{}) - - r := regexp.MustCompile(pattern) - values := r.FindAllStringSubmatch(string(text), -1) - for _, match := range values { - key := strings.Replace(match[1], " ", "_", -1) //nolint - if _, ok := configMap[key]; ok { - switch configMap[key].(type) { //nolint - case string: - configMap[key] = []interface{}{configMap[key]} - } - configMap[key] = append(configMap[key].([]interface{}), match[2]) //nolint - } else { - configMap[key] = match[2] - } - } - return configMap -} diff --git a/internal/factsengine/entities/fact_value.go b/pkg/factsengine/entities/fact_value.go similarity index 100% rename from internal/factsengine/entities/fact_value.go rename to pkg/factsengine/entities/fact_value.go diff --git a/internal/factsengine/entities/fact_value_test.go b/pkg/factsengine/entities/fact_value_test.go similarity index 98% rename from internal/factsengine/entities/fact_value_test.go rename to pkg/factsengine/entities/fact_value_test.go index a49c0640..84e9945f 100644 --- a/internal/factsengine/entities/fact_value_test.go +++ b/pkg/factsengine/entities/fact_value_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) type FactValueTestSuite struct { diff --git a/internal/factsengine/entities/facts_gathered.go b/pkg/factsengine/entities/facts_gathered.go similarity index 100% rename from internal/factsengine/entities/facts_gathered.go rename to pkg/factsengine/entities/facts_gathered.go diff --git a/internal/factsengine/entities/facts_gathering_requested.go b/pkg/factsengine/entities/facts_gathering_requested.go similarity index 100% rename from internal/factsengine/entities/facts_gathering_requested.go rename to pkg/factsengine/entities/facts_gathering_requested.go diff --git a/internal/factsengine/plugininterface/interface.go b/pkg/factsengine/plugininterface/interface.go similarity index 93% rename from internal/factsengine/plugininterface/interface.go rename to pkg/factsengine/plugininterface/interface.go index ccf9b6ad..78ce9460 100644 --- a/internal/factsengine/plugininterface/interface.go +++ b/pkg/factsengine/plugininterface/interface.go @@ -5,7 +5,7 @@ import ( "net/rpc" "github.com/hashicorp/go-plugin" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) // TODO: move this to a common place in the pkg folder diff --git a/internal/factsengine/plugininterface/rpc.go b/pkg/factsengine/plugininterface/rpc.go similarity index 88% rename from internal/factsengine/plugininterface/rpc.go rename to pkg/factsengine/plugininterface/rpc.go index a4d5bd71..2852469d 100644 --- a/internal/factsengine/plugininterface/rpc.go +++ b/pkg/factsengine/plugininterface/rpc.go @@ -3,7 +3,7 @@ package plugininterface import ( "net/rpc" - "github.com/trento-project/agent/internal/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/entities" ) type GathererRPC struct{ client *rpc.Client } diff --git a/internal/utils/commandexecutor.go b/pkg/utils/commandexecutor.go similarity index 100% rename from internal/utils/commandexecutor.go rename to pkg/utils/commandexecutor.go diff --git a/internal/utils/mocks/CommandExecutor.go b/pkg/utils/mocks/CommandExecutor.go similarity index 100% rename from internal/utils/mocks/CommandExecutor.go rename to pkg/utils/mocks/CommandExecutor.go diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go new file mode 100644 index 00000000..6ebe9d66 --- /dev/null +++ b/pkg/utils/utils.go @@ -0,0 +1,32 @@ +package utils + +import ( + "regexp" + "strings" +) + +// FindMatches finds regular expression matches in a key/value based +// text (ini files, for example), and returns a map with them. +// If the matched key has spaces, they will be replaced with underscores +// If the same keys is found multiple times, the entry of the map will +// have a list as value with all of the matched values +// The pattern must have 2 groups. For example: `(.+)=(.*)` +func FindMatches(pattern string, text []byte) map[string]interface{} { + configMap := make(map[string]interface{}) + + r := regexp.MustCompile(pattern) + values := r.FindAllStringSubmatch(string(text), -1) + for _, match := range values { + key := strings.Replace(match[1], " ", "_", -1) //nolint + if _, ok := configMap[key]; ok { + switch configMap[key].(type) { //nolint + case string: + configMap[key] = []interface{}{configMap[key]} + } + configMap[key] = append(configMap[key].([]interface{}), match[2]) //nolint + } else { + configMap[key] = match[2] + } + } + return configMap +} diff --git a/plugin_examples/dummy.go b/plugin_examples/dummy.go index 3292c850..938b0cc0 100644 --- a/plugin_examples/dummy.go +++ b/plugin_examples/dummy.go @@ -8,8 +8,8 @@ import ( "github.com/hashicorp/go-plugin" log "github.com/sirupsen/logrus" - "github.com/trento-project/agent/internal/factsengine/entities" - "github.com/trento-project/agent/internal/factsengine/plugininterface" + "github.com/trento-project/agent/pkg/factsengine/entities" + "github.com/trento-project/agent/pkg/factsengine/plugininterface" ) type dummyGatherer struct {