-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.go
More file actions
131 lines (120 loc) · 5.34 KB
/
config.go
File metadata and controls
131 lines (120 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
// configuration module
//
// Copyright (c) 2019 - Valentin Kuznetsov <vkuznet@gmail.com>
//
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"strings"
"time"
)
// Configuration stores server configuration parameters
type Configuration struct {
Port int `json:"port"` // server port number
URI string `json:"uri"` // server mongodb URI
Base string `json:"base"` // base path
DBName string `json:"dbname"` // mongo db name
DBColl string `json:"dbcoll"` // mongo db name
FilesDBUri string `json:"filesdburi"` // server FilesDB URI
Templates string `json:"templates"` // location of server templates
Jscripts string `json:"jscripts"` // location of server JavaScript files
Images string `json:"images"` // location of server images
Styles string `json:"styles"` // location of server CSS styles
LogFormatter string `json:"logFormatter"` // LogFormatter type
Verbose int `json:"verbose"` // verbosity level
Realm string `json:"realm"` // kerberos realm
Keytab string `json:"keytab"` // kerberos keytab
Krb5Conf string `json:"krb5Conf"` // kerberos krb5.conf
ServerKey string `json:"ckey"` // tls.key file
ServerCrt string `json:"cert"` // tls.cert file
RootCA string `json:"rootCA"` // RootCA file
TestMode bool `json:"testMode"` // test mode to bypass auth
LogFile string `json:"logFile"` // location of service log file
SchemaFiles []string `json:"schemaFiles"` // schema files
SchemaRenewInterval int `json:"schemaRenewInterval"` // schema renew interval
SchemaSections []string `json:"schemaSections"` // logical schema section list
WebSectionKeys map[string][]string `json:"webSectionKeys"` // section order dict
}
// Config variable represents configuration object
var Config Configuration
// String returns string representation of server Config
func (c *Configuration) String() string {
dbAttrs := strings.Split(c.FilesDBUri, "@")
var cc Configuration
cc = *c
if len(dbAttrs) > 1 {
cc.FilesDBUri = dbAttrs[1]
}
data, _ := json.MarshalIndent(cc, "", " ")
return fmt.Sprintf(string(data))
}
// ParseConfig parse given config file
func ParseConfig(configFile string) {
data, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatalf("Unable to read logfile %s, error %v", configFile, err)
}
err = json.Unmarshal(data, &Config)
if err != nil {
log.Fatalf("Unable to parse logfile %s, error %v", configFile, err)
}
if Config.SchemaRenewInterval == 0 {
Config.SchemaRenewInterval = 600
}
SchemaRenewInterval = time.Duration(Config.SchemaRenewInterval) * time.Second
}
// MetaData provides details about CHESS experiment
type MetaData struct {
Date int64 `json:"Date"`
PI string `json:"PI"`
Affliation string `json:"Affiliation"`
Email string `json:"Email"`
Proposal string `json:"Proposal"`
BTR int64 `json:"BTR"`
RawDataDirectory string `json:"RawDataDirectory"`
AuxDataDirectory string `json:"AuxDataDirectory"`
}
// Material defines details of used sample in CHESS experiment
type Material struct {
SpecName string `json:"SpecName"`
CalibrationSample bool `json:"CalibrationSample"`
MaterialClass string `json:"MaterialClass"`
CommonName string `json:"CommonName"`
AbbreviatedName string `json:"AbbreviatedName"`
ConstituentElements []string `json:"ConstituentElements"`
Phases []string `json:"Phases"`
Processing string `json:"Processing"`
}
// Experiment provides Meta-Data attributes about CHESS experiment
type Experiment struct {
ExperimentType []string `json:"ExperimentType"`
XrayModality string `json:"XrayModality"`
XrayTechnique []string `json:"XrawTechnique"`
SupplementaryMeasurements []string `json:"SupplementaryMeasurements"`
Furnance []string `json:"Furnance"`
LoadFrame []string `json:"LoadFrame"`
Detectors []string `json:"Detectors"`
}
// ChessMetaData represents input CHESS meta-data
type ChessMetaData struct {
User string `json:"user"`
MetaData MetaData `json:"MetaData"`
Material Material `json:"Material"`
Experiment Experiment `json:"Experiment"`
Description string `json:"description"`
}
// String returns string representation of server Config
func (c *ChessMetaData) String() string {
data, _ := json.Marshal(c)
return fmt.Sprintf(string(data))
}
// ToRecord convert ChessMetaData structure into json record
func (c *ChessMetaData) ToRecord() Record {
rec := make(Record)
data, _ := json.Marshal(c)
json.Unmarshal(data, &rec)
return rec
}