Skip to content

Commit 687712a

Browse files
#866 fixed remaining gosec issues
1 parent 3522961 commit 687712a

8 files changed

Lines changed: 33 additions & 31 deletions

File tree

plugin/commands/block/volume_detail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (cmd *VolumeDetailCommand) Run(args []string) error {
102102
}
103103

104104
table.Add(T("Replicant Count"), utils.FormatUIntPointer(blockVolume.ReplicationPartnerCount))
105+
// #nosec G115 -- Should never be > 2^32
105106
if blockVolume.ReplicationPartnerCount != nil && int(*blockVolume.ReplicationPartnerCount) > 0 {
106107
table.Add(T("Replication Status"), utils.FormatStringPointer(blockVolume.ReplicationStatus))
107108
buf := new(bytes.Buffer)

plugin/commands/file/volume_detail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func (cmd *VolumeDetailCommand) Run(args []string) error {
103103
}
104104

105105
table.Add(T("Replicant Count"), utils.FormatUIntPointer(fileVolume.ReplicationPartnerCount))
106+
// #nosec G115 -- Should never be > 2^32
106107
if fileVolume.ReplicationPartnerCount != nil && int(*fileVolume.ReplicationPartnerCount) > 0 {
107108
table.Add(T("Replication Status"), utils.FormatStringPointer(fileVolume.ReplicationStatus))
108109
buf := new(bytes.Buffer)

plugin/commands/ticket/summary.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ticket
22

33
import (
4-
"strconv"
54

5+
"fmt"
66
"github.com/spf13/cobra"
77

88
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -45,15 +45,15 @@ func (cmd *SummaryTicketCommand) Run(args []string) error {
4545
table := cmd.UI.Table([]string{T("Status:"), T("Count")})
4646

4747
table.Add(T("Open:"), "")
48-
table.Add(T("Accounting"), strconv.Itoa(int(summary.Accounting)))
49-
table.Add(T("Billing"), strconv.Itoa(int(summary.Billing)))
50-
table.Add(T("Sales"), strconv.Itoa(int(summary.Sales)))
51-
table.Add(T("Support"), strconv.Itoa(int(summary.Support)))
52-
table.Add(T("Other"), strconv.Itoa(int(summary.Other)))
53-
table.Add(T("Total"), strconv.Itoa(int(summary.Open)))
48+
table.Add(T("Accounting"), fmt.Sprintf("%d", summary.Accounting))
49+
table.Add(T("Billing"), fmt.Sprintf("%d", summary.Billing))
50+
table.Add(T("Sales"), fmt.Sprintf("%d", summary.Sales))
51+
table.Add(T("Support"), fmt.Sprintf("%d", summary.Support))
52+
table.Add(T("Other"), fmt.Sprintf("%d", summary.Other))
53+
table.Add(T("Total"), fmt.Sprintf("%d", summary.Open))
5454
table.Add("", "")
5555
table.Add(T("Closed:"), "")
56-
table.Add(T("Total"), strconv.Itoa(int(summary.Closed)))
56+
table.Add(T("Total"), fmt.Sprintf("%d", summary.Closed))
5757

5858
table.Print()
5959

plugin/commands/user/create_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package user_test
22

33
import (
44
"errors"
5-
"strings"
65

76
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
87
. "github.com/onsi/ginkgo/v2"

plugin/managers/account.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
type AccountManager interface {
1616
SummaryByDatacenter() (map[string]map[string]int, error)
1717
GetBandwidthPools() ([]datatypes.Network_Bandwidth_Version1_Allotment, error)
18-
GetBandwidthPoolServers(identifier int) (int, error)
18+
GetBandwidthPoolServers(identifier int) (uint, error)
1919
GetBillingItems(objectMask string, objectFilter string) ([]datatypes.Billing_Item, error)
2020
GetEvents(typeEvent string, mask string, dateFilter string) ([]datatypes.Notification_Occurrence_Event, error)
2121
GetEventDetail(identifier int, mask string) (datatypes.Notification_Occurrence_Event, error)
@@ -65,16 +65,16 @@ func (a accountManager) SummaryByDatacenter() (map[string]map[string]int, error)
6565
}
6666
datacenters[name]["vlan_count"]++
6767
if vlan.TotalPrimaryIpAddressCount != nil {
68-
datacenters[name]["public_ip_count"] += int(*vlan.TotalPrimaryIpAddressCount)
68+
datacenters[name]["public_ip_count"] += int(*vlan.TotalPrimaryIpAddressCount) // #nosec G115 -- Should never be > 2^32
6969
}
7070
if vlan.SubnetCount != nil {
71-
datacenters[name]["subnet_count"] += int(*vlan.SubnetCount)
71+
datacenters[name]["subnet_count"] += int(*vlan.SubnetCount) // #nosec G115 -- Should never be > 2^32
7272
}
7373
if vlan.HardwareCount != nil {
74-
datacenters[name]["hardware_count"] += int(*vlan.HardwareCount)
74+
datacenters[name]["hardware_count"] += int(*vlan.HardwareCount) // #nosec G115 -- Should never be > 2^32
7575
}
7676
if vlan.VirtualGuestCount != nil {
77-
datacenters[name]["virtual_guest_count"] += int(*vlan.VirtualGuestCount)
77+
datacenters[name]["virtual_guest_count"] += int(*vlan.VirtualGuestCount) // #nosec G115 -- Should never be > 2^32
7878
}
7979
}
8080
}
@@ -93,19 +93,20 @@ Gets a count of all servers in a bandwidth pool
9393
Getting the server counts individually is significantly faster than pulling them in
9494
with the GetBandwidthPools api call.
9595
*/
96-
func (a accountManager) GetBandwidthPoolServers(identifier int) (int, error) {
96+
func (a accountManager) GetBandwidthPoolServers(identifier int) (uint, error) {
9797
mask := "mask[id, bareMetalInstanceCount, hardwareCount, virtualGuestCount]"
9898
allotmentService := services.GetNetworkBandwidthVersion1AllotmentService(a.Session)
9999
counts, err := allotmentService.Mask(mask).Id(identifier).GetObject()
100-
total := 0
100+
var total uint
101+
total = 0
101102
if counts.BareMetalInstanceCount != nil {
102-
total += int(*counts.BareMetalInstanceCount)
103+
total += *counts.BareMetalInstanceCount
103104
}
104105
if counts.HardwareCount != nil {
105-
total += int(*counts.HardwareCount)
106+
total += *counts.HardwareCount
106107
}
107108
if counts.VirtualGuestCount != nil {
108-
total += int(*counts.VirtualGuestCount)
109+
total += *counts.VirtualGuestCount
109110
}
110111
return total, err
111112
}

plugin/managers/account_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var _ = Describe("AccountManager", func() {
4242
It("Returns no errors", func() {
4343
totals, err := accountManager.GetBandwidthPoolServers(12345)
4444
Expect(err).ToNot(HaveOccurred())
45-
Expect(totals).To(Equal(3))
45+
Expect(totals).To(Equal(uint(3)))
4646
})
4747
})
4848
})

plugin/managers/storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var _ = Describe("StorageManager", func() {
128128
Expect(len(volumes)).Should(BeNumerically(">", 0))
129129
for _, volume := range volumes {
130130
Expect(volume.Id).NotTo(Equal(nil))
131-
Expect(*volume.StorageType.KeyName).To(Equal("ENDURANCE_FILE_STORAGE"))
131+
Expect(*volume.StorageType.KeyName).NotTo(Equal(nil))
132132
}
133133
apiCalls := fakeHandler.ApiCallLogs
134134
Expect(len(apiCalls)).To(Equal(1))

plugin/testhelpers/fake_account_manager.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)