CCF
Loading...
Searching...
No Matches
gov_endpoint_registry.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6#include "node/gov/api_schema.h"
13#include "node/share_manager.h"
14
15namespace ccf
16{
17 // Eventually, this should extend BaseEndpointRegistry, rather than
18 // CommonEndpointRegistry. But for now, we still support the old gov API by
19 // extending this, and that includes the common endpoints
21 {
22 private:
23 NetworkState& network;
24 ShareManager share_manager;
25
26 public:
28 NetworkState& network_, ccf::AbstractNodeContext& context_) :
30 network(network_),
31 share_manager(network_.ledger_secrets)
32 {}
33
45
46 bool request_needs_root(const RpcContext& rpc_ctx) override
47 {
49 (rpc_ctx.get_request_verb() == HTTP_POST &&
50 rpc_ctx.get_request_path() == "/gov/members/proposals:create");
51 }
52
53 // Log these events on /gov frontend. Everything here is public, so
54 // safe to display in clear in the log
56 const ccf::endpoints::RequestCompletedEvent& event) override
57 {
59 "RequestCompletedEvent: {} {} {} {}ms {} attempt(s)",
60 event.method,
61 event.dispatch_path,
62 event.status,
63 event.exec_time.count(),
64 event.attempts);
65 }
66
68 const ccf::endpoints::DispatchFailedEvent& event) override
69 {
70 GOV_INFO_FMT("DispatchFailedEvent: {} {}", event.method, event.status);
71 }
72
74 {
75 using namespace ccf::gov::endpoints;
76
77 const char* error_code = nullptr;
78 const auto api_version =
79 get_api_version(ctx, ApiVersion::MIN, &error_code);
80 if (api_version.has_value())
81 {
82 switch (api_version.value())
83 {
84 case ApiVersion::preview_v1:
85 {
86 ctx.rpc_ctx->set_response_body(schema::v2023_06_01_preview);
87 ctx.rpc_ctx->set_response_header(
88 http::headers::CONTENT_TYPE,
89 http::headervalues::contenttype::JSON);
90 ctx.rpc_ctx->set_response_status(HTTP_STATUS_OK);
91 break;
92 }
93 case ApiVersion::v1:
94 {
95 ctx.rpc_ctx->set_response_body(schema::v2024_07_01);
96 ctx.rpc_ctx->set_response_header(
97 http::headers::CONTENT_TYPE,
98 http::headervalues::contenttype::JSON);
99 ctx.rpc_ctx->set_response_status(HTTP_STATUS_OK);
100 break;
101 }
102 }
103 }
104 else
105 {
106 // If an _invalid_ API version was passed, then an error response has
107 // already been populated
108 if (error_code == ccf::errors::UnsupportedApiVersionValue)
109 {
110 return;
111 }
112
113 // Else (API version parameter was missing) return the classic API
115 }
116 }
117 };
118}
ccf::AbstractNodeContext & context
Definition base_endpoint_registry.h:123
Definition common_endpoint_registry.h:16
void init_handlers() override
Definition common_endpoint_registry.cpp:69
virtual void api_endpoint(ccf::endpoints::ReadOnlyEndpointContext &ctx)
Definition common_endpoint_registry.cpp:298
Definition gov_endpoint_registry.h:21
void init_handlers() override
Definition gov_endpoint_registry.h:34
void handle_event_request_completed(const ccf::endpoints::RequestCompletedEvent &event) override
Definition gov_endpoint_registry.h:55
void handle_event_dispatch_failed(const ccf::endpoints::DispatchFailedEvent &event) override
Definition gov_endpoint_registry.h:67
void api_endpoint(ccf::endpoints::ReadOnlyEndpointContext &ctx) override
Definition gov_endpoint_registry.h:73
GovEndpointRegistry(NetworkState &network_, ccf::AbstractNodeContext &context_)
Definition gov_endpoint_registry.h:27
bool request_needs_root(const RpcContext &rpc_ctx) override
Definition gov_endpoint_registry.h:46
Describes the currently executing RPC.
Definition rpc_context.h:58
Definition share_manager.h:167
virtual bool request_needs_root(const ccf::RpcContext &rpc_ctx)
Definition endpoint_registry.cpp:560
#define GOV_INFO_FMT
Definition gov_logging.h:10
virtual std::string get_request_path() const =0
virtual const ccf::RESTVerb & get_request_verb() const =0
Definition api_version.h:11
void init_proposals_handlers(ccf::BaseEndpointRegistry &registry, NetworkState &network, ccf::AbstractNodeContext &node_context)
Definition proposals.h:387
void init_ack_handlers(ccf::BaseEndpointRegistry &registry, NetworkState &network, ShareManager &share_manager)
Definition acks.h:13
void init_recovery_handlers(ccf::BaseEndpointRegistry &registry, ShareManager &share_manager, ccf::AbstractNodeContext &node_context)
Definition recovery.h:12
void init_service_state_handlers(ccf::BaseEndpointRegistry &registry)
Definition service_state.h:164
void init_transactions_handlers(ccf::BaseEndpointRegistry &registry)
Definition transactions.h:13
Definition app_interface.h:14
constexpr auto get_actor_prefix(ActorsType at)
Definition actors.h:31
ActorsType
Definition actors.h:11
Definition node_context.h:12
Definition network_state.h:12
std::shared_ptr< ccf::RpcContext > rpc_ctx
Definition endpoint_context.h:31
Definition endpoint_registry.h:55
int status
Definition endpoint_registry.h:57
std::string method
Definition endpoint_registry.h:56
Definition endpoint_context.h:70
Definition endpoint_registry.h:42
std::string dispatch_path
Definition endpoint_registry.h:48
int status
Definition endpoint_registry.h:49
std::string method
Definition endpoint_registry.h:43
std::chrono::milliseconds exec_time
Definition endpoint_registry.h:50
size_t attempts
Definition endpoint_registry.h:51