-
Notifications
You must be signed in to change notification settings - Fork 9
[#1177] ProtectedAtomDB #1216
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
Closed
Closed
[#1177] ProtectedAtomDB #1216
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
55fa0f3
Add the ProtectedAtomDB class as a wrapper for AtomDB and include the…
marcocapozzoli eb51342
Merge branch 'master' into masc/1177-atomdb-authorization
marcocapozzoli 3fbb964
Fix the method signatures
marcocapozzoli fad7f77
Create AtomDBFactory
marcocapozzoli c75e72d
Add tests for AtomDBFactory
marcocapozzoli f6377ca
Add tests for AtomDB protection and factory wrapping.
marcocapozzoli d8ca7e4
Fix minor in tests
marcocapozzoli feb1b4c
Improve RemoteAtomDBFactoryConstruction.*
marcocapozzoli a00b4f1
add return ""
marcocapozzoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include "AtomDBFactory.h" | ||
|
|
||
| #include "InMemoryDB.h" | ||
| #include "MorkDB.h" | ||
| #include "ProtectedAtomDB.h" | ||
| #include "RedisMongoDB.h" | ||
| #include "Utils.h" | ||
|
|
||
| using namespace atomdb; | ||
| using namespace commons; | ||
|
|
||
| // -------------------------------------------------------------------------------- | ||
| // Public methods | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::create(const JsonConfig& config, const string& context) { | ||
| return wrap_if_protected(create_backend(config, context)); | ||
| } | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::create_backend(const JsonConfig& config, const string& context) { | ||
| auto atomdb_type = config.at_path("type").get_or<string>(""); | ||
|
|
||
| if (atomdb_type == "redismongodb") { | ||
| return shared_ptr<AtomDB>(new RedisMongoDB(context, false, config)); | ||
| } | ||
| if (atomdb_type == "morkdb") { | ||
| return shared_ptr<AtomDB>(new MorkDB(context, config)); | ||
| } | ||
| if (atomdb_type == "inmemorydb") { | ||
| return make_shared<InMemoryDB>(context.empty() ? "inmemorydb_" : context); | ||
| } | ||
|
|
||
| RAISE_ERROR("AtomDBFactory: unsupported AtomDB type: " + atomdb_type); | ||
| return shared_ptr<AtomDB>{}; | ||
| } | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::wrap_if_protected(shared_ptr<AtomDB> backend) { | ||
| if (!backend) { | ||
| RAISE_ERROR("AtomDBFactory::wrap_if_protected() received null backend"); | ||
| } | ||
| if (!backend->is_protected()) { | ||
| return backend; | ||
| } | ||
| if (dynamic_pointer_cast<ProtectedAtomDB>(backend)) { | ||
| return backend; | ||
| } | ||
| return shared_ptr<AtomDB>(new ProtectedAtomDB(backend)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "AtomDB.h" | ||
| #include "JsonConfig.h" | ||
|
|
||
| using namespace std; | ||
| using namespace commons; | ||
|
|
||
| namespace atomdb { | ||
|
|
||
| /** | ||
| * @brief Single entry point to construct concrete AtomDB backends. | ||
| * | ||
| * Use this instead of calling RedisMongoDB/MorkDB/InMemoryDB constructors directly. | ||
| */ | ||
| class AtomDBFactory { | ||
| public: | ||
| /** | ||
| * @brief Creates a backend and wraps it with ProtectedAtomDB when is_protected(). | ||
| */ | ||
| static shared_ptr<AtomDB> create(const JsonConfig& config, const string& context = ""); | ||
|
|
||
| /** | ||
| * @brief Creates a concrete backend without authorization wrapping. | ||
| * | ||
| * Supported types: redismongodb, morkdb, inmemorydb. | ||
| */ | ||
| static shared_ptr<AtomDB> create_backend(const JsonConfig& config, const string& context = ""); | ||
|
|
||
| /** | ||
| * @brief Wraps backend with ProtectedAtomDB when protected and not already wrapped. | ||
| */ | ||
| static shared_ptr<AtomDB> wrap_if_protected(shared_ptr<AtomDB> backend); | ||
| }; | ||
|
|
||
| } // namespace atomdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "protected_atomdb_lib", | ||
| includes = ["."], | ||
| deps = [ | ||
| ":protected_atomdb", | ||
| ], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "protected_atomdb", | ||
| srcs = ["ProtectedAtomDB.cc"], | ||
| hdrs = ["ProtectedAtomDB.h"], | ||
| includes = ["."], | ||
| deps = [ | ||
| "//atomdb", | ||
| "//atomdb:atomdb_api_types", | ||
| "//commons:commons_lib", | ||
| "//commons/atoms:atoms_lib", | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.