Skip to content

Commit

Permalink
Move RequestExtension from js_generic to public includes
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed May 21, 2024
1 parent 6aa8840 commit 997cc12
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ set(CCF_JS_SOURCES
${CCF_DIR}/src/js/extensions/ccf/network.cpp
${CCF_DIR}/src/js/extensions/ccf/node.cpp
${CCF_DIR}/src/js/extensions/ccf/rpc.cpp
${CCF_DIR}/src/js/extensions/ccf/request_extension.cpp
)

if(COMPILE_TARGET STREQUAL "sgx")
Expand Down Expand Up @@ -590,9 +591,7 @@ elseif(COMPILE_TARGET STREQUAL "virtual")
set(JS_SNP_ATTESTATION_VIRTUAL js_snp_attestation.virtual)
endif()

set(JS_GENERIC_SOURCES ${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
${CCF_DIR}/src/apps/js_generic/request_extension.cpp
)
set(JS_GENERIC_SOURCES ${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp)
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(js_generic_base.enclave ${JS_GENERIC_SOURCES})
target_link_libraries(js_generic_base.enclave PUBLIC ccf.enclave)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ccf/js/extensions/extension_interface.h"
#include "ccf/rpc_context.h"

namespace ccfapp
namespace ccf::js::extensions
{
/**
**/
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions samples/apps/basic/custom_endpoints/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ccf/js/extensions/ccf/kv.h"
#include "ccf/js/extensions/ccf/rpc.h"
#include "ccf/js/extensions/console.h"
#include "ccf/js/extensions/ccf/request_extension.h"
#include "ccf/js/extensions/math/random.h"
#include "ccf/service/tables/modules.h"
#include "endpoint.h"
Expand Down Expand Up @@ -243,6 +244,37 @@ namespace basicapp
// Make the heap and stack limits safe while we init the runtime
ctx.runtime().reset_runtime_options();

// TBD: module loader
// JS_SetModuleLoaderFunc(
// ctx.runtime(), nullptr, js::js_app_module_loader, &endpoint_ctx.tx);

// Extensions with a dependency on this endpoint context (invocation),
// which must be removed after execution.
ccf::js::extensions::Extensions local_extensions;

// ccf.kv.*
local_extensions.emplace_back(
std::make_shared<ccf::js::extensions::KvExtension>(&endpoint_ctx.tx));

// ccf.rpc.*
local_extensions.emplace_back(
std::make_shared<ccf::js::extensions::RpcExtension>(
endpoint_ctx.rpc_ctx.get()));

auto request_extension =
std::make_shared<ccf::js::extensions::RequestExtension>(endpoint_ctx.rpc_ctx.get());
local_extensions.push_back(request_extension);

for (auto extension : local_extensions)
{
ctx.add_extension(extension);
}

if (pre_exec_hook.has_value())
{
pre_exec_hook.value()(ctx);
}

// TBD: Run fetched endpoint
CCF_APP_INFO("CUSTOM ENDPOINT: {}", endpoint->dispatch.uri_path);
}
Expand Down
6 changes: 3 additions & 3 deletions src/apps/js_generic/js_generic_base.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#include "apps/js_generic/named_auth_policies.h"
#include "apps/js_generic/request_extension.h"
#include "ccf/js/named_auth_policies.h"
#include "ccf/js/extensions/ccf/request_extension.h"
#include "ccf/app_interface.h"
#include "ccf/crypto/key_wrap.h"
#include "ccf/crypto/rsa_key_pair.h"
Expand Down Expand Up @@ -162,7 +162,7 @@ namespace ccfapp
endpoint_ctx.rpc_ctx.get()));

auto request_extension =
std::make_shared<RequestExtension>(endpoint_ctx.rpc_ctx.get());
std::make_shared<ccf::js::extensions::RequestExtension>(endpoint_ctx.rpc_ctx.get());
local_extensions.push_back(request_extension);

for (auto extension : local_extensions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.

#include "apps/js_generic/request_extension.h"
#include "ccf/js/extensions/ccf/request_extension.h"

#include "apps/js_generic/named_auth_policies.h"
#include "ccf/js/named_auth_policies.h"
#include "ccf/endpoints/authentication/all_of_auth.h"
#include "ccf/endpoints/authentication/cert_auth.h"
#include "ccf/endpoints/authentication/cose_auth.h"
Expand All @@ -13,7 +13,7 @@

#include <quickjs/quickjs.h>

namespace ccfapp
namespace ccf::js::extensions
{
namespace
{
Expand Down

0 comments on commit 997cc12

Please sign in to comment.