Db
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -31,7 +31,8 @@ Makefile
|
|||||||
*.lib
|
*.lib
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
dropshell_template_registry
|
simple_object_storage
|
||||||
|
sos
|
||||||
|
|
||||||
# IDE specific files
|
# IDE specific files
|
||||||
.vscode/
|
.vscode/
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(dropshell_template_registry)
|
project(simple_object_storage)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -27,25 +27,15 @@ include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create executable
|
# Create executable
|
||||||
add_executable(dropshell_template_registry ${SOURCES})
|
add_executable(simple_object_storage ${SOURCES})
|
||||||
|
|
||||||
# Link libraries
|
# Link libraries
|
||||||
target_link_libraries(dropshell_template_registry
|
target_link_libraries(simple_object_storage
|
||||||
Threads::Threads # Use modern Threads target
|
Threads::Threads
|
||||||
SQLite::SQLite3 # Use SQLite3 target
|
SQLite::SQLite3
|
||||||
# ssl and crypto might still be needed by httplib if used
|
|
||||||
# ssl
|
|
||||||
# crypto
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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 target
|
||||||
install(TARGETS dropshell_template_registry
|
install(TARGETS simple_object_storage
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
)
|
)
|
@@ -21,7 +21,7 @@ RUN mkdir build && cd build && \
|
|||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
# Copy binary from builder
|
# 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)
|
# Create data directory (though mounting is preferred)
|
||||||
# RUN mkdir -p /data
|
# RUN mkdir -p /data
|
||||||
@@ -34,4 +34,4 @@ COPY --from=builder /src/build/dropshell_template_registry /dropshell_template_r
|
|||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
# Run server (assuming config is mounted at /data/config.json)
|
# Run server (assuming config is mounted at /data/config.json)
|
||||||
ENTRYPOINT ["/dropshell_template_registry"]
|
ENTRYPOINT ["/sos"]
|
@@ -1,8 +1,8 @@
|
|||||||
# Dropshell Template Registry
|
# simple_object_storage Template Registry
|
||||||
|
|
||||||
## Introduction
|
## 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 provide a store of binary objects (the objects can be large),
|
||||||
which are available over http.
|
which are available over http.
|
||||||
|
|
||||||
|
2
build.sh
2
build.sh
@@ -16,4 +16,4 @@ cmake ..
|
|||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
|
|
||||||
echo "Build completed successfully!"
|
echo "Build completed successfully!"
|
||||||
echo "The executable is located at: $(pwd)/dropshell_template_registry"
|
echo "The executable is located at: $(pwd)/simple_object_storage_template_registry"
|
@@ -4,7 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
bool load_config(const std::string& config_path, ServerConfig& config) {
|
bool load_config(const std::string& config_path, ServerConfig& config) {
|
||||||
try {
|
try {
|
||||||
@@ -44,4 +44,4 @@ bool load_config(const std::string& config_path, ServerConfig& config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
@@ -5,7 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
struct ServerConfig {
|
struct ServerConfig {
|
||||||
std::vector<std::string> write_tokens;
|
std::vector<std::string> write_tokens;
|
||||||
@@ -16,6 +16,6 @@ struct ServerConfig {
|
|||||||
|
|
||||||
bool load_config(const std::string& config_path, ServerConfig& config);
|
bool load_config(const std::string& config_path, ServerConfig& config);
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
||||||
|
|
||||||
#endif
|
#endif
|
0
src/database.cpp
Normal file
0
src/database.cpp
Normal file
34
src/database.hpp
Normal file
34
src/database.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef DATABASE_HPP
|
||||||
|
#define DATABASE_HPP
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include <json.hpp>
|
||||||
|
|
||||||
|
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<dbEntry>& entries);
|
||||||
|
private:
|
||||||
|
std::filesystem::path path_;
|
||||||
|
sqlite3* db_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace simple_object_storage
|
||||||
|
|
||||||
|
#endif // DATABASE_HPP
|
@@ -7,7 +7,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
uint64_t hash_file(const std::string &path) {
|
uint64_t hash_file(const std::string &path) {
|
||||||
// Create hash state
|
// Create hash state
|
||||||
@@ -112,4 +112,4 @@ int hash_demo_raw(const std::string & path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
uint64_t hash_file(const std::string &path);
|
uint64_t hash_file(const std::string &path);
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ namespace dropshell {
|
|||||||
|
|
||||||
int hash_demo_raw(const std::string & path);
|
int hash_demo_raw(const std::string & path);
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
35
src/main.cpp
35
src/main.cpp
@@ -1,14 +1,35 @@
|
|||||||
#include "server.hpp"
|
#include "server.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace simple_object_storage {
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
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());
|
std::filesystem::create_directories(config_path.parent_path());
|
||||||
|
|
||||||
dropshell::ServerConfig config;
|
ServerConfig config;
|
||||||
if (!dropshell::load_config(config_path, 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 "<<config_path << std::endl;
|
std::cerr << "Failed to load configuration at "<<config_path << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -16,7 +37,7 @@ int main(int argc, char* argv[]) {
|
|||||||
std::cout << "Starting server at " << config.host << ":" << config.port << std::endl;
|
std::cout << "Starting server at " << config.host << ":" << config.port << std::endl;
|
||||||
std::cout << "Object store path: " << config.object_store_path << std::endl;
|
std::cout << "Object store path: " << config.object_store_path << std::endl;
|
||||||
|
|
||||||
dropshell::Server server(config);
|
Server server(config);
|
||||||
if (!server.start()) {
|
if (!server.start()) {
|
||||||
std::cerr << "Failed to start server" << std::endl;
|
std::cerr << "Failed to start server" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -24,3 +45,9 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace simple_object_storage
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
return simple_object_storage::main(argc, argv);
|
||||||
|
}
|
@@ -11,7 +11,7 @@
|
|||||||
#include <sqlite3.h> // Include SQLite
|
#include <sqlite3.h> // Include SQLite
|
||||||
#include <stdexcept> // For std::runtime_error
|
#include <stdexcept> // For std::runtime_error
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
// Simple RAII helper for file deletion
|
// Simple RAII helper for file deletion
|
||||||
class ScopeFileDeleter {
|
class ScopeFileDeleter {
|
||||||
@@ -125,7 +125,7 @@ void Server::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::setup_routes() {
|
void Server::setup_routes() {
|
||||||
const std::string welcome_page = "<html><body><h1>Dropshell Template Registry</h1></body></html>";
|
const std::string welcome_page = "<html><body><h1>simple_object_storage Template Registry</h1></body></html>";
|
||||||
// Welcome page
|
// Welcome page
|
||||||
server_.Get("/", [welcome_page](const httplib::Request&, httplib::Response& res) {
|
server_.Get("/", [welcome_page](const httplib::Request&, httplib::Response& res) {
|
||||||
res.set_content(welcome_page, "text/html");
|
res.set_content(welcome_page, "text/html");
|
||||||
@@ -403,4 +403,4 @@ std::pair<std::string, std::string> Server::parse_label_tag(const std::string& l
|
|||||||
return {label_tag.substr(0, colon_pos), label_tag.substr(colon_pos + 1)};
|
return {label_tag.substr(0, colon_pos), label_tag.substr(colon_pos + 1)};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
@@ -11,7 +11,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <sqlite3.h> // Include SQLite header
|
#include <sqlite3.h> // Include SQLite header
|
||||||
|
|
||||||
namespace dropshell {
|
namespace simple_object_storage {
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
public:
|
public:
|
||||||
@@ -41,6 +41,6 @@ private:
|
|||||||
// Removed _isInitialized - will rely on db_ pointer
|
// Removed _isInitialized - will rely on db_ pointer
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace simple_object_storage
|
||||||
|
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user