@@ -19,8 +19,8 @@ import "github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/authorizer"
1919- [ type ContextKey] ( < #ContextKey > )
2020- [ type Instancer] ( < #Instancer > )
2121- [ type MetadataBasedAuthorizer] ( < #MetadataBasedAuthorizer > )
22- - [ func \( s MetadataBasedAuthorizer\) Configure\(\_ string, \_ map\[ string\] dbrole.DbRole\) ] ( < #MetadataBasedAuthorizer.Configure > )
23- - [ func \( s MetadataBasedAuthorizer\) GetAuthContext\( orgId string, roles ...string\) context.Context] ( < #MetadataBasedAuthorizer.GetAuthContext > )
22+ - [ func \( s \* MetadataBasedAuthorizer\) Configure\( tableName string, roleMapping map\[ string\] dbrole.DbRole\) ] ( < #MetadataBasedAuthorizer.Configure > )
23+ - [ func \( s \* MetadataBasedAuthorizer\) GetAuthContext\( orgId string, roles ...string\) context.Context] ( < #MetadataBasedAuthorizer.GetAuthContext > )
2424 - [ func \( s \* MetadataBasedAuthorizer\) GetDefaultOrgAdminContext\(\) context.Context] ( < #MetadataBasedAuthorizer.GetDefaultOrgAdminContext > )
2525 - [ func \( s \* MetadataBasedAuthorizer\) GetMatchingDbRole\( ctx context.Context, tableNames ...string\) \( dbrole.DbRole, error\) ] ( < #MetadataBasedAuthorizer.GetMatchingDbRole > )
2626 - [ func \( s \* MetadataBasedAuthorizer\) GetOrgFromContext\( ctx context.Context\) \( string, error\) ] ( < #MetadataBasedAuthorizer.GetOrgFromContext > )
@@ -106,34 +106,36 @@ type Instancer interface {
106106```
107107
108108<a name =" MetadataBasedAuthorizer " ></a >
109- ## type [ MetadataBasedAuthorizer] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L42 > )
109+ ## type [ MetadataBasedAuthorizer] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L42-L44 > )
110110
111111
112112
113113``` go
114- type MetadataBasedAuthorizer struct {}
114+ type MetadataBasedAuthorizer struct {
115+ // contains filtered or unexported fields
116+ }
115117```
116118
117119<a name =" MetadataBasedAuthorizer.Configure " ></a >
118- ### func \( MetadataBasedAuthorizer\) [ Configure] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L80 > )
120+ ### func \(\* MetadataBasedAuthorizer\) [ Configure] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L107 > )
119121
120122``` go
121- func (s MetadataBasedAuthorizer ) Configure (_ string , _ map [string ]dbrole .DbRole )
123+ func (s * MetadataBasedAuthorizer ) Configure (tableName string , roleMapping map [string ]dbrole .DbRole )
122124```
123125
124126
125127
126128<a name="MetadataBasedAuthorizer.GetAuthContext"></a>
127- ### func \(MetadataBasedAuthorizer\) [GetAuthContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L85 >)
129+ ### func \(\* MetadataBasedAuthorizer\) [GetAuthContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L116 >)
128130
129131```go
130- func (s MetadataBasedAuthorizer) GetAuthContext(orgId string, roles ...string) context.Context
132+ func (s * MetadataBasedAuthorizer) GetAuthContext(orgId string, roles ...string) context.Context
131133```
132134
133135
134136
135137<a name="MetadataBasedAuthorizer.GetDefaultOrgAdminContext"></a>
136- ### func \(\*MetadataBasedAuthorizer\) [GetDefaultOrgAdminContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L89 >)
138+ ### func \(\*MetadataBasedAuthorizer\) [GetDefaultOrgAdminContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L124 >)
137139
138140```go
139141func (s *MetadataBasedAuthorizer) GetDefaultOrgAdminContext() context.Context
@@ -142,7 +144,7 @@ func (s *MetadataBasedAuthorizer) GetDefaultOrgAdminContext() context.Context
142144
143145
144146<a name="MetadataBasedAuthorizer.GetMatchingDbRole"></a>
145- ### func \(\*MetadataBasedAuthorizer\) [GetMatchingDbRole](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L58 >)
147+ ### func \(\*MetadataBasedAuthorizer\) [GetMatchingDbRole](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L60 >)
146148
147149```go
148150func (s *MetadataBasedAuthorizer) GetMatchingDbRole(ctx context.Context, tableNames ...string) (dbrole.DbRole, error)
@@ -151,7 +153,7 @@ func (s *MetadataBasedAuthorizer) GetMatchingDbRole(ctx context.Context, tableNa
151153
152154
153155<a name="MetadataBasedAuthorizer.GetOrgFromContext"></a>
154- ### func \(\*MetadataBasedAuthorizer\) [GetOrgFromContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L44 >)
156+ ### func \(\*MetadataBasedAuthorizer\) [GetOrgFromContext](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/authorizer/metadata_authorizer.go#L46 >)
155157
156158```go
157159func (s *MetadataBasedAuthorizer) GetOrgFromContext(ctx context.Context) (string, error)
@@ -675,8 +677,8 @@ func main() {
675677
676678 // Registers the necessary structs with their corresponding role mappings.
677679 roleMapping := map [string ]dbrole.DbRole {
678- SERVICE_AUDITOR: dbrole.READER ,
679- SERVICE_ADMIN: dbrole.WRITER ,
680+ SERVICE_AUDITOR: dbrole.INSTANCE_READER ,
681+ SERVICE_ADMIN: dbrole.INSTANCE_WRITER ,
680682 }
681683 if err = ds.Register (context.TODO (), roleMapping, &Person{}); err != nil {
682684 log.Fatalf (" Failed to create DB tables: %+v " , err)
@@ -998,15 +1000,13 @@ type TestHelper interface {
9981000import " github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/dbrole"
9991001```
10001002
1001- DAL uses 4 database roles/users to perform all operations,
1002-
1003- - \` TENANT\_ READER\` \- has read access to its tenant's data
1004- - \` READER\` \- has read access to all tenants' data
1005- - \` TENANT\_ WRITER\` \- has read & write access to its tenant's data
1006- - \` WRITER\` \- has read & write access to all tenants' data
1007-
10081003Corresponding \* INSTANCE\_\* roles access is determined by the Instancer's configuration, allowing it to access records exclusively with a specific instance.
10091004
1005+ - \` TENANT\_ INSTANCE\_ READER\` \- has read access to its tenant instance's data
1006+ - \` INSTANCE\_ READER\` \- has read access to specific instance data
1007+ - \` TENANT\_ INSTANCE\_ WRITER\` \- has read & write access to its tenant instance's data
1008+ - \` INSTANCE\_ WRITER\` \- has read & write access to specific instance data
1009+
10101010DAL allows to map a user's service role to the DB role that will be used for that user. If a user has multiple service roles which map to several DB roles, the DB role with the most extensive privileges will be used \( see \` DbRoles\(\)\` for reference to ordered list of DbRoles.
10111011
10121012## Index
@@ -1015,7 +1015,6 @@ DAL allows to map a user's service role to the DB role that will be used for tha
10151015 - [ func Max\( dbRoles \[\] DbRole\) DbRole] ( < #Max > )
10161016 - [ func Min\( dbRoles \[\] DbRole\) DbRole] ( < #Min > )
10171017 - [ func \( dbRole DbRole\) GetRoleWithInstancer\(\) DbRole] ( < #DbRole.GetRoleWithInstancer > )
1018- - [ func \( dbRole DbRole\) GetRoleWithTenancy\(\) DbRole] ( < #DbRole.GetRoleWithTenancy > )
10191018 - [ func \( dbRole DbRole\) IsDbRoleInstanceScoped\(\) bool] ( < #DbRole.IsDbRoleInstanceScoped > )
10201019 - [ func \( dbRole DbRole\) IsDbRoleTenantScoped\(\) bool] ( < #DbRole.IsDbRoleTenantScoped > )
10211020- [ type DbRoleSlice] ( < #DbRoleSlice > )
@@ -1026,7 +1025,7 @@ DAL allows to map a user's service role to the DB role that will be used for tha
10261025
10271026
10281027<a name =" DbRole " ></a >
1029- ## type [ DbRole] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L38 > )
1028+ ## type [ DbRole] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L42 > )
10301029
10311030DbRole Database roles/users.
10321031
@@ -1053,7 +1052,7 @@ const (
10531052```
10541053
10551054<a name =" Max " ></a >
1056- ### func [ Max] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L133 > )
1055+ ### func [ Max] ( < https://github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L123 > )
10571056
10581057``` go
10591058func Max (dbRoles []DbRole ) DbRole
@@ -1062,7 +1061,7 @@ func Max(dbRoles []DbRole) DbRole
10621061
10631062
10641063<a name="Min"></a>
1065- ### func [Min](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L138 >)
1064+ ### func [Min](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L128 >)
10661065
10671066```go
10681067func Min(dbRoles []DbRole) DbRole
@@ -1071,25 +1070,16 @@ func Min(dbRoles []DbRole) DbRole
10711070
10721071
10731072<a name="DbRole.GetRoleWithInstancer"></a>
1074- ### func \(DbRole\) [GetRoleWithInstancer](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L82 >)
1073+ ### func \(DbRole\) [GetRoleWithInstancer](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L88 >)
10751074
10761075```go
10771076func (dbRole DbRole) GetRoleWithInstancer() DbRole
10781077```
10791078
1080- Map roles to instancer based when Instancer is set.
1081-
1082- <a name="DbRole.GetRoleWithTenancy"></a>
1083- ### func \(DbRole\) [GetRoleWithTenancy](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L98>)
1084-
1085- ```go
1086- func (dbRole DbRole) GetRoleWithTenancy() DbRole
1087- ```
1088-
1089- Map roles to tenancy based roles as tenant column is configured.
1079+ Map roles to instancer based when Instancer is set. Useful for backward compatibility when role Mapping do not reference \*INSTANCE\* roles, but an Instancer is configured to limit the access to an instance.
10901080
10911081<a name="DbRole.IsDbRoleInstanceScoped"></a>
1092- ### func \(DbRole\) [IsDbRoleInstanceScoped](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L77 >)
1082+ ### func \(DbRole\) [IsDbRoleInstanceScoped](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L81 >)
10931083
10941084```go
10951085func (dbRole DbRole) IsDbRoleInstanceScoped() bool
@@ -1098,7 +1088,7 @@ func (dbRole DbRole) IsDbRoleInstanceScoped() bool
10981088
10991089
11001090<a name="DbRole.IsDbRoleTenantScoped"></a>
1101- ### func \(DbRole\) [IsDbRoleTenantScoped](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L73 >)
1091+ ### func \(DbRole\) [IsDbRoleTenantScoped](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L77 >)
11021092
11031093```go
11041094func (dbRole DbRole) IsDbRoleTenantScoped() bool
@@ -1107,7 +1097,7 @@ func (dbRole DbRole) IsDbRoleTenantScoped() bool
11071097
11081098
11091099<a name="DbRoleSlice"></a>
1110- ## type [DbRoleSlice](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L123 >)
1100+ ## type [DbRoleSlice](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L113 >)
11111101
11121102
11131103
@@ -1116,7 +1106,7 @@ type DbRoleSlice []DbRole // Needed for sorting records
11161106```
11171107
11181108<a name="DbRoles"></a>
1119- ### func [DbRoles](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L58 >)
1109+ ### func [DbRoles](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L62 >)
11201110
11211111```go
11221112func DbRoles() DbRoleSlice
@@ -1125,7 +1115,7 @@ func DbRoles() DbRoleSlice
11251115Returns \*Ordered\* slice of DbRoles. A reader role is always considered to have fewer permissions than a writer role. and a tenant\-specific reader/writer role is always considered to have fewer permissions, than a non\-tenant specific reader/writer role, respectively.
11261116
11271117<a name="DbRoleSlice.Len"></a>
1128- ### func \(DbRoleSlice\) [Len](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L131 >)
1118+ ### func \(DbRoleSlice\) [Len](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L121 >)
11291119
11301120```go
11311121func (a DbRoleSlice) Len() int
@@ -1134,7 +1124,7 @@ func (a DbRoleSlice) Len() int
11341124
11351125
11361126<a name="DbRoleSlice.Less"></a>
1137- ### func \(DbRoleSlice\) [Less](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L127 >)
1127+ ### func \(DbRoleSlice\) [Less](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L117 >)
11381128
11391129```go
11401130func (a DbRoleSlice) Less(i, j int) bool
@@ -1143,7 +1133,7 @@ func (a DbRoleSlice) Less(i, j int) bool
11431133Returns true if the first role has fewer permissions than the second role, and true if the two roles are the same or the second role has more permissions.
11441134
11451135<a name="DbRoleSlice.Swap"></a>
1146- ### func \(DbRoleSlice\) [Swap](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L129 >)
1136+ ### func \(DbRoleSlice\) [Swap](<https:// github.com/vmware-labs/multi-tenant-persistence-for-saas/blob/main/pkg/dbrole/dbrole.go#L119 >)
11471137
11481138```go
11491139func (a DbRoleSlice) Swap(i, j int)
0 commit comments