Skip to content

Commit 87ef30c

Browse files
committed
debug for cache check owner
1 parent 78c8c09 commit 87ef30c

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

pkg/http/data.go

+13-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"k8s.io/klog/v2"
77
"net/http"
88
"strconv"
9+
"strings"
910

1011
"github.com/tomasen/realip"
1112

@@ -17,10 +18,7 @@ type handleFunc func(w http.ResponseWriter, r *http.Request, d *common.Data) (in
1718

1819
func handle(fn handleFunc, prefix string, server *settings.Server) http.Handler {
1920
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20-
checked, err := CheckPathOwner(r, prefix)
21-
if err != nil {
22-
http.Error(w, err.Error(), http.StatusForbidden)
23-
}
21+
checked := CheckPathOwner(r, prefix)
2422
if !checked {
2523
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
2624
}
@@ -55,13 +53,12 @@ func NeedCheckPrefix(prefix string) bool {
5553
}
5654
}
5755

58-
func CheckPathOwner(r *http.Request, prefix string) (bool, error) {
56+
func CheckPathOwner(r *http.Request, prefix string) bool {
5957
klog.Infof("~~~~Temp log: URL = %s, prefix = %s", r.URL, prefix)
6058
if !NeedCheckPrefix(prefix) {
61-
return true, nil
59+
return true
6260
}
6361

64-
var err error = nil
6562
method := r.Method
6663
src := r.URL.Path
6764

@@ -84,28 +81,22 @@ func CheckPathOwner(r *http.Request, prefix string) (bool, error) {
8481

8582
klog.Infof("Checking owner for method: %s, prefix: %s, srcType: %s, src: %s, dstType: %s, dst: %s", method, prefix, srcType, src, dstType, dst)
8683

87-
bflRequest := r.Header.Get("X-Bfl-User")
88-
bflParsed := ""
84+
bfl := r.Header.Get("X-Bfl-User")
85+
pvc := ""
8986
if drives.IsBaseDrives(srcType) {
90-
bflParsed, err = rpc.PVCs.GetBfl(rpc.ExtractPvcFromURL(src))
91-
if err != nil {
92-
return false, err
93-
}
94-
if bflParsed != bflRequest {
95-
return false, nil
87+
pvc = rpc.ExtractPvcFromURL(src)
88+
if !strings.HasPrefix(pvc, "pvc-userspace-"+bfl+"-") && !strings.HasPrefix(pvc, "pvc-appcache-"+bfl+"-") {
89+
return false
9690
}
9791
}
9892

9993
if prefix == "/api/paste" || (prefix == "/api/resources" && r.Method == http.MethodPatch) {
10094
if drives.IsBaseDrives(dstType) {
101-
bflParsed, err = rpc.PVCs.GetBfl(rpc.ExtractPvcFromURL(dst))
102-
if err != nil {
103-
return false, err
104-
}
105-
if bflParsed != bflRequest {
106-
return false, nil
95+
pvc = rpc.ExtractPvcFromURL(src)
96+
if !strings.HasPrefix(pvc, "pvc-userspace-"+bfl+"-") && !strings.HasPrefix(pvc, "pvc-appcache-"+bfl+"-") {
97+
return false
10798
}
10899
}
109100
}
110-
return true, nil
101+
return true
111102
}

0 commit comments

Comments
 (0)