working commit
This commit is contained in:
+24
-16
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||||
|
*
|
||||||
|
* This work is published and licensed under a Creative Commons
|
||||||
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||||
|
*
|
||||||
|
* Distribution of this work is permitted, but commercial use and
|
||||||
|
* modifications are strictly prohibited.
|
||||||
|
*/
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -52,16 +61,19 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return success, accountID, err
|
return success, accountID, err
|
||||||
}
|
}
|
||||||
|
success, id, err := hand.ValidatePassword(rctx.Ctx, username, password)
|
||||||
|
if err != nil {
|
||||||
|
return false, accountID, err
|
||||||
|
}
|
||||||
|
if !success {
|
||||||
|
err = fmt.Errorf("Incorrect username or password")
|
||||||
|
return false, accountID, err
|
||||||
|
}
|
||||||
|
accountID = id
|
||||||
|
return success, accountID, err
|
||||||
}
|
}
|
||||||
success, id, err := hand.ValidatePassword(rctx.Ctx, username, password)
|
success = true
|
||||||
if err != nil {
|
accountID = descr.AnonymousID
|
||||||
return false, accountID, err
|
|
||||||
}
|
|
||||||
if !success {
|
|
||||||
err = fmt.Errorf("Incorrect username or password")
|
|
||||||
return false, accountID, err
|
|
||||||
}
|
|
||||||
accountID = id
|
|
||||||
return success, accountID, err
|
return success, accountID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,16 +102,12 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s
|
|||||||
var res bool
|
var res bool
|
||||||
hand.logg.Debugf("Cop check your right %s: %s %s", accountID, right, subject)
|
hand.logg.Debugf("Cop check your right %s: %s %s", accountID, right, subject)
|
||||||
// =[]=
|
// =[]=
|
||||||
// /------\
|
// .------.
|
||||||
// .---[-] [#] \--,
|
// .---[-] [#] \--,
|
||||||
// >| [ ] [ ] |
|
// >| [ ] [ ] |
|
||||||
// '--0-------0----'
|
// '--0-------0----'
|
||||||
// Bad news for you, baby.... #
|
// Bad news for you, baby.... #
|
||||||
|
//
|
||||||
// TODO: defer logger
|
|
||||||
|
|
||||||
defer hand.logg.Debugf("Checking right %s for %s: %v", right, accountID, res)
|
|
||||||
|
|
||||||
exists, grant, err := hand.mdb.GetGrantByAccoundIDRight(ctx, accountID, right)
|
exists, grant, err := hand.mdb.GetGrantByAccoundIDRight(ctx, accountID, right)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
@@ -107,7 +115,6 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s
|
|||||||
if !exists {
|
if !exists {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch right {
|
switch right {
|
||||||
case descr.RightReadFiles, descr.RightWriteFiles:
|
case descr.RightReadFiles, descr.RightWriteFiles:
|
||||||
grant.Pattern = ".*"
|
grant.Pattern = ".*"
|
||||||
@@ -122,5 +129,6 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s
|
|||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
res = true
|
res = true
|
||||||
|
hand.logg.Debugf("Checking right %s for %s: %v", right, accountID, res)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||||
|
*
|
||||||
|
* This work is published and licensed under a Creative Commons
|
||||||
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
||||||
|
*
|
||||||
|
* Distribution of this work is permitted, but commercial use and
|
||||||
|
* modifications are strictly prohibited.
|
||||||
|
*/
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -15,33 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (hand *Handler) SendHello(rctx *router.Context) {
|
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{}
|
params := &operator.SendHelloParams{}
|
||||||
res, _ := hand.oper.SendHello(params)
|
res, _ := hand.oper.SendHello(params)
|
||||||
hand.SendResult(rctx, res)
|
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"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package operator
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"mstore/app/descr"
|
"mstore/app/descr"
|
||||||
"mstore/pkg/auxtool"
|
"mstore/pkg/auxtool"
|
||||||
@@ -36,6 +37,12 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = regexp.Compile(params.Pattern)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Cannot compile regexp %s: %v", err)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern)
|
grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
+6
-6
@@ -53,12 +53,12 @@ func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.F
|
|||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
file.Collection = resp.Header.Get("Content-Collection")
|
file.Collection = resp.Header.Get("Content-Collection")
|
||||||
file.Name = resp.Header.Get("Content-Name")
|
file.Name = resp.Header.Get("Content-Name")
|
||||||
//contentSize := resp.Header.Get("Content-Size")
|
contentSize := resp.Header.Get("Content-Size")
|
||||||
//size, err := strconv.ParseInt(contentSize, 10, 64)
|
size, err := strconv.ParseInt(contentSize, 10, 64)
|
||||||
//if err != nil {
|
if err != nil {
|
||||||
//return exists, file, err
|
return exists, file, err
|
||||||
//}
|
}
|
||||||
//file.Size = size
|
file.Size = size
|
||||||
file.Type = resp.Header.Get("Content-Type")
|
file.Type = resp.Header.Get("Content-Type")
|
||||||
file.Checksum = resp.Header.Get("Content-Digest")
|
file.Checksum = resp.Header.Get("Content-Digest")
|
||||||
exists = true
|
exists = true
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import (
|
|||||||
func xxxTestImageLife(t *testing.T) {
|
func xxxTestImageLife(t *testing.T) {
|
||||||
var srvport int64 = 10250
|
var srvport int64 = 10250
|
||||||
srvdir := t.TempDir()
|
srvdir := t.TempDir()
|
||||||
srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport)
|
srvaddr := fmt.Sprintf("mstore:mstore@127.0.0.1:%d", srvport)
|
||||||
|
|
||||||
srv, err := server.NewServer()
|
srv, err := server.NewServer()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user