Skip to content

Commit

Permalink
feat: update generator to generate User client v2 (#381)
Browse files Browse the repository at this point in the history
This PR generates the missing V2 of the user client as mentioned in
#373

v2beta is deprecated and is throwing warnings when using the client.
This adds the GA v2 client without breaking the applications that are
already on v2beta

Biggest change other than adding the generated code is to add a methods
to `pkg/client/client.go` to support the new client versions

### Definition of Ready

- [x] I am happy with the code
- [x] Short description of the feature/issue is added in the pr
description
- [x] PR is linked to the corresponding user story
- [x] Acceptance criteria are met
- [x] All open todos and follow ups are defined in a new ticket and
justified
- [x] Deviations from the acceptance criteria and design are agreed with
the PO and documented.
- [x] No debug or dead code
- [x] My code has no repetitions
- [ ] Critical parts are tested automatically
- [x] Where possible E2E tests are implemented
- [x] Documentation/examples are up-to-date
- [x] All non-functional requirements are met
- [x] Functionality of the acceptance criteria is checked manually on
the dev system.
  • Loading branch information
livio-a authored Sep 24, 2024
2 parents 0ebcb4b + b09083d commit 0e123ac
Show file tree
Hide file tree
Showing 39 changed files with 30,386 additions and 26 deletions.
12 changes: 10 additions & 2 deletions build/zitadel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,20 @@ RUN ./build/zitadel/generate-grpc-client.sh ${PROJECT_PATH} \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/auth/auth_grpc.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/auth/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/management/management_grpc.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/management/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/system/system_grpc.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/system/ \
# v2beta packages
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/session/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/session/v2beta/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/oidc/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/oidc/v2beta/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/org/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/org/v2beta/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/settings/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/settings/v2beta/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/user/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/user/v2beta/
#######################
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/user/v2beta/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/user/v2beta/ \
# v2 packages
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/session/v2/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/session/v2/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/oidc/v2/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/oidc/v2/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/org/v2/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/org/v2/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/settings/v2/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/settings/v2/ \
&& mv /go/src/github.com/zitadel/zitadel/pkg/grpc/user/v2/*.pb.go /zitadel-api/go/src/${PROJECT_PATH}/zitadel/user/v2/

#######################
## prepare generated files for output
#######################
FROM scratch as zitadel-copy
Expand Down
24 changes: 24 additions & 0 deletions build/zitadel/generate-grpc-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protoc \
--go_opt=Mzitadel/session/v2beta/challenge.proto=${ZITADEL_IMPORT}/session/v2beta \
--go_opt=Mzitadel/session/v2beta/session.proto=${ZITADEL_IMPORT}/session/v2beta \
--go_opt=Mzitadel/session/v2beta/session_service.proto=${ZITADEL_IMPORT}/session/v2beta \
--go_opt=Mzitadel/session/v2/session_service.proto=${ZITADEL_IMPORT}/session/v2 \
--go_opt=Mzitadel/oidc/v2beta/authorization.proto=${ZITADEL_IMPORT}/oidc/v2beta \
--go_opt=Mzitadel/oidc/v2beta/oidc_service.proto=${ZITADEL_IMPORT}/oidc/v2beta \
--go_opt=Mzitadel/org/v2beta/org_service.proto=${ZITADEL_IMPORT}/org/v2beta \
Expand All @@ -69,6 +70,29 @@ protoc \
--go_opt=Mzitadel/user/v2beta/query.proto=${ZITADEL_IMPORT}/user/v2beta \
--go_opt=Mzitadel/user/v2beta/user.proto=${ZITADEL_IMPORT}/user/v2beta \
--go_opt=Mzitadel/user/v2beta/user_service.proto=${ZITADEL_IMPORT}/user/v2beta \
--go_opt=Mzitadel/object/v2/object.proto=${ZITADEL_IMPORT}/object/v2 \
--go_opt=Mzitadel/session/v2/challenge.proto=${ZITADEL_IMPORT}/session/v2 \
--go_opt=Mzitadel/session/v2/session.proto=${ZITADEL_IMPORT}/session/v2 \
--go_opt=Mzitadel/oidc/v2/authorization.proto=${ZITADEL_IMPORT}/oidc/v2 \
--go_opt=Mzitadel/oidc/v2/oidc_service.proto=${ZITADEL_IMPORT}/oidc/v2 \
--go_opt=Mzitadel/org/v2/org_service.proto=${ZITADEL_IMPORT}/org/v2 \
--go_opt=Mzitadel/settings/v2/branding_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/domain_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/legal_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/lockout_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/login_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/password_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/security_settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/settings.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/settings/v2/settings_service.proto=${ZITADEL_IMPORT}/settings/v2 \
--go_opt=Mzitadel/user/v2/auth.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/email.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/idp.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/password.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/phone.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/query.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/user.proto=${ZITADEL_IMPORT}/user/v2 \
--go_opt=Mzitadel/user/v2/user_service.proto=${ZITADEL_IMPORT}/user/v2 \
--go_out /go/src \
--go-grpc_out /go/src \
$(find /proto/include/zitadel -iname *.proto)
93 changes: 69 additions & 24 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import (
"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/admin"
"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/auth"
"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/management"
oidc_pb "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/oidc/v2beta"
org "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/org/v2beta"
session "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/session/v2beta"
settings "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/settings/v2beta"
oidcV2_pb "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/oidc/v2"
oidcV2Beta_pb "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/oidc/v2beta"
orgV2 "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/org/v2"
orgV2Beta "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/org/v2beta"
sessionV2 "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/session/v2"
sessionV2Beta "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/session/v2beta"
settingsV2 "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/settings/v2"
settingsV2Beta "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/settings/v2beta"
"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/system"
user "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/user/v2beta"
userV2 "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/user/v2"
userV2Beta "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/user/v2beta"
"github.com/zitadel/zitadel-go/v3/pkg/zitadel"
)

Expand Down Expand Up @@ -44,15 +49,20 @@ func WithGRPCDialOptions(opts ...grpc.DialOption) Option {
type Client struct {
connection *grpc.ClientConn

systemService system.SystemServiceClient
adminService admin.AdminServiceClient
managementService management.ManagementServiceClient
userService user.UserServiceClient
authService auth.AuthServiceClient
settingsService settings.SettingsServiceClient
sessionService session.SessionServiceClient
organizationService org.OrganizationServiceClient
oidcService oidc_pb.OIDCServiceClient
systemService system.SystemServiceClient
adminService admin.AdminServiceClient
managementService management.ManagementServiceClient
userService userV2Beta.UserServiceClient
userServiceV2 userV2.UserServiceClient
authService auth.AuthServiceClient
settingsService settingsV2Beta.SettingsServiceClient
settingsServiceV2 settingsV2.SettingsServiceClient
sessionService sessionV2Beta.SessionServiceClient
sessionServiceV2 sessionV2.SessionServiceClient
organizationService orgV2Beta.OrganizationServiceClient
organizationServiceV2 orgV2.OrganizationServiceClient
oidcService oidcV2Beta_pb.OIDCServiceClient
oidcServiceV2 oidcV2_pb.OIDCServiceClient
}

func New(ctx context.Context, zitadel *zitadel.Zitadel, opts ...Option) (*Client, error) {
Expand Down Expand Up @@ -128,37 +138,72 @@ func (c *Client) AuthService() auth.AuthServiceClient {
return c.authService
}

func (c *Client) UserService() user.UserServiceClient {
func (c *Client) UserService() userV2Beta.UserServiceClient {
if c.userService == nil {
c.userService = user.NewUserServiceClient(c.connection)
c.userService = userV2Beta.NewUserServiceClient(c.connection)
}
return c.userService
}

func (c *Client) SettingsService() settings.SettingsServiceClient {
func (c *Client) UserServiceV2() userV2.UserServiceClient {
if c.userServiceV2 == nil {
c.userServiceV2 = userV2.NewUserServiceClient(c.connection)
}
return c.userServiceV2
}

func (c *Client) SettingsService() settingsV2Beta.SettingsServiceClient {
if c.settingsService == nil {
c.settingsService = settings.NewSettingsServiceClient(c.connection)
c.settingsService = settingsV2Beta.NewSettingsServiceClient(c.connection)
}
return c.settingsService
}

func (c *Client) SessionService() session.SessionServiceClient {
func (c *Client) SettingsServiceV2() settingsV2.SettingsServiceClient {
if c.settingsServiceV2 == nil {
c.settingsServiceV2 = settingsV2.NewSettingsServiceClient(c.connection)
}
return c.settingsServiceV2
}

func (c *Client) SessionService() sessionV2Beta.SessionServiceClient {
if c.sessionService == nil {
c.sessionService = session.NewSessionServiceClient(c.connection)
c.sessionService = sessionV2Beta.NewSessionServiceClient(c.connection)
}
return c.sessionService
}

func (c *Client) OIDCService() oidc_pb.OIDCServiceClient {
func (c *Client) SessionServiceV2() sessionV2.SessionServiceClient {
if c.sessionServiceV2 == nil {
c.sessionServiceV2 = sessionV2.NewSessionServiceClient(c.connection)
}
return c.sessionServiceV2
}

func (c *Client) OIDCService() oidcV2Beta_pb.OIDCServiceClient {
if c.oidcService == nil {
c.oidcService = oidc_pb.NewOIDCServiceClient(c.connection)
c.oidcService = oidcV2Beta_pb.NewOIDCServiceClient(c.connection)
}
return c.oidcService
}

func (c *Client) OrganizationService() org.OrganizationServiceClient {
func (c *Client) OIDCServiceV2() oidcV2_pb.OIDCServiceClient {
if c.oidcServiceV2 == nil {
c.oidcServiceV2 = oidcV2_pb.NewOIDCServiceClient(c.connection)
}
return c.oidcServiceV2
}

func (c *Client) OrganizationService() orgV2Beta.OrganizationServiceClient {
if c.organizationService == nil {
c.organizationService = org.NewOrganizationServiceClient(c.connection)
c.organizationService = orgV2Beta.NewOrganizationServiceClient(c.connection)
}
return c.organizationService
}

func (c *Client) OrganizationServiceV2() orgV2.OrganizationServiceClient {
if c.organizationServiceV2 == nil {
c.organizationServiceV2 = orgV2.NewOrganizationServiceClient(c.connection)
}
return c.organizationServiceV2
}
25 changes: 25 additions & 0 deletions pkg/client/oidc/v2/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v2

import (
"context"

"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel"
oidc "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/oidc/v2"
)

type Client struct {
Connection *zitadel.Connection
oidc.OIDCServiceClient
}

func NewClient(ctx context.Context, issuer, api string, scopes []string, options ...zitadel.Option) (*Client, error) {
conn, err := zitadel.NewConnection(ctx, issuer, api, scopes, options...)
if err != nil {
return nil, err
}

return &Client{
Connection: conn,
OIDCServiceClient: oidc.NewOIDCServiceClient(conn.ClientConn),
}, nil
}
25 changes: 25 additions & 0 deletions pkg/client/org/v2/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v2

import (
"context"

"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel"
org "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/org/v2"
)

type Client struct {
Connection *zitadel.Connection
org.OrganizationServiceClient
}

func NewClient(ctx context.Context, issuer, api string, scopes []string, options ...zitadel.Option) (*Client, error) {
conn, err := zitadel.NewConnection(ctx, issuer, api, scopes, options...)
if err != nil {
return nil, err
}

return &Client{
Connection: conn,
OrganizationServiceClient: org.NewOrganizationServiceClient(conn.ClientConn),
}, nil
}
25 changes: 25 additions & 0 deletions pkg/client/session/v2/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v2

import (
"context"

"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel"
session "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/session/v2"
)

type Client struct {
Connection *zitadel.Connection
session.SessionServiceClient
}

func NewClient(ctx context.Context, issuer, api string, scopes []string, options ...zitadel.Option) (*Client, error) {
conn, err := zitadel.NewConnection(ctx, issuer, api, scopes, options...)
if err != nil {
return nil, err
}

return &Client{
Connection: conn,
SessionServiceClient: session.NewSessionServiceClient(conn.ClientConn),
}, nil
}
25 changes: 25 additions & 0 deletions pkg/client/settings/v2/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v2

import (
"context"

"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel"
settings "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/settings/v2"
)

type Client struct {
Connection *zitadel.Connection
settings.SettingsServiceClient
}

func NewClient(ctx context.Context, issuer, api string, scopes []string, options ...zitadel.Option) (*Client, error) {
conn, err := zitadel.NewConnection(ctx, issuer, api, scopes, options...)
if err != nil {
return nil, err
}

return &Client{
Connection: conn,
SettingsServiceClient: settings.NewSettingsServiceClient(conn.ClientConn),
}, nil
}
25 changes: 25 additions & 0 deletions pkg/client/user/v2/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v2

import (
"context"

"github.com/zitadel/zitadel-go/v3/pkg/client/zitadel"
user "github.com/zitadel/zitadel-go/v3/pkg/client/zitadel/user/v2"
)

type Client struct {
Connection *zitadel.Connection
user.UserServiceClient
}

func NewClient(ctx context.Context, issuer, api string, scopes []string, options ...zitadel.Option) (*Client, error) {
conn, err := zitadel.NewConnection(ctx, issuer, api, scopes, options...)
if err != nil {
return nil, err
}

return &Client{
Connection: conn,
UserServiceClient: user.NewUserServiceClient(conn.ClientConn),
}, nil
}
Loading

0 comments on commit 0e123ac

Please sign in to comment.