Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acl improvements #249

Merged
merged 17 commits into from
Sep 24, 2024
Merged

Conversation

ol-imorozko
Copy link
Collaborator

Some improvements for ACL code.
Mainly reducing boilerplate code for acl unittests

Simplifyes handling of different data types in acl::rule_t actions.
This way we can see possible variants more cleanly
Simplified the static_assert to exclude int64_t directly
Replaced multiple if-else cases with a std::visit and generic lambda
in the ACL rule processing logic. Makes future modifications easier
and ensures that we processed all possible variant types
This is completly redundant:
[class.mfct]: "A member function may be defined (9.5) in its class
definition, in which case it is an inline (9.2.7) member
function if it is attached to the global module"
This is redundant, we have a MAX_COUNT fields with the description
Add a little description to an acl_value functions.

Also extract functionality from a compile method into different methods
for clarity
Otherwise the name is a little too long
The previous use of true and false as template arguments did not immediately
convey their meaning without referencing the Actions definition.
So replacing true/false with ActionsPath::WithCheckState and
ActionsPath::Default will improve readability
The changes are:
- Publically inherit BaseActions<WithCheckState> from BaseActions<Default>

  The check-state version should have all the functionality of the default path.
  Inheriting minimizes code duplication by directly reusing path manipulation methods.

  We avoid using overriding, as the only methods that differ between the two
  classes (push and pop) are never called from the base class pointers.
  Since we're not aiming to use polymorphism there's no need to introduce a
  vtable and the associated runtime overhead.

- Add helper methods for retrieving the size of paths and accessing the last
  actions from both the check-state and default paths (helps with tests)
…aliases

Some types are used a lot like common::globalBase::tFlow, so we can save
some time by adding an alias
Centralize setup and action visitation logic, reducing duplicated code in unittests
Introduce custom GTest matchers to check for specific variants in `RawAction`.
Replace EXPECT_THAT with ::testing::Eq mather with `EXPECT_EQ`.

Overall, these changes reduces verbosity and make the code easier to follow.
Moved path validation logic into `compile_acl` to reduce code duplication.
Also using newly added methods to `BaseActions` for cleaner access to default
and check-state paths.
Replaced multiple constructors of `rule_t` with a single templated constructor
to handle all variants of `rule_action`.

This reduces code duplication. Constructor for `skipto` remains unchanged.
@GeorgyKirichenko GeorgyKirichenko merged commit a69935d into yanet-platform:main Sep 24, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants