Skip to content

Commit 81603b2

Browse files
jkatzJonathan S. Katz
authored andcommitted
Add support for the "*" permission to pgo create pgorole --permissions
While "*" has been supported for awhile in the PostgreSQL Operator, one could not add it while using the `pgo create pgorole --permissions` as it failed the validation check. This rectifies this oversight and fixes said bug. Issue: [ch8909]
1 parent 396e719 commit 81603b2

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

apiserver/pgoroleservice/pgoroleimpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func validPermissions(perms string) error {
250250
fields := strings.Split(perms, ",")
251251

252252
for _, v := range fields {
253-
if apiserver.PermMap[strings.TrimSpace(v)] == "" {
253+
if apiserver.PermMap[strings.TrimSpace(v)] == "" && strings.TrimSpace(v) != "*" {
254254
return errors.New(v + " not a valid Permission")
255255
}
256256
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package pgoroleservice
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/crunchydata/postgres-operator/internal/apiserver"
8+
)
9+
10+
func TestValidPermissions(t *testing.T) {
11+
apiserver.PermMap = map[string]string{
12+
apiserver.CREATE_CLUSTER_PERM: "yes",
13+
apiserver.CREATE_PGBOUNCER_PERM: "yes",
14+
}
15+
16+
t.Run("with valid permission", func(t *testing.T) {
17+
perms := apiserver.CREATE_CLUSTER_PERM
18+
19+
if err := validPermissions(perms); err != nil {
20+
t.Errorf("%q should be a valid permission", perms)
21+
}
22+
})
23+
24+
t.Run("with multiple valid permissions", func(t *testing.T) {
25+
perms := fmt.Sprintf("%s,%s", apiserver.CREATE_CLUSTER_PERM, apiserver.CREATE_PGBOUNCER_PERM)
26+
27+
if err := validPermissions(perms); err != nil {
28+
t.Errorf("%v should be a valid permission", perms)
29+
}
30+
})
31+
32+
t.Run("with an invalid permission", func(t *testing.T) {
33+
perms := "bogus"
34+
35+
if err := validPermissions(perms); err == nil {
36+
t.Errorf("%q should raise an error", perms)
37+
}
38+
})
39+
40+
t.Run("with a mix of valid and invalid permissions", func(t *testing.T) {
41+
perms := fmt.Sprintf("%s,%s", apiserver.CREATE_CLUSTER_PERM, "bogus")
42+
43+
if err := validPermissions(perms); err == nil {
44+
t.Errorf("%q should raise an error", perms)
45+
}
46+
})
47+
48+
t.Run("with *", func(t *testing.T) {
49+
perms := "*"
50+
51+
if err := validPermissions(perms); err != nil {
52+
t.Errorf("%q should be a valid permission", perms)
53+
}
54+
})
55+
}

0 commit comments

Comments
 (0)