mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
read static scenario/group mapping from JSON file #61
This commit is contained in:
parent
e1654941a1
commit
ad44f8d1eb
2 changed files with 43 additions and 3 deletions
|
@ -22,7 +22,10 @@
|
||||||
package configuration
|
package configuration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -33,9 +36,7 @@ import (
|
||||||
// Global configuration
|
// Global configuration
|
||||||
var GlobalConfig *config.Config = nil
|
var GlobalConfig *config.Config = nil
|
||||||
|
|
||||||
var ScenarioGroupMap = map[string][]int{
|
var ScenarioGroupMap = map[string][]int{}
|
||||||
"moodle-l2pmanager@13306": {1, 2, 3},
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitConfig() error {
|
func InitConfig() error {
|
||||||
if GlobalConfig != nil {
|
if GlobalConfig != nil {
|
||||||
|
@ -73,6 +74,7 @@ func InitConfig() error {
|
||||||
contactName = flag.String("contact-name", "Steffen Vogel", "Name of the administrative contact")
|
contactName = flag.String("contact-name", "Steffen Vogel", "Name of the administrative contact")
|
||||||
contactMail = flag.String("contact-mail", "svogel2@eonerc.rwth-aachen.de", "EMail of the administrative contact")
|
contactMail = flag.String("contact-mail", "svogel2@eonerc.rwth-aachen.de", "EMail of the administrative contact")
|
||||||
testDataPath = flag.String("test-data-path", "database/testdata.json", "The path to the test data json file (used in test mode)")
|
testDataPath = flag.String("test-data-path", "database/testdata.json", "The path to the test data json file (used in test mode)")
|
||||||
|
groupsPath = flag.String("groups-path", "configuration/groups.json", "The path to the JSON file that maps user groups to scenario IDs")
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -103,6 +105,7 @@ func InitConfig() error {
|
||||||
"contact.name": *contactName,
|
"contact.name": *contactName,
|
||||||
"contact.mail": *contactMail,
|
"contact.mail": *contactMail,
|
||||||
"test.datapath": *testDataPath,
|
"test.datapath": *testDataPath,
|
||||||
|
"groups.path": *groupsPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if *s3NoSSL == true {
|
if *s3NoSSL == true {
|
||||||
|
@ -162,5 +165,39 @@ func InitConfig() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gPath, err := GlobalConfig.String("groups.path")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if gPath != "" {
|
||||||
|
err = readGroupsFile(gPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readGroupsFile(path string) error {
|
||||||
|
|
||||||
|
jsonFile, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error opening json file for groups: %v", err)
|
||||||
|
}
|
||||||
|
log.Println("Successfully opened json groups file", path)
|
||||||
|
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
|
|
||||||
|
err = json.Unmarshal(byteValue, &ScenarioGroupMap)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error unmarshalling json into ScenarioGroupMap: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("ScenarioGroupMap", ScenarioGroupMap)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
3
configuration/groups.json
Normal file
3
configuration/groups.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"moodle-l2pmanager@13306": [1, 2, 3]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue