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

fix:deck konnect commands do not honor --headers flag #468 #557

Merged
merged 6 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,6 @@ func initKonnectConfig() error {
konnectConfig.Password = password
konnectConfig.Debug = (viper.GetInt("verbose") >= 1)
konnectConfig.Address = viper.GetString("konnect-addr")
konnectConfig.Headers = viper.GetStringSlice("headers")
return nil
}
2 changes: 1 addition & 1 deletion konnect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ClientOpts struct {
// NewClient returns a Client which talks to Konnect's API.
func NewClient(httpClient *http.Client, opts ClientOpts) (*Client, error) {
if httpClient == nil {
httpClient = http.DefaultClient
return nil, fmt.Errorf("nil httpClient passed")
Copy link
Member

@hbagdi hbagdi Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this since this change is unrelated.

}
client := new(Client)
client.client = httpClient
Expand Down
13 changes: 13 additions & 0 deletions utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ type KonnectConfig struct {
Debug bool

Address string

Headers []string
}

// ForWorkspace returns a copy of KongClientConfig that produces a KongClient for the workspace specified by argument.
Expand Down Expand Up @@ -193,6 +195,17 @@ func parseHeaders(headers []string) (http.Header, error) {
func GetKonnectClient(httpClient *http.Client, config KonnectConfig) (*konnect.Client,
error) {
address := CleanAddress(config.Address)

if httpClient == nil {
defaultTransport := http.DefaultTransport.(*http.Transport)
httpClient = http.DefaultClient
httpClient.Transport = defaultTransport
}
headers, err := parseHeaders(config.Headers)
if err != nil {
return nil, fmt.Errorf("parsing headers: %w", err)
}
httpClient = kong.HTTPClientWithHeaders(httpClient, headers)
client, err := konnect.NewClient(httpClient, konnect.ClientOpts{
BaseURL: address,
})
Expand Down