Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix edge case in initialization of auth manager.
kishorenc9f83d9e0c24f
diff --git a/src/auth_manager.cpp b/src/auth_manager.cppindex 3389207a..fe2f3e37 100644--- a/src/auth_manager.cpp+++ b/src/auth_manager.cpp@@ -1,9 +1,40 @@#include "auth_manager.h"#include <openssl/evp.h>-#include <openssl/hmac.h>constexpr const char* AuthManager::DOCUMENTS_SEARCH_ACTION;+Option<bool> AuthManager::init(Store *store) {+ this->store = store;++ std::string next_api_key_id_str;+ StoreStatus next_api_key_id_status = store->get(API_KEY_NEXT_ID_KEY, next_api_key_id_str);++ if(next_api_key_id_status == StoreStatus::ERROR) {+ return Option<bool>(500, "Error while fetching the next API key id from the store.");+ }++ if(next_api_key_id_status == StoreStatus::FOUND) {+ next_api_key_id = (uint32_t) StringUtils::deserialize_uint32_t(next_api_key_id_str);+ } else {+ next_api_key_id = 0;+ }++ std::vector<std::string> api_key_json_strs;+ store->scan_fill(API_KEYS_PREFIX, api_key_json_strs);++ for(auto & api_key_json_str: api_key_json_strs) {+ api_key_t api_key;+ Option<bool> load_op = api_key.load(api_key_json_str);+ if(!load_op.ok()) {+ return Option<bool>(load_op.code(), load_op.error());+ }++ api_keys.emplace(api_key.value, api_key);+ }++ return Option<bool>(true);+}+Option<std::vector<api_key_t>> AuthManager::list_keys() {std::vector<std::string> api_key_json_strs;store->scan_fill(API_KEYS_PREFIX, api_key_json_strs);@@ -90,38 +121,6 @@ uint32_t AuthManager::get_next_api_key_id() {return next_api_key_id++;}-Option<bool> AuthManager::init(Store *store) {- this->store = store;-- std::string next_api_key_id_str;- StoreStatus next_api_key_id_status = store->get(API_KEY_NEXT_ID_KEY, next_api_key_id_str);-- if(next_api_key_id_status == StoreStatus::ERROR) {- return Option<bool>(500, "Error while fetching the next API key id from the store.");- }-- if(next_api_key_id_status == StoreStatus::FOUND) {- next_api_key_id = (uint32_t) StringUtils::deserialize_uint32_t(next_api_key_id_str);- } else {- next_api_key_id = 0;- }-- std::vector<std::string> api_key_json_strs;- store->scan_fill(API_KEYS_PREFIX, api_key_json_strs);-- for(auto & api_key_json_str: api_key_json_strs) {- api_key_t api_key;- Option<bool> load_op = api_key.load(api_key_json_str);- if(!load_op.ok()) {- return Option<bool>(load_op.code(), load_op.error());- }-- api_keys.emplace(api_key.value, api_key);- }-- return Option<bool>(true);-}-bool AuthManager::authenticate(const std::string& req_api_key, const std::string& action,const std::string& collection, std::map<std::string, std::string>& params) {diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex e08f0ba9..6d0b667d 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -64,11 +64,14 @@ void CollectionManager::init(Store *store,this->store = store;this->bootstrap_auth_key = auth_key;this->max_memory_ratio = max_memory_ratio;-- auth_manager.init(store);}Option<bool> CollectionManager::load(const size_t init_batch_size) {+ Option<bool> auth_init_op = auth_manager.init(store);+ if(!auth_init_op.ok()) {+ LOG(ERROR) << "Auth manager init failed, error=" << auth_init_op.error();+ }+std::string next_collection_id_str;StoreStatus next_coll_id_status = store->get(NEXT_COLLECTION_ID_KEY, next_collection_id_str);diff --git a/src/core_api.cpp b/src/core_api.cppindex 26f830cb..5a296f8c 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -953,7 +953,8 @@ bool get_keys(http_req &req, http_res &res) {nlohmann::json res_json;res_json["keys"] = nlohmann::json::array();- for(const auto & key: keys_op.get()) {+ const std::vector<api_key_t>& keys = keys_op.get();+ for(const auto & key: keys) {nlohmann::json key_obj = key.to_json();key_obj["value_prefix"] = key_obj["value"];key_obj.erase("value");