Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom dial options to grpc connection #325

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions pkg/client/zitadel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
insecure bool
unaryInterceptors []grpc.UnaryClientInterceptor
streamInterceptors []grpc.StreamClientInterceptor
dialOptions []grpc.DialOption
*grpc.ClientConn
}

Expand Down Expand Up @@ -50,7 +51,7 @@
c.streamInterceptors...,
),
}

dialOptions = append(dialOptions, c.dialOptions...)

Check warning on line 54 in pkg/client/zitadel/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/client/zitadel/client.go#L54

Added line #L54 was not covered by tests
opt, err := transportOption(c.api, c.insecure)
if err != nil {
return nil, err
Expand Down Expand Up @@ -107,7 +108,7 @@

type Option func(*Connection) error

//WithCustomURL replaces the standard issuer (https://issuer.zitadel.ch) and api endpoint (api.zitadel.ch:443)
// WithCustomURL replaces the standard issuer (https://issuer.zitadel.ch) and api endpoint (api.zitadel.ch:443)
func WithCustomURL(issuer, api string) func(*Connection) error {
return func(client *Connection) error {
client.issuer = issuer
Expand All @@ -116,10 +117,10 @@
}
}

//WithKeyPath sets the path to the key.json used for the authentication
//if not set env var ZITADEL_KEY_PATH will be used
// WithKeyPath sets the path to the key.json used for the authentication
// if not set env var ZITADEL_KEY_PATH will be used
//
//Deprecated: use WithJWTProfileTokenSource(middleware.JWTProfileFromPath(keyPath)) instead
// Deprecated: use WithJWTProfileTokenSource(middleware.JWTProfileFromPath(keyPath)) instead
func WithKeyPath(keyPath string) func(*Connection) error {
return func(client *Connection) error {
client.jwtProfileTokenSource = func(issuer string, scopes []string) (oauth2.TokenSource, error) {
Expand All @@ -129,45 +130,53 @@
}
}

//WithJWTProfileTokenSource sets the provider used for the authentication
//if not set, the key file will be read from the path set in env var ZITADEL_KEY_PATH
// WithJWTProfileTokenSource sets the provider used for the authentication
// if not set, the key file will be read from the path set in env var ZITADEL_KEY_PATH
func WithJWTProfileTokenSource(provider middleware.JWTProfileTokenSource) func(*Connection) error {
return func(client *Connection) error {
client.jwtProfileTokenSource = provider
return nil
}
}

//WithOrgID sets the organization context (where the api calls are executed)
//if not set the resource owner (organisation) of the calling user will be used
// WithOrgID sets the organization context (where the api calls are executed)
// if not set the resource owner (organisation) of the calling user will be used
func WithOrgID(orgID string) func(*Connection) error {
return func(client *Connection) error {
client.orgID = orgID
return nil
}
}

//WithInsecure disables transport security for the client connection
//use only when absolutely necessary (local development)
// WithInsecure disables transport security for the client connection
// use only when absolutely necessary (local development)
func WithInsecure() func(*Connection) error {
return func(client *Connection) error {
client.insecure = true
return nil
}
}

//WithUnaryInterceptors adds non ZITADEL specific interceptors to the connection
// WithUnaryInterceptors adds non ZITADEL specific interceptors to the connection
func WithUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) func(*Connection) error {
return func(client *Connection) error {
client.unaryInterceptors = append(client.unaryInterceptors, interceptors...)
return nil
}
}

//WithStreamInterceptors adds non ZITADEL specific interceptors to the connection
// WithStreamInterceptors adds non ZITADEL specific interceptors to the connection
func WithStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) func(*Connection) error {
return func(client *Connection) error {
client.streamInterceptors = append(client.streamInterceptors, interceptors...)
return nil
}
}

// WithDialOptions adds non ZITADEL specific dial options to the connection
func WithDialOptions(opts ...grpc.DialOption) func(*Connection) error {
return func(client *Connection) error {
client.dialOptions = append(client.dialOptions, opts...)
return nil

Check warning on line 180 in pkg/client/zitadel/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/client/zitadel/client.go#L177-L180

Added lines #L177 - L180 were not covered by tests
}
}
Loading