[#91] Add support namespaces #96

Merged
alexvanin merged 1 commit from :feature/91-add_support_namespaces into master 2023-12-01 10:12:57 +00:00
Member

Close #91

Signed-off-by: Roman Loginov r.loginov@yadro.com

Close #91 Signed-off-by: Roman Loginov <r.loginov@yadro.com>
r.loginov self-assigned this 2023-11-28 08:42:35 +00:00
r.loginov requested review from storage-services-committers 2023-11-28 08:49:18 +00:00
r.loginov requested review from storage-services-developers 2023-11-28 08:49:18 +00:00
dkirillov reviewed 2023-11-28 10:06:33 +00:00
@ -318,0 +332,4 @@
|----------------------|------------|---------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------|
| `namespace_header` | `string` | yes | `X-Frostfs-Namespace` | Header to determine zone to resolve bucket name. |
| `allow` | `[]string` | no | | List of container zones which are available to resolve. Mutual exclusive with `deny` list. Prioritized over `deny` list. |
| `default_namespaces` | `[]string` | n/d | ["","root"] | Namespaces that should be handled as default. |
Member

Actually we support sighup reload for default_namespaces

Actually we support sighup reload for `default_namespaces`
dkirillov marked this conversation as resolved
@ -88,2 +89,4 @@
ctx := utils.GetContextFromRequest(c)
nsBytes := c.Request.Header.Peek(h.config.NamespaceHeader())
ctx = middleware.SetNamespace(ctx, string(nsBytes))
Member

Can we set namespace to context once in some middleware?

Can we set namespace to context once in some middleware?
dkirillov marked this conversation as resolved
@ -184,0 +214,4 @@
}
zone, _ := settings.FormContainerZone(namespace)
d.SetZone(zone)
Member

Can we add some integration test to check this?
For example:

diff --git a/cmd/http-gw/integration_test.go b/cmd/http-gw/integration_test.go
index 76a8325..1a1b0ce 100644
--- a/cmd/http-gw/integration_test.go
+++ b/cmd/http-gw/integration_test.go
@@ -29,6 +29,7 @@ import (
        "github.com/stretchr/testify/require"
        "github.com/testcontainers/testcontainers-go"
        "github.com/testcontainers/testcontainers-go/wait"
+       "go.uber.org/zap/zapcore"
 )
 
 type putResponse struct {
@@ -68,6 +69,7 @@ func TestIntegration(t *testing.T) {
                t.Run("simple get "+version, func(t *testing.T) { simpleGet(ctx, t, clientPool, ownerID, CID, version) })
                t.Run("get by attribute "+version, func(t *testing.T) { getByAttr(ctx, t, clientPool, ownerID, CID, version) })
                t.Run("get zip "+version, func(t *testing.T) { getZip(ctx, t, clientPool, ownerID, CID, version) })
+               t.Run("test namespaces "+version, func(t *testing.T) { checkNamespaces(ctx, t, clientPool, ownerID, CID, version) })
 
                cancel()
                server.Wait()
@@ -81,7 +83,7 @@ func runServer() (App, context.CancelFunc) {
        cancelCtx, cancel := context.WithCancel(context.Background())
 
        v := getDefaultConfig()
-       l, lvl := newLogger(v)
+       l, lvl := newStdoutLogger(zapcore.DebugLevel)
        application := newApp(cancelCtx, WithConfig(v), WithLogger(l, lvl))
        go application.Serve()
 
@@ -289,6 +291,31 @@ func getZip(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID us
        makeZipTest(t, baseURL, names, contents)
 }
 
+func checkNamespaces(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID user.ID, CID cid.ID, version string) {
+       content := "content of file"
+       attributes := map[string]string{
+               "some-attr": "some-get-value",
+       }
+
+       id := putObject(ctx, t, clientPool, ownerID, CID, content, attributes)
+
+       req, err := http.NewRequest(http.MethodGet, testHost+"/get/"+testContainerName+"/"+id.String(), nil)
+       require.NoError(t, err)
+       req.Header.Set(defaultNamespaceHeader, "root")
+
+       resp, err := http.DefaultClient.Do(req)
+       require.NoError(t, err)
+       checkGetResponse(t, resp, content, attributes)
+
+       req, err = http.NewRequest(http.MethodGet, testHost+"/get/"+testContainerName+"/"+id.String(), nil)
+       require.NoError(t, err)
+       req.Header.Set(defaultNamespaceHeader, "root2")
+
+       resp, err = http.DefaultClient.Do(req)
+       require.NoError(t, err)
+       require.Equal(t, http.StatusNotFound, resp.StatusCode)
+}
+

Can we add some integration test to check this? For example: ```diff diff --git a/cmd/http-gw/integration_test.go b/cmd/http-gw/integration_test.go index 76a8325..1a1b0ce 100644 --- a/cmd/http-gw/integration_test.go +++ b/cmd/http-gw/integration_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" + "go.uber.org/zap/zapcore" ) type putResponse struct { @@ -68,6 +69,7 @@ func TestIntegration(t *testing.T) { t.Run("simple get "+version, func(t *testing.T) { simpleGet(ctx, t, clientPool, ownerID, CID, version) }) t.Run("get by attribute "+version, func(t *testing.T) { getByAttr(ctx, t, clientPool, ownerID, CID, version) }) t.Run("get zip "+version, func(t *testing.T) { getZip(ctx, t, clientPool, ownerID, CID, version) }) + t.Run("test namespaces "+version, func(t *testing.T) { checkNamespaces(ctx, t, clientPool, ownerID, CID, version) }) cancel() server.Wait() @@ -81,7 +83,7 @@ func runServer() (App, context.CancelFunc) { cancelCtx, cancel := context.WithCancel(context.Background()) v := getDefaultConfig() - l, lvl := newLogger(v) + l, lvl := newStdoutLogger(zapcore.DebugLevel) application := newApp(cancelCtx, WithConfig(v), WithLogger(l, lvl)) go application.Serve() @@ -289,6 +291,31 @@ func getZip(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID us makeZipTest(t, baseURL, names, contents) } +func checkNamespaces(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID user.ID, CID cid.ID, version string) { + content := "content of file" + attributes := map[string]string{ + "some-attr": "some-get-value", + } + + id := putObject(ctx, t, clientPool, ownerID, CID, content, attributes) + + req, err := http.NewRequest(http.MethodGet, testHost+"/get/"+testContainerName+"/"+id.String(), nil) + require.NoError(t, err) + req.Header.Set(defaultNamespaceHeader, "root") + + resp, err := http.DefaultClient.Do(req) + require.NoError(t, err) + checkGetResponse(t, resp, content, attributes) + + req, err = http.NewRequest(http.MethodGet, testHost+"/get/"+testContainerName+"/"+id.String(), nil) + require.NoError(t, err) + req.Header.Set(defaultNamespaceHeader, "root2") + + resp, err = http.DefaultClient.Do(req) + require.NoError(t, err) + require.Equal(t, http.StatusNotFound, resp.StatusCode) +} + ```
dkirillov marked this conversation as resolved
r.loginov force-pushed feature/91-add_support_namespaces from 239cbb696d to cbaa5efc5e 2023-11-28 12:14:39 +00:00 Compare
dkirillov approved these changes 2023-11-28 13:35:33 +00:00
dkirillov left a comment
Member

LGTM

LGTM
mbiryukova approved these changes 2023-11-28 14:47:49 +00:00
alexvanin approved these changes 2023-12-01 10:12:35 +00:00
alexvanin merged commit a375af7d98 into master 2023-12-01 10:12:57 +00:00
alexvanin deleted branch feature/91-add_support_namespaces 2023-12-01 10:13:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-http-gw#96
No description provided.