Feat: Role Based Capabilities #174
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of change
This PR introduces a new module
audit_trail::role_mapproviding theRoleMap<P>struct and associated functions:A very simple example-integration of the
RoleMapcan be found below in the most bottom section.RoleMapintegration into AuditTrails:RoleMapis integrated in theaudit_trail::mainmodule to manage access to the audit trail records andtheir operations. See here for an example.
RoleMapis created by theAuditTrailin it's create function.The
RoleMapdirectly depends on theaudit_trail::capability::Capabilitymodule. Both modules are tight strongly together but can be used generically by all of our TF products and by community developer projects as dependencies.As the
RoleMapand theaudit_trail::capability::Capabilitymodules can be used with any TF product or community developer smart contract, it shall be moved to theproduct-corerepository. Theaudit_trail::mainmodule will use these modules as dependencies then. The current plan is to introduce a new package inproduct-coreto collect modules, dedicated to be used by community developers. The packageproduct_commonis dedicated to be used internally by the PA team and the new package would contain modules (Move, Rust, TS) officially provided for community devs.All names are not set in stone and there might be better names, especially for the
RoleMapwhich might better be calledRoleBasedCapabilities(RBC) or ..... ???This PR also extends the
audit_trail::capability::Capabilitys with additional optional restrictions:issued_to,valid_untilandvalid_from.How the change has been tested
In the
audit-trail-movefolder:Remaining TODOs / Known Issues
RoleMapfieldissued_capabilitiesuses aVecSet<ID>ATM causing size limitation. Will probably replaced by aiota::table<ID>.Example for integrating the
RoleMapinto 3rd party shared objects (or TF products)To use the
RoleMapfor a custom project (i.e. a shared Counter like this) one would just need to define a Permission enum similar to the enum we are using for Audit Trails.For example the Permission enum for a shared
Countercould look like this:In the file
counter/permission.move:The
Counterobject then would need to instantiate therole_map::RoleMap<CounterPermission>in its create function like this:In the file
counter/counter.move:Later on the
Countercan use theRoleMap.is_capability_valid()function like the Audit Trail does:In the file
counter/counter.move:Using the shared Counter object would look like this:
In the file
tests/counter_tests.move: