2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-02 06:55:16 +00:00

[#3483] Renamed CA callouts

This commit is contained in:
Francis Dupont
2024-07-23 19:25:01 +02:00
parent bb6a1d3b8f
commit 6045a46ad7
4 changed files with 29 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2017-2024 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -23,7 +23,7 @@ command.
@section agentHooksHookPoints Hooks in the Control Agent @section agentHooksHookPoints Hooks in the Control Agent
@subsection agentHooksAuth auth @subsection agentHooksAuth http_auth
- @b Arguments: - @b Arguments:
- name: @b request, type: isc::http::HttpRequestPtr, direction: <b>in/out</b> - name: @b request, type: isc::http::HttpRequestPtr, direction: <b>in/out</b>
@@ -39,7 +39,7 @@ command.
response is set the processing will stop and the response is returned. response is set the processing will stop and the response is returned.
In particular the command is not forwarded. In particular the command is not forwarded.
@subsection agentHooksResponse response @subsection agentHooksResponse http_response
- @b Arguments: - @b Arguments:
- name: @b request, type: isc::http::HttpRequestPtr, direction: <b>in</b> - name: @b request, type: isc::http::HttpRequestPtr, direction: <b>in</b>

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2017-2024 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -28,13 +28,13 @@ namespace {
/// Structure that holds registered hook indexes. /// Structure that holds registered hook indexes.
struct CtrlAgentHooks { struct CtrlAgentHooks {
int hook_index_auth_; ///< index of "auth" hook point. int hook_index_http_auth_; ///< index of "http_auth" hook point.
int hook_index_response_; ///< index of "response" hook point. int hook_index_http_response_; ///< index of "http_response" hook point.
/// Constructor that registers hook points. /// Constructor that registers hook points.
CtrlAgentHooks() { CtrlAgentHooks() {
hook_index_auth_ = HooksManager::registerHook("auth"); hook_index_http_auth_ = HooksManager::registerHook("http_auth");
hook_index_response_ = HooksManager::registerHook("response"); hook_index_http_response_ = HooksManager::registerHook("http_response");
} }
}; };
@@ -116,9 +116,9 @@ createDynamicHttpResponse(HttpRequestPtr request) {
} }
} }
// Callout point for "auth". // Callout point for "http_auth".
bool reset_handle = false; bool reset_handle = false;
if (HooksManager::calloutsPresent(Hooks.hook_index_auth_)) { if (HooksManager::calloutsPresent(Hooks.hook_index_http_auth_)) {
// Get callout handle. // Get callout handle.
CalloutHandlePtr callout_handle = request->getCalloutHandle(); CalloutHandlePtr callout_handle = request->getCalloutHandle();
ScopedCalloutHandleState callout_handle_state(callout_handle); ScopedCalloutHandleState callout_handle_state(callout_handle);
@@ -128,7 +128,8 @@ createDynamicHttpResponse(HttpRequestPtr request) {
callout_handle->setArgument("response", http_response); callout_handle->setArgument("response", http_response);
// Call callouts. // Call callouts.
HooksManager::callCallouts(Hooks.hook_index_auth_, *callout_handle); HooksManager::callCallouts(Hooks.hook_index_http_auth_,
*callout_handle);
callout_handle->getArgument("request", request); callout_handle->getArgument("request", request);
callout_handle->getArgument("response", http_response); callout_handle->getArgument("response", http_response);
@@ -180,8 +181,8 @@ createDynamicHttpResponse(HttpRequestPtr request) {
http_response->setBodyAsJson(response); http_response->setBodyAsJson(response);
http_response->finalize(); http_response->finalize();
// Callout point for "response". // Callout point for "http_response".
if (HooksManager::calloutsPresent(Hooks.hook_index_response_)) { if (HooksManager::calloutsPresent(Hooks.hook_index_http_response_)) {
// Get callout handle. // Get callout handle.
CalloutHandlePtr callout_handle = request->getCalloutHandle(); CalloutHandlePtr callout_handle = request->getCalloutHandle();
ScopedCalloutHandleState callout_handle_state(callout_handle); ScopedCalloutHandleState callout_handle_state(callout_handle);
@@ -191,7 +192,7 @@ createDynamicHttpResponse(HttpRequestPtr request) {
callout_handle->setArgument("response", http_response); callout_handle->setArgument("response", http_response);
// Call callouts. // Call callouts.
HooksManager::callCallouts(Hooks.hook_index_response_, HooksManager::callCallouts(Hooks.hook_index_http_response_,
*callout_handle); *callout_handle);
callout_handle->getArgument("response", http_response); callout_handle->getArgument("response", http_response);

View File

@@ -158,12 +158,12 @@ unload() {
// Callout functions. // Callout functions.
/// @brief This callout is called at the "auth" hook. /// @brief This callout is called at the "http_auth" hook.
/// ///
/// @param handle CalloutHandle. /// @param handle CalloutHandle.
/// @return 0 upon success, non-zero otherwise. /// @return 0 upon success, non-zero otherwise.
int int
auth(CalloutHandle& handle) { http_auth(CalloutHandle& handle) {
// Sanity. // Sanity.
if (!impl) { if (!impl) {
std::cerr << "no implementation" << std::endl; std::cerr << "no implementation" << std::endl;
@@ -222,12 +222,12 @@ auth(CalloutHandle& handle) {
return (0); return (0);
} }
/// @brief This callout is called at the "response" hook. /// @brief This callout is called at the "http_response" hook.
/// ///
/// @param handle CalloutHandle. /// @param handle CalloutHandle.
/// @return 0 upon success, non-zero otherwise. /// @return 0 upon success, non-zero otherwise.
int int
response(CalloutHandle& handle) { http_response(CalloutHandle& handle) {
// Sanity. // Sanity.
if (!impl) { if (!impl) {
std::cerr << "no implementation" << std::endl; std::cerr << "no implementation" << std::endl;

View File

@@ -389,15 +389,16 @@ TEST_F(CtrlAgentResponseCreatorTest, hookBasicAuth) {
// Body: "list-commands" is natively supported by the command manager. // Body: "list-commands" is natively supported by the command manager.
// We add a random value in the extra entry: // We add a random value in the extra entry:
// - this proves that the auth callout can get the request argument // - this proves that the http_auth callout can get the request argument
// - this proves that the auth callout can modify the request argument // - this proves that the http_auth callout can modify the request
// before the request is executed (the extra entry if still present // argument before the request is executed (the extra entry
// would make the command to be rejected as malformed) // if still present would make the command to be rejected as malformed)
// - this proves that a value can be communicate between the auth // - this proves that a value can be communicate between the http_auth
// and response callout points // and http_response callout points
// - this proves that the response callout can get the response argument // - this proves that the http_response callout can get the
// - this proves that the response callout can modify the response // response argument
// argument // - this proves that the http_response callout can modify the
// response argument
auto r32 = isc::cryptolink::random(4); auto r32 = isc::cryptolink::random(4);
ASSERT_EQ(4, r32.size()); ASSERT_EQ(4, r32.size());
int extra = r32[0]; int extra = r32[0];