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

fix: add StringAdapter for Enforcer to pass policy as string #204

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

cs1137195420
Copy link
Contributor

fix: #200

Description

I added void LoadPolicy(std::string policy) for Enforcer to pass policy to Adapter as a sting buffer, which could be called as the following code:

casbin::Enforcer e("./path/to/model.conf");
std::string policy = "p, alice, data1, read\np, bob, data2, write";
e.LoadPolicy(policy);

Since c++ doesn't support overloaded functions with the same number and type of parameters, I didn't add a constructor like Enforcer(const std::string& model_path, const std::string &policy) in issue #200, that conflicts with Enforcer(const std::string& model_path, const std::string& policy_file)

@casbin-bot
Copy link
Member

@EmperorYP7 @divy9881 @noob20000405 @sheny1xuan please review

@hsluoyz
Copy link
Member

hsluoyz commented Jul 3, 2022

@cs1137195420 fix all errors:

image

@cs1137195420 cs1137195420 changed the title fix: add LoadPolicy for Enforcer to pass policy as string fix: add StringAdapter for Enforcer to pass policy as string Jul 3, 2022
@cs1137195420
Copy link
Contributor Author

@hsluoyz I modified the code referring to the implementation of StringAdapter in golang. Is this PR OK now?

@hsluoyz
Copy link
Member

hsluoyz commented Jul 3, 2022

@sheny1xuan plz review

casbin/enforcer.cpp Outdated Show resolved Hide resolved
@cs1137195420 cs1137195420 force-pushed the master branch 5 times, most recently from 1279e0a to 3133e17 Compare July 4, 2022 10:38
@cs1137195420
Copy link
Contributor Author

@sheny1xuan I've modified the code, could you plz review it again?

Copy link
Contributor

@sheny1xuan sheny1xuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

casbin/persist/file_adapter/file_adapter.cpp Outdated Show resolved Hide resolved
casbin/persist/string_adapter.cpp Outdated Show resolved Hide resolved
@hsluoyz
Copy link
Member

hsluoyz commented Jul 8, 2022

@MaximAxelrodFirebolt plz review

@hsluoyz hsluoyz merged commit 3e1e242 into casbin:master Jul 8, 2022
@github-actions
Copy link

github-actions bot commented Jul 8, 2022

🎉 This PR is included in version 1.50.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Passing policy to Adapter as a sting buffer instead of a text filepath
4 participants