diff --git a/cmd/executionspace/main.go b/cmd/executionspace/main.go index f52d5b4..4f33c41 100644 --- a/cmd/executionspace/main.go +++ b/cmd/executionspace/main.go @@ -23,7 +23,7 @@ import ( "runtime/debug" "syscall" - config "github.com/eiffel-community/etos-api/internal/configs/executionspace" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/database/etcd" "github.com/eiffel-community/etos-api/internal/executionspace/provider" "github.com/eiffel-community/etos-api/internal/logging" @@ -39,7 +39,7 @@ import ( // main sets up logging and starts up the webservice. func main() { - cfg := config.Get() + cfg := config.NewExecutionSpaceConfig() ctx := context.Background() var hooks []logrus.Hook @@ -120,7 +120,7 @@ func fileLogging(cfg config.Config) logrus.Hook { // remoteLogging starts a new rabbitmq publisher if the rabbitmq parameters are set // Warning: Must call publisher.Close() on the publisher returned from this function -func remoteLogging(cfg config.Config) *rabbitmq.Publisher { +func remoteLogging(cfg config.ExecutionSpaceConfig) *rabbitmq.Publisher { if cfg.RabbitMQHookURL() != "" { if cfg.RabbitMQHookExchangeName() == "" { panic("-rabbitmq_hook_exchange (env:ETOS_RABBITMQ_EXCHANGE) must be set when using -rabbitmq_hook_url (env:ETOS_RABBITMQ_URL)") diff --git a/cmd/iut/main.go b/cmd/iut/main.go index 19cb0bd..65548a3 100644 --- a/cmd/iut/main.go +++ b/cmd/iut/main.go @@ -24,7 +24,7 @@ import ( "syscall" "time" - config "github.com/eiffel-community/etos-api/internal/configs/iut" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/logging" server "github.com/eiffel-community/etos-api/internal/server" "github.com/eiffel-community/etos-api/pkg/application" @@ -37,7 +37,7 @@ import ( // main sets up logging and starts up the webserver. func main() { - cfg := config.Get() + cfg := config.NewIUTConfig() ctx := context.Background() var hooks []logrus.Hook diff --git a/cmd/logarea/main.go b/cmd/logarea/main.go index 7ce6c3e..4715812 100644 --- a/cmd/logarea/main.go +++ b/cmd/logarea/main.go @@ -24,7 +24,7 @@ import ( "syscall" "time" - config "github.com/eiffel-community/etos-api/internal/configs/logarea" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/logging" "github.com/eiffel-community/etos-api/internal/server" "github.com/eiffel-community/etos-api/pkg/application" @@ -36,7 +36,7 @@ import ( // main sets up logging and starts up the logarea webservice. func main() { - cfg := config.Get() + cfg := config.NewLogAreaConfig() ctx := context.Background() var hooks []logrus.Hook diff --git a/cmd/sse/main.go b/cmd/sse/main.go index c18b87d..5037335 100644 --- a/cmd/sse/main.go +++ b/cmd/sse/main.go @@ -24,7 +24,7 @@ import ( "syscall" "time" - config "github.com/eiffel-community/etos-api/internal/configs/sse" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/logging" "github.com/eiffel-community/etos-api/internal/server" "github.com/eiffel-community/etos-api/pkg/application" @@ -37,7 +37,7 @@ import ( // main sets up logging and starts up the sse webserver. func main() { - cfg := config.Get() + cfg := config.NewSSEConfig() ctx := context.Background() var hooks []logrus.Hook diff --git a/internal/configs/base/config.go b/internal/config/base.go similarity index 89% rename from internal/configs/base/config.go rename to internal/config/base.go index 316f5da..f5bde17 100644 --- a/internal/configs/base/config.go +++ b/internal/config/base.go @@ -32,8 +32,8 @@ type Config interface { DatabaseURI() string } -// cfg implements the Config interface. -type cfg struct { +// baseCfg implements the Config interface. +type baseCfg struct { serviceHost string servicePort string stripPrefix string @@ -44,9 +44,9 @@ type cfg struct { databasePort string } -// Get creates a config interface based on input parameters or environment variables. -func Get() Config { - var conf cfg +// load the command line vars for a base configuration. +func load() Config { + var conf baseCfg flag.StringVar(&conf.serviceHost, "address", EnvOrDefault("SERVICE_HOST", "127.0.0.1"), "Address to serve API on") flag.StringVar(&conf.servicePort, "port", EnvOrDefault("SERVICE_PORT", "8080"), "Port to serve API on") @@ -56,18 +56,16 @@ func Get() Config { flag.StringVar(&conf.etosNamespace, "etosnamespace", ReadNamespaceOrEnv("ETOS_NAMESPACE"), "Path, including filename, for the log files to create.") flag.StringVar(&conf.databaseHost, "databasehost", EnvOrDefault("ETOS_ETCD_HOST", "etcd-client"), "Host to the database.") flag.StringVar(&conf.databasePort, "databaseport", EnvOrDefault("ETOS_ETCD_PORT", "2379"), "Port to the database.") - - flag.Parse() return &conf } // ServiceHost returns the host of the service. -func (c *cfg) ServiceHost() string { +func (c *baseCfg) ServiceHost() string { return c.serviceHost } // ServicePort returns the port of the service. -func (c *cfg) ServicePort() string { +func (c *baseCfg) ServicePort() string { return c.servicePort } @@ -77,22 +75,22 @@ func (c *cfg) StripPrefix() string { } // LogLevel returns the log level. -func (c *cfg) LogLevel() string { +func (c *baseCfg) LogLevel() string { return c.logLevel } // LogFilePath returns the path to where log files should be stored, including filename. -func (c *cfg) LogFilePath() string { +func (c *baseCfg) LogFilePath() string { return c.logFilePath } // ETOSNamespace returns the ETOS namespace. -func (c *cfg) ETOSNamespace() string { +func (c *baseCfg) ETOSNamespace() string { return c.etosNamespace } // DatabaseURI returns the URI to the ETOS database. -func (c *cfg) DatabaseURI() string { +func (c *baseCfg) DatabaseURI() string { return fmt.Sprintf("%s:%s", c.databaseHost, c.databasePort) } diff --git a/internal/configs/sse/config_test.go b/internal/config/base_test.go similarity index 90% rename from internal/configs/sse/config_test.go rename to internal/config/base_test.go index abb00ee..292cd2f 100644 --- a/internal/configs/sse/config_test.go +++ b/internal/config/base_test.go @@ -16,7 +16,6 @@ package config import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -29,12 +28,12 @@ func TestGet(t *testing.T) { logLevel := "DEBUG" logFilePath := "path/to/a/file" - os.Setenv("SERVICE_HOST", serverHost) - os.Setenv("SERVICE_PORT", port) - os.Setenv("LOGLEVEL", logLevel) - os.Setenv("LOG_FILE_PATH", logFilePath) + t.Setenv("SERVICE_HOST", serverHost) + t.Setenv("SERVICE_PORT", port) + t.Setenv("LOGLEVEL", logLevel) + t.Setenv("LOG_FILE_PATH", logFilePath) - conf, ok := Get().(*cfg) + conf, ok := load().(*baseCfg) assert.Truef(t, ok, "cfg returned from get is not a config interface") assert.Equal(t, port, conf.servicePort) assert.Equal(t, serverHost, conf.serviceHost) @@ -46,7 +45,7 @@ type getter func() string // Test that the getters in the Cfg struct return the values from the struct. func TestGetters(t *testing.T) { - conf := &cfg{ + conf := &baseCfg{ serviceHost: "127.0.0.1", servicePort: "8080", logLevel: "TRACE", @@ -54,7 +53,7 @@ func TestGetters(t *testing.T) { } tests := []struct { name string - cfg *cfg + cfg *baseCfg function getter value string }{ diff --git a/internal/config/executionspace.go b/internal/config/executionspace.go new file mode 100644 index 0000000..e5ab9cd --- /dev/null +++ b/internal/config/executionspace.go @@ -0,0 +1,110 @@ +// Copyright Axis Communications AB. +// +// For a full list of individual contributors, please see the commit history. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package config + +import ( + "flag" + "os" + "time" + + "github.com/sirupsen/logrus" +) + +type ExecutionSpaceConfig interface { + Config + StripPrefix() string + Hostname() string + Timeout() time.Duration + ExecutionSpaceWaitTimeout() time.Duration + RabbitMQHookURL() string + RabbitMQHookExchangeName() string + EiffelGoerURL() string +} + +// executionSpaceCfg implements the ExecutionSpaceConfig interface. +type executionSpaceCfg struct { + Config + stripPrefix string + hostname string + timeout time.Duration + executionSpaceWaitTimeout time.Duration + rabbitmqHookURL string + rabbitmqHookExchange string + eiffelGoerURL string +} + +// NewExecutionSpaceConfig creates an executio nspace config interface based on input parameters or environment variables. +func NewExecutionSpaceConfig() ExecutionSpaceConfig { + var conf executionSpaceCfg + + defaultTimeout, err := time.ParseDuration(EnvOrDefault("REQUEST_TIMEOUT", "1m")) + if err != nil { + logrus.Panic(err) + } + + executionSpaceWaitTimeout, err := time.ParseDuration(EnvOrDefault("EXECUTION_SPACE_WAIT_TIMEOUT", "1h")) + if err != nil { + logrus.Panic(err) + } + + flag.StringVar(&conf.stripPrefix, "stripprefix", EnvOrDefault("STRIP_PREFIX", ""), "Strip prefix") + flag.StringVar(&conf.hostname, "hostname", EnvOrDefault("PROVIDER_HOSTNAME", "http://localhost"), "Host to supply to ESR for starting executors") + flag.DurationVar(&conf.timeout, "timeout", defaultTimeout, "Maximum timeout for requests to Execution space provider Service.") + flag.DurationVar(&conf.executionSpaceWaitTimeout, "executionSpaceWaitTimeout", executionSpaceWaitTimeout, "Timeout duration to wait when trying to checkout execution space(s)") + flag.StringVar(&conf.rabbitmqHookURL, "rabbitmq_hook_url", os.Getenv("ETOS_RABBITMQ_URL"), "URL to the ETOS rabbitmq for logs") + flag.StringVar(&conf.rabbitmqHookExchange, "rabbitmq_hook_exchange", os.Getenv("ETOS_RABBITMQ_EXCHANGE"), "Exchange to use for the ETOS rabbitmq for logs") + flag.StringVar(&conf.eiffelGoerURL, "event_repository_host", os.Getenv("EIFFEL_GOER_URL"), "Event repository URL used for Eiffel event lookup") + base := load() + flag.Parse() + conf.Config = base + + return &conf +} + +// StripPrefix returns a prefix that is supposed to be stripped from URL. +func (c *executionSpaceCfg) StripPrefix() string { + return c.stripPrefix +} + +// Hostname returns the hostname to use for executors. +func (c *executionSpaceCfg) Hostname() string { + return c.hostname +} + +// Timeout returns the request timeout for Execution space provider Service API. +func (c *executionSpaceCfg) Timeout() time.Duration { + return c.timeout +} + +// ExecutionSpaceWaitTimeout returns the timeout for checking out execution spaces. +func (c *executionSpaceCfg) ExecutionSpaceWaitTimeout() time.Duration { + return c.executionSpaceWaitTimeout +} + +// RabbitMQHookURL returns the rabbitmq url for ETOS logs +func (c *executionSpaceCfg) RabbitMQHookURL() string { + return c.rabbitmqHookURL +} + +// EventRepositoryURL returns the Eiffel event repository used for event lookups +func (c *executionSpaceCfg) EiffelGoerURL() string { + return c.eiffelGoerURL +} + +// RabbitMQHookExchangeName returns the rabbitmq exchange name used for ETOS logs +func (c *executionSpaceCfg) RabbitMQHookExchangeName() string { + return c.rabbitmqHookExchange +} diff --git a/internal/config/iut.go b/internal/config/iut.go new file mode 100644 index 0000000..008d34d --- /dev/null +++ b/internal/config/iut.go @@ -0,0 +1,29 @@ +// Copyright Axis Communications AB. +// +// For a full list of individual contributors, please see the commit history. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package config + +import "flag" + +type IUTConfig interface { + Config +} + +// NewIUTConfig creates an iut config interface based on input parameters or environment variables. +func NewIUTConfig() IUTConfig { + cfg := load() + flag.Parse() + return cfg +} diff --git a/internal/config/logarea.go b/internal/config/logarea.go new file mode 100644 index 0000000..fb69724 --- /dev/null +++ b/internal/config/logarea.go @@ -0,0 +1,29 @@ +// Copyright Axis Communications AB. +// +// For a full list of individual contributors, please see the commit history. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package config + +import "flag" + +type LogAreaConfig interface { + Config +} + +// NewLogAreaConfig creates a log area config interface based on input parameters or environment variables. +func NewLogAreaConfig() LogAreaConfig { + cfg := load() + flag.Parse() + return cfg +} diff --git a/internal/config/sse.go b/internal/config/sse.go new file mode 100644 index 0000000..7052089 --- /dev/null +++ b/internal/config/sse.go @@ -0,0 +1,29 @@ +// Copyright Axis Communications AB. +// +// For a full list of individual contributors, please see the commit history. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package config + +import "flag" + +type SSEConfig interface { + Config +} + +// NewSSEConfig creates a sse config interface based on input parameters or environment variables. +func NewSSEConfig() SSEConfig { + cfg := load() + flag.Parse() + return cfg +} diff --git a/internal/configs/base/config_test.go b/internal/configs/base/config_test.go deleted file mode 100644 index abb00ee..0000000 --- a/internal/configs/base/config_test.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -// Test that it is possible to get a Cfg from Get with values taken from environment variables. -func TestGet(t *testing.T) { - port := "8080" - serverHost := "127.0.0.1" - logLevel := "DEBUG" - logFilePath := "path/to/a/file" - - os.Setenv("SERVICE_HOST", serverHost) - os.Setenv("SERVICE_PORT", port) - os.Setenv("LOGLEVEL", logLevel) - os.Setenv("LOG_FILE_PATH", logFilePath) - - conf, ok := Get().(*cfg) - assert.Truef(t, ok, "cfg returned from get is not a config interface") - assert.Equal(t, port, conf.servicePort) - assert.Equal(t, serverHost, conf.serviceHost) - assert.Equal(t, logLevel, conf.logLevel) - assert.Equal(t, logFilePath, conf.logFilePath) -} - -type getter func() string - -// Test that the getters in the Cfg struct return the values from the struct. -func TestGetters(t *testing.T) { - conf := &cfg{ - serviceHost: "127.0.0.1", - servicePort: "8080", - logLevel: "TRACE", - logFilePath: "a/file/path.json", - } - tests := []struct { - name string - cfg *cfg - function getter - value string - }{ - {name: "ServiceHost", cfg: conf, function: conf.ServiceHost, value: conf.serviceHost}, - {name: "ServicePort", cfg: conf, function: conf.ServicePort, value: conf.servicePort}, - {name: "LogLevel", cfg: conf, function: conf.LogLevel, value: conf.logLevel}, - {name: "LogFilePath", cfg: conf, function: conf.LogFilePath, value: conf.logFilePath}, - } - for _, testCase := range tests { - t.Run(testCase.name, func(t *testing.T) { - assert.Equal(t, testCase.value, testCase.function()) - }) - } -} diff --git a/internal/configs/executionspace/config.go b/internal/configs/executionspace/config.go deleted file mode 100644 index 63e4b78..0000000 --- a/internal/configs/executionspace/config.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "flag" - "fmt" - "os" - "time" - - "github.com/sirupsen/logrus" -) - -// Config interface for retreiving configuration options. -type Config interface { - ServiceHost() string - ServicePort() string - StripPrefix() string - Hostname() string - LogLevel() string - LogFilePath() string - Timeout() time.Duration - ExecutionSpaceWaitTimeout() time.Duration - RabbitMQHookURL() string - RabbitMQHookExchangeName() string - DatabaseURI() string - ETOSNamespace() string - EiffelGoerURL() string -} - -// cfg implements the Config interface. -type cfg struct { - serviceHost string - servicePort string - stripPrefix string - hostname string - logLevel string - logFilePath string - timeout time.Duration - databaseHost string - databasePort string - executionSpaceWaitTimeout time.Duration - rabbitmqHookURL string - rabbitmqHookExchange string - eiffelGoerURL string - etosNamespace string -} - -// Get creates a config interface based on input parameters or environment variables. -func Get() Config { - var conf cfg - - defaultTimeout, err := time.ParseDuration(EnvOrDefault("REQUEST_TIMEOUT", "1m")) - if err != nil { - logrus.Panic(err) - } - - executionSpaceWaitTimeout, err := time.ParseDuration(EnvOrDefault("EXECUTION_SPACE_WAIT_TIMEOUT", "1h")) - if err != nil { - logrus.Panic(err) - } - - flag.StringVar(&conf.serviceHost, "address", EnvOrDefault("SERVICE_HOST", "127.0.0.1"), "Address to serve API on") - flag.StringVar(&conf.servicePort, "port", EnvOrDefault("SERVICE_PORT", "8080"), "Port to serve API on") - flag.StringVar(&conf.stripPrefix, "stripprefix", EnvOrDefault("STRIP_PREFIX", ""), "Strip prefix") - flag.StringVar(&conf.hostname, "hostname", EnvOrDefault("PROVIDER_HOSTNAME", "http://localhost"), "Host to supply to ESR for starting executors") - flag.StringVar(&conf.logLevel, "loglevel", EnvOrDefault("LOGLEVEL", "INFO"), "Log level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC).") - flag.StringVar(&conf.logFilePath, "logfilepath", os.Getenv("LOG_FILE_PATH"), "Path, including filename, for the log files to create.") - flag.DurationVar(&conf.timeout, "timeout", defaultTimeout, "Maximum timeout for requests to Execution space provider Service.") - flag.StringVar(&conf.databaseHost, "database_host", EnvOrDefault("ETOS_ETCD_HOST", "etcd-client"), "Host to ETOS database") - flag.StringVar(&conf.databasePort, "database_port", EnvOrDefault("ETOS_ETCD_PORT", "2379"), "Port to ETOS database") - flag.StringVar(&conf.etosNamespace, "etos_namespace", os.Getenv("ETOS_NAMESPACE"), "Namespace to start testrunner k8s jobs") - flag.DurationVar(&conf.executionSpaceWaitTimeout, "execution space wait timeout", executionSpaceWaitTimeout, "Timeout duration to wait when trying to checkout execution space(s)") - flag.StringVar(&conf.rabbitmqHookURL, "rabbitmq_hook_url", os.Getenv("ETOS_RABBITMQ_URL"), "URL to the ETOS rabbitmq for logs") - flag.StringVar(&conf.rabbitmqHookExchange, "rabbitmq_hook_exchange", os.Getenv("ETOS_RABBITMQ_EXCHANGE"), "Exchange to use for the ETOS rabbitmq for logs") - flag.StringVar(&conf.eiffelGoerURL, "event_repository_host", os.Getenv("EIFFEL_GOER_URL"), "Event repository URL used for Eiffel event lookup") - flag.Parse() - return &conf -} - -// ServiceHost returns the host of the service. -func (c *cfg) ServiceHost() string { - return c.serviceHost -} - -// ServicePort returns the port of the service. -func (c *cfg) ServicePort() string { - return c.servicePort -} - -// StripPrefix returns a prefix that is supposed to be stripped from URL. -func (c *cfg) StripPrefix() string { - return c.stripPrefix -} - -// Hostname returns the hostname to use for executors -func (c *cfg) Hostname() string { - return c.hostname -} - -// LogLevel returns the log level. -func (c *cfg) LogLevel() string { - return c.logLevel -} - -// LogFilePath returns the path to where log files should be stored, including filename. -func (c *cfg) LogFilePath() string { - return c.logFilePath -} - -// Timeout returns the request timeout for Execution space provider Service API. -func (c *cfg) Timeout() time.Duration { - return c.timeout -} - -// ExecutionSpaceWaitTimeout returns the timeout for checking out execution spaces. -func (c *cfg) ExecutionSpaceWaitTimeout() time.Duration { - return c.executionSpaceWaitTimeout -} - -// RabbitMQHookURL returns the rabbitmq url for ETOS logs -func (c *cfg) RabbitMQHookURL() string { - return c.rabbitmqHookURL -} - -// EventRepositoryURL returns the Eiffel event repository used for event lookups -func (c *cfg) EiffelGoerURL() string { - return c.eiffelGoerURL -} - -// RabbitMQHookExchangeName returns the rabbitmq exchange name used for ETOS logs -func (c *cfg) RabbitMQHookExchangeName() string { - return c.rabbitmqHookExchange -} - -// DatabaseURI returns the URI to the ETOS database. -func (c *cfg) DatabaseURI() string { - return fmt.Sprintf("%s:%s", c.databaseHost, c.databasePort) -} - -// ETOSNamespace returns the namespace where k8s jobs shall be deployed. -func (c *cfg) ETOSNamespace() string { - return c.etosNamespace -} - -// EnvOrDefault will look up key in environment variables and return if it exists, else return the fallback value. -func EnvOrDefault(key, fallback string) string { - if value, ok := os.LookupEnv(key); ok { - return value - } - return fallback -} diff --git a/internal/configs/executionspace/config_test.go b/internal/configs/executionspace/config_test.go deleted file mode 100644 index a8698a1..0000000 --- a/internal/configs/executionspace/config_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "os" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -// Test that it is possible to get a Cfg from Get with values taken from environment variables. -func TestGet(t *testing.T) { - port := "8080" - serverHost := "127.0.0.1" - logLevel := "DEBUG" - logFilePath := "path/to/a/file" - timeoutStr := "1m" - - os.Setenv("SERVICE_HOST", serverHost) - os.Setenv("SERVICE_PORT", port) - os.Setenv("LOGLEVEL", logLevel) - os.Setenv("LOG_FILE_PATH", logFilePath) - os.Setenv("REQUEST_TIMEOUT", timeoutStr) - - timeout, _ := time.ParseDuration(timeoutStr) - - conf, ok := Get().(*cfg) - assert.Truef(t, ok, "cfg returned from get is not a config interface") - assert.Equal(t, port, conf.servicePort) - assert.Equal(t, serverHost, conf.serviceHost) - assert.Equal(t, logLevel, conf.logLevel) - assert.Equal(t, logFilePath, conf.logFilePath) - assert.Equal(t, timeout, conf.timeout) -} - -type getter func() string - -// Test that the getters in the Cfg struct return the values from the struct. -func TestGetters(t *testing.T) { - conf := &cfg{ - serviceHost: "127.0.0.1", - servicePort: "8080", - logLevel: "TRACE", - logFilePath: "a/file/path.json", - } - tests := []struct { - name string - cfg *cfg - function getter - value string - }{ - {name: "ServiceHost", cfg: conf, function: conf.ServiceHost, value: conf.serviceHost}, - {name: "ServicePort", cfg: conf, function: conf.ServicePort, value: conf.servicePort}, - {name: "LogLevel", cfg: conf, function: conf.LogLevel, value: conf.logLevel}, - {name: "LogFilePath", cfg: conf, function: conf.LogFilePath, value: conf.logFilePath}, - } - for _, testCase := range tests { - t.Run(testCase.name, func(t *testing.T) { - assert.Equal(t, testCase.value, testCase.function()) - }) - } -} - -// TestTimeoutGetter tests the getter for Timeout. Similar to TestGetters, but since -// Timeout is not a "func() string" we separate its test. -func TestTimeoutGetter(t *testing.T) { - timeout, _ := time.ParseDuration("1m") - conf := &cfg{ - timeout: timeout, - } - assert.Equal(t, conf.timeout, conf.Timeout()) -} diff --git a/internal/configs/iut/config.go b/internal/configs/iut/config.go deleted file mode 100644 index b945115..0000000 --- a/internal/configs/iut/config.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2022 Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "flag" - "fmt" - "os" -) - -// Config interface for retrieving configuration options. -type Config interface { - ServiceHost() string - ServicePort() string - StripPrefix() string - LogLevel() string - LogFilePath() string - ETOSNamespace() string - DatabaseURI() string -} - -// cfg implements the Config interface. -type cfg struct { - serviceHost string - servicePort string - stripPrefix string - logLevel string - logFilePath string - etosNamespace string - databaseHost string - databasePort string -} - -// Get creates a config interface based on input parameters or environment variables. -func Get() Config { - var conf cfg - - flag.StringVar(&conf.serviceHost, "address", EnvOrDefault("SERVICE_HOST", "127.0.0.1"), "Address to serve API on") - flag.StringVar(&conf.servicePort, "port", EnvOrDefault("SERVICE_PORT", "8080"), "Port to serve API on") - flag.StringVar(&conf.stripPrefix, "stripprefix", EnvOrDefault("STRIP_PREFIX", ""), "Strip a URL prefix. Useful when a reverse proxy sets a subpath. I.e. reverse proxy sets /stream as prefix, making the etos API available at /stream/v1/events. In that case we want to set stripprefix to /stream") - flag.StringVar(&conf.logLevel, "loglevel", EnvOrDefault("LOGLEVEL", "INFO"), "Log level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC).") - flag.StringVar(&conf.logFilePath, "logfilepath", os.Getenv("LOG_FILE_PATH"), "Path, including filename, for the log files to create.") - flag.StringVar(&conf.databaseHost, "database_host", EnvOrDefault("ETOS_ETCD_HOST", "etcd-client"), "Host to ETOS database") - flag.StringVar(&conf.databasePort, "database_port", EnvOrDefault("ETOS_ETCD_PORT", "2379"), "Port to ETOS database") - flag.Parse() - - return &conf -} - -// ServiceHost returns the host of the service. -func (c *cfg) ServiceHost() string { - return c.serviceHost -} - -// ServicePort returns the port of the service. -func (c *cfg) ServicePort() string { - return c.servicePort -} - -// StripPrefix returns the prefix to strip. Empty string if no prefix. -func (c *cfg) StripPrefix() string { - return c.stripPrefix -} - -// LogLevel returns the log level. -func (c *cfg) LogLevel() string { - return c.logLevel -} - -// LogFilePath returns the path to where log files should be stored, including filename. -func (c *cfg) LogFilePath() string { - return c.logFilePath -} - -// ETOSNamespace returns the ETOS namespace. -func (c *cfg) ETOSNamespace() string { - return c.etosNamespace -} - -// DatabaseURI returns the URI to the ETOS database. -func (c *cfg) DatabaseURI() string { - return fmt.Sprintf("%s:%s", c.databaseHost, c.databasePort) -} - -// EnvOrDefault will look up key in environment variables and return if it exists, else return the fallback value. -func EnvOrDefault(key, fallback string) string { - if value, ok := os.LookupEnv(key); ok { - return value - } - return fallback -} diff --git a/internal/configs/iut/config_test.go b/internal/configs/iut/config_test.go deleted file mode 100644 index b5039da..0000000 --- a/internal/configs/iut/config_test.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2022 Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "fmt" - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -// Test that it is possible to get a Cfg from Get with values taken from environment variables. -func TestGet(t *testing.T) { - port := "8080" - serverHost := "127.0.0.1" - logLevel := "DEBUG" - logFilePath := "path/to/a/file" - databaseHost := "etcd" - databasePort := "12345" - - os.Setenv("SERVICE_HOST", serverHost) - os.Setenv("SERVICE_PORT", port) - os.Setenv("LOGLEVEL", logLevel) - os.Setenv("LOG_FILE_PATH", logFilePath) - os.Setenv("ETOS_ETCD_HOST", databaseHost) - os.Setenv("ETOS_ETCD_PORT", databasePort) - - conf, ok := Get().(*cfg) - assert.Truef(t, ok, "cfg returned from get is not a config interface") - assert.Equal(t, port, conf.servicePort) - assert.Equal(t, serverHost, conf.serviceHost) - assert.Equal(t, logLevel, conf.logLevel) - assert.Equal(t, logFilePath, conf.logFilePath) - assert.Equal(t, databaseHost, conf.databaseHost) - assert.Equal(t, databasePort, conf.databasePort) -} - -type getter func() string - -// Test that the getters in the Cfg struct return the values from the struct. -func TestGetters(t *testing.T) { - conf := &cfg{ - serviceHost: "127.0.0.1", - servicePort: "8080", - logLevel: "TRACE", - logFilePath: "a/file/path.json", - databaseHost: "etcd", - databasePort: "12345", - } - tests := []struct { - name string - cfg *cfg - function getter - value string - }{ - {name: "ServiceHost", cfg: conf, function: conf.ServiceHost, value: conf.serviceHost}, - {name: "ServicePort", cfg: conf, function: conf.ServicePort, value: conf.servicePort}, - {name: "LogLevel", cfg: conf, function: conf.LogLevel, value: conf.logLevel}, - {name: "LogFilePath", cfg: conf, function: conf.LogFilePath, value: conf.logFilePath}, - {name: "DatabaseURI", cfg: conf, function: conf.DatabaseURI, value: fmt.Sprintf("%s:%s", conf.databaseHost, conf.databasePort)}, - } - for _, testCase := range tests { - t.Run(testCase.name, func(t *testing.T) { - assert.Equal(t, testCase.value, testCase.function()) - }) - } -} diff --git a/internal/configs/logarea/config.go b/internal/configs/logarea/config.go deleted file mode 100644 index 316f5da..0000000 --- a/internal/configs/logarea/config.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "flag" - "fmt" - "os" -) - -// Config interface for retreiving configuration options. -type Config interface { - ServiceHost() string - ServicePort() string - StripPrefix() string - LogLevel() string - LogFilePath() string - ETOSNamespace() string - DatabaseURI() string -} - -// cfg implements the Config interface. -type cfg struct { - serviceHost string - servicePort string - stripPrefix string - logLevel string - logFilePath string - etosNamespace string - databaseHost string - databasePort string -} - -// Get creates a config interface based on input parameters or environment variables. -func Get() Config { - var conf cfg - - flag.StringVar(&conf.serviceHost, "address", EnvOrDefault("SERVICE_HOST", "127.0.0.1"), "Address to serve API on") - flag.StringVar(&conf.servicePort, "port", EnvOrDefault("SERVICE_PORT", "8080"), "Port to serve API on") - flag.StringVar(&conf.stripPrefix, "stripprefix", EnvOrDefault("STRIP_PREFIX", ""), "Strip a URL prefix. Useful when a reverse proxy sets a subpath. I.e. reverse proxy sets /stream as prefix, making the etos API available at /stream/v1/events. In that case we want to set stripprefix to /stream") - flag.StringVar(&conf.logLevel, "loglevel", EnvOrDefault("LOGLEVEL", "INFO"), "Log level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC).") - flag.StringVar(&conf.logFilePath, "logfilepath", os.Getenv("LOG_FILE_PATH"), "Path, including filename, for the log files to create.") - flag.StringVar(&conf.etosNamespace, "etosnamespace", ReadNamespaceOrEnv("ETOS_NAMESPACE"), "Path, including filename, for the log files to create.") - flag.StringVar(&conf.databaseHost, "databasehost", EnvOrDefault("ETOS_ETCD_HOST", "etcd-client"), "Host to the database.") - flag.StringVar(&conf.databasePort, "databaseport", EnvOrDefault("ETOS_ETCD_PORT", "2379"), "Port to the database.") - - flag.Parse() - return &conf -} - -// ServiceHost returns the host of the service. -func (c *cfg) ServiceHost() string { - return c.serviceHost -} - -// ServicePort returns the port of the service. -func (c *cfg) ServicePort() string { - return c.servicePort -} - -// StripPrefix returns the prefix to strip. Empty string if no prefix. -func (c *cfg) StripPrefix() string { - return c.stripPrefix -} - -// LogLevel returns the log level. -func (c *cfg) LogLevel() string { - return c.logLevel -} - -// LogFilePath returns the path to where log files should be stored, including filename. -func (c *cfg) LogFilePath() string { - return c.logFilePath -} - -// ETOSNamespace returns the ETOS namespace. -func (c *cfg) ETOSNamespace() string { - return c.etosNamespace -} - -// DatabaseURI returns the URI to the ETOS database. -func (c *cfg) DatabaseURI() string { - return fmt.Sprintf("%s:%s", c.databaseHost, c.databasePort) -} - -// EnvOrDefault will look up key in environment variables and return if it exists, else return the fallback value. -func EnvOrDefault(key, fallback string) string { - if value, ok := os.LookupEnv(key); ok { - return value - } - return fallback -} - -// ReadNamespaceOrEnv checks if there's a nemspace file inside the container, else returns -// environment variable with envKey as name. -func ReadNamespaceOrEnv(envKey string) string { - inClusterNamespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") - if err != nil { - return os.Getenv(envKey) - } - return string(inClusterNamespace) -} diff --git a/internal/configs/logarea/config_test.go b/internal/configs/logarea/config_test.go deleted file mode 100644 index abb00ee..0000000 --- a/internal/configs/logarea/config_test.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -// Test that it is possible to get a Cfg from Get with values taken from environment variables. -func TestGet(t *testing.T) { - port := "8080" - serverHost := "127.0.0.1" - logLevel := "DEBUG" - logFilePath := "path/to/a/file" - - os.Setenv("SERVICE_HOST", serverHost) - os.Setenv("SERVICE_PORT", port) - os.Setenv("LOGLEVEL", logLevel) - os.Setenv("LOG_FILE_PATH", logFilePath) - - conf, ok := Get().(*cfg) - assert.Truef(t, ok, "cfg returned from get is not a config interface") - assert.Equal(t, port, conf.servicePort) - assert.Equal(t, serverHost, conf.serviceHost) - assert.Equal(t, logLevel, conf.logLevel) - assert.Equal(t, logFilePath, conf.logFilePath) -} - -type getter func() string - -// Test that the getters in the Cfg struct return the values from the struct. -func TestGetters(t *testing.T) { - conf := &cfg{ - serviceHost: "127.0.0.1", - servicePort: "8080", - logLevel: "TRACE", - logFilePath: "a/file/path.json", - } - tests := []struct { - name string - cfg *cfg - function getter - value string - }{ - {name: "ServiceHost", cfg: conf, function: conf.ServiceHost, value: conf.serviceHost}, - {name: "ServicePort", cfg: conf, function: conf.ServicePort, value: conf.servicePort}, - {name: "LogLevel", cfg: conf, function: conf.LogLevel, value: conf.logLevel}, - {name: "LogFilePath", cfg: conf, function: conf.LogFilePath, value: conf.logFilePath}, - } - for _, testCase := range tests { - t.Run(testCase.name, func(t *testing.T) { - assert.Equal(t, testCase.value, testCase.function()) - }) - } -} diff --git a/internal/configs/sse/config.go b/internal/configs/sse/config.go deleted file mode 100644 index 316f5da..0000000 --- a/internal/configs/sse/config.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright Axis Communications AB. -// -// For a full list of individual contributors, please see the commit history. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package config - -import ( - "flag" - "fmt" - "os" -) - -// Config interface for retreiving configuration options. -type Config interface { - ServiceHost() string - ServicePort() string - StripPrefix() string - LogLevel() string - LogFilePath() string - ETOSNamespace() string - DatabaseURI() string -} - -// cfg implements the Config interface. -type cfg struct { - serviceHost string - servicePort string - stripPrefix string - logLevel string - logFilePath string - etosNamespace string - databaseHost string - databasePort string -} - -// Get creates a config interface based on input parameters or environment variables. -func Get() Config { - var conf cfg - - flag.StringVar(&conf.serviceHost, "address", EnvOrDefault("SERVICE_HOST", "127.0.0.1"), "Address to serve API on") - flag.StringVar(&conf.servicePort, "port", EnvOrDefault("SERVICE_PORT", "8080"), "Port to serve API on") - flag.StringVar(&conf.stripPrefix, "stripprefix", EnvOrDefault("STRIP_PREFIX", ""), "Strip a URL prefix. Useful when a reverse proxy sets a subpath. I.e. reverse proxy sets /stream as prefix, making the etos API available at /stream/v1/events. In that case we want to set stripprefix to /stream") - flag.StringVar(&conf.logLevel, "loglevel", EnvOrDefault("LOGLEVEL", "INFO"), "Log level (TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, PANIC).") - flag.StringVar(&conf.logFilePath, "logfilepath", os.Getenv("LOG_FILE_PATH"), "Path, including filename, for the log files to create.") - flag.StringVar(&conf.etosNamespace, "etosnamespace", ReadNamespaceOrEnv("ETOS_NAMESPACE"), "Path, including filename, for the log files to create.") - flag.StringVar(&conf.databaseHost, "databasehost", EnvOrDefault("ETOS_ETCD_HOST", "etcd-client"), "Host to the database.") - flag.StringVar(&conf.databasePort, "databaseport", EnvOrDefault("ETOS_ETCD_PORT", "2379"), "Port to the database.") - - flag.Parse() - return &conf -} - -// ServiceHost returns the host of the service. -func (c *cfg) ServiceHost() string { - return c.serviceHost -} - -// ServicePort returns the port of the service. -func (c *cfg) ServicePort() string { - return c.servicePort -} - -// StripPrefix returns the prefix to strip. Empty string if no prefix. -func (c *cfg) StripPrefix() string { - return c.stripPrefix -} - -// LogLevel returns the log level. -func (c *cfg) LogLevel() string { - return c.logLevel -} - -// LogFilePath returns the path to where log files should be stored, including filename. -func (c *cfg) LogFilePath() string { - return c.logFilePath -} - -// ETOSNamespace returns the ETOS namespace. -func (c *cfg) ETOSNamespace() string { - return c.etosNamespace -} - -// DatabaseURI returns the URI to the ETOS database. -func (c *cfg) DatabaseURI() string { - return fmt.Sprintf("%s:%s", c.databaseHost, c.databasePort) -} - -// EnvOrDefault will look up key in environment variables and return if it exists, else return the fallback value. -func EnvOrDefault(key, fallback string) string { - if value, ok := os.LookupEnv(key); ok { - return value - } - return fallback -} - -// ReadNamespaceOrEnv checks if there's a nemspace file inside the container, else returns -// environment variable with envKey as name. -func ReadNamespaceOrEnv(envKey string) string { - inClusterNamespace, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") - if err != nil { - return os.Getenv(envKey) - } - return string(inClusterNamespace) -} diff --git a/internal/database/etcd/etcd.go b/internal/database/etcd/etcd.go index c57fdaa..f54e814 100644 --- a/internal/database/etcd/etcd.go +++ b/internal/database/etcd/etcd.go @@ -22,7 +22,7 @@ import ( "io" "time" - config "github.com/eiffel-community/etos-api/internal/configs/base" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/database" "github.com/google/uuid" "github.com/sirupsen/logrus" diff --git a/internal/executionspace/provider/kubernetes.go b/internal/executionspace/provider/kubernetes.go index 97c5b71..9aa833c 100644 --- a/internal/executionspace/provider/kubernetes.go +++ b/internal/executionspace/provider/kubernetes.go @@ -19,7 +19,7 @@ import ( "fmt" "sync" - config "github.com/eiffel-community/etos-api/internal/configs/executionspace" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/database" "github.com/eiffel-community/etos-api/internal/executionspace/executor" ) @@ -29,7 +29,7 @@ type Kubernetes struct { } // New creates a copy of a Kubernetes provider -func (k Kubernetes) New(db database.Opener, cfg config.Config) Provider { +func (k Kubernetes) New(db database.Opener, cfg config.ExecutionSpaceConfig) Provider { return &Kubernetes{ providerCore{ db: db, diff --git a/internal/executionspace/provider/provider.go b/internal/executionspace/provider/provider.go index a73a4ff..6a5ec35 100644 --- a/internal/executionspace/provider/provider.go +++ b/internal/executionspace/provider/provider.go @@ -19,7 +19,7 @@ import ( "context" "sync" - config "github.com/eiffel-community/etos-api/internal/configs/executionspace" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/database" "github.com/eiffel-community/etos-api/internal/executionspace/executor" "github.com/eiffel-community/etos-api/pkg/executionspace/executionspace" @@ -28,7 +28,7 @@ import ( ) type Provider interface { - New(database.Opener, config.Config) Provider + New(database.Opener, config.ExecutionSpaceConfig) Provider Status(*logrus.Entry, context.Context, uuid.UUID) (*executionspace.ExecutionSpace, error) Checkout(*logrus.Entry, context.Context, ExecutorConfig) Checkin(*logrus.Entry, context.Context, []executionspace.ExecutorSpec) error @@ -52,7 +52,7 @@ type ExecutorConfig struct { // be included into another struct that implements the rest of the interface. type providerCore struct { db database.Opener - cfg config.Config + cfg config.ExecutionSpaceConfig url string active *sync.WaitGroup executor executor.Executor diff --git a/internal/kubernetes/kubernetes.go b/internal/kubernetes/kubernetes.go index cb8bee7..a43a955 100644 --- a/internal/kubernetes/kubernetes.go +++ b/internal/kubernetes/kubernetes.go @@ -19,7 +19,7 @@ import ( "context" "fmt" - config "github.com/eiffel-community/etos-api/internal/configs/base" + "github.com/eiffel-community/etos-api/internal/config" "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" diff --git a/internal/server/server.go b/internal/server/server.go index 47c5698..6c8cba7 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -20,7 +20,7 @@ import ( "fmt" "net/http" - config "github.com/eiffel-community/etos-api/internal/configs/base" + "github.com/eiffel-community/etos-api/internal/config" "github.com/sirupsen/logrus" ) diff --git a/pkg/executionspace/v1alpha/executor.go b/pkg/executionspace/v1alpha/executor.go index e98f4e1..eafe573 100644 --- a/pkg/executionspace/v1alpha/executor.go +++ b/pkg/executionspace/v1alpha/executor.go @@ -24,7 +24,7 @@ import ( "time" "github.com/eiffel-community/eiffelevents-sdk-go" - config "github.com/eiffel-community/etos-api/internal/configs/executionspace" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/eventrepository" "github.com/eiffel-community/etos-api/internal/executionspace/executor" "github.com/eiffel-community/etos-api/pkg/executionspace/executionspace" @@ -176,7 +176,7 @@ type state struct { } // getSubSuite gets a sub suite from event repository -func (s *state) getSubSuite(ctx context.Context, cfg config.Config) (*eiffelevents.TestSuiteStartedV3, error) { +func (s *state) getSubSuite(ctx context.Context, cfg config.ExecutionSpaceConfig) (*eiffelevents.TestSuiteStartedV3, error) { if s.environment == nil { event, err := eventrepository.EnvironmentDefined(ctx, cfg.EiffelGoerURL(), s.ExecutorSpec.Instructions.Environment["ENVIRONMENT_ID"]) if err != nil { @@ -202,7 +202,7 @@ func (s *state) getSubSuite(ctx context.Context, cfg config.Config) (*eiffeleven } // waitStart waits for a job to start completely -func (s *state) waitStart(ctx context.Context, cfg config.Config, logger *logrus.Entry, executor executor.Executor) error { +func (s *state) waitStart(ctx context.Context, cfg config.ExecutionSpaceConfig, logger *logrus.Entry, executor executor.Executor) error { var event *eiffelevents.TestSuiteStartedV3 var err error if err = retry.Constant(ctx, 5*time.Second, func(ctx context.Context) error { diff --git a/pkg/executionspace/v1alpha/provider.go b/pkg/executionspace/v1alpha/provider.go index 0bbfd69..a03bbfd 100644 --- a/pkg/executionspace/v1alpha/provider.go +++ b/pkg/executionspace/v1alpha/provider.go @@ -28,7 +28,7 @@ import ( "sync" "github.com/eiffel-community/eiffelevents-sdk-go" - config "github.com/eiffel-community/etos-api/internal/configs/executionspace" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/executionspace/provider" "github.com/eiffel-community/etos-api/pkg/application" httperrors "github.com/eiffel-community/etos-api/pkg/executionspace/errors" @@ -57,14 +57,14 @@ var ( type ProviderServiceApplication struct { logger *logrus.Entry - cfg config.Config + cfg config.ExecutionSpaceConfig provider provider.Provider wg *sync.WaitGroup } type ProviderServiceHandler struct { logger *logrus.Entry - cfg config.Config + cfg config.ExecutionSpaceConfig provider provider.Provider wg *sync.WaitGroup } @@ -150,7 +150,7 @@ func (a *ProviderServiceApplication) Close() { } // New returns a new ProviderServiceApplication object/struct -func New(cfg config.Config, log *logrus.Entry, provider provider.Provider, ctx context.Context) application.Application { +func New(cfg config.ExecutionSpaceConfig, log *logrus.Entry, provider provider.Provider, ctx context.Context) application.Application { return &ProviderServiceApplication{ logger: log, cfg: cfg, diff --git a/pkg/iut/v1alpha1/v1alpha1.go b/pkg/iut/v1alpha1/v1alpha1.go index 53f356c..b4ad7f1 100644 --- a/pkg/iut/v1alpha1/v1alpha1.go +++ b/pkg/iut/v1alpha1/v1alpha1.go @@ -25,7 +25,7 @@ import ( "time" eiffelevents "github.com/eiffel-community/eiffelevents-sdk-go" - config "github.com/eiffel-community/etos-api/internal/configs/iut" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/pkg/application" packageurl "github.com/package-url/packageurl-go" clientv3 "go.etcd.io/etcd/client/v3" @@ -37,20 +37,19 @@ import ( type V1Alpha1Application struct { logger *logrus.Entry - cfg config.Config + cfg config.IUTConfig database *clientv3.Client wg *sync.WaitGroup } type V1Alpha1Handler struct { logger *logrus.Entry - cfg config.Config + cfg config.IUTConfig database *clientv3.Client wg *sync.WaitGroup } -type Dataset struct { -} +type Dataset struct{} // RespondWithJSON writes a JSON response with a status code to the HTTP ResponseWriter. func RespondWithJSON(w http.ResponseWriter, code int, payload interface{}) { @@ -72,7 +71,7 @@ func (a *V1Alpha1Application) Close() { } // New returns a new V1Alpha1Application object/struct -func New(cfg config.Config, log *logrus.Entry, ctx context.Context, cli *clientv3.Client) application.Application { +func New(cfg config.IUTConfig, log *logrus.Entry, ctx context.Context, cli *clientv3.Client) application.Application { return &V1Alpha1Application{ logger: log, cfg: cfg, diff --git a/pkg/logarea/v1alpha/logarea.go b/pkg/logarea/v1alpha/logarea.go index 3b016c3..6ad8bd3 100644 --- a/pkg/logarea/v1alpha/logarea.go +++ b/pkg/logarea/v1alpha/logarea.go @@ -25,7 +25,7 @@ import ( "runtime" "time" - config "github.com/eiffel-community/etos-api/internal/configs/logarea" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/pkg/application" "github.com/julienschmidt/httprouter" "github.com/sirupsen/logrus" @@ -40,14 +40,14 @@ const ( type LogAreaApplication struct { logger *logrus.Entry - cfg config.Config + cfg config.LogAreaConfig client *clientv3.Client regex *regexp.Regexp } type LogAreaHandler struct { logger *logrus.Entry - cfg config.Config + cfg config.LogAreaConfig client *clientv3.Client regex *regexp.Regexp } @@ -58,7 +58,7 @@ func (a *LogAreaApplication) Close() { } // New returns a new LogAreaApplication object/struct. -func New(cfg config.Config, log *logrus.Entry) application.Application { +func New(cfg config.LogAreaConfig, log *logrus.Entry) application.Application { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{cfg.DatabaseURI()}, DialTimeout: 5 * time.Second, diff --git a/pkg/sse/v1/sse.go b/pkg/sse/v1/sse.go index b9ab450..c9a809c 100644 --- a/pkg/sse/v1/sse.go +++ b/pkg/sse/v1/sse.go @@ -25,7 +25,7 @@ import ( "strconv" "time" - config "github.com/eiffel-community/etos-api/internal/configs/sse" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/kubernetes" "github.com/eiffel-community/etos-api/pkg/application" "github.com/eiffel-community/etos-api/pkg/events" @@ -35,14 +35,14 @@ import ( type SSEApplication struct { logger *logrus.Entry - cfg config.Config + cfg config.SSEConfig ctx context.Context cancel context.CancelFunc } type SSEHandler struct { logger *logrus.Entry - cfg config.Config + cfg config.SSEConfig ctx context.Context kube *kubernetes.Kubernetes } @@ -53,7 +53,7 @@ func (a *SSEApplication) Close() { } // New returns a new SSEApplication object/struct -func New(cfg config.Config, log *logrus.Entry, ctx context.Context) application.Application { +func New(cfg config.SSEConfig, log *logrus.Entry, ctx context.Context) application.Application { ctx, cancel := context.WithCancel(ctx) return &SSEApplication{ logger: log, diff --git a/pkg/sse/v1alpha/sse.go b/pkg/sse/v1alpha/sse.go index aaf50b2..5b90c9d 100644 --- a/pkg/sse/v1alpha/sse.go +++ b/pkg/sse/v1alpha/sse.go @@ -27,7 +27,7 @@ import ( "strconv" "time" - config "github.com/eiffel-community/etos-api/internal/configs/sse" + "github.com/eiffel-community/etos-api/internal/config" "github.com/eiffel-community/etos-api/internal/kubernetes" "github.com/eiffel-community/etos-api/pkg/application" "github.com/eiffel-community/etos-api/pkg/events" @@ -37,14 +37,14 @@ import ( type SSEApplication struct { logger *logrus.Entry - cfg config.Config + cfg config.SSEConfig ctx context.Context cancel context.CancelFunc } type SSEHandler struct { logger *logrus.Entry - cfg config.Config + cfg config.SSEConfig ctx context.Context kube *kubernetes.Kubernetes } @@ -55,7 +55,7 @@ func (a *SSEApplication) Close() { } // New returns a new SSEApplication object/struct -func New(cfg config.Config, log *logrus.Entry, ctx context.Context) application.Application { +func New(cfg config.SSEConfig, log *logrus.Entry, ctx context.Context) application.Application { ctx, cancel := context.WithCancel(ctx) return &SSEApplication{ logger: log, diff --git a/test/testconfig/testconfig.go b/test/testconfig/testconfig.go index 3c8b004..85b0e80 100644 --- a/test/testconfig/testconfig.go +++ b/test/testconfig/testconfig.go @@ -17,7 +17,7 @@ package testconfig import ( - config "github.com/eiffel-community/etos-api/internal/configs/base" + "github.com/eiffel-community/etos-api/internal/config" ) type cfg struct {