From: gyuyoung Date: Thu, 29 Aug 2024 14:30:58 +0000 (+0900) Subject: Implement the configuration data management code in modelmgmtservice X-Git-Tag: 4.0.0~30 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=b420b8a621593e2404e56ab1d59796653d110f2c;p=aiml-fw%2Fawmf%2Fmodelmgmtservice.git Implement the configuration data management code in modelmgmtservice - Add 'config' package for easy and safe handling of configuration data - Add 'godotenv' library to load environment files(ex, .env) - Update 'main.go' to utilize the new 'config' package - Modify env_loader.go to use viper package - Add new validation layer to check whether config data is valid or not - Add test codes of config package - Rebase origin HEAD - Modify 'validate error msg' to provide user with clear messages Issue-ID: AIMLFW-147 Change-Id: I3cea95f0d528c27ccf82a802759b965b06afe34d Signed-off-by: gyuyoung --- diff --git a/config/config_manager.go b/config/config_manager.go new file mode 100644 index 0000000..0a68c91 --- /dev/null +++ b/config/config_manager.go @@ -0,0 +1,54 @@ +package config + +import ( + "bytes" + "sync" +) + +var ( + manager = &configManager{} + once sync.Once +) + +type configValidator interface { + validate(*configManager) error +} + +type configLoader interface { + load(*configManager) +} + +func GetConfigManager() configManager { + return *manager +} + +// This function is executed only once, after execution you can't load config data +func Load(validator configValidator, loaders ...configLoader) error { + var err error = nil + once.Do(func() { + for _, loader := range loaders { + loader.load(manager) + } + if validator != nil { + err = validator.validate(manager) + } + }) + return err +} + +type configManager struct { + App AppConfigData + DB DBConfigData +} + +func (c configManager) String() string { + var buf bytes.Buffer + buf.WriteString("------------Config Data------------") + buf.WriteString("\n") + buf.WriteString(c.App.String()) + buf.WriteString("\n") + buf.WriteString(c.DB.String()) + buf.WriteString("\n") + buf.WriteString("-----------------------------------") + return buf.String() +} diff --git a/config/config_manager_test.go b/config/config_manager_test.go new file mode 100644 index 0000000..3012163 --- /dev/null +++ b/config/config_manager_test.go @@ -0,0 +1,74 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLoadWhenSuccess(t *testing.T) { + defaultEnvData := DefaultEnvData{ + ENV_KEY_DB_S3_SECRET_KEY: "secret", + ENV_KEY_DB_INFO_FILE_POSTFIX: "_test.info", + ENV_KEY_DB_MODEL_FILE_POSTFIX: "_test.zip", + } + unsetFunc := osSetData(defaultEnvData) + defer unsetFunc() + + Load(nil, NewEnvDataLoader(nil)) + assert.Equal(t, "secret", manager.DB.S3_SECRET_KEY) + assert.Equal(t, "_test.info", manager.DB.INFO_FILE_POSTFIX) + assert.Equal(t, "_test.zip", manager.DB.MODEL_FILE_POSTFIX) +} + +func TestLoadWhenCalledTwice(t *testing.T) { + defaultEnvData := DefaultEnvData{ + ENV_KEY_DB_S3_SECRET_KEY: "secret", + } + unsetFunc := osSetData(defaultEnvData) + defer unsetFunc() + + Load(nil, NewEnvDataLoader(nil)) + + assert.Equal(t, "secret", manager.DB.S3_SECRET_KEY) + + defaultEnvData = DefaultEnvData{ + ENV_KEY_DB_S3_SECRET_KEY: "secret2", + } + unsetFunc = osSetData(defaultEnvData) + defer unsetFunc() + Load(nil, NewEnvDataLoader(nil)) + + assert.Equal(t, "secret", manager.DB.S3_SECRET_KEY) +} + +func TestGetConfigManagerWhenTriedToOverWrite(t *testing.T) { + defaultEnvData := DefaultEnvData{ + ENV_KEY_DB_S3_SECRET_KEY: "secret", + } + unsetFunc := osSetData(defaultEnvData) + defer unsetFunc() + + configManagerInstance := GetConfigManager() + + assert.Equal(t, "secret", configManagerInstance.DB.S3_SECRET_KEY) + + configManagerInstance.DB.S3_SECRET_KEY = "secret2" + + configManagerInstance = GetConfigManager() + assert.Equal(t, "secret", configManagerInstance.DB.S3_SECRET_KEY) +} + +// Please check plain text log manually +func TestConfigManagerString(t *testing.T) { + defaultEnvData := DefaultEnvData{ + ENV_KEY_DB_S3_SECRET_KEY: "secret", + } + unsetFunc := osSetData(defaultEnvData) + defer unsetFunc() + + configManagerInstance := GetConfigManager() + summary := configManagerInstance.String() + + assert.NotEmpty(t, summary) +} diff --git a/config/data.go b/config/data.go new file mode 100644 index 0000000..f960c61 --- /dev/null +++ b/config/data.go @@ -0,0 +1,27 @@ +package config + +import "encoding/json" + +type AppConfigData struct { + MMES_URL string `json:"mmes_url"` + LOG_FILE_NAME string `json:"log_file_name"` +} + +func (a AppConfigData) String() string { + b, _ := json.MarshalIndent(a, "", " ") + return string(b) +} + +type DBConfigData struct { + MODEL_FILE_POSTFIX string `json:"model_file_postfix"` + INFO_FILE_POSTFIX string `json:"info_file_postfix"` + S3_URL string `json:"s3_url"` + S3_ACCESS_KEY string `json:"s3_access_key"` + S3_SECRET_KEY string `json:"s3_secret_key"` + S3_REGION string `json:"s3_region"` +} + +func (d DBConfigData) String() string { + b, _ := json.MarshalIndent(d, "", " ") + return string(b) +} diff --git a/config/env_loader.go b/config/env_loader.go new file mode 100644 index 0000000..d761feb --- /dev/null +++ b/config/env_loader.go @@ -0,0 +1,80 @@ +package config + +import ( + "bytes" + "fmt" + "os" + + "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging" + "github.com/spf13/viper" +) + +// DB ENV KEY +const ( + ENV_KEY_DB_S3_URL = "S3_URL" + ENV_KEY_DB_S3_ACCESS_KEY = "S3_ACCESS_KEY" + ENV_KEY_DB_S3_SECRET_KEY = "S3_SECRET_KEY" + ENV_KEY_DB_S3_REGION = "S3_REGION" + ENV_KEY_DB_INFO_FILE_POSTFIX = "INFO_FILE_POSTFIX" + ENV_KEY_DB_MODEL_FILE_POSTFIX = "MODEL_FILE_POSTFIX" +) + +// APP ENV KEY +const ( + ENV_KEY_APP_MMES_URL = "MMES_URL" + ENV_KEY_APP_LOG_FILE_NAME = "LOG_FILE_NAME" +) + +type DefaultEnvData map[string]string + +type envDataLoader struct { +} + +func NewEnvDataLoader(defaultData DefaultEnvData, envFilePath ...string) *envDataLoader { + viper.SetConfigType("env") + viper.AutomaticEnv() + if len(envFilePath) != 0 { + for _, envFile := range envFilePath { + content, err := os.ReadFile(envFile) + if err != nil { + logging.ERROR(fmt.Sprintf("Failed to open env file, error msg: %s", err)) + continue + } + + err = viper.ReadConfig(bytes.NewBuffer(content)) + if err != nil { + logging.ERROR(fmt.Sprintf("Failed to load env file, error msg: %s", err)) + continue + } + } + } + + for k, v := range defaultData { + if viper.GetString(k) != "" { + continue + } + + viper.SetDefault(k, v) + } + + return &envDataLoader{} +} + +func (e *envDataLoader) load(c *configManager) { + e.appDataLoad(c) + e.dbDataLoad(c) +} + +func (e *envDataLoader) dbDataLoad(c *configManager) { + c.DB.S3_URL = viper.GetString(ENV_KEY_DB_S3_URL) + c.DB.S3_ACCESS_KEY = viper.GetString(ENV_KEY_DB_S3_ACCESS_KEY) + c.DB.S3_SECRET_KEY = viper.GetString(ENV_KEY_DB_S3_SECRET_KEY) + c.DB.S3_REGION = viper.GetString(ENV_KEY_DB_S3_REGION) + c.DB.INFO_FILE_POSTFIX = viper.GetString(ENV_KEY_DB_INFO_FILE_POSTFIX) + c.DB.MODEL_FILE_POSTFIX = viper.GetString(ENV_KEY_DB_MODEL_FILE_POSTFIX) +} + +func (e *envDataLoader) appDataLoad(c *configManager) { + c.App.MMES_URL = viper.GetString(ENV_KEY_APP_MMES_URL) + c.App.LOG_FILE_NAME = viper.GetString(ENV_KEY_APP_LOG_FILE_NAME) +} diff --git a/config/env_loader_test.go b/config/env_loader_test.go new file mode 100644 index 0000000..ad3d8d9 --- /dev/null +++ b/config/env_loader_test.go @@ -0,0 +1,107 @@ +package config + +import ( + "fmt" + "os" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" +) + +func createTempEnvFile(filename string, envDataMap map[string]string) (func(), error) { + file, err := os.Create(filename) + if err != nil { + return nil, err + } + defer file.Close() + for k, v := range envDataMap { + file.WriteString(fmt.Sprintf("%s=%s\n", k, v)) + } + + return func() { + os.Remove(filename) + }, nil +} + +func osSetData(envDataMap map[string]string) func() { + for k, v := range envDataMap { + os.Setenv(k, v) + } + + return func() { + for k := range envDataMap { + os.Unsetenv(k) + } + } +} + +func unSetViperDefault(envDataMap map[string]string) { + for k := range envDataMap { + viper.SetDefault(k, nil) + } +} + +func TestNewEnvDataLoadWhenGivenDefaultEnvFilePath(t *testing.T) { + envFilePath := "./test.env" + + envDataMap := map[string]string{ + "testkey1": "test-value1", + "testkey2": "test-value2", + } + deleteFunc, err := createTempEnvFile(envFilePath, envDataMap) + if err != nil { + t.Errorf("Failed to generate envfile %s\n", err) + return + } + defer deleteFunc() + + NewEnvDataLoader(nil, envFilePath) + assert.Equal(t, envDataMap["testkey1"], viper.GetString("testkey1")) + assert.Equal(t, envDataMap["testkey2"], viper.GetString("testkey2")) + assert.NotEqual(t, envDataMap["testkey1"], viper.GetString("testkey2")) + assert.Empty(t, envDataMap["testkey3"]) +} + +func TestNewEnvDataLoadWhenGivenDefaultEnvData(t *testing.T) { + defaultEnvData := DefaultEnvData{ + "testkey1": "test-value1", + ENV_KEY_DB_S3_URL: "google", + } + NewEnvDataLoader(defaultEnvData) + defer unSetViperDefault(defaultEnvData) + + assert.Equal(t, defaultEnvData["testkey1"], viper.GetString("testkey1")) + assert.Equal(t, defaultEnvData[ENV_KEY_DB_S3_URL], viper.GetString(ENV_KEY_DB_S3_URL)) + assert.NotEqual(t, defaultEnvData["testkey1"], viper.GetString(ENV_KEY_DB_S3_URL)) + assert.Empty(t, defaultEnvData["testkey3"]) +} + +func TestNewEnvDataLoadWhenSuccess(t *testing.T) { + os.Setenv(ENV_KEY_DB_S3_URL, "google") + os.Setenv(ENV_KEY_APP_LOG_FILE_NAME, "test.log") + + unsetFunc := osSetData(map[string]string{ + ENV_KEY_DB_S3_URL: "google", + ENV_KEY_APP_LOG_FILE_NAME: "test.log", + }) + defer unsetFunc() + + loader := NewEnvDataLoader(nil) + configManager := configManager{} + loader.load(&configManager) + + assert.Equal(t, "google", configManager.DB.S3_URL) + assert.Equal(t, "test.log", configManager.App.LOG_FILE_NAME) + +} + +func TestNewEnvDataLoaderWhenFailedReadFile(t *testing.T) { + defaultEnvData := DefaultEnvData{ + "testkey": "test-value1", + } + NewEnvDataLoader(defaultEnvData, "test.env") + defer unSetViperDefault(defaultEnvData) + + assert.Equal(t, "test-value1", viper.GetString("testkey")) +} diff --git a/config/validator.go b/config/validator.go new file mode 100644 index 0000000..ccc26d9 --- /dev/null +++ b/config/validator.go @@ -0,0 +1,65 @@ +package config + +import ( + "errors" + "fmt" +) + +var ( + ErrInvalidConfigData = errors.New("invalid config data") +) + +func NewConfigDataValidator() *configDataValidator { + return &configDataValidator{ + errs: []error{}, + } +} + +type configDataValidator struct { + errs []error +} + +func (c *configDataValidator) result() error { + var err error = nil + if len(c.errs) > 0 { + err = errors.Join(ErrInvalidConfigData, errors.Join(c.errs...)) + } + + return err +} + +func (c *configDataValidator) validate(manager *configManager) error { + if manager.App.LOG_FILE_NAME == "" { + c.errs = append(c.errs, fmt.Errorf("log_file_name is not set/available or empty")) + } + + if manager.App.MMES_URL == "" { + c.errs = append(c.errs, fmt.Errorf("mmes_url is not set/available or empty")) + } + + if manager.DB.MODEL_FILE_POSTFIX == "" { + c.errs = append(c.errs, fmt.Errorf("model_file_postfix is not set/available or empty")) + } + + if manager.DB.INFO_FILE_POSTFIX == "" { + c.errs = append(c.errs, fmt.Errorf("model_info_file_postfix is not set/available or empty")) + } + + if manager.DB.S3_URL == "" { + c.errs = append(c.errs, fmt.Errorf("s3_url is not set/available or empty")) + } + + if manager.DB.S3_ACCESS_KEY == "" { + c.errs = append(c.errs, fmt.Errorf("s3_access_key is not set/available or empty")) + } + + if manager.DB.S3_SECRET_KEY == "" { + c.errs = append(c.errs, fmt.Errorf("s3_secret_key is not set/available or empty")) + } + + if manager.DB.S3_REGION == "" { + c.errs = append(c.errs, fmt.Errorf("s3_region is not set/available or empty")) + } + + return c.result() +} diff --git a/config/validator_test.go b/config/validator_test.go new file mode 100644 index 0000000..b95ac4e --- /dev/null +++ b/config/validator_test.go @@ -0,0 +1,59 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestValidateWhenSuccess(t *testing.T) { + configDataValidator := NewConfigDataValidator() + manager := configManager{ + App: AppConfigData{ + MMES_URL: "test", + LOG_FILE_NAME: "test", + }, + DB: DBConfigData{ + MODEL_FILE_POSTFIX: "test", + INFO_FILE_POSTFIX: "test", + S3_URL: "test", + S3_ACCESS_KEY: "test", + S3_SECRET_KEY: "test", + S3_REGION: "test", + }, + } + + err := configDataValidator.validate(&manager) + assert.Nil(t, err) +} + +func TestValidateWhenFailedValidate(t *testing.T) { + configDataValidator := NewConfigDataValidator() + manager := configManager{} + + err := configDataValidator.validate(&manager) + assert.NotNil(t, err) + assert.ErrorIs(t, err, ErrInvalidConfigData) +} + +func TestValidateWhenFailedDBS3URL(t *testing.T) { + configDataValidator := NewConfigDataValidator() + manager := configManager{ + App: AppConfigData{ + MMES_URL: "test", + LOG_FILE_NAME: "test", + }, + DB: DBConfigData{ + MODEL_FILE_POSTFIX: "test", + INFO_FILE_POSTFIX: "test", + S3_ACCESS_KEY: "test", + S3_SECRET_KEY: "test", + S3_REGION: "test", + }, + } + + err := configDataValidator.validate(&manager) + assert.NotNil(t, err) + assert.ErrorIs(t, err, ErrInvalidConfigData) + assert.Equal(t, "", manager.DB.S3_URL) +} diff --git a/go.mod b/go.mod index 6c95709..f2f4848 100644 --- a/go.mod +++ b/go.mod @@ -7,23 +7,25 @@ toolchain go1.23.2 require ( github.com/aws/aws-sdk-go v1.47.3 github.com/gin-gonic/gin v1.9.1 - github.com/stretchr/testify v1.8.3 + github.com/google/uuid v1.6.0 + github.com/spf13/viper v1.19.0 + github.com/stretchr/testify v1.9.0 gorm.io/driver/postgres v1.5.9 gorm.io/gorm v1.25.12 - github.com/google/uuid v1.6.0 - ) require ( github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.5.5 // indirect @@ -33,23 +35,35 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect - github.com/stretchr/objx v0.5.0 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/objx v0.5.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.21.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 56727c4..b23e795 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,14 @@ github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZX github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -26,10 +30,13 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= @@ -51,64 +58,92 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -119,5 +154,3 @@ gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkw gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/main.go b/main.go index 1bb51c3..7412df0 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ import ( "time" "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/apis" + "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/config" "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core" modelDB "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/db" "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging" @@ -34,6 +35,13 @@ import ( ) func main() { + if err := config.Load(config.NewConfigDataValidator(), config.NewEnvDataLoader(nil)); err != nil { + logging.ERROR(err) + os.Exit(-1) + } + + configManager := config.GetConfigManager() + logging.INFO(configManager) // setup the database connection @@ -69,7 +77,7 @@ func main() { repo, )) server := http.Server{ - Addr: os.Getenv("MMES_URL"), + Addr: configManager.App.MMES_URL, Handler: router, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second,