working commit

This commit is contained in:
2026-02-12 12:00:17 +02:00
parent ae15bddb15
commit b279687623
20 changed files with 639 additions and 192 deletions
+14 -14
View File
@@ -1,10 +1,6 @@
package handler
import (
//"encoding/base64"
//"fmt"
//"strings"
"mstore/app/router"
"mstore/pkg/auxhttp"
)
@@ -18,12 +14,14 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
var handlerFunc router.HandlerFunc
handlerFunc = func(rctx *router.Context) {
authSuccessful, authError := hand.CheckAccess(rctx)
if authSuccessful && authError == nil {
hand.logg.Debugf("Call authorization middleware")
success, username, err := hand.CheckAccess(rctx)
if success && err == nil {
rctx.SetBool(authTag, true)
rctx.SetString(userTag, username)
}
if authError != nil {
hand.logg.Errorf("Authorization middleware error: %v", authError)
if err != nil {
hand.logg.Errorf("Authorization middleware error: %v", err)
}
next.ServeHTTP(rctx)
@@ -31,21 +29,23 @@ func (hand *Handler) AuthMiddleware(next router.Handler) router.Handler {
return handlerFunc
}
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, error) {
func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
var err error
var res bool
var success bool
var username string
var password string
authHeader := rctx.GetHeader("Authorization")
if authHeader != "" {
hand.logg.Debugf("Authorization header is %s", authHeader)
username, password, err := auxhttp.ParseBasicAuth(authHeader)
username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil {
return res, err
return success, username, err
}
hand.logg.Debugf("Authorization username is %s:%s", username, password)
}
res = true
success = true
return res, err
return success, username, err
}
+101
View File
@@ -0,0 +1,101 @@
package handler
import (
"mstore/app/operator"
"mstore/app/router"
)
// POST /v3/grant/create 200 200
func (hand *Handler) CreateGrant(rctx *router.Context) {
var err error
params := &operator.CreateGrantParams{}
err = rctx.BindJSON(params)
if err != nil {
hand.SendError(rctx, err)
return
}
res, err := hand.oper.CreateGrant(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err)
return
}
hand.SendResult(rctx, res)
}
// POST /v3/grant/get 200 200
func (hand *Handler) GetGrant(rctx *router.Context) {
var err error
params := &operator.GetGrantParams{}
err = rctx.BindJSON(params)
if err != nil {
hand.SendError(rctx, err)
return
}
res, err := hand.oper.GetGrant(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("CreateGrant error: %v", err)
hand.SendError(rctx, err)
return
}
hand.SendResult(rctx, res)
}
// POST /v3/grants/list 200 200
func (hand *Handler) ListGrants(rctx *router.Context) {
var err error
params := &operator.ListGrantsParams{}
err = rctx.BindJSON(params)
if err != nil {
hand.SendError(rctx, err)
return
}
res, err := hand.oper.ListGrants(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("ListGrants error: %v", err)
hand.SendError(rctx, err)
return
}
hand.SendResult(rctx, res)
}
// POST /v3/grant/get 200 200
func (hand *Handler) UpdateGrant(rctx *router.Context) {
var err error
params := &operator.UpdateGrantParams{}
err = rctx.BindJSON(params)
if err != nil {
hand.SendError(rctx, err)
return
}
res, err := hand.oper.UpdateGrant(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("UpdateGrant error: %v", err)
hand.SendError(rctx, err)
return
}
hand.SendResult(rctx, res)
}
// POST /v3/grant/delete 200 200
func (hand *Handler) DeleteGrant(rctx *router.Context) {
var err error
params := &operator.DeleteGrantParams{}
err = rctx.BindJSON(params)
if err != nil {
hand.SendError(rctx, err)
return
}
res, err := hand.oper.DeleteGrant(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("DeleteGrant error: %v", err)
hand.SendError(rctx, err)
return
}
hand.SendResult(rctx, res)
}
+26
View File
@@ -15,7 +15,33 @@ import (
)
func (hand *Handler) SendHello(rctx *router.Context) {
authSuccess, _ := rctx.Bools[authTag]
authUser, _ := rctx.Strings[userTag]
hand.logg.Debugf("%s:%v", authTag, authSuccess)
hand.logg.Debugf("%s:%v", userTag, authUser)
if authSuccess {
}
params := &operator.SendHelloParams{}
res, _ := hand.oper.SendHello(params)
hand.SendResult(rctx, res)
}
/*
func checkGrant(who, subject, operation string) (bool, error) {
return true, error
}
type Grant struct {
AccountID `xxxx-xxxx`
Subject `file`
Operation `putFile`
Path "foo/bare"
}
*/