Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/baton-zendesk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func getConnector(ctx context.Context, cfg *config.Zendesk) (types.ConnectorServ
cfg.Subdomain,
cfg.Email,
cfg.ApiToken,
cfg.BaseUrl,
)
if err != nil {
logger.Error("error creating connector", zap.Error(err))
Expand Down
16 changes: 12 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@ type ZendeskClient struct {
client *zendesk.Client
}

func New(ctx context.Context, httpClient *http.Client, subdomain string, email string, apiToken string) (*ZendeskClient, error) {
func New(ctx context.Context, httpClient *http.Client, subdomain string, email string, apiToken string, baseURL string) (*ZendeskClient, error) {
zc := &ZendeskClient{}
client, err := zendesk.NewClient(httpClient)
if err != nil {
return nil, err
}
err = client.SetSubdomain(subdomain)
if err != nil {
return nil, err
// Custom base URL takes precedence over subdomain-based URL
if baseURL != "" {
err = client.SetEndpointURL(baseURL)
if err != nil {
return nil, err
}
} else {
err = client.SetSubdomain(subdomain)
if err != nil {
return nil, err
}
}
client.SetCredential(zendesk.NewAPITokenCredential(email, apiToken))
zc.client = client
Expand Down
13 changes: 8 additions & 5 deletions pkg/config/conf.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ var (
field.WithDisplayName("Organizations"),
field.WithDescription("Limit syncing to specific organizations"),
)
BaseURLField = field.StringField(
"base-url",
field.WithDisplayName("Base URL"),
field.WithDescription("Override the Zendesk API URL (for testing)"),
field.WithHidden(true),
field.WithExportTarget(field.ExportTargetCLIOnly),
)

ConfigurationFields = []field.SchemaField{
SubdomainField,
ApiTokenField,
EmailField,
OrgsField,
BaseURLField,
}
)

Expand Down
6 changes: 4 additions & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Connector struct {
subdomain string
email string
apiToken string
baseURL string
}

func (c *Connector) cacheUsers(ctx context.Context) ([]zendesk.User, error) {
Expand Down Expand Up @@ -124,11 +125,11 @@ func (d *Connector) Validate(ctx context.Context) (annotations.Annotations, erro
}

// New returns a new instance of the connector.
func New(ctx context.Context, zendeskOrgs []string, subdomain string, email string, apiToken string) (*Connector, error) {
func New(ctx context.Context, zendeskOrgs []string, subdomain string, email string, apiToken string, baseURL string) (*Connector, error) {
var zc *client.ZendeskClient
if apiToken != "" {
var err error
zc, err = client.New(ctx, nil, subdomain, email, apiToken)
zc, err = client.New(ctx, nil, subdomain, email, apiToken, baseURL)
if err != nil {
return nil, err
}
Expand All @@ -140,5 +141,6 @@ func New(ctx context.Context, zendeskOrgs []string, subdomain string, email stri
subdomain: subdomain,
email: email,
apiToken: apiToken,
baseURL: baseURL,
}, nil
}
Loading