Skip to content

Commit e0f9a4b

Browse files
committed
ci: make reviewable
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
1 parent 841c385 commit e0f9a4b

File tree

4 files changed

+894
-367
lines changed

4 files changed

+894
-367
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Check the example:
6060
2. Create managed resources for your SQL server flavor:
6161

6262
- **MySQL**: `Database`, `Grant`, `User` (See [the examples](examples/mysql))
63-
- **PostgreSQL**: `Database`, `Grant`, `Extension`, `Role` (See [the examples](examples/postgresql))
63+
- **PostgreSQL**: `Database`, `Schema`, `Grant`, `Extension`, `Role` (See [the examples](examples/postgresql))
6464
- **MSSQL**: `Database`, `Grant`, `User` (See [the examples](examples/mssql))
6565

6666
[crossplane]: https://crossplane.io

apis/postgresql/v1alpha1/grant_types.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ package v1alpha1
1818

1919
import (
2020
"context"
21-
"github.com/pkg/errors"
21+
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"sigs.k8s.io/controller-runtime/pkg/client"
2424

2525
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
2626
"github.com/crossplane/crossplane-runtime/pkg/reference"
27+
"github.com/pkg/errors"
2728
)
2829

2930
const (
@@ -117,41 +118,41 @@ func (gp *GrantParameters) filledInFields() *stringSet {
117118
return set
118119
}
119120

121+
var grantTypeFields = map[GrantType][]string{
122+
RoleMember: {"MemberOf"},
123+
RoleDatabase: {"Database"},
124+
RoleSchema: {"Database", "Schema"},
125+
RoleTable: {"Database", "Schema", "Tables"},
126+
RoleColumn: {"Database", "Schema", "Tables", "Columns"},
127+
RoleSequence: {"Database", "Schema", "Sequences"},
128+
RoleRoutine: {"Database", "Schema", "Routines"},
129+
RoleForeignServer: {"Database", "ForeignServers"},
130+
RoleForeignDataWrapper: {"Database", "ForeignDataWrappers"},
131+
}
132+
120133
// IdentifyGrantType return the deduced GrantType from the filled in fields.
121134
func (gp *GrantParameters) IdentifyGrantType() (GrantType, error) {
122-
fields := gp.filledInFields()
135+
ff := gp.filledInFields()
123136
pc := len(gp.Privileges)
124137

125-
grantTypeFields := map[GrantType][]string{
126-
RoleMember: {"MemberOf"},
127-
RoleDatabase: {"Database"},
128-
RoleSchema: {"Database", "Schema"},
129-
RoleTable: {"Database", "Schema", "Tables"},
130-
RoleColumn: {"Database", "Schema", "Tables", "Columns"},
131-
RoleSequence: {"Database", "Schema", "Sequences"},
132-
RoleRoutine: {"Database", "Schema", "Routines"},
133-
RoleForeignServer: {"Database", "ForeignServers"},
134-
RoleForeignDataWrapper: {"Database", "ForeignDataWrappers"},
135-
}
136-
137-
var role *GrantType
138+
var gt *GrantType
138139

139-
for key, expectedFields := range grantTypeFields {
140-
if fields.containsExactly(expectedFields...) {
141-
role = &key
140+
for k, v := range grantTypeFields {
141+
if ff.containsExactly(v...) {
142+
gt = &k
142143
break
143144
}
144145
}
145-
if role == nil {
146+
if gt == nil {
146147
return "", errors.New(errUnknownGrant)
147148
}
148-
if *role == RoleMember && pc > 0 {
149+
if *gt == RoleMember && pc > 0 {
149150
return "", errors.New(errMemberOfWithPrivileges)
150151
}
151-
if *role != RoleMember && pc < 1 {
152+
if *gt != RoleMember && pc < 1 {
152153
return "", errors.New(errNoPrivileges)
153154
}
154-
return *role, nil
155+
return *gt, nil
155156
}
156157

157158
// Some privileges are shorthands for multiple privileges. These translations
@@ -196,21 +197,21 @@ var grantReplacements = map[GrantType]map[GrantPrivilege]GrantPrivileges{
196197

197198
// ExpandPrivileges expands any shorthand privileges to their full equivalents.
198199
func (gp *GrantParameters) ExpandPrivileges() GrantPrivileges {
199-
grantType, err := gp.IdentifyGrantType()
200+
gt, err := gp.IdentifyGrantType()
200201
if err != nil {
201202
return gp.Privileges
202203
}
203-
replacements, hasReplacements := grantReplacements[grantType]
204-
if !hasReplacements {
204+
gr, ex := grantReplacements[gt]
205+
if !ex {
205206
return gp.Privileges
206207
}
207208

208209
privilegeSet := make(map[GrantPrivilege]struct{})
209210

210211
// Replace any shorthand privileges with their full equivalents
211212
for _, p := range gp.Privileges {
212-
if _, ok := replacements[p]; ok {
213-
for _, rp := range replacements[p] {
213+
if _, ok := gr[p]; ok {
214+
for _, rp := range gr[p] {
214215
privilegeSet[rp] = struct{}{}
215216
}
216217
} else {

0 commit comments

Comments
 (0)