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:
Jakob Schrettenbrunner 2018-05-17 21:18:02 +02:00
parent 09da18f42e
commit 53a3fbc464
5 changed files with 11 additions and 12 deletions

View File

@ -51,7 +51,7 @@ func (api *InternalAPI) Listen() {
func (api *InternalAPI) register() {
v1 := api.router.Group("/api/v1")
{
v1.GET("/", AuthHandler(""), GetIndex)
v1.GET("", AuthHandler(""), GetIndex)
//v1.PATCH("/config", AuthHandler("c:config"), PatchConfiguration)
v1.GET("/servers", AuthHandler("c:list"), handleGetServers)
@ -59,15 +59,15 @@ func (api *InternalAPI) register() {
v1ServerRoutes := v1.Group("/servers/:server")
{
v1ServerRoutes.GET("/", AuthHandler("s:get"), handleGetServer)
v1ServerRoutes.PATCH("/", AuthHandler("s:config"), handlePatchServer)
v1ServerRoutes.DELETE("/", AuthHandler("g:server:delete"), handleDeleteServer)
v1ServerRoutes.GET("", AuthHandler("s:get"), handleGetServer)
v1ServerRoutes.PATCH("", AuthHandler("s:config"), handlePatchServer)
v1ServerRoutes.DELETE("", AuthHandler("g:server:delete"), handleDeleteServer)
v1ServerRoutes.POST("/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall)
v1ServerRoutes.POST("/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild)
v1ServerRoutes.POST("/password", AuthHandler(""), handlePostServerPassword)
v1ServerRoutes.POST("/power", AuthHandler("s:power"), handlePostServerPower)
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("/unsuspend", AuthHandler(""), handlePostServerUnsuspend)
}

View File

@ -2,8 +2,9 @@ package api
import (
"net/http"
"strings"
"strconv"
"strconv"
"github.com/gin-gonic/gin"
"github.com/google/jsonapi"
@ -71,7 +72,9 @@ func (a *authorizationManager) HasPermission(permission string) bool {
func AuthHandler(permission string) gin.HandlerFunc {
return func(c *gin.Context) {
requestToken := c.Request.Header.Get(accessTokenHeader)
if requestToken == "" {
if requestToken != "" && strings.HasPrefix(requestToken, "Baerer ") {
requestToken = requestToken[7:]
} else {
requestToken = c.Query("token")
}
requestServer := c.Param("server")

View File

@ -181,10 +181,6 @@ func handleGetConsole(c *gin.Context) {
server.Websockets().Upgrade(c.Writer, c.Request)
}
func handleGetServerLog(c *gin.Context) {
}
func handlePostServerSuspend(c *gin.Context) {
}

View File

@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
)
const configFile = "../config.yml.example"
const configFile = "../config.example.yml"
func TestLoadConfiguraiton(t *testing.T) {
err := LoadConfiguration(configFile)

Binary file not shown.