Skip to content

Commit 0351630

Browse files
committed
allow application to create ziti context without credentials and then query for external providers
1 parent 781ec45 commit 0351630

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

ziti/client.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
"crypto/x509/pkix"
2626
"encoding/pem"
2727
"fmt"
28+
"strings"
29+
"sync/atomic"
30+
2831
"github.com/go-openapi/strfmt"
2932
"github.com/golang-jwt/jwt/v5"
3033
"github.com/google/uuid"
@@ -46,8 +49,6 @@ import (
4649
"github.com/openziti/sdk-golang/ziti/edge/posture"
4750
"github.com/openziti/transport/v2"
4851
"github.com/pkg/errors"
49-
"strings"
50-
"sync/atomic"
5152
)
5253

5354
// CtrlClient is a stateful version of ZitiEdgeClient that simplifies operations
@@ -69,6 +70,15 @@ type CtrlClient struct {
6970
capabilitiesLoaded atomic.Bool
7071
}
7172

73+
func (self *CtrlClient) GetExternalSigners() (rest_model.ClientExternalJWTSignerList, error) {
74+
response, err := self.API.ExternalJWTSigner.ListExternalJWTSigners(nil)
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
return response.Payload.Data, nil
80+
}
81+
7282
// GetCurrentApiSession returns the current cached ApiSession or nil
7383
func (self *CtrlClient) GetCurrentApiSession() apis.ApiSession {
7484
return self.ClientApiClient.GetCurrentApiSession()
@@ -92,7 +102,7 @@ func (self *CtrlClient) Refresh() (apis.ApiSession, error) {
92102
}
93103

94104
// IsServiceListUpdateAvailable will contact the controller to determine if a new set of services are available. Service
95-
// updates could entail gaining/losing services access via policy or runtime authorization revocation due to posture
105+
// updates could entail gaining/losing service access via policy or runtime authorization revocation due to posture
96106
// checks.
97107
func (self *CtrlClient) IsServiceListUpdateAvailable() (bool, *strfmt.DateTime, error) {
98108
resp, err := self.API.CurrentAPISession.ListServiceUpdates(current_api_session.NewListServiceUpdatesParams(), self.GetCurrentApiSession())
@@ -104,7 +114,7 @@ func (self *CtrlClient) IsServiceListUpdateAvailable() (bool, *strfmt.DateTime,
104114
return self.lastServiceUpdate == nil || !resp.Payload.Data.LastChangeAt.Equal(*self.lastServiceUpdate), resp.Payload.Data.LastChangeAt, nil
105115
}
106116

107-
// Authenticate attempts to use authenticate, overwriting any existing ApiSession.
117+
// Authenticate attempts to authenticate, overwriting any existing ApiSession.
108118
func (self *CtrlClient) Authenticate() (apis.ApiSession, error) {
109119
var err error
110120

ziti/contexts.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,9 @@ func NewContextWithOpts(cfg *Config, options *Options) (Context, error) {
9898
newContext.maxDefaultConnections = 1
9999
}
100100

101-
if cfg.ID.Cert != "" && cfg.ID.Key != "" {
102-
idCredentials := edge_apis.NewIdentityCredentialsFromConfig(cfg.ID)
103-
idCredentials.ConfigTypes = cfg.ConfigTypes
104-
cfg.Credentials = idCredentials
105-
} else if cfg.Credentials == nil {
106-
return nil, errors.New("either cfg.ID or cfg.Credentials must be provided")
107-
}
101+
idCredentials := edge_apis.NewIdentityCredentialsFromConfig(cfg.ID)
102+
idCredentials.ConfigTypes = cfg.ConfigTypes
103+
cfg.Credentials = idCredentials
108104

109105
var apiStrs []string
110106
if len(cfg.ZtAPIs) > 0 {

ziti/ziti.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ type Context interface {
8888
// creation.
8989
Authenticate() error
9090

91+
// GetExternalSigners retrieves a list of external JWT signers with their details.
92+
// Returns an error if the operation fails.
93+
GetExternalSigners() ([]*rest_model.ClientExternalJWTSignerDetail, error)
94+
9195
// SetCredentials sets the credentials used to authenticate against the Edge Client API.
9296
SetCredentials(authenticator apis.Credentials)
9397

@@ -107,17 +111,17 @@ type Context interface {
107111
// DialWithOptions performs the same logic as Dial but allows specification of DialOptions.
108112
DialWithOptions(serviceName string, options *DialOptions) (edge.Conn, error)
109113

110-
// DialAddr finds the service for given address and performs a Dial for it.
114+
// DialAddr finds the service for a given address and performs a Dial for it.
111115
DialAddr(network string, addr string) (edge.Conn, error)
112116

113117
// Listen attempts to host a service by the given service name; authenticating as necessary in order to obtain
114118
// a service session, attach to Edge Routers, and bind (host) the service.
115119
Listen(serviceName string) (edge.Listener, error)
116120

117-
// ListenWithOptions performs the same logic as Listen, but allows the specification of ListenOptions.
121+
// ListenWithOptions performs the same logic as Listen but allows the specification of ListenOptions.
118122
ListenWithOptions(serviceName string, options *ListenOptions) (edge.Listener, error)
119123

120-
// GetServiceId will return the id of a specific service by service name. If not found, false, will be returned
124+
// GetServiceId will return the id of a specific service by service name. If not found, false will be returned
121125
// with an empty string.
122126
GetServiceId(serviceName string) (string, bool, error)
123127

@@ -128,15 +132,15 @@ type Context interface {
128132
// GetService will return the service details of a specific service by service name.
129133
GetService(serviceName string) (*rest_model.ServiceDetail, bool)
130134

131-
// GetServiceForAddr finds the service with intercept that matches best to given address
135+
// GetServiceForAddr finds the service with intercept that matches best to the given address
132136
GetServiceForAddr(network, hostname string, port uint16) (*rest_model.ServiceDetail, int, error)
133137

134138
// RefreshServices forces the context to refresh the list of services the current authenticating identity has access
135139
// to.
136140
RefreshServices() error
137141

138142
// RefreshService forces the context to refresh just the service with the given name. If the given service isn't
139-
// found, a nil will be returned
143+
// found, nil will be returned
140144
RefreshService(serviceName string) (*rest_model.ServiceDetail, error)
141145

142146
// GetServiceTerminators will return a slice of rest_model.TerminatorClientDetail for a specific service name.
@@ -668,6 +672,11 @@ func (context *ContextImpl) refreshSessions() {
668672
}
669673
}
670674

675+
func (context *ContextImpl) GetExternalSigners() ([]*rest_model.ClientExternalJWTSignerDetail, error) {
676+
result, err := context.CtrlClt.GetExternalSigners()
677+
return result, err
678+
}
679+
671680
func (context *ContextImpl) RefreshServices() error {
672681
return context.refreshServices(true, false)
673682
}

0 commit comments

Comments
 (0)