Skip to content

Commit 44aedf1

Browse files
mwfarbjuagargi
authored andcommitted
moved all paths into CmdOptions struct
1 parent b381ff4 commit 44aedf1

File tree

9 files changed

+113
-98
lines changed

9 files changed

+113
-98
lines changed

webapp/lib/bwcont.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func ExtractBwtestRespData(resp string, d *model.BwTestItem, start time.Time) {
151151
}
152152

153153
// GetBwByTimeHandler request the bwtest results stored since provided time.
154-
func GetBwByTimeHandler(w http.ResponseWriter, r *http.Request, active bool, srcpath string) {
154+
func GetBwByTimeHandler(w http.ResponseWriter, r *http.Request, active bool) {
155155
r.ParseForm()
156156
since := r.PostFormValue("since")
157157
log.Info("Requesting bwtest data since", "timestamp", since)
@@ -187,10 +187,10 @@ func removeOuterQuotes(s string) string {
187187
}
188188

189189
// WriteCmdCsv appends the cmd data (bwtest or echo) in csv-format to srcpath.
190-
func WriteCmdCsv(d model.CmdItem, srcpath string, appSel string) {
190+
func WriteCmdCsv(d model.CmdItem, options *CmdOptions, appSel string) {
191191
// newfile name for every day
192192
dataFileCmd := "data/" + appSel + "-" + time.Now().Format("2006-01-02") + ".csv"
193-
cmdDataPath := path.Join(srcpath, dataFileCmd)
193+
cmdDataPath := path.Join(options.StaticRoot, dataFileCmd)
194194
// write headers if file is new
195195
writeHeader := false
196196
if _, err := os.Stat(dataFileCmd); os.IsNotExist(err) {

webapp/lib/config.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ type UserSetting struct {
3535
MyIA string `json:"myIa"`
3636
}
3737

38+
type CmdOptions struct {
39+
StaticRoot, BrowseRoot, AppsRoot, ScionRoot, ScionBin, ScionGen, ScionGenCache, ScionLogs string
40+
}
41+
3842
// WriteUserSetting writes the settings to disk.
39-
func WriteUserSetting(srcpath string, settings UserSetting) {
40-
cliUserFp := path.Join(srcpath, cfgFileCliUser)
43+
func WriteUserSetting(options *CmdOptions, settings UserSetting) {
44+
cliUserFp := path.Join(options.StaticRoot, cfgFileCliUser)
4145
settingsJSON, _ := json.Marshal(settings)
4246

4347
err := ioutil.WriteFile(cliUserFp, settingsJSON, 0644)
4448
CheckError(err)
4549
}
4650

4751
// ReadUserSetting reads the settings from disk.
48-
func ReadUserSetting(srcpath string) UserSetting {
52+
func ReadUserSetting(options *CmdOptions) UserSetting {
4953
var settings UserSetting
50-
cliUserFp := path.Join(srcpath, cfgFileCliUser)
54+
cliUserFp := path.Join(options.StaticRoot, cfgFileCliUser)
5155

5256
// no problem when user settings not set yet
5357
raw, err := ioutil.ReadFile(cliUserFp)
@@ -59,11 +63,11 @@ func ReadUserSetting(srcpath string) UserSetting {
5963
}
6064

6165
// ScanLocalIAs will load list of locally available IAs
62-
func ScanLocalIAs(scionRoot string) []string {
66+
func ScanLocalIAs(options *CmdOptions) []string {
6367
var localIAs []string
6468
var reIaFilePathCap = `\/ISD([0-9]+)\/AS(\w+)`
6569
re := regexp.MustCompile(reIaFilePathCap)
66-
var searchPath = path.Join(scionRoot, "gen")
70+
var searchPath = path.Join(options.ScionRoot, "gen")
6771
filepath.Walk(searchPath, func(path string, f os.FileInfo, _ error) error {
6872
if f != nil && f.IsDir() {
6973
capture := re.FindStringSubmatch(path)
@@ -129,11 +133,11 @@ func (c byPrefInterface) Less(i, j int) bool {
129133
}
130134

131135
// GenServerNodeDefaults creates server defaults for localhost testing
132-
func GenServerNodeDefaults(srcpath string, localIAs []string) {
136+
func GenServerNodeDefaults(options *CmdOptions, localIAs []string) {
133137
// reverse sort so that the default server will oppose the default client
134138
sort.Sort(sort.Reverse(sort.StringSlice(localIAs)))
135139

136-
serFp := path.Join(srcpath, cfgFileSerUser)
140+
serFp := path.Join(options.StaticRoot, cfgFileSerUser)
137141
jsonBuf := []byte(`{ "all": [`)
138142
for i := 0; i < len(localIAs); i++ {
139143
// use all localhost endpoints as possible servers for bwtester as least
@@ -152,8 +156,8 @@ func GenServerNodeDefaults(srcpath string, localIAs []string) {
152156

153157
// GenClientNodeDefaults queries network interfaces and writes local client
154158
// SCION addresses as json
155-
func GenClientNodeDefaults(srcpath, cisdas string) {
156-
cliFp := path.Join(srcpath, cfgFileCliDef)
159+
func GenClientNodeDefaults(options *CmdOptions, cisdas string) {
160+
cliFp := path.Join(options.StaticRoot, cfgFileCliDef)
157161
cport := cliPortDef
158162

159163
// find interface addresses
@@ -191,19 +195,19 @@ func GenClientNodeDefaults(srcpath, cisdas string) {
191195
}
192196

193197
// GetNodesHandler queries the local environment for user/default nodes.
194-
func GetNodesHandler(w http.ResponseWriter, r *http.Request, srcpath string) {
198+
func GetNodesHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions) {
195199
r.ParseForm()
196200
nodes := r.PostFormValue("node_type")
197201
var fp string
198202
switch nodes {
199203
case "clients_default":
200-
fp = path.Join(srcpath, cfgFileCliDef)
204+
fp = path.Join(options.StaticRoot, cfgFileCliDef)
201205
case "servers_default":
202-
fp = path.Join(srcpath, cfgFileSerDef)
206+
fp = path.Join(options.StaticRoot, cfgFileSerDef)
203207
case "clients_user":
204-
fp = path.Join(srcpath, cfgFileCliUser)
208+
fp = path.Join(options.StaticRoot, cfgFileCliUser)
205209
case "servers_user":
206-
fp = path.Join(srcpath, cfgFileSerUser)
210+
fp = path.Join(options.StaticRoot, cfgFileSerUser)
207211
default:
208212
panic("Unhandled nodes type!")
209213
}

webapp/lib/echocont.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func ExtractEchoRespData(resp string, d *model.EchoItem, start time.Time) {
107107
}
108108

109109
// GetEchoByTimeHandler request the echo results stored since provided time.
110-
func GetEchoByTimeHandler(w http.ResponseWriter, r *http.Request, active bool, srcpath string) {
110+
func GetEchoByTimeHandler(w http.ResponseWriter, r *http.Request, active bool) {
111111
r.ParseForm()
112112
since := r.PostFormValue("since")
113113
log.Info("Requesting echo data since", "timestamp", since)

webapp/lib/health.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,33 @@ type ResHealthCheck struct {
4545

4646
// HealthCheckHandler handles calling the default health-check scripts and
4747
// returning the json-formatted results of each script.
48-
func HealthCheckHandler(w http.ResponseWriter, r *http.Request, scionRoot string, srcpath string, ia string) {
49-
hcResFp := path.Join(srcpath, resFileHealthCheck)
48+
func HealthCheckHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions, ia string) {
49+
hcResFp := path.Join(options.StaticRoot, resFileHealthCheck)
5050
// read specified tests from json definition
51-
fp := path.Join(srcpath, defFileHealthCheck)
51+
fp := path.Join(options.StaticRoot, defFileHealthCheck)
5252
raw, err := ioutil.ReadFile(fp)
5353
if CheckError(err) {
5454
fmt.Fprintf(w, `{ "err": "`+err.Error()+`" }`)
5555
return
5656
}
5757
log.Debug("HealthCheckHandler", "resFileHealthCheck", string(raw))
5858

59-
err = os.Setenv("SCION_ROOT", scionRoot+"/")
59+
err = os.Setenv("SCION_ROOT", options.ScionRoot+"/")
6060
if CheckError(err) {
6161
fmt.Fprintf(w, `{ "err": "`+err.Error()+`" }`)
6262
return
6363
}
64-
err = os.Setenv("SCION_BIN", scionRoot+"/bin/")
64+
err = os.Setenv("SCION_BIN", options.ScionBin+"/")
6565
if CheckError(err) {
6666
fmt.Fprintf(w, `{ "err": "`+err.Error()+`" }`)
6767
return
6868
}
69-
err = os.Setenv("SCION_GEN", scionRoot+"/gen/")
69+
err = os.Setenv("SCION_GEN", options.ScionGen+"/")
7070
if CheckError(err) {
7171
fmt.Fprintf(w, `{ "err": "`+err.Error()+`" }`)
7272
return
7373
}
74-
err = os.Setenv("SCION_LOGS", scionRoot+"/logs/")
74+
err = os.Setenv("SCION_LOGS", options.ScionLogs+"/")
7575
if CheckError(err) {
7676
fmt.Fprintf(w, `{ "err": "`+err.Error()+`" }`)
7777
return

webapp/lib/image.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func findNewestFileExt(dir, extRegEx string) (imgFilename string, imgTimestamp i
7272
}
7373

7474
// FindImageInfoHandler locating most recent image and writing text info data about it.
75-
func FindImageInfoHandler(w http.ResponseWriter, r *http.Request, staticRoot string) {
76-
filesDir := path.Join(staticRoot, "data/images")
75+
func FindImageInfoHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions) {
76+
filesDir := path.Join(options.StaticRoot, "data/images")
7777
imgFilename, _ := findNewestFileExt(filesDir, regexImageFiles)
7878
if imgFilename == "" {
7979
return
@@ -83,8 +83,8 @@ func FindImageInfoHandler(w http.ResponseWriter, r *http.Request, staticRoot str
8383
}
8484

8585
// FindImageHandler locating most recent image formatting it for graphic display in response.
86-
func FindImageHandler(w http.ResponseWriter, r *http.Request, staticRoot string, browserAddr string, port int) {
87-
filesDir := path.Join(staticRoot, "data/images")
86+
func FindImageHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions, browserAddr string, port int) {
87+
filesDir := path.Join(options.StaticRoot, "data/images")
8888
imgFilename, _ := findNewestFileExt(filesDir, regexImageFiles)
8989
if imgFilename == "" {
9090
fmt.Fprint(w, "Error: Unable to find image file locally.")

webapp/lib/sciond.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func getNetworkByIA(iaCli string) (*snet.SCIONNetwork, error) {
8282
// sciond data sources and calls
8383

8484
// PathTopoHandler handles requests for paths, returning results from sciond.
85-
func PathTopoHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
85+
func PathTopoHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions) {
8686
r.ParseForm()
8787
SIa := r.PostFormValue("ia_ser")
8888
CIa := r.PostFormValue("ia_cli")
@@ -116,7 +116,7 @@ func PathTopoHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
116116

117117
// Since segments data is supplimentary to paths data, if segments data
118118
// fails, provide the error, but we must still allow paths data to return.
119-
segments, err := getSegmentsJSON(*clientCCAddr, scionRoot)
119+
segments, err := getSegmentsJSON(*clientCCAddr, options)
120120
if CheckError(err) {
121121
returnPathHandler(w, paths, nil, err)
122122
return
@@ -126,9 +126,9 @@ func PathTopoHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
126126
returnPathHandler(w, paths, segments, err)
127127
}
128128

129-
func getSegmentsJSON(local snet.Addr, scionRoot string) ([]byte, error) {
129+
func getSegmentsJSON(local snet.Addr, options *CmdOptions) ([]byte, error) {
130130
// load segments from paths database
131-
var dbSrcFile = findDBFilename(local.IA, scionRoot)
131+
var dbSrcFile = findDBFilename(local.IA, options)
132132
dbTmpFile, err := copyDBToTemp(dbSrcFile)
133133
if err != nil {
134134
return nil, err
@@ -168,14 +168,14 @@ func getSegmentsJSON(local snet.Addr, scionRoot string) ([]byte, error) {
168168
return jsonSegsInfo, nil
169169
}
170170

171-
func findDBFilename(ia addr.IA, scionRoot string) string {
172-
filenames, err := filepath.Glob(filepath.Join(scionRoot, "gen-cache", "ps*path.db"))
171+
func findDBFilename(ia addr.IA, options *CmdOptions) string {
172+
filenames, err := filepath.Glob(filepath.Join(options.ScionGenCache, "ps*path.db"))
173173
CheckError(err)
174174
if len(filenames) == 1 {
175175
return filenames[0]
176176
}
177177
pathDBFileName := fmt.Sprintf("ps%s-1.path.db", ia.FileFmt(false))
178-
return filepath.Join(scionRoot, "gen-cache", pathDBFileName)
178+
return filepath.Join(options.ScionGenCache, pathDBFileName)
179179
}
180180

181181
// returns the name of the created file
@@ -288,10 +288,10 @@ func AsTopoHandler(w http.ResponseWriter, r *http.Request) {
288288
}
289289

290290
// TrcHandler handles requests for all local trust root data.
291-
func TrcHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
291+
func TrcHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions) {
292292
r.ParseForm()
293293
CIa := r.PostFormValue("src")
294-
raw, err := loadJSONCerts(CIa, "*.trc", scionRoot)
294+
raw, err := loadJSONCerts(CIa, "*.trc", options)
295295
if CheckError(err) {
296296
returnError(w, err)
297297
return
@@ -301,10 +301,10 @@ func TrcHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
301301
}
302302

303303
// CrtHandler handles requests for all local certificate data.
304-
func CrtHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
304+
func CrtHandler(w http.ResponseWriter, r *http.Request, options *CmdOptions) {
305305
r.ParseForm()
306306
CIa := r.PostFormValue("src")
307-
raw, err := loadJSONCerts(CIa, "*.crt", scionRoot)
307+
raw, err := loadJSONCerts(CIa, "*.crt", options)
308308
if CheckError(err) {
309309
returnError(w, err)
310310
return
@@ -313,13 +313,13 @@ func CrtHandler(w http.ResponseWriter, r *http.Request, scionRoot string) {
313313
fmt.Fprintf(w, string(raw))
314314
}
315315

316-
func loadJSONCerts(src, pattern string, scionRoot string) ([]byte, error) {
316+
func loadJSONCerts(src, pattern string, options *CmdOptions) ([]byte, error) {
317317
ia, err := addr.IAFromString(src)
318318
if err != nil {
319319
return nil, err
320320
}
321-
certDir := path.Join(scionRoot, fmt.Sprintf("gen/ISD%d/AS%s/endhost/certs", ia.I, ia.A.FileFmt()))
322-
cacheDir := path.Join(scionRoot, "gen-cache")
321+
certDir := path.Join(options.ScionGen, fmt.Sprintf("ISD%d/AS%s/endhost/certs", ia.I, ia.A.FileFmt()))
322+
cacheDir := options.ScionGenCache
323323
files, err := filepath.Glob(fmt.Sprintf("%s/%s", certDir, pattern))
324324
if err != nil {
325325
return nil, err

webapp/lib/traceroutecont.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func handleHopData(line string, runTimeKey int64) {
120120
}
121121

122122
// GetTracerouteByTimeHandler request the traceroute results stored since provided time.
123-
func GetTracerouteByTimeHandler(w http.ResponseWriter, r *http.Request, active bool, srcpath string) {
123+
func GetTracerouteByTimeHandler(w http.ResponseWriter, r *http.Request, active bool) {
124124
r.ParseForm()
125125
since := r.PostFormValue("since")
126126
log.Info("Requesting traceroute data since", "timestamp", since)

webapp/tests/health/beaconstest.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pcb_ms=10000
1111
iaFile=$(echo $1 | sed "s/:/_/g")
1212
echo "IA found: $iaFile"
1313

14-
# format log file and beacons grep string
15-
logfile=$SCION_LOGS/bs${iaFile}-1.DEBUG
14+
# format log file and beacons grep string (was .DEBUG)
15+
logfile=$SCION_LOGS/bs${iaFile}-1.log
1616
echo "Log: $logfile"
1717

18-
# seek last log entry for verified PCBs
19-
regex_pcb="Successfully verified PCB"
18+
# seek last log entry for verified PCBs (was "Successfully verified PCB")
19+
regex_pcb="Registered beacons"
2020
echo "Seeking regex: $regex_pcb"
2121

2222
epoch_s=$(date +"%s%6N")

0 commit comments

Comments
 (0)