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

Nil pointer safety #408

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions bmc/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Loop:
func GetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}) (biosConfig map[string]string, metadata Metadata, err error) {
implementations := make([]biosConfigurationGetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := biosConfigurationGetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationGetter:
Expand All @@ -178,6 +181,9 @@ func GetBiosConfigurationInterfaces(ctx context.Context, generic []interface{})
func SetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}, biosConfig map[string]string) (metadata Metadata, err error) {
implementations := make([]biosConfigurationSetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := biosConfigurationSetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationSetter:
Expand All @@ -204,6 +210,9 @@ func SetBiosConfigurationInterfaces(ctx context.Context, generic []interface{},
func SetBiosConfigurationFromFileInterfaces(ctx context.Context, generic []interface{}, cfg string) (metadata Metadata, err error) {
implementations := make([]biosConfigurationSetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := biosConfigurationSetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationSetter:
Expand All @@ -230,6 +239,9 @@ func SetBiosConfigurationFromFileInterfaces(ctx context.Context, generic []inter
func ResetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}) (metadata Metadata, err error) {
implementations := make([]biosConfigurationResetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := biosConfigurationResetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationResetter:
Expand Down
6 changes: 6 additions & 0 deletions bmc/boot_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func setBootDevice(ctx context.Context, timeout time.Duration, bootDevice string
func SetBootDeviceFromInterfaces(ctx context.Context, timeout time.Duration, bootDevice string, setPersistent, efiBoot bool, generic []interface{}) (ok bool, metadata Metadata, err error) {
bdSetters := make([]bootDeviceProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := bootDeviceProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case BootDeviceSetter:
Expand Down Expand Up @@ -148,6 +151,9 @@ func GetBootDeviceOverrideFromInterface(
metadata = newMetadata()

for _, elem := range providers {
if elem == nil {
continue
}
switch p := elem.(type) {
case BootDeviceOverrideGetter:
provider := &bootOverrideProvider{name: getProviderName(elem), bootOverrideGetter: p}
Expand Down
6 changes: 6 additions & 0 deletions bmc/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func OpenConnectionFromInterfaces(ctx context.Context, timeout time.Duration, pr
// For every provider, launch a goroutine that attempts to open a connection and report
// back via the results channel what happened.
for _, elem := range providers {
if elem == nil {
continue
}
switch p := elem.(type) {
case Opener:
providerName := getProviderName(elem)
Expand Down Expand Up @@ -138,6 +141,9 @@ func CloseConnectionFromInterfaces(ctx context.Context, generic []interface{}) (

closers := make([]connectionProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := connectionProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case Closer:
Expand Down
21 changes: 21 additions & 0 deletions bmc/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func FirmwareInstallFromInterfaces(ctx context.Context, component, operationAppl

implementations := make([]firmwareInstallerProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareInstallerProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstaller:
Expand Down Expand Up @@ -152,6 +155,9 @@ func FirmwareInstallStatusFromInterfaces(ctx context.Context, installVersion, co

implementations := make([]firmwareInstallVerifierProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareInstallVerifierProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstallVerifier:
Expand Down Expand Up @@ -227,6 +233,9 @@ func FirmwareInstallUploadAndInitiateFromInterfaces(ctx context.Context, compone

implementations := make([]firmwareInstallProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareInstallProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstallProvider:
Expand Down Expand Up @@ -306,6 +315,9 @@ func FirmwareInstallerUploadedFromInterfaces(ctx context.Context, component, upl

implementations := make([]firmwareInstallerWithOptionsProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareInstallerWithOptionsProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstallerUploaded:
Expand Down Expand Up @@ -345,6 +357,9 @@ func FirmwareInstallStepsFromInterfaces(ctx context.Context, component string, g

implementations := make([]firmwareInstallStepsGetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareInstallStepsGetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareInstallStepsGetter:
Expand Down Expand Up @@ -413,6 +428,9 @@ func FirmwareUploadFromInterfaces(ctx context.Context, component string, file *o

implementations := make([]firmwareUploaderProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareUploaderProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareUploader:
Expand Down Expand Up @@ -527,6 +545,9 @@ func FirmwareTaskStatusFromInterfaces(ctx context.Context, kind bconsts.Firmware

implementations := make([]firmwareTaskVerifierProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := firmwareTaskVerifierProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FirmwareTaskVerifier:
Expand Down
6 changes: 6 additions & 0 deletions bmc/floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func mountFloppyImage(ctx context.Context, image io.Reader, p []floppyImageUploa
func MountFloppyImageFromInterfaces(ctx context.Context, image io.Reader, p []interface{}) (metadata Metadata, err error) {
providers := make([]floppyImageUploaderProvider, 0)
for _, elem := range p {
if elem == nil {
continue
}
temp := floppyImageUploaderProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FloppyImageMounter:
Expand Down Expand Up @@ -125,6 +128,9 @@ func unmountFloppyImage(ctx context.Context, p []floppyImageUnmounterProvider) (
func UnmountFloppyImageFromInterfaces(ctx context.Context, p []interface{}) (metadata Metadata, err error) {
providers := make([]floppyImageUnmounterProvider, 0)
for _, elem := range p {
if elem == nil {
continue
}
temp := floppyImageUnmounterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case FloppyImageUnmounter:
Expand Down
3 changes: 3 additions & 0 deletions bmc/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func GetInventoryFromInterfaces(ctx context.Context, generic []interface{}) (dev

implementations := make([]inventoryGetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := inventoryGetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case InventoryGetter:
Expand Down
3 changes: 3 additions & 0 deletions bmc/postcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func postCode(ctx context.Context, generic []postCodeGetterProvider) (status str
func GetPostCodeInterfaces(ctx context.Context, generic []interface{}) (status string, code int, metadata Metadata, err error) {
implementations := make([]postCodeGetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := postCodeGetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case PostCodeGetter:
Expand Down
6 changes: 6 additions & 0 deletions bmc/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func SetPowerStateFromInterfaces(ctx context.Context, timeout time.Duration, sta

powerSetter := make([]powerProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := powerProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case PowerSetter:
Expand Down Expand Up @@ -132,6 +135,9 @@ func GetPowerStateFromInterfaces(ctx context.Context, timeout time.Duration, gen

powerStateGetter := make([]powerProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := powerProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case PowerStateGetter:
Expand Down
3 changes: 3 additions & 0 deletions bmc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type Provider interface {
// getProviderName returns the name a provider supplies if they implement the Provider interface
// if not implemented then the concrete type is returned
func getProviderName(provider interface{}) string {
if provider == nil {
return ""
}
switch p := provider.(type) {
case Provider:
return p.Name()
Expand Down
3 changes: 3 additions & 0 deletions bmc/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func ResetBMCFromInterfaces(ctx context.Context, timeout time.Duration, resetTyp

bmcSetters := make([]bmcProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := bmcProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case BMCResetter:
Expand Down
3 changes: 3 additions & 0 deletions bmc/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func screenshot(ctx context.Context, generic []screenshotGetterProvider) (image
func ScreenshotFromInterfaces(ctx context.Context, generic []interface{}) (image []byte, fileType string, metadata Metadata, err error) {
implementations := make([]screenshotGetterProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := screenshotGetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case ScreenshotGetter:
Expand Down
9 changes: 9 additions & 0 deletions bmc/sel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func clearSystemEventLog(ctx context.Context, timeout time.Duration, s []systemE
func ClearSystemEventLogFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (metadata Metadata, err error) {
selServices := make([]systemEventLogProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := systemEventLogProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case SystemEventLog:
Expand Down Expand Up @@ -107,6 +110,9 @@ func getSystemEventLog(ctx context.Context, timeout time.Duration, s []systemEve
func GetSystemEventLogFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (sel SystemEventLogEntries, metadata Metadata, err error) {
selServices := make([]systemEventLogProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := systemEventLogProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case SystemEventLog:
Expand Down Expand Up @@ -158,6 +164,9 @@ func getSystemEventLogRaw(ctx context.Context, timeout time.Duration, s []system
func GetSystemEventLogRawFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (eventlog string, metadata Metadata, err error) {
selServices := make([]systemEventLogProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := systemEventLogProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case SystemEventLog:
Expand Down
3 changes: 3 additions & 0 deletions bmc/sol.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func deactivateSOL(ctx context.Context, timeout time.Duration, b []deactivatorPr
func DeactivateSOLFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (metadata Metadata, err error) {
deactivators := make([]deactivatorProvider, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := deactivatorProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case SOLDeactivator:
Expand Down
12 changes: 12 additions & 0 deletions bmc/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func createUser(ctx context.Context, timeout time.Duration, user, pass, role str
func CreateUserFromInterfaces(ctx context.Context, timeout time.Duration, user, pass, role string, generic []interface{}) (ok bool, metadata Metadata, err error) {
userCreators := make([]userProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := userProviders{name: getProviderName(elem)}
switch u := elem.(type) {
case UserCreator:
Expand Down Expand Up @@ -128,6 +131,9 @@ func updateUser(ctx context.Context, timeout time.Duration, user, pass, role str
func UpdateUserFromInterfaces(ctx context.Context, timeout time.Duration, user, pass, role string, generic []interface{}) (ok bool, metadata Metadata, err error) {
userUpdaters := make([]userProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := userProviders{name: getProviderName(elem)}
switch u := elem.(type) {
case UserUpdater:
Expand Down Expand Up @@ -181,6 +187,9 @@ func deleteUser(ctx context.Context, timeout time.Duration, user string, u []use
func DeleteUserFromInterfaces(ctx context.Context, timeout time.Duration, user string, generic []interface{}) (ok bool, metadata Metadata, err error) {
userDeleters := make([]userProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := userProviders{name: getProviderName(elem)}
switch u := elem.(type) {
case UserDeleter:
Expand Down Expand Up @@ -230,6 +239,9 @@ func readUsers(ctx context.Context, timeout time.Duration, u []userProviders) (u
func ReadUsersFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (users []map[string]string, metadata Metadata, err error) {
userReaders := make([]userProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := userProviders{name: getProviderName(elem)}
switch u := elem.(type) {
case UserReader:
Expand Down
3 changes: 3 additions & 0 deletions bmc/virtual_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func setVirtualMedia(ctx context.Context, kind string, mediaURL string, b []virt
func SetVirtualMediaFromInterfaces(ctx context.Context, kind string, mediaURL string, generic []interface{}) (ok bool, metadata Metadata, err error) {
bdSetters := make([]virtualMediaProviders, 0)
for _, elem := range generic {
if elem == nil {
continue
}
temp := virtualMediaProviders{name: getProviderName(elem)}
switch p := elem.(type) {
case VirtualMediaSetter:
Expand Down
4 changes: 2 additions & 2 deletions providers/supermicro/firmware_bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Test_setComponentUpdateMisc(t *testing.T) {
t.Fatal(err)
}

serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

serviceClient.csrfToken = "foobar"
Expand Down Expand Up @@ -171,7 +171,7 @@ func Test_setBIOSFirmwareInstallMode(t *testing.T) {
t.Fatal(err)
}

serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

serviceClient.csrfToken = "foobar"
Expand Down
Loading
Loading