X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fconfig.go;h=34b056d59ad806b47363a8bf943a647b2d41ad14;hb=2389606af9e77879c76e2f87822b5b7d68920d19;hp=8a2784a96911c98af2dcbd16a291c82974a86eec;hpb=82378715d387362e97a064665a2467c587afdeed;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/config.go b/dmaap-mediator-producer/internal/config/config.go index 8a2784a9..34b056d5 100644 --- a/dmaap-mediator-producer/internal/config/config.go +++ b/dmaap-mediator-producer/internal/config/config.go @@ -21,6 +21,8 @@ package config import ( + "encoding/json" + "fmt" "os" "strconv" @@ -28,35 +30,30 @@ import ( ) type Config struct { - LogLevel string - InfoProducerSupervisionCallbackHost string - InfoProducerSupervisionCallbackPort int - InfoJobCallbackHost string - InfoJobCallbackPort int - InfoCoordinatorAddress string - MRHost string - MRPort int -} - -type ProducerRegistrationInfo struct { - InfoProducerSupervisionCallbackUrl string `json:"info_producer_supervision_callback_url"` - SupportedInfoTypes []string `json:"supported_info_types"` - InfoJobCallbackUrl string `json:"info_job_callback_url"` + LogLevel log.Level + InfoProducerHost string + InfoProducerPort int + InfoCoordinatorAddress string + DMaaPMRAddress string + ProducerCertPath string + ProducerKeyPath string } func New() *Config { return &Config{ - LogLevel: getEnv("LOG_LEVEL", "Info"), - InfoProducerSupervisionCallbackHost: getEnv("INFO_PRODUCER_SUPERVISION_CALLBACK_HOST", ""), - InfoProducerSupervisionCallbackPort: getEnvAsInt("INFO_PRODUCER_SUPERVISION_CALLBACK_PORT", 8085), - InfoJobCallbackHost: getEnv("INFO_JOB_CALLBACK_HOST", ""), - InfoJobCallbackPort: getEnvAsInt("INFO_JOB_CALLBACK_PORT", 8086), - InfoCoordinatorAddress: getEnv("INFO_COORD_ADDR", "http://enrichmentservice:8083"), - MRHost: getEnv("MR_HOST", "http://message-router.onap"), - MRPort: getEnvAsInt("MR_PORT", 3904), + InfoProducerHost: getEnv("INFO_PRODUCER_HOST", ""), + InfoProducerPort: getEnvAsInt("INFO_PRODUCER_PORT", 8085), + InfoCoordinatorAddress: getEnv("INFO_COORD_ADDR", "https://enrichmentservice:8434"), + DMaaPMRAddress: getEnv("DMAAP_MR_ADDR", "https://message-router.onap:3905"), + ProducerCertPath: getEnv("PRODUCER_CERT_PATH", "security/producer.crt"), + ProducerKeyPath: getEnv("PRODUCER_KEY_PATH", "security/producer.key"), + LogLevel: getLogLevel(), } } +func (c Config) String() string { + return fmt.Sprintf("InfoProducerHost: %v, InfoProducerPort: %v, InfoCoordinatorAddress: %v, DMaaPMRAddress: %v, ProducerCertPath: %v, ProducerKeyPath: %v, LogLevel: %v", c.InfoProducerHost, c.InfoProducerPort, c.InfoCoordinatorAddress, c.DMaaPMRAddress, c.ProducerCertPath, c.ProducerKeyPath, c.LogLevel) +} func getEnv(key string, defaultVal string) string { if value, exists := os.LookupEnv(key); exists { return value @@ -75,3 +72,29 @@ func getEnvAsInt(name string, defaultVal int) int { return defaultVal } + +func getLogLevel() log.Level { + logLevelStr := getEnv("LOG_LEVEL", "Info") + if loglevel, err := log.ParseLevel(logLevelStr); err == nil { + return loglevel + } else { + log.Warnf("Invalid log level: %v. Log level will be Info!", logLevelStr) + return log.InfoLevel + } +} + +func GetJobTypesFromConfiguration(configFile string) ([]TypeDefinition, error) { + typeDefsByte, err := os.ReadFile(configFile) + if err != nil { + return nil, err + } + typeDefs := struct { + Types []TypeDefinition `json:"types"` + }{} + err = json.Unmarshal(typeDefsByte, &typeDefs) + if err != nil { + return nil, err + } + + return typeDefs.Types, nil +}