Skip to content

Commit 31dbebe

Browse files
committed
ci: make reviewable
Signed-off-by: Julien Christophe <[email protected]>
1 parent 841c385 commit 31dbebe

File tree

4 files changed

+890
-364
lines changed

4 files changed

+890
-364
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: 23 additions & 22 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

0 commit comments

Comments
 (0)