@@ -109,7 +109,7 @@ func LoadJsonFile(filePath string) map[string]interface{} {
109
109
if FileExists (filePath ) {
110
110
fileContent , err := ioutil .ReadFile (GetFilePath (filePath )) // just pass the file name
111
111
if err != nil {
112
- log .Err ("Can't read file: " , filePath , err )
112
+ log .Err ("Can't read file:" , filePath , err )
113
113
return nil
114
114
}
115
115
@@ -191,7 +191,7 @@ func getRawData(data map[string]interface{}) {
191
191
// for every host get data
192
192
var rawData []interface {}
193
193
hosts := pyraconv .ToInterfaceMap (data ["hosts" ])
194
- log .Dbg ("Data hosts: " , hosts )
194
+ log .Dbg ("Data hosts:" , hosts )
195
195
results := pyraconv .ToInterfaceMap (data ["results" ])
196
196
masterName := pyraconv .ToString (hosts ["master" ])
197
197
masterResults := pyraconv .ToInterfaceMap (results [masterName ])
@@ -300,7 +300,7 @@ func generateMdReport(checkId string, reportFilename string, reportData map[stri
300
300
reporTpl := templates .Lookup (reportFileName )
301
301
data := reportData
302
302
if reporTpl == nil {
303
- log .Err ("Template " + checkId + ".tpl not found. " )
303
+ log .Err ("Template " + checkId + ".tpl not found" )
304
304
getRawData (data )
305
305
reportFileName = "raw.tpl"
306
306
reporTpl = templates .Lookup (reportFileName )
@@ -415,6 +415,7 @@ func main() {
415
415
projectDataPtr := flag .String ("project" , "" , "target project used during uploading" )
416
416
pathDataPtr := flag .String ("path" , "" , "path to artifacts directory used during uploading" )
417
417
apiUrlDataPtr := flag .String ("apiurl" , "" , "API URL for reports uploading" )
418
+
418
419
flag .Parse ()
419
420
checkData = * checkDataPtr
420
421
@@ -431,27 +432,24 @@ func main() {
431
432
log .DEBUG = false
432
433
}
433
434
434
- if * modeDataPtr == "upload" {
435
+ switch * modeDataPtr {
436
+ case "upload" :
435
437
token := * tokenDataPtr
436
438
project := * projectDataPtr
437
439
path := * pathDataPtr
438
440
apiUrl := * apiUrlDataPtr
439
441
440
442
if len (token ) == 0 {
441
- log .Err ("Token is not defined" )
442
- return
443
+ log .Fatal ("Token is not defined" )
443
444
}
444
445
if len (apiUrl ) == 0 {
445
- log .Err ("API URL is not defined" )
446
- return
446
+ log .Fatal ("API URL is not defined" )
447
447
}
448
448
if len (project ) == 0 {
449
- log .Err ("Project (for reports uploading) is not defined" )
450
- return
449
+ log .Fatal ("Project (for reports uploading) is not defined" )
451
450
}
452
451
if len (path ) == 0 {
453
- log .Err ("Artifacts directory is not defined" )
454
- return
452
+ log .Fatal ("Artifacts directory is not defined" )
455
453
}
456
454
457
455
err := upload .UploadReport (apiUrl , token , project , path )
@@ -460,28 +458,47 @@ func main() {
460
458
os .Exit (1 )
461
459
}
462
460
461
+ return
462
+ case "loadcfg" :
463
+ path := * pathDataPtr
464
+ if len (path ) == 0 {
465
+ log .Fatal ("Config path is not defined" )
466
+ }
467
+
468
+ config , err := loadConfig (path )
469
+ if err != nil {
470
+ log .Fatal (fmt .Sprintf ("Cannot load config. %s" , err ))
471
+ os .Exit (1 )
472
+ }
473
+
474
+ if len (config ) == 0 {
475
+ log .Fatal (fmt .Sprintf ("Config '%s' is empty" , path ))
476
+ }
477
+
478
+ outputConfig (config )
479
+
463
480
return
464
481
}
465
482
466
483
if FileExists (checkData ) {
467
484
resultData = LoadJsonFile (checkData )
468
485
469
486
if resultData == nil {
470
- log .Fatal ("ERROR: File given by --checkdata content wrong json data. " )
487
+ log .Fatal ("File given by --checkdata content wrong json data" )
471
488
return
472
489
}
473
490
474
491
resultData ["source_path_full" ] = checkData
475
492
resultData ["source_path_parts" ] = strings .Split (checkData , string (os .PathSeparator ))
476
493
} else {
477
- log .Err ("ERROR: File given by --checkdata not found" )
494
+ log .Err ("File given by --checkdata not found" )
478
495
return
479
496
}
480
497
481
498
if resultData != nil {
482
499
checkId = pyraconv .ToString (resultData ["checkId" ])
483
500
} else {
484
- log .Fatal ("ERROR: Content given by --checkdata is wrong json content. " )
501
+ log .Fatal ("Content defined by ' --checkdata' is invalid JSON " )
485
502
}
486
503
487
504
checkId = strings .ToUpper (checkId )
@@ -490,7 +507,7 @@ func main() {
490
507
491
508
err := reorderHosts (resultData )
492
509
if err != nil {
493
- log .Err ("There is no data to generate the report. " )
510
+ log .Err ("There is no data to generate the report" )
494
511
}
495
512
496
513
config := cfg .NewConfig ()
@@ -511,13 +528,13 @@ func main() {
511
528
512
529
reportDone := generateMdReports (checkId , resultData , outputDir )
513
530
if ! reportDone {
514
- log .Fatal ("Cannot generate report. Data file or template is wrong. " )
531
+ log .Fatal ("Cannot generate report. Data file or template is wrong" )
515
532
}
516
533
}
517
534
518
535
func preprocessReportData (checkId string , config cfg.Config ,
519
536
data map [string ]interface {}) error {
520
- switch checkId {
537
+ switch strings . ToUpper ( checkId ) {
521
538
case "A002" :
522
539
// Try to load actual Postgres versions.
523
540
err := config .LoadVersions ()
0 commit comments