2023-11-05 20:23:31 +01:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2024-01-13 23:26:04 +01:00
|
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/config"
|
2023-11-05 20:23:31 +01:00
|
|
|
"gitlab.hamburg.ccc.de/ccchh/spaceapid/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StateOpen(
|
2024-01-13 23:26:04 +01:00
|
|
|
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
2024-01-14 01:53:36 +01:00
|
|
|
resp *types.SpaceState,
|
2023-11-05 20:23:31 +01:00
|
|
|
) func(http.ResponseWriter, *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2024-01-14 01:04:01 +01:00
|
|
|
body := updateEndpointValidator(authDB, validCredentials, w, r)
|
2023-11-05 20:23:31 +01:00
|
|
|
|
|
|
|
// Parse request body
|
|
|
|
newState, err := strconv.ParseBool(string(body))
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to parse request body from", r.RemoteAddr)
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
_, _ = io.WriteString(w, "HTTP request body should either be true or false")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set SpaceAPI response values
|
2024-01-14 01:53:36 +01:00
|
|
|
resp.Open = newState
|
|
|
|
resp.LastChange = time.Now().Unix()
|
2023-11-05 20:23:31 +01:00
|
|
|
|
|
|
|
_, _ = io.WriteString(w, "Update Successful")
|
|
|
|
}
|
|
|
|
}
|