remove trailing slashes from api
use correct handler to provide server logs remove Baerer from Authorization header to compare it with known tokens fix wings-api.paw routes
This commit is contained in:
parent
09da18f42e
commit
53a3fbc464
10
api/api.go
10
api/api.go
|
@ -51,7 +51,7 @@ func (api *InternalAPI) Listen() {
|
||||||
func (api *InternalAPI) register() {
|
func (api *InternalAPI) register() {
|
||||||
v1 := api.router.Group("/api/v1")
|
v1 := api.router.Group("/api/v1")
|
||||||
{
|
{
|
||||||
v1.GET("/", AuthHandler(""), GetIndex)
|
v1.GET("", AuthHandler(""), GetIndex)
|
||||||
//v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration)
|
//v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration)
|
||||||
|
|
||||||
v1.GET("/servers", AuthHandler("c:list"), handleGetServers)
|
v1.GET("/servers", AuthHandler("c:list"), handleGetServers)
|
||||||
|
@ -59,15 +59,15 @@ func (api *InternalAPI) register() {
|
||||||
|
|
||||||
v1ServerRoutes := v1.Group("/servers/:server")
|
v1ServerRoutes := v1.Group("/servers/:server")
|
||||||
{
|
{
|
||||||
v1ServerRoutes.GET("/", AuthHandler("s:get"), handleGetServer)
|
v1ServerRoutes.GET("", AuthHandler("s:get"), handleGetServer)
|
||||||
v1ServerRoutes.PATCH("/", AuthHandler("s:config"), handlePatchServer)
|
v1ServerRoutes.PATCH("", AuthHandler("s:config"), handlePatchServer)
|
||||||
v1ServerRoutes.DELETE("/", AuthHandler("g:server:delete"), handleDeleteServer)
|
v1ServerRoutes.DELETE("", AuthHandler("g:server:delete"), handleDeleteServer)
|
||||||
v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall)
|
v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall)
|
||||||
v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)
|
v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)
|
||||||
v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword)
|
v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword)
|
||||||
v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower)
|
v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower)
|
||||||
v1ServerRoutes.POST("/command", AuthHandler("s:command"), handlePostServerCommand)
|
v1ServerRoutes.POST("/command", AuthHandler("s:command"), handlePostServerCommand)
|
||||||
v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetServerLog)
|
v1ServerRoutes.GET("/log", AuthHandler("s:console"), handleGetConsole)
|
||||||
v1ServerRoutes.POST("/suspend", AuthHandler(""), handlePostServerSuspend)
|
v1ServerRoutes.POST("/suspend", AuthHandler(""), handlePostServerSuspend)
|
||||||
v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend)
|
v1ServerRoutes.POST("/unsuspend", AuthHandler(""), handlePostServerUnsuspend)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,9 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/jsonapi"
|
"github.com/google/jsonapi"
|
||||||
|
@ -71,7 +72,9 @@ func (a *authorizationManager) HasPermission(permission string) bool {
|
||||||
func AuthHandler(permission string) gin.HandlerFunc {
|
func AuthHandler(permission string) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
requestToken := c.Request.Header.Get(accessTokenHeader)
|
requestToken := c.Request.Header.Get(accessTokenHeader)
|
||||||
if requestToken == "" {
|
if requestToken != "" && strings.HasPrefix(requestToken, "Baerer ") {
|
||||||
|
requestToken = requestToken[7:]
|
||||||
|
} else {
|
||||||
requestToken = c.Query("token")
|
requestToken = c.Query("token")
|
||||||
}
|
}
|
||||||
requestServer := c.Param("server")
|
requestServer := c.Param("server")
|
||||||
|
|
|
@ -181,10 +181,6 @@ func handleGetConsole(c *gin.Context) {
|
||||||
server.Websockets().Upgrade(c.Writer, c.Request)
|
server.Websockets().Upgrade(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGetServerLog(c *gin.Context) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func handlePostServerSuspend(c *gin.Context) {
|
func handlePostServerSuspend(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configFile = "../config.yml.example"
|
const configFile = "../config.example.yml"
|
||||||
|
|
||||||
func TestLoadConfiguraiton(t *testing.T) {
|
func TestLoadConfiguraiton(t *testing.T) {
|
||||||
err := LoadConfiguration(configFile)
|
err := LoadConfiguration(configFile)
|
||||||
|
|
BIN
wings-api.paw
BIN
wings-api.paw
Binary file not shown.
Loading…
Reference in New Issue
Block a user