Merge "NONRTRIC - Implement DMaaP mediator producer service in Java"
[nonrtric.git] / dmaap-mediator-producer / internal / config / config.go
index 9b7b1dd..eef1b5f 100644 (file)
@@ -21,6 +21,7 @@
 package config
 
 import (
+       "fmt"
        "os"
        "strconv"
 
@@ -28,31 +29,30 @@ import (
 )
 
 type Config struct {
-       LogLevel               string
+       LogLevel               log.Level
        InfoProducerHost       string
        InfoProducerPort       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"`
+       DMaaPMRAddress         string
+       ProducerCertPath       string
+       ProducerKeyPath        string
 }
 
 func New() *Config {
        return &Config{
-               LogLevel:               getEnv("LOG_LEVEL", "Info"),
                InfoProducerHost:       getEnv("INFO_PRODUCER_HOST", ""),
                InfoProducerPort:       getEnvAsInt("INFO_PRODUCER_PORT", 8085),
-               InfoCoordinatorAddress: getEnv("INFO_COORD_ADDR", "http://enrichmentservice:8083"),
-               MRHost:                 getEnv("MR_HOST", "http://message-router.onap"),
-               MRPort:                 getEnvAsInt("MR_PORT", 3904),
+               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
@@ -71,3 +71,13 @@ 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
+       }
+}