Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
This commit is contained in:
1 parent
3cac890ce9
commit
ab64147f9d
114 files changed
+23777
-1392
No files matched your search
@@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Error.hpp>
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Build::Registry {
|
||||
|
||||
struct HttpRequest {
|
||||
std::string method;
|
||||
std::string raw_target;
|
||||
std::string path;
|
||||
std::map<std::string, std::string, std::less<>> query;
|
||||
std::map<std::string, std::string, std::less<>> headers; // lowercase header keys
|
||||
std::map<std::string, std::string, std::less<>> cookies;
|
||||
std::string body;
|
||||
|
||||
[[nodiscard]] std::optional<std::string_view>
|
||||
header(std::string_view lower_name) const noexcept;
|
||||
[[nodiscard]] std::optional<std::string_view> cookie(std::string_view name) const noexcept;
|
||||
};
|
||||
|
||||
struct HttpResponse {
|
||||
std::uint16_t status{200};
|
||||
std::string reason{"OK"};
|
||||
std::map<std::string, std::string, std::less<>> headers;
|
||||
std::vector<std::string> set_cookies;
|
||||
std::string body;
|
||||
|
||||
static HttpResponse json(std::uint16_t status, std::string payload);
|
||||
static HttpResponse error_json(std::uint16_t status, std::string_view code,
|
||||
std::string_view message);
|
||||
};
|
||||
|
||||
using HttpHandler = std::function<HttpResponse(const HttpRequest &)>;
|
||||
|
||||
struct HttpServerOptions {
|
||||
std::string bind_address{"127.0.0.1"}; // Loopback default (Plan 16).
|
||||
std::uint16_t port{0}; // 0 = ephemeral OS port.
|
||||
std::size_t max_header_bytes{64ULL * 1024ULL};
|
||||
std::size_t max_body_bytes{64ULL * 1024ULL * 1024ULL};
|
||||
};
|
||||
|
||||
// Concrete loopback HTTP/1.1 TCP server adapter (VL-004).
|
||||
class HttpServer {
|
||||
public:
|
||||
HttpServer() = default;
|
||||
~HttpServer() noexcept;
|
||||
|
||||
HttpServer(const HttpServer &) = delete;
|
||||
HttpServer &operator=(const HttpServer &) = delete;
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
||||
start(const HttpServerOptions &options, HttpHandler handler);
|
||||
|
||||
void stop() noexcept;
|
||||
|
||||
[[nodiscard]] std::uint16_t bound_port() const noexcept { return bound_port_; }
|
||||
[[nodiscard]] bool running() const noexcept { return running_.load(); }
|
||||
|
||||
private:
|
||||
void accept_loop();
|
||||
void handle_client(int client_fd);
|
||||
|
||||
int listen_fd_{-1};
|
||||
std::uint16_t bound_port_{0};
|
||||
HttpServerOptions options_;
|
||||
HttpHandler handler_;
|
||||
std::atomic<bool> running_{false};
|
||||
std::thread accept_thread_;
|
||||
};
|
||||
|
||||
// Simple loopback HTTP/1.1 client helper for testing and local registry operations.
|
||||
struct HttpClientResponse {
|
||||
std::uint16_t status{0};
|
||||
std::map<std::string, std::string, std::less<>> headers;
|
||||
std::vector<std::string> set_cookies;
|
||||
std::string body;
|
||||
};
|
||||
|
||||
[[nodiscard]] Void::Result::Result<HttpClientResponse, Void::Result::Error>
|
||||
send_loopback_http(std::uint16_t port, std::string_view method, std::string_view target,
|
||||
const std::map<std::string, std::string, std::less<>> &headers = {},
|
||||
std::string_view body = {});
|
||||
|
||||
} // namespace Void::Build::Registry
|
||||
@@ -0,0 +1,150 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Build/Registry/HttpServer.hpp>
|
||||
#include <Void/Functional/Error.hpp>
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Build::Registry {
|
||||
|
||||
enum class Role { Reader, Publisher, Admin };
|
||||
|
||||
struct UserRecord {
|
||||
std::string username;
|
||||
Role role{Role::Reader};
|
||||
std::string password_salt_hex;
|
||||
std::string password_hash_hex;
|
||||
bool active{true};
|
||||
};
|
||||
|
||||
struct ApiTokenRecord {
|
||||
std::string token_id;
|
||||
std::string username;
|
||||
std::string label;
|
||||
std::string token_sha256; // Never stores plaintext bearer secret!
|
||||
std::set<std::string> scopes; // "read", "publish", "admin"
|
||||
std::int64_t expires_epoch{0}; // 0 = no expiry
|
||||
bool revoked{false};
|
||||
};
|
||||
|
||||
struct SessionRecord {
|
||||
std::string session_id_hash;
|
||||
std::string username;
|
||||
std::string csrf_token;
|
||||
std::int64_t expires_epoch{0};
|
||||
};
|
||||
|
||||
struct ReleaseMeta {
|
||||
std::string version;
|
||||
std::string sha256;
|
||||
std::uint64_t size_bytes{0};
|
||||
bool yanked{false};
|
||||
std::string publisher;
|
||||
std::int64_t published_epoch{0};
|
||||
};
|
||||
|
||||
struct PackageMeta {
|
||||
std::string name;
|
||||
std::string description;
|
||||
bool is_private{false};
|
||||
std::set<std::string> owners;
|
||||
std::map<std::string, ReleaseMeta, std::less<>> releases; // version -> ReleaseMeta
|
||||
};
|
||||
|
||||
struct AuditEntry {
|
||||
std::int64_t timestamp{0};
|
||||
std::string actor;
|
||||
std::string action;
|
||||
std::string target;
|
||||
std::string outcome;
|
||||
std::string detail; // Always secret-redacted!
|
||||
};
|
||||
|
||||
struct RegistryConfig {
|
||||
std::filesystem::path data_dir;
|
||||
std::filesystem::path web_root;
|
||||
std::string bind_address{"127.0.0.1"};
|
||||
std::uint16_t port{0};
|
||||
std::uint64_t max_upload_bytes{32ULL * 1024ULL * 1024ULL};
|
||||
std::uint64_t max_storage_bytes{2ULL * 1024ULL * 1024ULL * 1024ULL};
|
||||
std::string bootstrap_admin_user{"admin"};
|
||||
std::string bootstrap_admin_password; // Required on initial empty DB creation.
|
||||
};
|
||||
|
||||
// Hosted C++ Package Registry Service (Plan 16 + Plan 17 API/UI backend):
|
||||
// - Filesystem CAS blobs + transactional durable metadata
|
||||
// - Immutable source/binary releases (idempotent same bytes, 409 Conflict on overwrite)
|
||||
// - Archive traversal/symlink validation (never executes uploaded recipes!)
|
||||
// - Reader/Publisher/Admin roles, package ownership, private/public isolation
|
||||
// - Hashed scoped bearer tokens + HttpOnly SameSite=Strict sessions with CSRF protection
|
||||
// - Secret-redacted audit log, orphan GC, storage quotas, consistent backup/restore.
|
||||
class RegistryService {
|
||||
public:
|
||||
[[nodiscard]] static Void::Result::Result<std::unique_ptr<RegistryService>, Void::Result::Error>
|
||||
open(RegistryConfig config);
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void, Void::Result::Error> start_http();
|
||||
void stop_http() noexcept;
|
||||
[[nodiscard]] std::uint16_t bound_port() const noexcept { return server_.bound_port(); }
|
||||
|
||||
// Handles a single HTTP request (directly testable without sockets too!).
|
||||
[[nodiscard]] HttpResponse handle_request(const HttpRequest &req);
|
||||
|
||||
// Consistent metadata + CAS blob backup and restore (Plan 16 acceptance #4).
|
||||
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
||||
backup_to(const std::filesystem::path &backup_dir);
|
||||
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
||||
restore_from(const std::filesystem::path &backup_dir);
|
||||
|
||||
// Direct user/token helpers for bootstrap and test fixtures.
|
||||
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
||||
create_user(std::string username, std::string password, Role role);
|
||||
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
||||
create_token(std::string username, std::string label, std::set<std::string> scopes,
|
||||
std::int64_t expires_epoch = 0);
|
||||
|
||||
private:
|
||||
explicit RegistryService(RegistryConfig config);
|
||||
|
||||
struct Principal {
|
||||
std::string username;
|
||||
Role role{Role::Reader};
|
||||
std::set<std::string> scopes;
|
||||
bool via_session_cookie{false};
|
||||
std::string csrf_token;
|
||||
};
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> load_locked();
|
||||
Void::Result::Result<void, Void::Result::Error> save_locked();
|
||||
std::optional<Principal> authenticate_locked(const HttpRequest &req,
|
||||
std::string &auth_err) const;
|
||||
bool check_csrf_locked(const HttpRequest &req, const Principal &p) const;
|
||||
void append_audit_locked(std::string actor, std::string action, std::string target,
|
||||
std::string outcome, std::string detail);
|
||||
std::uint64_t total_storage_bytes_locked() const;
|
||||
std::filesystem::path blob_path(std::string_view sha256) const;
|
||||
HttpResponse serve_static_web_asset(std::string_view req_path) const;
|
||||
|
||||
RegistryConfig config_;
|
||||
std::filesystem::path blobs_dir_;
|
||||
std::filesystem::path meta_file_;
|
||||
std::filesystem::path lock_file_;
|
||||
mutable std::mutex mu_;
|
||||
|
||||
std::map<std::string, UserRecord, std::less<>> users_;
|
||||
std::map<std::string, ApiTokenRecord, std::less<>> tokens_;
|
||||
std::map<std::string, SessionRecord, std::less<>> sessions_;
|
||||
std::map<std::string, PackageMeta, std::less<>> packages_;
|
||||
std::vector<AuditEntry> audits_;
|
||||
HttpServer server_;
|
||||
};
|
||||
|
||||
} // namespace Void::Build::Registry
|
||||
Reference in new issue
Block a user