Skip to content

Commit c95105e

Browse files
authored
Merge main into connect (#134)
* Introduce namespaces for memberships. (#132) * Merge main into connect branch.
1 parent da8159e commit c95105e

File tree

17 files changed

+1577
-249
lines changed

17 files changed

+1577
-249
lines changed

api/v1/project_member.pb.go

Lines changed: 27 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/tenant.pb.go

Lines changed: 33 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/tenant_member.pb.go

Lines changed: 24 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
logger := slog.New(jsonHandler)
2424
logger.Info("Starting Client")
2525

26-
c := client.New(client.DialConfig{
26+
c := client.New(&client.Config{
2727
BaseURL: "http://localhost:9090",
2828
Debug: true,
2929
UserAgent: "sample-client",

pkg/client/client.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package client
22

33
import (
4+
"context"
5+
6+
"connectrpc.com/connect"
47
compress "github.com/klauspost/connect-compress/v2"
8+
v1 "github.com/metal-stack/masterdata-api/api/v1"
59
"github.com/metal-stack/masterdata-api/api/v1/apiv1connect"
610
)
711

@@ -16,12 +20,12 @@ type (
1620
}
1721

1822
client struct {
19-
config DialConfig
23+
config *Config
2024
}
2125
)
2226

2327
// GRPCClient is a Client implementation with grpc transport.
24-
func New(config DialConfig) Client {
28+
func New(config *Config) Client {
2529
return &client{
2630
config: config,
2731
}
@@ -42,6 +46,7 @@ func (c client) ProjectMember() apiv1connect.ProjectMemberServiceClient {
4246
c.config.HttpClient(),
4347
c.config.BaseURL,
4448
compress.WithAll(compress.LevelBalanced),
49+
connect.WithInterceptors(NamespaceInterceptor(c.config.Namespace)),
4550
)
4651
}
4752

@@ -51,6 +56,7 @@ func (c client) Tenant() apiv1connect.TenantServiceClient {
5156
c.config.HttpClient(),
5257
c.config.BaseURL,
5358
compress.WithAll(compress.LevelBalanced),
59+
connect.WithInterceptors(NamespaceInterceptor(c.config.Namespace)),
5460
)
5561
}
5662

@@ -60,6 +66,7 @@ func (c client) TenantMember() apiv1connect.TenantMemberServiceClient {
6066
c.config.HttpClient(),
6167
c.config.BaseURL,
6268
compress.WithAll(compress.LevelBalanced),
69+
connect.WithInterceptors(NamespaceInterceptor(c.config.Namespace)),
6370
)
6471
}
6572

@@ -70,3 +77,41 @@ func (c client) Version() apiv1connect.VersionServiceClient {
7077
compress.WithAll(compress.LevelBalanced),
7178
)
7279
}
80+
81+
func NamespaceInterceptor(namespace string) connect.UnaryInterceptorFunc {
82+
return func(uf connect.UnaryFunc) connect.UnaryFunc {
83+
return func(ctx context.Context, ar connect.AnyRequest) (connect.AnyResponse, error) {
84+
switch r := ar.Any().(type) {
85+
case *v1.TenantMemberCreateRequest:
86+
if r.TenantMember.Namespace == "" {
87+
r.TenantMember.Namespace = namespace
88+
}
89+
case *v1.ProjectMemberCreateRequest:
90+
if r.ProjectMember.Namespace == "" {
91+
r.ProjectMember.Namespace = namespace
92+
}
93+
case *v1.TenantMemberFindRequest:
94+
if r.Namespace == "" {
95+
r.Namespace = namespace
96+
}
97+
case *v1.ProjectMemberFindRequest:
98+
if r.Namespace == "" {
99+
r.Namespace = namespace
100+
}
101+
case *v1.FindParticipatingProjectsRequest:
102+
if r.Namespace == "" {
103+
r.Namespace = namespace
104+
}
105+
case *v1.FindParticipatingTenantsRequest:
106+
if r.Namespace == "" {
107+
r.Namespace = namespace
108+
}
109+
case *v1.ListTenantMembersRequest:
110+
if r.Namespace == "" {
111+
r.Namespace = namespace
112+
}
113+
}
114+
return uf(ctx, ar)
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)