Skip to content

Commit

Permalink
Merge pull request #93 from fly-apps/update-settings-http
Browse files Browse the repository at this point in the history
Add update settings http endpoint
  • Loading branch information
rugwirobaker committed Dec 1, 2022
2 parents 488d3c8 + 8454f2c commit 4ec305f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions pkg/commands/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os/exec"
"time"
Expand Down Expand Up @@ -147,3 +148,29 @@ func handleViewSettings(w http.ResponseWriter, r *http.Request) {
}
render.JSON(w, res, http.StatusOK)
}

func handleUpdateSettings(w http.ResponseWriter, r *http.Request) {
env, err := util.BuildEnv()
if err != nil {
render.Err(w, err)
return
}

config, err := io.ReadAll(r.Body)

defer r.Body.Close()

if err != nil {
err = fmt.Errorf("failed to read request body: %w", err)
render.Err(w, err)
return
}

if _, err := stolon.Ctl([]string{"update", "--patch", string(config)}, env); err != nil {
render.Err(w, err)
return
}
resp := &Response{Result: "Ok"}

render.JSON(w, resp, http.StatusOK)
}
2 changes: 1 addition & 1 deletion pkg/commands/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Handler() http.Handler {
r.Get("/failover/trigger", handleFailoverTrigger)
r.Get("/restart", handleRestart)
r.Get("/settings/view", handleViewSettings)

r.Post("/settings/update", handleUpdateSettings)
})

return r
Expand Down

0 comments on commit 4ec305f

Please sign in to comment.