Skip to content

Commit 314f930

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #875 from SoftLayer/issues722
Adds a username lookup for file and block commands.
2 parents 2a34a5b + e87b49c commit 314f930

File tree

90 files changed

+444
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+444
-445
lines changed

.secrets.baseline

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-09-04T21:46:16Z",
6+
"generated_at": "2024-10-16T21:46:33Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -124,31 +124,31 @@
124124
"hashed_secret": "49f18203810a56503e8b16bea101314713ce1a0c",
125125
"is_secret": false,
126126
"is_verified": false,
127-
"line_number": 86,
127+
"line_number": 82,
128128
"type": "Secret Keyword",
129129
"verified_result": null
130130
},
131131
{
132132
"hashed_secret": "4283f377a2ad3c107b4a3c9920c6ab508c6b1099",
133133
"is_secret": false,
134134
"is_verified": false,
135-
"line_number": 106,
135+
"line_number": 102,
136136
"type": "Secret Keyword",
137137
"verified_result": null
138138
},
139139
{
140140
"hashed_secret": "aa1f122c9be20b5a2aff7f2c513e3b065c033894",
141141
"is_secret": false,
142142
"is_verified": false,
143-
"line_number": 137,
143+
"line_number": 133,
144144
"type": "Secret Keyword",
145145
"verified_result": null
146146
},
147147
{
148148
"hashed_secret": "b2b24235714bf178e052e52a4af5a21a1f17c445",
149149
"is_secret": false,
150150
"is_verified": false,
151-
"line_number": 164,
151+
"line_number": 160,
152152
"type": "Secret Keyword",
153153
"verified_result": null
154154
}

plugin/commands/block/access_authorize.go

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

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -32,9 +30,7 @@ func NewAccessAuthorizeCommand(sl *metadata.SoftlayerStorageCommand) *AccessAuth
3230
cobraCmd := &cobra.Command{
3331
Use: "access-authorize " + T("IDENTIFIER"),
3432
Short: T("Authorize hosts to access a given volume."),
35-
Long: T(`${COMMAND_NAME} sl {{.storageType}} access-authorize VOLUME_ID [OPTIONS]
36-
37-
EXAMPLE:
33+
Long: T(`EXAMPLE:
3834
${COMMAND_NAME} sl {{.storageType}} access-authorize 12345678 --virtual-id 87654321
3935
This command authorizes virtual server with ID 87654321 to access volume with ID 12345678.`, sl.StorageI18n),
4036
Args: metadata.OneArgs,
@@ -54,9 +50,9 @@ EXAMPLE:
5450

5551
func (cmd *AccessAuthorizeCommand) Run(args []string) error {
5652

57-
volumeID, err := strconv.Atoi(args[0])
53+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5854
if err != nil {
59-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
55+
return err
6056
}
6157
IPIds := cmd.Ip_address_id
6258
IPs := cmd.Ip_address

plugin/commands/block/access_authorize_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var _ = Describe("Access Authorize", func() {
3636
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3737
cliCommand.StorageManager = FakeStorageManager
3838
cliCommand.NetworkManager = fakeNetworkManager
39+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3940
})
4041

4142
Describe("Access Authorize", func() {
@@ -47,14 +48,6 @@ var _ = Describe("Access Authorize", func() {
4748
Expect(strings.Contains(err.Error(), "Incorrect Usage: This command requires one argument")).To(BeTrue())
4849
})
4950
})
50-
Context("Access Authorize with wrong volume id", func() {
51-
It("error resolving volume ID", func() {
52-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
53-
Expect(err).To(HaveOccurred())
54-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
55-
})
56-
})
57-
5851
Context("Access Authorize with correct volume id and virtual server id", func() {
5952
BeforeEach(func() {
6053
FakeStorageManager.AuthorizeHostToVolumeReturns([]datatypes.Network_Storage_Allowed_Host{}, nil)

plugin/commands/block/access_list.go

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

33
import (
4-
"sort"
5-
"strconv"
6-
74
"github.com/spf13/cobra"
5+
"sort"
86

97
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
108
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
@@ -29,9 +27,7 @@ func NewAccessListCommand(sl *metadata.SoftlayerStorageCommand) *AccessListComma
2927
cobraCmd := &cobra.Command{
3028
Use: "access-list " + T("IDENTIFIER"),
3129
Short: T("List hosts that are authorized to access the volume."),
32-
Long: T(`${COMMAND_NAME} sl {{.storageType}} access-list VOLUME_ID [OPTIONS]
33-
34-
EXAMPLE:
30+
Long: T(`EXAMPLE:
3531
${COMMAND_NAME} sl {{.storageType}} access-list 12345678 --sortby id
3632
This command lists all hosts that are authorized to access volume with ID 12345678 and sorts them by ID.`, sl.StorageI18n),
3733
Args: metadata.OneArgs,
@@ -47,9 +43,9 @@ EXAMPLE:
4743

4844
func (cmd *AccessListCommand) Run(args []string) error {
4945

50-
volumeID, err := strconv.Atoi(args[0])
46+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5147
if err != nil {
52-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
48+
return err
5349
}
5450

5551
sortby := cmd.Sortby

plugin/commands/block/access_list_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var _ = Describe("Access List Tests", func() {
3333
cliCommand = block.NewAccessListCommand(slCommand)
3434
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3535
cliCommand.StorageManager = FakeStorageManager
36+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3637
})
3738

3839
Describe("Access List", func() {
@@ -43,13 +44,6 @@ var _ = Describe("Access List Tests", func() {
4344
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4445
})
4546
})
46-
Context("Access Authorize with wrong volume id", func() {
47-
It("error resolving volume ID", func() {
48-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
49-
Expect(err).To(HaveOccurred())
50-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
51-
})
52-
})
5347

5448
Context("Access Authorize with correct volume id", func() {
5549
BeforeEach(func() {

plugin/commands/block/access_password.go

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

33
import (
4-
"fmt"
54
"strconv"
65

76
"github.com/spf13/cobra"
@@ -45,7 +44,6 @@ func NewAccessPasswordCommand(sl *metadata.SoftlayerStorageCommand) *AccessPassw
4544

4645
func (cmd *AccessPasswordCommand) Run(args []string) error {
4746

48-
fmt.Printf("===AccessPasswordCommand===")
4947
hostID, err := strconv.Atoi(args[0])
5048
if err != nil {
5149
return slErr.NewInvalidSoftlayerIdInputError("allowed access host ID")

plugin/commands/block/access_password_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package block_test
22

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

76
. "github.com/onsi/ginkgo/v2"
87
. "github.com/onsi/gomega"
@@ -31,7 +30,6 @@ var _ = Describe("Access Password", func() {
3130
cliCommand = block.NewAccessPasswordCommand(slCommand)
3231
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3332
cliCommand.StorageManager = FakeStorageManager
34-
3533
})
3634

3735
Describe("Access password", func() {
@@ -49,13 +47,6 @@ var _ = Describe("Access Password", func() {
4947
Expect(err.Error()).To(ContainSubstring(`required flag(s) "password" not set`))
5048
})
5149
})
52-
Context("Access password with wrong hostId", func() {
53-
It("return error", func() {
54-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc", "--password", "abcdefg")
55-
Expect(err).To(HaveOccurred())
56-
Expect(strings.Contains(err.Error(), "Invalid input for 'allowed access host ID'. It must be a positive integer.")).To(BeTrue())
57-
})
58-
})
5950
Context("Access password with server fails", func() {
6051
BeforeEach(func() {
6152
FakeStorageManager.SetCredentialPasswordReturns(errors.New("Internal Server Error"))
@@ -64,8 +55,8 @@ var _ = Describe("Access Password", func() {
6455
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--password", "abcdefg")
6556
Expect(err).To(HaveOccurred())
6657
Expect(fakeUI.Outputs()).NotTo(ContainSubstring("OK"))
67-
Expect(strings.Contains(err.Error(), "Failed to set password for host 1234.")).To(BeTrue())
68-
Expect(strings.Contains(err.Error(), "Internal Server Error")).To(BeTrue())
58+
Expect(err.Error()).To(ContainSubstring("Failed to set password for host 1234."))
59+
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
6960
})
7061
})
7162
Context("Access password", func() {

plugin/commands/block/access_revoke.go

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

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -52,9 +50,9 @@ EXAMPLE:
5250
}
5351

5452
func (cmd *AccessRevokeCommand) Run(args []string) error {
55-
volumeID, err := strconv.Atoi(args[0])
53+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5654
if err != nil {
57-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
55+
return err
5856
}
5957

6058
if len(cmd.Hardware_id) == 0 && len(cmd.Virtual_id) == 0 && len(cmd.Ip_address_id) == 0 && len(cmd.Ip_address) == 0 {

plugin/commands/block/access_revoke_test.go

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package block_test
22

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

7-
. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/matchers"
86
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
97
. "github.com/onsi/ginkgo/v2"
108
. "github.com/onsi/gomega"
@@ -36,21 +34,15 @@ var _ = Describe("Access Revoke", func() {
3634
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3735
cliCommand.StorageManager = FakeStorageManager
3836
cliCommand.NetworkManager = fakeNetworkManager
37+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3938
})
4039

4140
Describe("Access Revoke", func() {
4241
Context("Access revoke without volume id", func() {
4342
It("return error", func() {
4443
err := testhelpers.RunCobraCommand(cliCommand.Command)
4544
Expect(err).To(HaveOccurred())
46-
Expect(strings.Contains(err.Error(), "Incorrect Usage: This command requires one argument")).To(BeTrue())
47-
})
48-
})
49-
Context("Access revoke with wrong volume id", func() {
50-
It("error resolving volume ID", func() {
51-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
52-
Expect(err).To(HaveOccurred())
53-
Expect(strings.Contains(err.Error(), "Invalid input for 'Volume ID'. It must be a positive integer.")).To(BeTrue())
45+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
5446
})
5547
})
5648

@@ -61,8 +53,7 @@ var _ = Describe("Access Revoke", func() {
6153
It("return no error", func() {
6254
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--virtual-id", "5678")
6355
Expect(err).NotTo(HaveOccurred())
64-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"OK"}))
65-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"Access to 1234 was revoked for virtual server 5678"}))
56+
Expect(fakeUI.Outputs()).To(ContainSubstring("Access to 1234 was revoked for virtual server 5678"))
6657
})
6758
})
6859

@@ -73,8 +64,7 @@ var _ = Describe("Access Revoke", func() {
7364
It("return no error", func() {
7465
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--hardware-id", "5678")
7566
Expect(err).NotTo(HaveOccurred())
76-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"OK"}))
77-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"Access to 1234 was revoked for hardware server 5678."}))
67+
Expect(fakeUI.Outputs()).To(ContainSubstring("Access to 1234 was revoked for hardware server 5678."))
7868
})
7969
})
8070

@@ -85,8 +75,7 @@ var _ = Describe("Access Revoke", func() {
8575
It("return no error", func() {
8676
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--ip-address-id", "5678")
8777
Expect(err).NotTo(HaveOccurred())
88-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"OK"}))
89-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"Access to 1234 was revoked for IP address 5678."}))
78+
Expect(fakeUI.Outputs()).To(ContainSubstring("Access to 1234 was revoked for IP address 5678."))
9079
})
9180
})
9281

@@ -98,8 +87,7 @@ var _ = Describe("Access Revoke", func() {
9887
It("return no error", func() {
9988
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--ip-address", "1.2.3.4")
10089
Expect(err).NotTo(HaveOccurred())
101-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"OK"}))
102-
Expect(fakeUI.Outputs()).To(ContainSubstrings([]string{"Access to 1234 was revoked for IP address 5678."}))
90+
Expect(fakeUI.Outputs()).To(ContainSubstring("Access to 1234 was revoked for IP address 5678."))
10391
})
10492
})
10593

@@ -111,22 +99,23 @@ var _ = Describe("Access Revoke", func() {
11199
It("return error", func() {
112100
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--ip-address", "1.2.3.4")
113101
Expect(err).To(HaveOccurred())
114-
Expect(fakeUI.Outputs()).NotTo(ContainSubstrings([]string{"OK"}))
115-
Expect(strings.Contains(err.Error(), "IP address 1.2.3.4 is not found on your account.Please confirm IP and try again.")).To(BeTrue())
116-
Expect(strings.Contains(err.Error(), "Not Found")).To(BeTrue())
102+
Expect(err.Error()).To(ContainSubstring("IP address 1.2.3.4 is not found on your account.Please confirm IP and try again."))
103+
Expect(err.Error()).To(ContainSubstring("Not Found"))
117104
})
118105
})
119106

120107
Context("Access Authorize with correct volume id but server API call fails", func() {
121108
BeforeEach(func() {
122-
FakeStorageManager.DeauthorizeHostToVolumeReturns([]datatypes.Network_Storage_Allowed_Host{}, errors.New("Internal Server Error"))
109+
FakeStorageManager.DeauthorizeHostToVolumeReturns(
110+
[]datatypes.Network_Storage_Allowed_Host{},
111+
errors.New("Internal Server Error"),
112+
)
123113
})
124114
It("return error", func() {
125115
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--virtual-id", "5678")
126116
Expect(err).To(HaveOccurred())
127-
Expect(fakeUI.Outputs()).NotTo(ContainSubstrings([]string{"OK"}))
128-
Expect(strings.Contains(err.Error(), "Failed to revoke access to volume 1234.")).To(BeTrue())
129-
Expect(strings.Contains(err.Error(), "Internal Server Error")).To(BeTrue())
117+
Expect(err.Error()).To(ContainSubstring("Failed to revoke access to volume 1234."))
118+
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
130119
})
131120
})
132121
})

plugin/commands/block/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
1212
StorageCommand := &metadata.SoftlayerStorageCommand{
1313
SoftlayerCommand: sl,
1414
StorageI18n: map[string]interface{}{"storageType": "block"},
15+
StorageType: "block",
1516
}
1617
cobraCmd := &cobra.Command{
1718
Use: "block",

0 commit comments

Comments
 (0)