about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authormaride <maride@darknebu.la>2018-09-04 16:11:40 +0200
committermaride <maride@darknebu.la>2018-09-04 16:11:40 +0200
commit76bc68cb6abb3105bfb154fc59ecdfd54f8ff564 (patch)
treec89a88c9927ae42916d3811679083b40cd9b610b /src
parent17eb37c2838d9d786ec7d5a7f071cc83b4a3044e (diff)
Increase logging
Diffstat (limited to 'src')
-rw-r--r--src/main.go19
-rw-r--r--src/seed.go27
2 files changed, 37 insertions, 9 deletions
diff --git a/src/main.go b/src/main.go
index ae50632..aac4f02 100644
--- a/src/main.go
+++ b/src/main.go
@@ -7,6 +7,7 @@ import (
 
 func main() {
 	// Set up flags
+	log.Println("Setting up components")
 	registerHTTPFlags()
 	registerSessionFlags()
 	registerCredentialsFlags()
@@ -15,12 +16,24 @@ func main() {
 	flag.Parse()
 
 	// Read challenges from file
-	getChallengesFromSeedFile()
+	log.Println("Reading seed file")
+	readChallengesError := getChallengesFromSeedFile()
+	if readChallengesError != nil {
+		log.Fatalln(readChallengesError.Error())
+	}
 
 	// Start our VPN container and network
-	startVPN()
+	log.Printf("Starting VPN container ('%s')", vpnContainerName)
+	startVPNError := startVPN()
+	if startVPNError != nil {
+		log.Fatalln(startVPNError.Error())
+	}
 	defer stopVPN()
 
 	// Run HTTP server
-	log.Fatalln(runHTTPServer())
+	log.Printf("Running HTTP server on port %d", *port)
+	runHTTPServerError := runHTTPServer()
+	if runHTTPServerError != nil {
+		log.Fatalln(runHTTPServerError)
+	}
 }
\ No newline at end of file
diff --git a/src/seed.go b/src/seed.go
index 5dc849c..3dce55f 100644
--- a/src/seed.go
+++ b/src/seed.go
@@ -2,6 +2,8 @@ package main
 
 import (
 	"flag"
+	"fmt"
+	"github.com/pkg/errors"
 	"io/ioutil"
 	"log"
 	"encoding/json"
@@ -17,21 +19,21 @@ func registerSeedFlags() {
 }
 
 // Read a given seed file and return their containing challenges
-func readSeedFile(path string) ([]Challenge) {
+func readSeedFile(path string) ([]Challenge, error) {
 	var jsonContents map[string]interface{}
 
 	// Read file
 	rawContents, readError := ioutil.ReadFile(path)
 	if readError != nil {
 		log.Printf("Failed to read seed file at %s: %s", *seedFilePath, readError.Error())
-		return nil
+		return nil, readError
 	}
 
 	// Convert JSON String to map
 	unmarshalError := json.Unmarshal(rawContents, &jsonContents)
 	if unmarshalError != nil {
 		log.Printf("Failed to parse JSON in seed file at %s: %s", *seedFilePath, unmarshalError.Error())
-		return nil
+		return nil, unmarshalError
 	}
 
 	tmpChallenges := []Challenge{}
@@ -62,16 +64,29 @@ func readSeedFile(path string) ([]Challenge) {
 		}
 	}
 
-	return tmpChallenges
+	return tmpChallenges, nil
 }
 
 // Read the file we set up using flags and store the returned challenge array
-func getChallengesFromSeedFile() {
-	tmpChallenges := readSeedFile(*seedFilePath)
+func getChallengesFromSeedFile() (error) {
+	tmpChallenges, error := readSeedFile(*seedFilePath)
+
+	if error != nil {
+		// Couldn't read file, return error
+		return error
+	}
+
+	if tmpChallenges == nil {
+		// Could read file, but it didn't contain any parseable challenges - return
+		return errors.New(fmt.Sprintf("Empty seed file at %s? No challenges found", *seedFilePath))
+	}
 
 	if tmpChallenges != nil {
+		// returned challenges found! Set them.
 		challenges = tmpChallenges
 	}
+
+	return nil
 }
 
 // Generate a JSON string from the stored challenges, stripped from content which might spoil the user