--wip-- [skip ci]
This commit is contained in:
parent
ccf3981d8d
commit
7a8b904852
10 changed files with 282 additions and 191 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
"git.hamburg.ccc.de/ccchh/spaceapid/types"
|
||||
)
|
||||
|
||||
func Root(resp *types.SpaceAPIResponseV14) func(http.ResponseWriter, *http.Request) {
|
||||
func Root(resp *types.SpaceAPIResponse) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if GET method
|
||||
if r.Method != http.MethodGet {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
func StateOpen(
|
||||
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||
resp *types.SpaceState,
|
||||
resp *types.SpaceAPIState,
|
||||
) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := updateEndpointValidator(authDB, validCredentials, w, r)
|
||||
|
|
@ -37,7 +37,7 @@ func StateOpen(
|
|||
|
||||
func StateMessagePUT(
|
||||
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||
resp *types.SpaceState,
|
||||
resp *types.SpaceAPIState,
|
||||
) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := updateEndpointValidator(authDB, validCredentials, w, r)
|
||||
|
|
@ -54,7 +54,7 @@ func StateMessagePUT(
|
|||
|
||||
func StateMessageDELETE(
|
||||
authDB config.HTTPBACredentials, validCredentials []config.HTTPBACredentialID,
|
||||
resp *types.SpaceState,
|
||||
resp *types.SpaceAPIState,
|
||||
) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := updateEndpointValidator(authDB, validCredentials, w, r)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func updateEndpointValidator(
|
|||
// Check BasicAuth credentials
|
||||
username, password, ok := r.BasicAuth()
|
||||
if !ok || !util.CheckCredentials(authDB, validCredentials, username, password) {
|
||||
w.Header()["WWW-Authenticate"] = []string{"Basic realm=\"spaceapid\""}
|
||||
w.Header().Set("WWW-Authenticate", "Basic realm=\"spaceapid\"")
|
||||
http.Error(w, "", http.StatusUnauthorized)
|
||||
return []byte{}, errors.New(fmt.Sprintf("Unauthorized request from %s Username: %s Password: %s", r.RemoteAddr, username, password))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue