@@ -31,7 +31,6 @@ pub struct DynamoDbConfig {
3131 /// Configured readers - maps a table name to a list of rules that are allowed to READ data
3232 r : HashMap < String , HashSet < String > > ,
3333 /// Reserved tables - list of 'reserved' table names which rules cannot access
34- /// For the purpose of preventing rules rule accessing 'storage' tables in
3534 #[ serde( default ) ]
3635 reserved_tables : Option < HashSet < String > > ,
3736}
@@ -46,12 +45,11 @@ pub struct DynamoDb {
4645 /// Configured readers - maps a table name to a list of rules that are allowed to READ data
4746 r : HashMap < String , HashSet < String > > ,
4847 /// Reserved tables - list of 'reserved' table names which rules cannot access
49- /// For the purpose of preventing rules rule accessing 'storage' tables in
5048 reserved_tables : Option < HashSet < String > > ,
5149}
5250
5351#[ derive( PartialEq , PartialOrd , Debug ) ]
54- /// Represents an access scope for a rule has to modify a DynamoDB table
52+ /// Represents an access scope that a rule has to modify a DynamoDB table
5553enum AccessScope {
5654 Read ,
5755 Write ,
@@ -106,8 +104,8 @@ impl DynamoDb {
106104 }
107105 }
108106
109- /// Checks if module can perform given give action
110- /// Modules are registerd as as read (R) or write (RW) under self.
107+ /// Checks if a module can perform a given action
108+ /// Modules are registered as as read (R) or write (RW) under self.
111109 /// This function checks:
112110 /// * If the table is a reserved table i.e. no Module is allowed to access reserved tables.
113111 /// * If the module is configured as a Reader or Writer of a given table
@@ -151,6 +149,14 @@ impl DynamoDb {
151149 Err ( ApiError :: BadRequest )
152150 }
153151 AccessScope :: Write => {
152+ // check if write access is configured for this table
153+ if let Some ( write_access) = self . rw . get ( table_name) {
154+ // check if this module has write access to this table
155+ if write_access. contains ( & module. to_string ( ) ) {
156+ return Ok ( ( ) ) ;
157+ } ;
158+ }
159+
154160 // check if read access is configured for this table
155161 if let Some ( table_readers) = self . r . get ( table_name) {
156162 // check if this module has read access to this table
@@ -162,14 +168,6 @@ impl DynamoDb {
162168 }
163169 }
164170
165- // check if write access is configured for this table
166- if let Some ( write_access) = self . rw . get ( table_name) {
167- // check if this module has write access to this table
168- if write_access. contains ( & module. to_string ( ) ) {
169- return Ok ( ( ) ) ;
170- } ;
171- }
172-
173171 warn ! (
174172 "[{module}] failed [write] permission check for dynamodb table [{table_name}]"
175173 ) ;
0 commit comments