Skip to content

Commit c17be3f

Browse files
committed
Do insecure upload if user allows it
1 parent 3571843 commit c17be3f

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

cmd/troubleshoot/cli/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ func parseTimeFlags(v *viper.Viper) (*time.Time, error) {
246246
return &sinceTime, nil
247247
}
248248

249-
func shouldRetryRequest(err error, httpClient *http.Client) bool {
250-
if strings.Contains(err.Error(), "x509") && httpClient == http.DefaultClient && canTryInsecure() {
251-
httpClient = &http.Client{Transport: &http.Transport{
249+
func shouldRetryRequest(err error) bool {
250+
if strings.Contains(err.Error(), "x509") && canTryInsecure() {
251+
httputil.AddTransport(&http.Transport{
252252
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
253-
}}
253+
})
254254
return true
255255
}
256256
return false

pkg/client/troubleshootclientset/fake/register.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/httputil/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func AddTransport(transport *http.Transport) {
1414
}
1515

1616
func GetHttpClient() *http.Client {
17-
1817
if httpTransport != nil {
1918
httpClient.Transport = httpTransport
2019
return httpClient

pkg/supportbundle/aftercollection.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func uploadSupportBundle(r *troubleshootv1beta2.ResultRequest, archivePath strin
4848
httpClient := httputil.GetHttpClient()
4949
resp, err := httpClient.Do(req)
5050
if err != nil {
51-
if shouldRetryRequest(err, httpClient) {
51+
if shouldRetryRequest(err) {
5252
continue
5353
}
5454
return errors.Wrap(err, "execute request")
@@ -82,7 +82,7 @@ func uploadSupportBundle(r *troubleshootv1beta2.ResultRequest, archivePath strin
8282
httpClient := httputil.GetHttpClient()
8383
resp, err := httpClient.Do(req)
8484
if err != nil {
85-
if shouldRetryRequest(err, httpClient) {
85+
if shouldRetryRequest(err) {
8686
continue
8787
}
8888
return errors.Wrap(err, "execute redaction request")
@@ -109,7 +109,7 @@ func callbackSupportBundleAPI(r *troubleshootv1beta2.ResultRequest, archivePath
109109
httpClient := httputil.GetHttpClient()
110110
resp, err := httpClient.Do(req)
111111
if err != nil {
112-
if shouldRetryRequest(err, httpClient) {
112+
if shouldRetryRequest(err) {
113113
continue
114114
}
115115
return errors.Wrap(err, "execute request")
@@ -133,11 +133,11 @@ func getExpectedContentType(uploadURL string) string {
133133
return parsedURL.Query().Get("Content-Type")
134134
}
135135

136-
func shouldRetryRequest(err error, httpClient *http.Client) bool {
137-
if strings.Contains(err.Error(), "x509") && httpClient == http.DefaultClient && canTryInsecure() {
138-
httpClient = &http.Client{Transport: &http.Transport{
136+
func shouldRetryRequest(err error) bool {
137+
if strings.Contains(err.Error(), "x509") && canTryInsecure() {
138+
httputil.AddTransport(&http.Transport{
139139
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
140-
}}
140+
})
141141
return true
142142
}
143143
return false

pkg/supportbundle/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func loadSpecFromURL(arg string) ([]byte, error) {
182182
httpClient := httputil.GetHttpClient()
183183
resp, err := httpClient.Do(req)
184184
if err != nil {
185-
if shouldRetryRequest(err, httpClient) {
185+
if shouldRetryRequest(err) {
186186
continue
187187
}
188188
return nil, errors.Wrap(err, "execute request")

0 commit comments

Comments
 (0)