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
5 changes: 5 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func Client(config jira.Config) *jira.Client {
config.MTLSConfig.ClientKey = viper.GetString("mtls.client_key")
}

// Custom Headers
if config.CustomHeaders == nil {
config.CustomHeaders = viper.GetStringMapString("custom_headers")
}

jiraClient = jira.NewClient(
config,
jira.WithTimeout(clientTimeout),
Expand Down
48 changes: 28 additions & 20 deletions pkg/jira/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,27 @@ type MTLSConfig struct {

// Config is a jira config.
type Config struct {
Server string
Login string
APIToken string
AuthType *AuthType
Insecure *bool
Debug bool
MTLSConfig MTLSConfig
Server string
Login string
APIToken string
AuthType *AuthType
Insecure *bool
Debug bool
MTLSConfig MTLSConfig
CustomHeaders map[string]string
}

// Client is a jira client.
type Client struct {
transport http.RoundTripper
insecure bool
server string
login string
authType *AuthType
token string
timeout time.Duration
debug bool
transport http.RoundTripper
insecure bool
server string
login string
authType *AuthType
token string
timeout time.Duration
debug bool
customHeaders map[string]string
}

// ClientFunc decorates option for client.
Expand All @@ -132,11 +134,12 @@ type ClientFunc func(*Client)
// NewClient instantiates new jira client.
func NewClient(c Config, opts ...ClientFunc) *Client {
client := Client{
server: strings.TrimSuffix(c.Server, "/"),
login: c.Login,
token: c.APIToken,
authType: c.AuthType,
debug: c.Debug,
server: strings.TrimSuffix(c.Server, "/"),
login: c.Login,
token: c.APIToken,
authType: c.AuthType,
debug: c.Debug,
customHeaders: c.CustomHeaders,
}

for _, opt := range opts {
Expand Down Expand Up @@ -266,6 +269,11 @@ func (c *Client) request(ctx context.Context, method, endpoint string, body []by
req.Header.Set(k, v)
}

// Apply custom headers from config.
for k, v := range c.customHeaders {
req.Header.Set(k, v)
}

// Set default auth type to `basic`.
if c.authType == nil {
basic := AuthTypeBasic
Expand Down