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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -33,9 +36,7 @@ import (
|
|||
// Global configuration
|
||||
var GlobalConfig *config.Config = nil
|
||||
|
||||
var ScenarioGroupMap = map[string][]int{
|
||||
"moodle-l2pmanager@13306": {1, 2, 3},
|
||||
}
|
||||
var ScenarioGroupMap = map[string][]int{}
|
||||
|
||||
func InitConfig() error {
|
||||
if GlobalConfig != nil {
|
||||
|
@ -73,6 +74,7 @@ func InitConfig() error {
|
|||
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")
|
||||
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()
|
||||
|
||||
|
@ -103,6 +105,7 @@ func InitConfig() error {
|
|||
"contact.name": *contactName,
|
||||
"contact.mail": *contactMail,
|
||||
"test.datapath": *testDataPath,
|
||||
"groups.path": *groupsPath,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
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