mirror of https://github.com/statping/statping
Fix local logins
parent
5982365c2d
commit
56645efb01
|
@ -1,13 +1,14 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/statping-ng/statping-ng/types/checkins"
|
||||
"github.com/statping-ng/statping-ng/types/errors"
|
||||
"github.com/statping-ng/statping-ng/types/services"
|
||||
"github.com/statping-ng/statping-ng/utils"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func findCheckin(r *http.Request) (*checkins.Checkin, string, error) {
|
||||
|
@ -23,8 +24,9 @@ func findCheckin(r *http.Request) (*checkins.Checkin, string, error) {
|
|||
return checkin, id, nil
|
||||
}
|
||||
|
||||
func apiAllCheckinsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
returnJson(checkins.All(), w, r)
|
||||
func apiAllCheckinsHandler(r *http.Request) interface{} {
|
||||
checkins := checkins.All()
|
||||
return checkins
|
||||
}
|
||||
|
||||
func apiCheckinHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -73,7 +73,11 @@ func IsReadAuthenticated(r *http.Request) bool {
|
|||
if ok := hasAuthorizationHeader(r); ok {
|
||||
return true
|
||||
}
|
||||
return IsFullAuthenticated(r)
|
||||
_, err := getJwtToken(r)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsFullAuthenticated returns true if the HTTP request is authenticated. You can set the environment variable GO_ENV=test
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/statping-ng/statping-ng/types/errors"
|
||||
"github.com/statping-ng/statping-ng/types/failures"
|
||||
"github.com/statping-ng/statping-ng/types/notifications"
|
||||
"github.com/statping-ng/statping-ng/types/services"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiAllNotifiersHandler(r *http.Request) interface{} {
|
||||
var notifs []notifications.Notification
|
||||
for _, n := range services.AllNotifiers() {
|
||||
notif := n.Select()
|
||||
no, err := notifications.Find(notif.Method)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
sendErrorJson(err, w, r)
|
||||
}
|
||||
notif.UpdateFields(no)
|
||||
notifs = append(notifs, *notif)
|
||||
}
|
||||
sort.Sort(notifications.NotificationOrder(notifs))
|
||||
returnJson(notifs, w, r)
|
||||
return notifs
|
||||
}
|
||||
|
||||
func apiNotifierGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/statping-ng/statping-ng/source"
|
||||
"github.com/statping-ng/statping-ng/types/core"
|
||||
"github.com/statping-ng/statping-ng/utils"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
_ "github.com/statping-ng/statping-ng/types/metrics"
|
||||
)
|
||||
|
@ -146,7 +147,7 @@ func Router() *mux.Router {
|
|||
api.Handle("/api/incidents/{id}/updates/{uid}", authenticated(apiDeleteIncidentUpdateHandler, false)).Methods("DELETE")
|
||||
|
||||
// API USER Routes
|
||||
api.Handle("/api/users", authenticated(apiAllUsersHandler, false)).Methods("GET")
|
||||
api.Handle("/api/users", scoped(apiAllUsersHandler)).Methods("GET")
|
||||
api.Handle("/api/users", authenticated(apiCreateUsersHandler, false)).Methods("POST")
|
||||
api.Handle("/api/users/token", http.HandlerFunc(apiCheckUserTokenHandler)).Methods("POST")
|
||||
api.Handle("/api/users/{id}", authenticated(apiUserHandler, false)).Methods("GET")
|
||||
|
@ -154,7 +155,7 @@ func Router() *mux.Router {
|
|||
api.Handle("/api/users/{id}", authenticated(apiUserDeleteHandler, false)).Methods("DELETE")
|
||||
|
||||
// API NOTIFIER Routes
|
||||
api.Handle("/api/notifiers", authenticated(apiNotifiersHandler, false)).Methods("GET")
|
||||
api.Handle("/api/notifiers", scoped(apiAllNotifiersHandler)).Methods("GET")
|
||||
api.Handle("/api/notifier/{notifier}", authenticated(apiNotifierGetHandler, false)).Methods("GET")
|
||||
api.Handle("/api/notifier/{notifier}", authenticated(apiNotifierUpdateHandler, false)).Methods("POST")
|
||||
api.Handle("/api/notifier/{notifier}/test", authenticated(testNotificationHandler, false)).Methods("POST")
|
||||
|
@ -167,7 +168,7 @@ func Router() *mux.Router {
|
|||
api.Handle("/api/messages/{id}", authenticated(apiMessageDeleteHandler, false)).Methods("DELETE")
|
||||
|
||||
// API CHECKIN Routes
|
||||
api.Handle("/api/checkins", authenticated(apiAllCheckinsHandler, false)).Methods("GET")
|
||||
api.Handle("/api/checkins", scoped(apiAllCheckinsHandler)).Methods("GET")
|
||||
api.Handle("/api/checkins", authenticated(checkinCreateHandler, false)).Methods("POST")
|
||||
api.Handle("/api/checkins/{api}", authenticated(apiCheckinHandler, false)).Methods("GET")
|
||||
api.Handle("/api/checkins/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE")
|
||||
|
|
|
@ -2,11 +2,12 @@ package handlers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/statping-ng/statping-ng/types/errors"
|
||||
"github.com/statping-ng/statping-ng/types/users"
|
||||
"github.com/statping-ng/statping-ng/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func findUser(r *http.Request) (*users.User, int64, error) {
|
||||
|
@ -75,9 +76,9 @@ func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sendJsonAction(user, "delete", w, r)
|
||||
}
|
||||
|
||||
func apiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiAllUsersHandler(r *http.Request) interface{} {
|
||||
allUsers := users.All()
|
||||
returnJson(allUsers, w, r)
|
||||
return allUsers
|
||||
}
|
||||
|
||||
func apiCheckUserTokenHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue