@@ -18,12 +18,13 @@ package v1alpha1
1818
1919import (
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
2930const (
@@ -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.
121134func (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