@@ -18,12 +18,13 @@ package v1alpha1
18
18
19
19
import (
20
20
"context"
21
- "github.com/pkg/errors"
21
+
22
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
23
"sigs.k8s.io/controller-runtime/pkg/client"
24
24
25
25
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
26
26
"github.com/crossplane/crossplane-runtime/pkg/reference"
27
+ "github.com/pkg/errors"
27
28
)
28
29
29
30
const (
@@ -117,41 +118,41 @@ func (gp *GrantParameters) filledInFields() *stringSet {
117
118
return set
118
119
}
119
120
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
+
120
133
// IdentifyGrantType return the deduced GrantType from the filled in fields.
121
134
func (gp * GrantParameters ) IdentifyGrantType () (GrantType , error ) {
122
- fields := gp .filledInFields ()
135
+ ff := gp .filledInFields ()
123
136
pc := len (gp .Privileges )
124
137
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
138
139
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
142
143
break
143
144
}
144
145
}
145
- if role == nil {
146
+ if gt == nil {
146
147
return "" , errors .New (errUnknownGrant )
147
148
}
148
- if * role == RoleMember && pc > 0 {
149
+ if * gt == RoleMember && pc > 0 {
149
150
return "" , errors .New (errMemberOfWithPrivileges )
150
151
}
151
- if * role != RoleMember && pc < 1 {
152
+ if * gt != RoleMember && pc < 1 {
152
153
return "" , errors .New (errNoPrivileges )
153
154
}
154
- return * role , nil
155
+ return * gt , nil
155
156
}
156
157
157
158
// Some privileges are shorthands for multiple privileges. These translations
0 commit comments