Merge "Allow remotedirect to ignore http*_proxy settings"

This commit is contained in:
Zuul 2020-03-27 18:46:23 +00:00 committed by Gerrit Code Review
commit 21c7c166ff
4 changed files with 28 additions and 6 deletions

View File

@ -226,4 +226,9 @@ type RemoteDirect struct {
// Ignore SSL certificate check. This options is useful for remote APIs
// with non-trusted or self-signed SSL certificates
Insecure bool `json:"insecure,omitempty"`
// Allow remotedirect requests to be proxied. This defaults to false
// because in general, most users will want to communicate directly
// with redfish and other bmc urls directly even if the environment
// has a proxy set
UseProxy bool `json:"useproxy,omitempty"`
}

View File

@ -85,6 +85,7 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
ephNodeID string,
isoPath string,
insecure bool,
useproxy bool,
) (RemoteDirect, error) {
if remoteURL == "" {
return RemoteDirect{},
@ -113,15 +114,25 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
UserAgent: "airshipctl/client",
}
// see https://github.com/golang/go/issues/26013
// We clone the default transport to ensure when we customize the transport
// that we are providing it sane timeouts and other defaults that we would
// normally get when not overriding the transport
defaultTransportCopy := (http.DefaultTransport.(*http.Transport))
transport := defaultTransportCopy.Clone()
if insecure {
cfg.HTTPClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, //nolint:gosec
},
},
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true, //nolint:gosec
}
}
if !useproxy {
transport.Proxy = nil
}
cfg.HTTPClient = &http.Client{
Transport: transport,
}
var api redfishApi.RedfishAPI = redfishClient.NewAPIClient(cfg).DefaultApi

View File

@ -249,6 +249,7 @@ func TestNewRedfishRemoteDirectClient(t *testing.T) {
computerSystemID,
"/tmp/test.iso",
true,
false,
)
assert.NoError(t, err)
@ -259,6 +260,7 @@ func TestNewRedfishRemoteDirectClient(t *testing.T) {
computerSystemID,
"/tmp/test.iso",
false,
false,
)
expectedError := "missing configuration: redfish remote url empty"
assert.EqualError(t, err, expectedError)
@ -270,6 +272,7 @@ func TestNewRedfishRemoteDirectClient(t *testing.T) {
"",
"/tmp/test.iso",
false,
false,
)
expectedError = "missing configuration: redfish ephemeral node id empty"
assert.EqualError(t, err, expectedError)
@ -281,6 +284,7 @@ func TestNewRedfishRemoteDirectClient(t *testing.T) {
computerSystemID,
"",
false,
false,
)
expectedError = "missing configuration: redfish ephemeral node iso Path empty"
assert.EqualError(t, err, expectedError)
@ -295,6 +299,7 @@ func getDefaultRedfishRemoteDirectObj(t *testing.T, api redfishAPI.RedfishAPI) R
computerSystemID,
"/tmp/test.iso",
false,
false,
)
require.NoError(t, err)

View File

@ -49,6 +49,7 @@ func getRemoteDirectClient(remoteConfig *config.RemoteDirect, remoteURL string)
nodeID,
remoteConfig.IsoURL,
remoteConfig.Insecure,
remoteConfig.UseProxy,
)
if err != nil {
alog.Debugf("redfish remotedirect client creation failed")