Skip to content

Commit 5462e9a

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #855 from SoftLayer/issues854
Reworked use permission lists to be more inline with cloud.ibm.com
2 parents 38fee5a + 90cff70 commit 5462e9a

File tree

16 files changed

+1364
-119
lines changed

16 files changed

+1364
-119
lines changed

.secrets.baseline

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
"files": "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-05-23T21:29:26Z",
6+
"generated_at": "2024-06-06T23:07:46Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
1010
},
1111
{
1212
"name": "ArtifactoryDetector"
1313
},
14+
{
15+
"name": "AzureStorageKeyDetector"
16+
},
1417
{
1518
"base64_limit": 4.5,
1619
"name": "Base64HighEntropyString"
@@ -28,6 +31,9 @@
2831
"ghe_instance": "github.ibm.com",
2932
"name": "GheDetector"
3033
},
34+
{
35+
"name": "GitHubTokenDetector"
36+
},
3137
{
3238
"hex_limit": 3,
3339
"name": "HexHighEntropyString"
@@ -48,6 +54,9 @@
4854
{
4955
"name": "MailchimpDetector"
5056
},
57+
{
58+
"name": "NpmDetector"
59+
},
5160
{
5261
"name": "PrivateKeyDetector"
5362
},
@@ -57,6 +66,9 @@
5766
{
5867
"name": "SoftlayerDetector"
5968
},
69+
{
70+
"name": "SquareOAuthDetector"
71+
},
6072
{
6173
"name": "StripeDetector"
6274
},
@@ -312,7 +324,7 @@
312324
"hashed_secret": "c2a6b03f190dfb2b4aa91f8af8d477a9bc3401dc",
313325
"is_secret": false,
314326
"is_verified": false,
315-
"line_number": 373,
327+
"line_number": 386,
316328
"type": "Secret Keyword",
317329
"verified_result": null
318330
}

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,15 @@ By default, every API call made to the SoftLayer API will load in the approprait
218218
To force errors:
219219

220220
```go
221-
fakeHandler := testhelpers.FakeTransportHandler{}
222-
fakeHandler.AddApiError("SoftLayer_Tag", "getAttachedTagsForCurrentUser", 500, "BAD")
223-
fakeSLSession := &session.Session{TransportHandler: fakeHandler,}
221+
// In the Top level BeforeEach
222+
fakeSession = testhelpers.NewFakeSoftlayerSession(nil)
223+
fakeHandler = testhelpers.GetSessionHandler(fakeSession)
224+
225+
// Then in a BeforeEach for the specific test...
226+
BeforeEach(func() {
227+
fakeHandler.AddApiError("SoftLayer_User_Customer", "getObject",
228+
500, "Internal Server Error")
229+
})
224230
```
225231

226232
To force a non-default JSON file to be loaded

bin/buildAndDeploy.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ def runTests() -> None:
6262
if re.match(r"fixtrues|vendor", mod) is None:
6363
clean_mods.append(mod)
6464

65+
## GO GENERATE
66+
go_generate = ['go', 'generate', './...']
67+
# Not using the 'real' command here because this looks neater.
68+
69+
print(f'[turquoise2]Running: go generate ./...')
70+
try:
71+
subprocess.run(go_generate, check=True)
72+
except subprocess.CalledProcessError as e:
73+
print(f"[red]>>> Go Generate failed <<<")
74+
sys.exit(e.returncode)
75+
6576
## GO VET
6677
go_vet = ['go', 'vet'] + clean_mods
6778
# Not using the 'real' command here because this looks neater.
@@ -73,16 +84,7 @@ def runTests() -> None:
7384
print(f"[red]>>> Go Vet failed <<<")
7485
sys.exit(e.returncode)
7586

76-
## GO GENERATE
77-
go_generate = ['go', 'generate', './...']
78-
# Not using the 'real' command here because this looks neater.
7987

80-
print(f'[turquoise2]Running: go generate ./...')
81-
try:
82-
subprocess.run(go_generate, check=True)
83-
except subprocess.CalledProcessError as e:
84-
print(f"[red]>>> Go Generate failed <<<")
85-
sys.exit(e.returncode)
8688

8789
## GO TEST
8890
go_test = ['go', 'test'] + clean_mods

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/nicksnyder/go-i18n/v2 v2.4.0
1616
github.com/onsi/ginkgo/v2 v2.17.0
1717
github.com/onsi/gomega v1.31.1
18-
github.com/softlayer/softlayer-go v1.1.3
18+
github.com/softlayer/softlayer-go v1.1.5
1919
github.com/spf13/cobra v1.8.0
2020
github.com/spf13/pflag v1.0.5
2121
github.com/stretchr/testify v1.7.0
@@ -32,16 +32,17 @@ require (
3232
github.com/google/go-cmp v0.6.0 // indirect
3333
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
3434
github.com/inconshreveable/mousetrap v1.1.0 // indirect
35-
github.com/kr/pretty v0.2.1 // indirect
35+
github.com/kr/text v0.2.0 // indirect
3636
github.com/mattn/go-colorable v0.1.13 // indirect
3737
github.com/mattn/go-isatty v0.0.20 // indirect
3838
github.com/mattn/go-runewidth v0.0.15 // indirect
3939
github.com/pmezard/go-difflib v1.0.0 // indirect
4040
github.com/rivo/uniseg v0.4.7 // indirect
41+
github.com/rogpeppe/go-internal v1.9.0 // indirect
4142
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
4243
golang.org/x/crypto v0.21.0 // indirect
4344
golang.org/x/mod v0.16.0 // indirect
44-
golang.org/x/net v0.22.0 // indirect
45+
golang.org/x/net v0.23.0 // indirect
4546
golang.org/x/sys v0.18.0 // indirect
4647
golang.org/x/term v0.18.0 // indirect
4748
golang.org/x/tools v0.19.0 // indirect

go.sum

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
88
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
99
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
1010
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
11+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1112
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1213
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1314
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -36,11 +37,10 @@ github.com/jarcoal/httpmock v1.0.5 h1:cHtVEcTxRSX4J0je7mWPfc9BpDpqzXSJ5HbymZmyHc
3637
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
3738
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
3839
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
39-
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
40-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
41-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
42-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
43-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
40+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
41+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
42+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
43+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4444
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
4545
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
4646
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -63,15 +63,17 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
6363
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6464
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
6565
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
66+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
67+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
6668
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
6769
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
6870
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
6971
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
7072
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
7173
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
7274
github.com/smartystreets/goconvey v1.6.7/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
73-
github.com/softlayer/softlayer-go v1.1.3 h1:dfFzt5eOKIAyB/b78fHMyDu5ICx0ZtxL9NRhBlf831A=
74-
github.com/softlayer/softlayer-go v1.1.3/go.mod h1:Pc7F57OgUKaAam7TtpqkUeqL7QyKknfiUI4R49h41/U=
75+
github.com/softlayer/softlayer-go v1.1.5 h1:UFFtgKxiw0yIuUw93XBCFIiIMYR5eLgmm4a5DqMHXGg=
76+
github.com/softlayer/softlayer-go v1.1.5/go.mod h1:WeJrBLoTJcaT8nO1azeyHyNpo/fDLtbpbvh+pzts+Qw=
7577
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e h1:3OgWYFw7jxCZPcvAg+4R8A50GZ+CCkARF10lxu2qDsQ=
7678
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e/go.mod h1:fKZCUVdirrxrBpwd9wb+lSoVixvpwAu8eHzbQB2tums=
7779
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=

plugin/commands/order/complex_type.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var TYPEMAP = map[string]interface{}{
2121
"SoftLayer_Container_Product_Order_Network_Interconnect_Upgrade": &datatypes.Container_Product_Order_Network_Interconnect_Upgrade{},
2222
"SoftLayer_Container_Product_Order_Network_LoadBalancer": &datatypes.Container_Product_Order_Network_LoadBalancer{},
2323
"SoftLayer_Container_Product_Order_Network_LoadBalancer_AsAService": &datatypes.Container_Product_Order_Network_LoadBalancer_AsAService{},
24-
"SoftLayer_Container_Product_Order_Network_LoadBalancer_Global": &datatypes.Container_Product_Order_Network_LoadBalancer_Global{},
2524
"SoftLayer_Container_Product_Order_Network_Message_Delivery": &datatypes.Container_Product_Order_Network_Message_Delivery{},
2625
"SoftLayer_Container_Product_Order_Network_PerformanceStorage": &datatypes.Container_Product_Order_Network_PerformanceStorage{},
2726
"SoftLayer_Container_Product_Order_Network_PerformanceStorage_Iscsi": &datatypes.Container_Product_Order_Network_PerformanceStorage_Iscsi{},

plugin/commands/user/details_test.go

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

33
import (
44
"errors"
5-
"fmt"
65
"time"
76

87
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
@@ -374,7 +373,6 @@ var _ = Describe("Detail", func() {
374373

375374
Context("user detail with correct id and logins", func() {
376375
It("return a user with logins", func() {
377-
fmt.Println("**")
378376
err := testhelpers.RunCobraCommand(cliCommand.Command, "5555", "--logins")
379377
Expect(err).NotTo(HaveOccurred())
380378
Expect(fakeUI.Outputs()).To(ContainSubstring("name value"))
@@ -401,7 +399,6 @@ var _ = Describe("Detail", func() {
401399

402400
Context("user detail with correct id and events", func() {
403401
It("return a user with events", func() {
404-
fmt.Println("**")
405402
err := testhelpers.RunCobraCommand(cliCommand.Command, "5555", "--events")
406403
Expect(err).NotTo(HaveOccurred())
407404
Expect(fakeUI.Outputs()).To(ContainSubstring("name value"))
Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package user
22

33
import (
4+
"bytes"
45
"strconv"
56

7+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
8+
"github.com/softlayer/softlayer-go/datatypes"
69
"github.com/spf13/cobra"
710
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
811
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
@@ -22,10 +25,14 @@ func NewPermissionsCommand(sl *metadata.SoftlayerCommand) (cmd *PermissionsComma
2225
SoftlayerCommand: sl,
2326
UserManager: managers.NewUserManager(sl.Session),
2427
}
25-
28+
subs := map[string]interface{}{
29+
"HelpUrl": "https://cloud.ibm.com/docs/account?topic=account-migrated_permissions",
30+
}
2631
cobraCmd := &cobra.Command{
2732
Use: "permissions " + T("USER_ID"),
2833
Short: T("View user permissions"),
34+
Long: T(`Some permissions here may also be managed by the IBM IAM service.
35+
See {{.HelpUrl}} for more details.`, subs),
2936
Args: metadata.OneArgs,
3037
RunE: func(cmd *cobra.Command, args []string) error {
3138
return thisCmd.Run(args)
@@ -36,7 +43,19 @@ func NewPermissionsCommand(sl *metadata.SoftlayerCommand) (cmd *PermissionsComma
3643
return thisCmd
3744
}
3845

46+
type PermissionCollection struct {
47+
Department string
48+
Permissions []Permission
49+
}
50+
51+
type Permission struct {
52+
KeyName string
53+
Assigned string
54+
Description string
55+
}
56+
3957
func (cmd *PermissionsCommand) Run(args []string) error {
58+
outputFormat := cmd.GetOutputFlag()
4059
id, err := strconv.Atoi(args[0])
4160
if err != nil {
4261
return errors.NewInvalidUsageError(T("User ID should be a number."))
@@ -48,17 +67,41 @@ func (cmd *PermissionsCommand) Run(args []string) error {
4867
return errors.NewAPIError(T("Failed to get user."), err.Error(), 2)
4968
}
5069

51-
allPermission, err := cmd.UserManager.GetAllPermission()
70+
allPermission, err := cmd.UserManager.GetAllPermissionDepartments()
5271
if err != nil {
5372
return errors.NewAPIError(T("Failed to get permissions."), err.Error(), 2)
5473
}
5574

75+
userPermissions := []PermissionCollection{}
76+
5677
isMasterUser := false
5778
if user.IsMasterUserFlag != nil && *user.IsMasterUserFlag {
58-
cmd.UI.Print(T("This account is the Master User and has all permissions enabled"))
79+
if outputFormat != "JSON" {
80+
cmd.UI.Print(T("This account is the Master User and has all permissions enabled"))
81+
}
5982
isMasterUser = true
6083
}
6184

85+
86+
for _, department := range allPermission {
87+
depPerm := PermissionCollection{Department: *department.KeyName}
88+
for _, perm := range department.Permissions {
89+
assignedPerm := UserHasPermission(user.Permissions, *perm.KeyName) || isMasterUser
90+
thisPerm := Permission{
91+
KeyName: *perm.KeyName,
92+
Description: *perm.Description,
93+
Assigned: strconv.FormatBool(assignedPerm),
94+
}
95+
depPerm.Permissions = append(depPerm.Permissions, thisPerm)
96+
}
97+
userPermissions = append(userPermissions, depPerm)
98+
}
99+
100+
if outputFormat == "JSON" {
101+
return utils.PrintPrettyJSON(cmd.UI, userPermissions)
102+
}
103+
104+
62105
table := cmd.UI.Table([]string{T("ID"), T("Role Name"), T("Description")})
63106

64107
for _, role := range user.Roles {
@@ -71,31 +114,28 @@ func (cmd *PermissionsCommand) Run(args []string) error {
71114
table.Add("", "", "")
72115
table.Print()
73116

74-
tablePermission := cmd.UI.Table([]string{T("Description"), T("KeyName"), T("Assigned")})
75-
for _, perm := range allPermission {
76-
var assigned bool
77-
// Display master user as having all permissions, even though they have none, technically.
78-
if isMasterUser {
79-
assigned = true
80-
}
81-
for _, userPerm := range user.Permissions {
82-
if perm.KeyName != nil && userPerm.KeyName != nil && *perm.KeyName == *userPerm.KeyName {
83-
assigned = true
84-
}
85-
86-
}
87-
flag := true
88-
arr := []string{"ACCOUNT_SUMMARY_VIEW", "REQUEST_COMPLIANCE_REPORT", "COMPANY_EDIT", "ONE_TIME_PAYMENTS", "UPDATE_PAYMENT_DETAILS",
89-
"EU_LIMITED_PROCESSING_MANAGE", "TICKET_ADD", "TICKET_EDIT", "TICKET_SEARCH", "TICKET_VIEW", "TICKET_VIEW_ALL"}
90-
for i := 0; i < len(arr); i++ {
91-
if *perm.KeyName == arr[i] {
92-
flag = false
93-
}
94-
}
95-
if flag == true {
96-
tablePermission.Add(utils.FormatStringPointer(perm.Name), utils.FormatStringPointer(perm.KeyName), strconv.FormatBool(assigned))
117+
tablePermission := cmd.UI.Table([]string{T("Department"), T("Permissions")})
118+
for _, department := range userPermissions {
119+
buf := new(bytes.Buffer)
120+
headers := []string{T("KeyName"), T("Assigned"), T("Description")}
121+
subTable := terminal.NewTable(buf, headers)
122+
for _, perm := range department.Permissions {
123+
subTable.Add(perm.KeyName, perm.Assigned, perm.Description)
97124
}
125+
subTable.Print()
126+
tablePermission.Add(department.Department, buf.String())
98127
}
99128
tablePermission.Print()
100129
return nil
101130
}
131+
132+
133+
func UserHasPermission(userPermissions []datatypes.User_Customer_CustomerPermission_Permission, keyName string) bool {
134+
assigned := false
135+
for _, userPerm := range userPermissions {
136+
if *userPerm.KeyName == keyName {
137+
assigned = true
138+
}
139+
}
140+
return assigned
141+
}

0 commit comments

Comments
 (0)