Merge pull request #364 from replicatedhq/divolgin/insecure

Do insecure upload if user allows it
This commit is contained in:
divolgin
2021-05-14 11:33:47 -07:00
committed by GitHub
5 changed files with 13 additions and 14 deletions

View File

@@ -246,11 +246,11 @@ func parseTimeFlags(v *viper.Viper) (*time.Time, error) {
return &sinceTime, nil
}
func shouldRetryRequest(err error, httpClient *http.Client) bool {
if strings.Contains(err.Error(), "x509") && httpClient == http.DefaultClient && canTryInsecure() {
httpClient = &http.Client{Transport: &http.Transport{
func shouldRetryRequest(err error) bool {
if strings.Contains(err.Error(), "x509") && canTryInsecure() {
httputil.AddTransport(&http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
})
return true
}
return false

View File

@@ -29,7 +29,7 @@ import (
var scheme = runtime.NewScheme()
var codecs = serializer.NewCodecFactory(scheme)
var parameterCodec = runtime.NewParameterCodec(scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
troubleshootv1beta1.AddToScheme,
troubleshootv1beta2.AddToScheme,

View File

@@ -14,7 +14,6 @@ func AddTransport(transport *http.Transport) {
}
func GetHttpClient() *http.Client {
if httpTransport != nil {
httpClient.Transport = httpTransport
return httpClient

View File

@@ -48,7 +48,7 @@ func uploadSupportBundle(r *troubleshootv1beta2.ResultRequest, archivePath strin
httpClient := httputil.GetHttpClient()
resp, err := httpClient.Do(req)
if err != nil {
if shouldRetryRequest(err, httpClient) {
if shouldRetryRequest(err) {
continue
}
return errors.Wrap(err, "execute request")
@@ -82,7 +82,7 @@ func uploadSupportBundle(r *troubleshootv1beta2.ResultRequest, archivePath strin
httpClient := httputil.GetHttpClient()
resp, err := httpClient.Do(req)
if err != nil {
if shouldRetryRequest(err, httpClient) {
if shouldRetryRequest(err) {
continue
}
return errors.Wrap(err, "execute redaction request")
@@ -109,7 +109,7 @@ func callbackSupportBundleAPI(r *troubleshootv1beta2.ResultRequest, archivePath
httpClient := httputil.GetHttpClient()
resp, err := httpClient.Do(req)
if err != nil {
if shouldRetryRequest(err, httpClient) {
if shouldRetryRequest(err) {
continue
}
return errors.Wrap(err, "execute request")
@@ -133,11 +133,11 @@ func getExpectedContentType(uploadURL string) string {
return parsedURL.Query().Get("Content-Type")
}
func shouldRetryRequest(err error, httpClient *http.Client) bool {
if strings.Contains(err.Error(), "x509") && httpClient == http.DefaultClient && canTryInsecure() {
httpClient = &http.Client{Transport: &http.Transport{
func shouldRetryRequest(err error) bool {
if strings.Contains(err.Error(), "x509") && canTryInsecure() {
httputil.AddTransport(&http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
})
return true
}
return false

View File

@@ -182,7 +182,7 @@ func loadSpecFromURL(arg string) ([]byte, error) {
httpClient := httputil.GetHttpClient()
resp, err := httpClient.Do(req)
if err != nil {
if shouldRetryRequest(err, httpClient) {
if shouldRetryRequest(err) {
continue
}
return nil, errors.Wrap(err, "execute request")