Skip to content

Commit

Permalink
Merge pull request rdkcentral#4940 from rdkcentral/RDK-45037-grpc
Browse files Browse the repository at this point in the history
RDK-45037 : Secure Storage Thunder Plugin
  • Loading branch information
anand-ky authored Mar 12, 2024
2 parents 51348a5 + 7c97bc7 commit 80553a1
Show file tree
Hide file tree
Showing 17 changed files with 1,321 additions and 19 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/L0-PersistentStore-grpc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: L0-PersistentStore-grpc

on:
push:
paths:
- PersistentStore/grpc/**
pull_request:
paths:
- PersistentStore/grpc/**

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
path: ${{github.repository}}

- name: Install valgrind, coverage, cmake, protoc, grpc_cpp_plugin, grpc
run: |
sudo apt update
sudo apt install -y valgrind lcov cmake protobuf-compiler protobuf-compiler-grpc libgrpc++-dev
- name: Build Thunder
working-directory: ${{github.workspace}}
run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh

- name: Build
working-directory: ${{github.workspace}}
run: |
cmake -S ${GITHUB_REPOSITORY}/PersistentStore/grpc/l0test -B build/grpcl0test -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror"
cmake --build build/grpcl0test --target install
- name: Run
working-directory: ${{github.workspace}}
run: PATH=${PWD}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/usr/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try grpcl0test

- name: Generate coverage
working-directory: ${{github.workspace}}
run: |
lcov -c -o coverage.info -d build/grpcl0test
genhtml -o coverage coverage.info
- name: Upload artifacts
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
coverage/
valgrind_log
if-no-files-found: warn
29 changes: 29 additions & 0 deletions .github/workflows/L2-PersistentStore-grpc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: L2-PersistentStore-grpc

on:
push:
paths:
- PersistentStore/grpc/**
pull_request:
paths:
- PersistentStore/grpc/**

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
path: ${{github.repository}}

- name: Install cmake, protoc, grpc_cpp_plugin, grpc
run: |
sudo apt update
sudo apt install -y cmake protobuf-compiler protobuf-compiler-grpc libgrpc++-dev
- name: Build
working-directory: ${{github.workspace}}
run: |
cmake -S ${GITHUB_REPOSITORY}/PersistentStore/grpc/l2test -B build/grpcl2test -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="-Wall -Werror"
cmake --build build/grpcl2test --target install
54 changes: 45 additions & 9 deletions PersistentStore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,83 @@ set(CMAKE_CXX_STANDARD 11)

find_package(WPEFramework)

set(PLUGIN_PERSISTENTSTORE_MODE "Off" CACHE STRING "Controls if the plugin should run in its own process, in process or remote")
set(PLUGIN_PERSISTENTSTORE_MODE "Local" CACHE STRING "Controls if the plugin should run in its own process, in process or remote")
set(PLUGIN_PERSISTENTSTORE_URI "ss.eu.prod.developer.comcast.com:443" CACHE STRING "Account scope endpoint")
set(PLUGIN_PERSISTENTSTORE_PATH "/opt/secure/persistent/rdkservicestore" CACHE STRING "Path")
set(PLUGIN_PERSISTENTSTORE_LEGACYPATH "/opt/persistent/rdkservicestore" CACHE STRING "Previously used path")
set(PLUGIN_PERSISTENTSTORE_KEY "" CACHE STRING "Encryption key")
set(PLUGIN_PERSISTENTSTORE_MAXSIZE "1000000" CACHE STRING "For all text data, in bytes")
set(PLUGIN_PERSISTENTSTORE_MAXVALUE "3000" CACHE STRING "For single text data, in bytes")
set(PLUGIN_PERSISTENTSTORE_LIMIT "10000" CACHE STRING "Default for all text data in namespace, in bytes")
set(PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND "" CACHE STRING "Shell command to get the service access token")
set(PLUGIN_PERSISTENTSTORE_STARTUPORDER "" CACHE STRING "To configure startup order of PersistentStore plugin")

add_library(${MODULE_NAME} SHARED
PersistentStore.cpp
PersistentStoreJsonRpc.cpp
Module.cpp
)

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(${NAMESPACE}Definitions REQUIRED)
target_link_libraries(${MODULE_NAME} PRIVATE
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${NAMESPACE}Definitions::${NAMESPACE}Definitions
)

install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)

set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation)
add_library(${PLUGIN_IMPLEMENTATION} SHARED
sqlite/Store2.cpp
sqlite/StoreCache.cpp
sqlite/StoreInspector.cpp
sqlite/StoreLimit.cpp
grpc/Store2.cpp
Module.cpp
)

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(${NAMESPACE}Definitions REQUIRED)
target_link_libraries(${MODULE_NAME} PRIVATE
target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${NAMESPACE}Definitions::${NAMESPACE}Definitions
)

find_package(PkgConfig REQUIRED)
pkg_search_module(SQLITE REQUIRED sqlite3)
target_link_libraries(${MODULE_NAME} PRIVATE ${SQLITE_LIBRARIES})
target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${SQLITE_LIBRARIES})

find_library(IARMBUS_LIBRARIES NAMES IARMBus)
if (IARMBUS_LIBRARIES)
find_path(IARMBUS_INCLUDE_DIRS NAMES libIBus.h PATH_SUFFIXES rdk/iarmbus REQUIRED)
find_path(IARMSYS_INCLUDE_DIRS NAMES sysMgr.h PATH_SUFFIXES rdk/iarmmgrs/sysmgr REQUIRED)
target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS} ${IARMSYS_INCLUDE_DIRS})
target_link_libraries(${MODULE_NAME} PRIVATE ${IARMBUS_LIBRARIES})
add_definitions(-DWITH_SYSMGR)
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ${IARMBUS_INCLUDE_DIRS} ${IARMSYS_INCLUDE_DIRS})
target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${IARMBUS_LIBRARIES})
target_compile_definitions(${PLUGIN_IMPLEMENTATION} PRIVATE WITH_SYSMGR)
endif ()

install(TARGETS ${MODULE_NAME}
find_package(Protobuf REQUIRED)
target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${Protobuf_LIBRARIES})

add_custom_target(protoc
${Protobuf_PROTOC_EXECUTABLE} --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR}/grpc/secure_storage ${CMAKE_CURRENT_SOURCE_DIR}/grpc/secure_storage/secure_storage.proto
)
add_dependencies(${PLUGIN_IMPLEMENTATION} protoc)

target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE grpc++)
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)

add_custom_target(protoc-gen-grpc
${Protobuf_PROTOC_EXECUTABLE} --grpc_out ${CMAKE_CURRENT_BINARY_DIR} --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} -I ${CMAKE_CURRENT_SOURCE_DIR}/grpc/secure_storage ${CMAKE_CURRENT_SOURCE_DIR}/grpc/secure_storage/secure_storage.proto
)
add_dependencies(${PLUGIN_IMPLEMENTATION} protoc-gen-grpc)

set(PROTO_SRCS secure_storage.pb.cc secure_storage.grpc.pb.cc)
target_sources(${PLUGIN_IMPLEMENTATION} PRIVATE ${PROTO_SRCS})
set_property(SOURCE ${PROTO_SRCS} PROPERTY GENERATED 1)
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

install(TARGETS ${PLUGIN_IMPLEMENTATION}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)

write_config(${PLUGIN_NAME})
1 change: 1 addition & 0 deletions PersistentStore/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define MAXSIZE_ENV "PERSISTENTSTORE_MAXSIZE"
#define MAXVALUE_ENV "PERSISTENTSTORE_MAXVALUE"
#define LIMIT_ENV "PERSISTENTSTORE_LIMIT"
#define TOKEN_COMMAND_ENV "PERSISTENTSTORE_TOKEN_COMMAND"
#define IARM_INIT_NAME "Thunder_Plugins"

#undef EXTERNAL
Expand Down
2 changes: 2 additions & 0 deletions PersistentStore/PersistentStore.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ configuration = JSON()

rootobject = JSON()
rootobject.add("mode", "@PLUGIN_PERSISTENTSTORE_MODE@")
rootobject.add("locator", "lib@[email protected]")
configuration.add("root", rootobject)

configuration.add("uri", "@PLUGIN_PERSISTENTSTORE_URI@")
Expand All @@ -15,3 +16,4 @@ configuration.add("key", "@PLUGIN_PERSISTENTSTORE_KEY@")
configuration.add("maxsize", "@PLUGIN_PERSISTENTSTORE_MAXSIZE@")
configuration.add("maxvalue", "@PLUGIN_PERSISTENTSTORE_MAXVALUE@")
configuration.add("limit", "@PLUGIN_PERSISTENTSTORE_LIMIT@")
configuration.add("tokencommand", "@PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND@")
19 changes: 9 additions & 10 deletions PersistentStore/PersistentStore.config
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
set (autostart true)
set (preconditions Platform)
set (callsign "org.rdk.PersistentStore")
set(autostart true)
set(preconditions Platform)
set(callsign "org.rdk.PersistentStore")

if(PLUGIN_PERSISTENTSTORE_STARTUPORDER)
set (startuporder ${PLUGIN_PERSISTENTSTORE_STARTUPORDER})
endif()

map()
kv(mode ${PLUGIN_PERSISTENTSTORE_MODE})
end()
ans(rootobject)

map()
key(root)
map()
kv(mode ${PLUGIN_PERSISTENTSTORE_MODE})
kv(locator lib${PLUGIN_IMPLEMENTATION}.so)
end()
kv(uri ${PLUGIN_PERSISTENTSTORE_URI})
kv(path ${PLUGIN_PERSISTENTSTORE_PATH})
kv(legacypath ${PLUGIN_PERSISTENTSTORE_LEGACYPATH})
kv(key ${PLUGIN_PERSISTENTSTORE_KEY})
kv(maxsize ${PLUGIN_PERSISTENTSTORE_MAXSIZE})
kv(maxvalue ${PLUGIN_PERSISTENTSTORE_MAXVALUE})
kv(limit ${PLUGIN_PERSISTENTSTORE_LIMIT})
kv(tokencommand ${PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND})
end()
ans(configuration)

map_append(${configuration} root ${rootobject})
1 change: 1 addition & 0 deletions PersistentStore/PersistentStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace Plugin {
Core::SystemInfo::SetEnvironment(MAXSIZE_ENV, std::to_string(_config.MaxSize.Value()));
Core::SystemInfo::SetEnvironment(MAXVALUE_ENV, std::to_string(_config.MaxValue.Value()));
Core::SystemInfo::SetEnvironment(LIMIT_ENV, std::to_string(_config.Limit.Value()));
Core::SystemInfo::SetEnvironment(TOKEN_COMMAND_ENV, _config.TokenCommand.Value());

uint32_t connectionId;

Expand Down
2 changes: 2 additions & 0 deletions PersistentStore/PersistentStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace Plugin {
Add(_T("maxsize"), &MaxSize);
Add(_T("maxvalue"), &MaxValue);
Add(_T("limit"), &Limit);
Add(_T("tokencommand"), &TokenCommand);
}

public:
Expand All @@ -60,6 +61,7 @@ namespace Plugin {
Core::JSON::DecUInt64 MaxSize;
Core::JSON::DecUInt64 MaxValue;
Core::JSON::DecUInt64 Limit;
Core::JSON::String TokenCommand;
};

class Store2Notification : public Exchange::IStore2::INotification {
Expand Down
8 changes: 8 additions & 0 deletions PersistentStore/grpc/Store2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "Store2.h"

namespace WPEFramework {
namespace Plugin {
class GrpcStore2 : public Grpc::Store2 {};
SERVICE_REGISTRATION(GrpcStore2, 1, 0);
} // namespace Plugin
} // namespace WPEFramework
Loading

0 comments on commit 80553a1

Please sign in to comment.