Add some very basic authentication
This commit is contained in:
parent
3fe42e1ff0
commit
69704a38ae
@ -4,6 +4,6 @@
|
||||
|
||||
- [x] Use timeout for fetching departures
|
||||
- [ ] Write ESP8266 client
|
||||
- [ ] Add basic auth
|
||||
- [x] Add basic auth
|
||||
- [ ] Create Nix package
|
||||
- [ ] Create container
|
||||
|
12
main.go
12
main.go
@ -5,6 +5,7 @@ import "fmt"
|
||||
import "log"
|
||||
import "net/http"
|
||||
import "net/url"
|
||||
import "os"
|
||||
import "slices"
|
||||
import "strconv"
|
||||
import "time"
|
||||
@ -81,7 +82,18 @@ func FetchDepartures(stopId string) (*DMResponse, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
password := os.Getenv("VRNP_PASSWORD")
|
||||
if len(password) == 0 {
|
||||
panic("Required environment variable VRNP_PASSWORD is not set");
|
||||
}
|
||||
|
||||
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
if !(ok && user == "admin" && pass == password) {
|
||||
http.Error(w, "You shall not pass", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
query := r.URL.Query()
|
||||
|
||||
if query["stop_id"] == nil || len(query["stop_id"]) < 1 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user