diff --git a/pkg/document/bundle.go b/pkg/document/bundle.go index 3f39c5372..28f629844 100644 --- a/pkg/document/bundle.go +++ b/pkg/document/bundle.go @@ -180,9 +180,9 @@ func (b *BundleFactory) GetByName(name string) (Document, error) { // by adding strongly typed errors switch found := len(resSet); { case found == 0: - return &DocumentFactory{}, fmt.Errorf("no documents found with name %s", name) + return &Factory{}, fmt.Errorf("no documents found with name %s", name) case found > 1: - return &DocumentFactory{}, fmt.Errorf("more than one document found with name %s", name) + return &Factory{}, fmt.Errorf("more than one document found with name %s", name) default: return NewDocument(resSet[0]) } diff --git a/pkg/document/document.go b/pkg/document/document.go index 73354c713..3b14691c4 100644 --- a/pkg/document/document.go +++ b/pkg/document/document.go @@ -4,8 +4,8 @@ import ( "sigs.k8s.io/kustomize/v3/pkg/resource" ) -// DocumentFactory holds document data -type DocumentFactory struct { +// Factory holds document data +type Factory struct { resource.Resource } @@ -29,90 +29,90 @@ type Document interface { } // GetNamespace returns the namespace the resource thinks it's in. -func (d *DocumentFactory) GetNamespace() string { +func (d *Factory) GetNamespace() string { r := d.GetKustomizeResource() return r.GetNamespace() } // GetString returns the string value at path. -func (d *DocumentFactory) GetString(path string) (string, error) { +func (d *Factory) GetString(path string) (string, error) { r := d.GetKustomizeResource() return r.GetString(path) } // GetStringSlice returns a string slice at path. -func (d *DocumentFactory) GetStringSlice(path string) ([]string, error) { +func (d *Factory) GetStringSlice(path string) ([]string, error) { r := d.GetKustomizeResource() return r.GetStringSlice(path) } // GetBool returns a bool at path. -func (d *DocumentFactory) GetBool(path string) (bool, error) { +func (d *Factory) GetBool(path string) (bool, error) { r := d.GetKustomizeResource() return r.GetBool(path) } // GetFloat64 returns a float64 at path. -func (d *DocumentFactory) GetFloat64(path string) (float64, error) { +func (d *Factory) GetFloat64(path string) (float64, error) { r := d.GetKustomizeResource() return r.GetFloat64(path) } // GetInt64 returns an int64 at path. -func (d *DocumentFactory) GetInt64(path string) (int64, error) { +func (d *Factory) GetInt64(path string) (int64, error) { r := d.GetKustomizeResource() return r.GetInt64(path) } // GetSlice returns a slice at path. -func (d *DocumentFactory) GetSlice(path string) ([]interface{}, error) { +func (d *Factory) GetSlice(path string) ([]interface{}, error) { r := d.GetKustomizeResource() return r.GetSlice(path) } // GetStringMap returns a string map at path. -func (d *DocumentFactory) GetStringMap(path string) (map[string]string, error) { +func (d *Factory) GetStringMap(path string) (map[string]string, error) { r := d.GetKustomizeResource() return r.GetStringMap(path) } // GetMap returns a map at path. -func (d *DocumentFactory) GetMap(path string) (map[string]interface{}, error) { +func (d *Factory) GetMap(path string) (map[string]interface{}, error) { r := d.GetKustomizeResource() return r.GetMap(path) } // AsYAML returns the document as a YAML byte stream. -func (d *DocumentFactory) AsYAML() ([]byte, error) { +func (d *Factory) AsYAML() ([]byte, error) { r := d.GetKustomizeResource() return r.AsYAML() } // MarshalJSON returns the document as JSON. -func (d *DocumentFactory) MarshalJSON() ([]byte, error) { +func (d *Factory) MarshalJSON() ([]byte, error) { r := d.GetKustomizeResource() return r.MarshalJSON() } // GetName returns the name: field from the document. -func (d *DocumentFactory) GetName() string { +func (d *Factory) GetName() string { r := d.GetKustomizeResource() return r.GetName() } // GetKind returns the Kind: field from the document. -func (d *DocumentFactory) GetKind() string { +func (d *Factory) GetKind() string { r := d.GetKustomizeResource() return r.GetKind() } // GetKustomizeResource returns a Kustomize Resource object for this document. -func (d *DocumentFactory) GetKustomizeResource() resource.Resource { +func (d *Factory) GetKustomizeResource() resource.Resource { return d.Resource } // SetKustomizeResource sets a Kustomize Resource object for this document. -func (d *DocumentFactory) SetKustomizeResource(r *resource.Resource) error { +func (d *Factory) SetKustomizeResource(r *resource.Resource) error { d.Resource = *r return nil } @@ -124,7 +124,7 @@ func (d *DocumentFactory) SetKustomizeResource(r *resource.Resource) error { // documents - e.g. in the future all documents require an airship // annotation X func NewDocument(r *resource.Resource) (Document, error) { - var doc Document = &DocumentFactory{} + var doc Document = &Factory{} err := doc.SetKustomizeResource(r) return doc, err } diff --git a/pkg/remote/errors.go b/pkg/remote/errors.go index f1a57645c..2f8fdcbdb 100644 --- a/pkg/remote/errors.go +++ b/pkg/remote/errors.go @@ -6,12 +6,12 @@ import ( aerror "opendev.org/airship/airshipctl/pkg/errors" ) -type RemoteDirectError struct { +type GenericError struct { aerror.AirshipError } func NewRemoteDirectErrorf(format string, v ...interface{}) error { - e := &RemoteDirectError{} + e := &GenericError{} e.Message = fmt.Sprintf(format, v...) return e } diff --git a/pkg/remote/redfish/errors.go b/pkg/remote/redfish/errors.go index 67ed07981..bd405959a 100644 --- a/pkg/remote/redfish/errors.go +++ b/pkg/remote/redfish/errors.go @@ -7,12 +7,12 @@ import ( aerror "opendev.org/airship/airshipctl/pkg/errors" ) -type RedfishClientError struct { +type ClientError struct { aerror.AirshipError } func NewRedfishClientErrorf(format string, v ...interface{}) error { - e := &RedfishClientError{} + e := &ClientError{} e.Message = fmt.Sprintf(format, v...) return e } diff --git a/pkg/remote/redfish/redfish.go b/pkg/remote/redfish/redfish.go index 2919b5923..aaf44e511 100644 --- a/pkg/remote/redfish/redfish.go +++ b/pkg/remote/redfish/redfish.go @@ -11,7 +11,7 @@ import ( alog "opendev.org/airship/airshipctl/pkg/log" ) -type RedfishRemoteDirect struct { +type RemoteDirect struct { // Context Context context.Context @@ -30,7 +30,7 @@ type RedfishRemoteDirect struct { } // Top level function to handle Redfish remote direct -func (cfg RedfishRemoteDirect) DoRemoteDirect() error { +func (cfg RemoteDirect) DoRemoteDirect() error { alog.Debugf("Using Redfish Endpoint: '%s'", cfg.RemoteURL.String()) /* TODO: Add Authentication when redfish library supports it. */ @@ -82,23 +82,23 @@ func NewRedfishRemoteDirectClient(ctx context.Context, remoteURL string, ephNodeID string, isoPath string, -) (RedfishRemoteDirect, error) { +) (RemoteDirect, error) { if remoteURL == "" { - return RedfishRemoteDirect{}, + return RemoteDirect{}, ErrRedfishMissingConfig{ What: "redfish remote url empty", } } if ephNodeID == "" { - return RedfishRemoteDirect{}, + return RemoteDirect{}, ErrRedfishMissingConfig{ What: "redfish ephemeral node id empty", } } if isoPath == "" { - return RedfishRemoteDirect{}, + return RemoteDirect{}, ErrRedfishMissingConfig{ What: "redfish ephemeral node iso Path empty", } @@ -114,13 +114,13 @@ func NewRedfishRemoteDirectClient(ctx context.Context, parsedURL, err := url.Parse(remoteURL) if err != nil { - return RedfishRemoteDirect{}, + return RemoteDirect{}, ErrRedfishMissingConfig{ What: fmt.Sprintf("invalid url format: %v", err), } } - client := RedfishRemoteDirect{ + client := RemoteDirect{ Context: ctx, RemoteURL: *parsedURL, EphemeralNodeID: ephNodeID, diff --git a/pkg/remote/redfish/redfish_test.go b/pkg/remote/redfish/redfish_test.go index bb57bdd13..d3e957ce9 100644 --- a/pkg/remote/redfish/redfish_test.go +++ b/pkg/remote/redfish/redfish_test.go @@ -75,7 +75,7 @@ func TestRedfishRemoteDirectInvalidSystemId(t *testing.T) { err := localRDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -96,7 +96,7 @@ func TestRedfishRemoteDirectGetSystemNetworkError(t *testing.T) { err := rDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -123,7 +123,7 @@ func TestRedfishRemoteDirectInvalidIsoPath(t *testing.T) { err := localRDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -148,7 +148,7 @@ func TestRedfishRemoteDirectCdDvdNotAvailableInBootSources(t *testing.T) { err := rDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -175,7 +175,7 @@ func TestRedfishRemoteDirectSetSystemBootSourceFailed(t *testing.T) { err := rDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -209,7 +209,7 @@ func TestRedfishRemoteDirectSystemRebootFailed(t *testing.T) { err := rDCfg.DoRemoteDirect() - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } @@ -240,7 +240,7 @@ func getTestSystem() redfishClient.ComputerSystem { } } -func getDefaultRedfishRemoteDirectObj(t *testing.T, api redfishAPI.RedfishAPI) RedfishRemoteDirect { +func getDefaultRedfishRemoteDirectObj(t *testing.T, api redfishAPI.RedfishAPI) RemoteDirect { t.Helper() rDCfg, err := NewRedfishRemoteDirectClient( diff --git a/pkg/remote/redfish/utils_test.go b/pkg/remote/redfish/utils_test.go index 643959bbc..e5efab361 100644 --- a/pkg/remote/redfish/utils_test.go +++ b/pkg/remote/redfish/utils_test.go @@ -25,7 +25,7 @@ func TestRedfishErrorNonNilErrorWithoutHttpResp(t *testing.T) { realErr := fmt.Errorf("sample error") err := ScreenRedfishError(nil, realErr) assert.Error(t, err) - _, ok := err.(*RedfishClientError) + _, ok := err.(*ClientError) assert.True(t, ok) } diff --git a/pkg/remote/remote_direct.go b/pkg/remote/remote_direct.go index ee6b126dc..19123e0c5 100644 --- a/pkg/remote/remote_direct.go +++ b/pkg/remote/remote_direct.go @@ -24,13 +24,13 @@ const ( ) // Interface to be implemented by remoteDirect implementation -type RemoteDirectClient interface { +type Client interface { DoRemoteDirect() error } // Get remotedirect client based on config -func getRemoteDirectClient(remoteConfig *config.RemoteDirect, remoteURL string) (RemoteDirectClient, error) { - var client RemoteDirectClient +func getRemoteDirectClient(remoteConfig *config.RemoteDirect, remoteURL string) (Client, error) { + var client Client switch remoteConfig.RemoteType { case AirshipRemoteTypeRedfish: alog.Debug("Remote type redfish") diff --git a/pkg/remote/remote_direct_test.go b/pkg/remote/remote_direct_test.go index e2a557ddb..387df6c96 100644 --- a/pkg/remote/remote_direct_test.go +++ b/pkg/remote/remote_direct_test.go @@ -36,7 +36,7 @@ func TestUnknownRemoteType(t *testing.T) { err := DoRemoteDirect(s) - _, ok := err.(*RemoteDirectError) + _, ok := err.(*GenericError) assert.True(t, ok) }