Merge "Change of ECS to ICS in test env"
[nonrtric.git] / dmaap-mediator-producer / internal / config / config.go
index dfd2505..e03c40a 100644 (file)
@@ -21,6 +21,8 @@
 package config
 
 import (
+       "encoding/json"
+       "fmt"
        "os"
        "strconv"
 
@@ -32,21 +34,26 @@ type Config struct {
        InfoProducerHost       string
        InfoProducerPort       int
        InfoCoordinatorAddress string
-       MRHost                 string
-       MRPort                 int
+       DMaaPMRAddress         string
+       ProducerCertPath       string
+       ProducerKeyPath        string
 }
 
 func New() *Config {
        return &Config{
-               LogLevel:               getLogLevel(),
                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://informationservice: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 +82,19 @@ func getLogLevel() log.Level {
                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
+}