Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Working toward #42
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankPetrilli committed Jan 17, 2018
1 parent 0b9fec8 commit dfca914
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions ipfs-cluster/trigger-server/triggerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"bytes"
)

const CONFIG_PATH = "/etc/trigger-server"
// HTTP API listen port
const PORT = 8082
var RUNNER_PATH = os.Getenv("GOPATH") + "src/github.com/ipfs/kubernetes-ipfs/ipfs-cluster/"
const configPath = "/etc/trigger-server"
// port is HTTP API listen port
const port = 8082
var runnerPath = os.Getenv("GOPATH") + "src/github.com/ipfs/kubernetes-ipfs/ipfs-cluster/"
// Runner takes two args
const RUNNER_NUM_NODES = "5"
const RUNNER_NUM_PINS = "5"
const runnerNumNodes = "5"
const runnerNumPins = "5"

// Secret is set by main
var secret = ""
Expand All @@ -35,8 +35,8 @@ func run(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintf(rw, "Invalid authentication\n")
} else {
// This command takes a while, so we'll hang out here while it runs
cmd := exec.Command("bash", "runner.sh", RUNNER_NUM_NODES, RUNNER_NUM_PINS)
cmd.Dir = RUNNER_PATH
cmd := exec.Command("bash", "runner.sh", runnerNumNodes, runnerNumPins)
cmd.Dir = runnerPath
out, err := cmd.CombinedOutput()
// Add the output to IPFS
addr, ipfsErr := sh.Add(bytes.NewReader(out))
Expand All @@ -63,25 +63,25 @@ func run(rw http.ResponseWriter, req *http.Request) {
}

func main() {
secret_bytes, readErr := ioutil.ReadFile(CONFIG_PATH)
secretBytes, readErr := ioutil.ReadFile(configPath)
if readErr != nil {
log.Printf("Missing secret configuration in %s. We'll generate one for you...\n", CONFIG_PATH)
log.Printf("Missing secret configuration in %s. We'll generate one for you...\n", configPath)
rand.Seed(time.Now().UnixNano())
secret_bytes = randLetters(30)
ioErr := ioutil.WriteFile(CONFIG_PATH, secret_bytes, 0644)
secretBytes = randLetters(30)
ioErr := ioutil.WriteFile(configPath, secretBytes, 0644)
if ioErr != nil {
log.Fatal("Unable to write new secret file; check permissions and try again")
}
}
secret = string(secret_bytes)
log.Printf("Starting with secret as %s on port %d\n", secret, PORT)
secret = string(secretBytes)
log.Printf("Starting with secret as %s on port %d\n", secret, port)
http.HandleFunc("/run", run)
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintf(rw, `Kubernetes-IPFS Trigger Server
https://github.com/ipfs/kubernetes-ipfs/
`)
})
log.Println(http.ListenAndServe(":" + strconv.FormatInt(PORT, 10), nil))
log.Println(http.ListenAndServe(":" + strconv.FormatInt(port, 10), nil))
}

var letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
Expand Down

0 comments on commit dfca914

Please sign in to comment.