Skip to content

Commit

Permalink
remove trailing slashes from api
Browse files Browse the repository at this point in the history
use correct handler to provide server logs
remove Baerer from Authorization header to compare it with known tokens
fix wings-api.paw routes
  • Loading branch information
schrej committed May 17, 2018
1 parent 09da18f commit 53a3fbc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
10 changes: 5 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ 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)
v1.POST("/servers", AuthHandler("c:create"), handlePostServers)

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)
}
Expand Down
7 changes: 5 additions & 2 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package api

import (
"net/http"
"strings"

"strconv"
"strconv"

"github.com/gin-gonic/gin"
"github.com/google/jsonapi"
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions api/handlers_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified wings-api.paw
Binary file not shown.

0 comments on commit 53a3fbc

Please sign in to comment.