Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/atomdb/AtomDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AtomDB : public HandleDecoder {

virtual bool allow_nested_indexing() = 0;
virtual bool composite_type_enabled() const = 0;
virtual bool is_protected() const = 0;

virtual shared_ptr<Atom> get_atom(const string& handle) = 0; // HandleDecoder interface
virtual shared_ptr<Node> get_node(const string& handle) = 0;
Expand Down
41 changes: 25 additions & 16 deletions src/atomdb/AtomDBSingleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "AdapterDB.h"
#include "MorkDB.h"
#include "ProtectedAtomDB.h"
#include "RedisMongoDB.h"
#include "RemoteAtomDB.h"
#include "Utils.h"
Expand All @@ -19,24 +20,32 @@ void AtomDBSingleton::init(const JsonConfig& atomdb_config) {
if (AtomDBSingleton::initialized) {
RAISE_ERROR(
"AtomDBSingleton already initialized. AtomDBSingleton::init() should be called only once.");
}

shared_ptr<AtomDB> atomdb;
auto atomdb_type = atomdb_config.at_path("type").get_or<string>("");

if (atomdb_type == "morkdb") {
atomdb = shared_ptr<AtomDB>(new MorkDB("", atomdb_config));
} else if (atomdb_type == "redismongodb") {
atomdb = shared_ptr<AtomDB>(new RedisMongoDB("", false, atomdb_config));
} else if (atomdb_type == "remotedb") {
auto remote_peers_config =
atomdb_config.at_path("remote_peers").get_or<JsonConfig>(JsonConfig());
atomdb = shared_ptr<AtomDB>(new RemoteAtomDB(remote_peers_config));
} else if (atomdb_type == "adapterdb") {
atomdb = shared_ptr<AtomDB>(new AdapterDB(atomdb_config));
} else {
RAISE_ERROR("Invalid AtomDB type: " + atomdb_type);
}

if (atomdb->is_protected()) {
AtomDBSingleton::atom_db = shared_ptr<AtomDB>(new ProtectedAtomDB(atomdb));
} else {
auto atomdb_type = atomdb_config.at_path("type").get_or<string>("");
if (atomdb_type == "morkdb") {
AtomDBSingleton::atom_db = shared_ptr<AtomDB>(new MorkDB("", atomdb_config));
} else if (atomdb_type == "redismongodb") {
AtomDBSingleton::atom_db = shared_ptr<AtomDB>(new RedisMongoDB("", false, atomdb_config));
} else if (atomdb_type == "remotedb") {
auto remote_peers_config =
atomdb_config.at_path("remote_peers").get_or<JsonConfig>(JsonConfig());
AtomDBSingleton::atom_db = shared_ptr<AtomDB>(new RemoteAtomDB(remote_peers_config));
} else if (atomdb_type == "adapterdb") {
AtomDBSingleton::atom_db = shared_ptr<AtomDB>(new AdapterDB(atomdb_config));
} else {
RAISE_ERROR("Invalid AtomDB type: " + atomdb_type);
}

AtomDBSingleton::initialized = true;
AtomDBSingleton::atom_db = atomdb;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

AtomDBSingleton::initialized = true;
}

shared_ptr<AtomDB> AtomDBSingleton::get_instance() {
Expand Down
2 changes: 2 additions & 0 deletions src/atomdb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cc_library(
":atomdb_singleton",
":atomdbutils",
"//atomdb/adapterdb:adapterdb_lib",
"//atomdb/auth:protected_atomdb_lib",
"//atomdb/inmemorydb:inmemorydb_lib",
"//atomdb/morkdb:morkdb_lib",
"//atomdb/redis_mongodb:redis_mongodb_lib",
Expand Down Expand Up @@ -58,6 +59,7 @@ cc_library(
deps = [
"//atomdb:atomdb_api_types",
"//atomdb/adapterdb",
"//atomdb/auth:protected_atomdb_lib",
"//atomdb/morkdb",
"//atomdb/redis_mongodb",
"//atomdb/remotedb:remotedb_lib",
Expand Down
5 changes: 5 additions & 0 deletions src/atomdb/adapterdb/AdapterDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ bool AdapterDB::composite_type_enabled() const {
return this->atomdb_backend->composite_type_enabled();
}

bool AdapterDB::is_protected() const {
this->ensure_backend_ready();
return this->atomdb_backend->is_protected();
}

shared_ptr<Atom> AdapterDB::get_atom(const string& handle) {
this->ensure_backend_ready();
return this->atomdb_backend->get_atom(handle);
Expand Down
2 changes: 2 additions & 0 deletions src/atomdb/adapterdb/AdapterDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AdapterDB : public AtomDB {
*/
bool composite_type_enabled() const override;

bool is_protected() const override;

shared_ptr<Atom> get_atom(const string& handle) override;
shared_ptr<Node> get_node(const string& handle) override;
shared_ptr<Link> get_link(const string& handle) override;
Expand Down
24 changes: 24 additions & 0 deletions src/atomdb/auth/BUILD
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",
],
)
Loading
Loading