23#ifdef PACS_WITH_MONITORING
38void add_cors_headers(crow::response &res,
const rest_server_context &ctx) {
39 if (ctx.config && !ctx.config->cors_allowed_origins.empty()) {
40 res.add_header(
"Access-Control-Allow-Origin",
41 ctx.config->cors_allowed_origins);
48std::string config_to_json(
const rest_server_config &config) {
49 std::ostringstream oss;
50 oss << R
"({"bind_address":")" << config.bind_address << R"(",)"
51 << R"("port":)" << config.port << R"(,)"
52 << R"("concurrency":)" << config.concurrency << R"(,)"
53 << R"("enable_cors":)" << (config.enable_cors ? "true" :
"false")
55 << R"("cors_allowed_origins":")" << config.cors_allowed_origins << R"(",)"
56 << R"("enable_tls":)" << (config.enable_tls ? "true" :
"false") << R
"(,)"
57 << R"("request_timeout_seconds":)" << config.request_timeout_seconds
59 << R"("max_body_size":)" << config.max_body_size << "}";
65bool check_permission(
const std::shared_ptr<rest_server_context> &ctx,
66 const crow::request &req, crow::response &res,
68 if (!ctx->security_manager) {
73 "Security manager not configured");
78 auto user_id_header = req.get_header_value(
"X-User-ID");
79 if (user_id_header.empty()) {
85 std::string user_id = user_id_header;
86 auto user_res = ctx->security_manager->get_user(user_id);
87 if (user_res.is_err()) {
93 auto user = user_res.unwrap();
94 if (!ctx->security_manager->check_permission(user, resource, action)) {
107 std::shared_ptr<rest_server_context> ctx) {
109 CROW_ROUTE(app,
"/api/v1/system/status")
110 .methods(crow::HTTPMethod::GET)([ctx](
const crow::request &req) {
112 res.add_header(
"Content-Type",
"application/json");
113 add_cors_headers(res, *ctx);
121 crow::json::wvalue status_json;
122 status_json[
"status"] =
"unknown";
123 status_json[
"message"] =
"Health checker not configured";
124 status_json[
"version"] =
"1.0.0";
126#ifdef PACS_WITH_MONITORING
127 if (ctx->health_checker) {
128 auto status = ctx->health_checker->get_status();
130 status_json = crow::json::load(
131 monitoring::to_json(status));
132 status_json[
"version"] =
"1.0.0";
134 status_json[
"status"] =
"unknown";
135 status_json[
"message"] =
"Health checker not configured";
145 CROW_ROUTE(app,
"/api/v1/system/metrics").methods(crow::HTTPMethod::GET)([ctx]() {
147 res.add_header(
"Content-Type",
"application/json");
148 add_cors_headers(res, *ctx);
150#ifdef PACS_WITH_MONITORING
153 std::ostringstream oss;
154 oss << R
"({"message":"Metrics available via pacs_metrics API"})";
155 res.body = oss.str();
159 R
"({"error":{"code":"METRICS_UNAVAILABLE","message":"Metrics provider not configured"}})";
165 R
"({"uptime_seconds":0,"requests_total":0,"message":"Metrics module not available"})";
172 CROW_ROUTE(app,
"/api/v1/system/config")
173 .methods(crow::HTTPMethod::GET)([ctx]() {
175 res.add_header(
"Content-Type",
"application/json");
176 add_cors_headers(res, *ctx);
179 res.body = config_to_json(*ctx->config);
183 "Configuration not available");
190 CROW_ROUTE(app,
"/api/v1/system/config")
191 .methods(crow::HTTPMethod::PUT)([ctx](
const crow::request &req) {
193 res.add_header(
"Content-Type",
"application/json");
194 add_cors_headers(res, *ctx);
197 auto content_type = req.get_header_value(
"Content-Type");
198 if (content_type.find(
"application/json") == std::string::npos) {
200 "Content-Type must be application/json");
206 if (req.body.empty()) {
222 CROW_ROUTE(app,
"/api/v1/system/version").methods(crow::HTTPMethod::GET)([ctx]() {
224 res.add_header(
"Content-Type",
"application/json");
225 add_cors_headers(res, *ctx);
228 R
"({"api_version":"v1","pacs_version":"1.2.0","crow_version":"1.2.0"})";
Health check service for PACS system components.
JSON serialization for health check data structures.
constexpr std::uint32_t Read
ResourceType
Categories of resources requiring protection.
@ System
System configuration and services.
void register_system_endpoints_impl(crow::SimpleApp &app, std::shared_ptr< rest_server_context > ctx)
std::string make_error_json(std::string_view code, std::string_view message)
Create JSON error response body with details.
std::string make_success_json(std::string_view message="OK")
Create success response with optional message.
Operation metrics collection for PACS DICOM services.
Configuration for REST API server.
Common types and utilities for REST API.
System API endpoints for REST server.
User definition for RBAC.