Remove BPA operator
[icn.git] / cmd / bpa-restapi-agent / internal / config / config.go
1 package config
2
3 import (
4   "encoding/json"
5   "log"
6   "os"
7 )
8
9 type Configuration struct {
10   Password        string  `json:  "password"`
11   DatabaseAddress string  `json:  "database-address"`
12   DatabaseType    string  `json:  "database-type"`
13   ServicePort     string  `json:  "service-port"`
14   MinIOAddress    string  `json:  "minio-address"`
15   MinIOPort       string  `json:  "minio-port"`
16   AccessKeyID     string  `json:  "access-key-id"`
17   SecretAccessKey string  `json:  "secret-access-key"`
18 }
19
20 var gConfig *Configuration
21
22 func readConfigFile(file string) (*Configuration, error) {
23   f, err := os.Open(file)
24   if err != nil {
25     return defaultConfiguration(), err
26   }
27   defer f.Close()
28
29   conf := defaultConfiguration()
30
31   decoder := json.NewDecoder(f)
32   err = decoder.Decode(conf)
33   if err != nil {
34     return conf, err
35   }
36
37   return conf, nil
38 }
39
40 func defaultConfiguration() *Configuration {
41   return &Configuration {
42     Password:           "",
43     DatabaseAddress:    "127.0.0.1",
44     DatabaseType:       "mongo",
45     ServicePort:        "9015",
46     MinIOAddress:       "127.0.0.1",
47     MinIOPort:          "9000",
48     AccessKeyID:        "ICN-ACCESSKEYID",
49     SecretAccessKey:    "ICN-SECRETACCESSKEY",
50   }
51 }
52
53 func GetConfiguration() *Configuration {
54   if gConfig == nil {
55     conf, err := readConfigFile("ICNconfig.json")
56     if err != nil {
57       log.Println("Error loading config file. Using defaults")
58     }
59
60     gConfig = conf
61   }
62
63   return gConfig
64 }