Implement secure communications
[nonrtric.git] / dmaap-mediator-producer / internal / config / config.go
index 6969f9f..b31b334 100644 (file)
@@ -22,19 +22,30 @@ package config
 
 import (
        "os"
+       "strconv"
+
+       log "github.com/sirupsen/logrus"
 )
 
 type Config struct {
-       LogLevel               string
-       JobResultUri           string
+       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"),
-               JobResultUri:           getEnv("JOB_RESULT_URI", ""),
-               InfoCoordinatorAddress: getEnv("INFO_COORD_ADDR", "http://enrichmentservice:8083"),
+               LogLevel:               getLogLevel(),
+               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", "configs/producer.crt"),
+               ProducerKeyPath:        getEnv("PRODUCER_KEY_PATH", "configs/producer.key"),
        }
 }
 
@@ -45,3 +56,24 @@ func getEnv(key string, defaultVal string) string {
 
        return defaultVal
 }
+
+func getEnvAsInt(name string, defaultVal int) int {
+       valueStr := getEnv(name, "")
+       if value, err := strconv.Atoi(valueStr); err == nil {
+               return value
+       } else if valueStr != "" {
+               log.Warnf("Invalid int value: %v for variable: %v. Default value: %v will be used", valueStr, name, defaultVal)
+       }
+
+       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
+       }
+}