diff --git a/.gitignore b/.gitignore index 46fb56b..78e9e2f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,8 @@ Makefile *.lib # Executables -dropshell_template_registry +simple_object_storage +sos # IDE specific files .vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b43454..9cbd042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(dropshell_template_registry) +project(simple_object_storage) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -27,25 +27,15 @@ include_directories( ) # Create executable -add_executable(dropshell_template_registry ${SOURCES}) +add_executable(simple_object_storage ${SOURCES}) # Link libraries -target_link_libraries(dropshell_template_registry - Threads::Threads # Use modern Threads target - SQLite::SQLite3 # Use SQLite3 target - # ssl and crypto might still be needed by httplib if used - # ssl - # crypto +target_link_libraries(simple_object_storage + Threads::Threads + SQLite::SQLite3 ) -# Set compile options for static linking -# Note: Static linking SQLite might require additional setup depending on the system -# set_target_properties(dropshell_template_registry PROPERTIES -# LINK_SEARCH_START_STATIC ON -# LINK_SEARCH_END_STATIC ON -# ) - # Install target -install(TARGETS dropshell_template_registry +install(TARGETS simple_object_storage RUNTIME DESTINATION bin ) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 34f5622..123a932 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN mkdir build && cd build && \ FROM scratch # Copy binary from builder -COPY --from=builder /src/build/dropshell_template_registry /dropshell_template_registry +COPY --from=builder /src/build/simple_object_storage /sos # Create data directory (though mounting is preferred) # RUN mkdir -p /data @@ -34,4 +34,4 @@ COPY --from=builder /src/build/dropshell_template_registry /dropshell_template_r EXPOSE 80 # Run server (assuming config is mounted at /data/config.json) -ENTRYPOINT ["/dropshell_template_registry"] \ No newline at end of file +ENTRYPOINT ["/sos"] \ No newline at end of file diff --git a/README.md b/README.md index 9e0359b..6e50cb0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Dropshell Template Registry +# simple_object_storage Template Registry ## Introduction -The DropShell template registry is a very simple C++ webserver +The simple_object_storage template registry is a very simple C++ webserver which provide a store of binary objects (the objects can be large), which are available over http. diff --git a/build.sh b/build.sh index 9bb7848..c8e399b 100755 --- a/build.sh +++ b/build.sh @@ -16,4 +16,4 @@ cmake .. make -j$(nproc) echo "Build completed successfully!" -echo "The executable is located at: $(pwd)/dropshell_template_registry" \ No newline at end of file +echo "The executable is located at: $(pwd)/simple_object_storage_template_registry" \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index e623350..88df257 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -4,7 +4,7 @@ #include #include -namespace dropshell { +namespace simple_object_storage { bool load_config(const std::string& config_path, ServerConfig& config) { try { @@ -44,4 +44,4 @@ bool load_config(const std::string& config_path, ServerConfig& config) { } } -} // namespace dropshell \ No newline at end of file +} // namespace simple_object_storage \ No newline at end of file diff --git a/src/config.hpp b/src/config.hpp index 9128a6d..9b54c75 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -5,7 +5,7 @@ #include #include -namespace dropshell { +namespace simple_object_storage { struct ServerConfig { std::vector write_tokens; @@ -16,6 +16,6 @@ struct ServerConfig { bool load_config(const std::string& config_path, ServerConfig& config); -} // namespace dropshell +} // namespace simple_object_storage #endif \ No newline at end of file diff --git a/src/database.cpp b/src/database.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/database.hpp b/src/database.hpp new file mode 100644 index 0000000..aecfadf --- /dev/null +++ b/src/database.hpp @@ -0,0 +1,34 @@ +#ifndef DATABASE_HPP +#define DATABASE_HPP + +#include +#include +#include +#include + +namespace simple_object_storage { + +class dbEntry { + public: + std::string label_tag; // unique identifier for the object + std::string hash; // hash of the object - not unique + nlohmann::json metadata; +}; + +class Database { + public: + Database(const std::filesystem::path& path); + ~Database(); + bool insert(const dbEntry& entry); + bool remove(const std::string& label_tag); + bool get(const std::string& label_tag, dbEntry& entry); + bool update(const std::string& label_tag, const dbEntry& entry); + bool list(std::vector& entries); + private: + std::filesystem::path path_; + sqlite3* db_; +}; + +} // namespace simple_object_storage + +#endif // DATABASE_HPP \ No newline at end of file diff --git a/src/hash.cpp b/src/hash.cpp index 8e9b107..203814a 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -7,7 +7,7 @@ #include #include -namespace dropshell { +namespace simple_object_storage { uint64_t hash_file(const std::string &path) { // Create hash state @@ -112,4 +112,4 @@ int hash_demo_raw(const std::string & path) return 0; } -} // namespace dropshell +} // namespace simple_object_storage diff --git a/src/hash.hpp b/src/hash.hpp index 7823fae..52ddfff 100644 --- a/src/hash.hpp +++ b/src/hash.hpp @@ -4,7 +4,7 @@ #include #include -namespace dropshell { +namespace simple_object_storage { uint64_t hash_file(const std::string &path); @@ -14,7 +14,7 @@ namespace dropshell { int hash_demo_raw(const std::string & path); -} // namespace dropshell +} // namespace simple_object_storage #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a050f0a..071bb44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,35 @@ #include "server.hpp" #include "config.hpp" #include +#include #include +namespace simple_object_storage { + int main(int argc, char* argv[]) { - std::filesystem::path config_path = std::filesystem::path(std::getenv("HOME")) / ".config/dropshell_template_registry/config.json"; + std::filesystem::path config_path = std::filesystem::path(std::getenv("HOME")) / ".config/simple_object_storage/config.json"; std::filesystem::create_directories(config_path.parent_path()); - dropshell::ServerConfig config; - if (!dropshell::load_config(config_path, config)) { + ServerConfig config; + if (!simple_object_storage::load_config(config_path, config)) { + // output default config using heredoc to config_path + std::ofstream config_file(config_path); + config_file << R"END( +{ + "write_tokens": [ + "fizzle1", + "fizzle2", + "fizzle3" + ], + "object_store_path": "/home/j/.simple_object_storage/", + "host": "0.0.0.0", + "port": 8123 +} +)END"; + config_file.close(); + } + + if (!simple_object_storage::load_config(config_path, config)) { std::cerr << "Failed to load configuration at "< // Include SQLite #include // For std::runtime_error -namespace dropshell { +namespace simple_object_storage { // Simple RAII helper for file deletion class ScopeFileDeleter { @@ -125,7 +125,7 @@ void Server::stop() { } void Server::setup_routes() { - const std::string welcome_page = "

Dropshell Template Registry

"; + const std::string welcome_page = "

simple_object_storage Template Registry

"; // Welcome page server_.Get("/", [welcome_page](const httplib::Request&, httplib::Response& res) { res.set_content(welcome_page, "text/html"); @@ -403,4 +403,4 @@ std::pair Server::parse_label_tag(const std::string& l return {label_tag.substr(0, colon_pos), label_tag.substr(colon_pos + 1)}; } -} // namespace dropshell \ No newline at end of file +} // namespace simple_object_storage \ No newline at end of file diff --git a/src/server.hpp b/src/server.hpp index c89e6d9..cede583 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -11,7 +11,7 @@ #include #include // Include SQLite header -namespace dropshell { +namespace simple_object_storage { class Server { public: @@ -41,6 +41,6 @@ private: // Removed _isInitialized - will rely on db_ pointer }; -} // namespace dropshell +} // namespace simple_object_storage #endif \ No newline at end of file