Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] Use core common lib converter #99

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ add_subdirectory(database)
add_subdirectory(iamclient)
add_subdirectory(iamserver)
add_subdirectory(nodeinfoprovider)
add_subdirectory(utils)
add_subdirectory(visidentifier)

# ######################################################################################################################
Expand Down
11 changes: 1 addition & 10 deletions src/iamclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,4 @@ target_compile_options(${TARGET} PRIVATE -Wstack-usage=${AOS_STACK_USAGE})
# Libraries
# ######################################################################################################################

target_link_libraries(
${TARGET}
PUBLIC aoscommon
aosiam
aosutils
aospbconvert
aoscoreapi-gen-iam
Poco::Util
utils
)
target_link_libraries(${TARGET} PUBLIC aoscommon aosiam aosutils aospbconvert aoscoreapi-gen-iam Poco::Util)
6 changes: 3 additions & 3 deletions src/iamclient/iamclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include <Poco/StreamCopier.h>

#include <pbconvert/common.hpp>
#include <pbconvert/iam.hpp>
#include <utils/exception.hpp>
#include <utils/grpchelper.hpp>

#include "iamclient.hpp"
#include "logger/logmodule.hpp"
#include "utils/convert.hpp"

/***********************************************************************************************************************
* Public
Expand Down Expand Up @@ -255,7 +255,7 @@ bool IAMClient::SendNodeInfo()
return false;
}

utils::ConvertToProto(*nodeInfo, *outgoingMsg.mutable_node_info());
*outgoingMsg.mutable_node_info() = aos::common::pbconvert::ConvertToProto(*nodeInfo);

LOG_DBG() << "Send node info: status=" << nodeInfo->mStatus;

Expand Down Expand Up @@ -519,7 +519,7 @@ bool IAMClient::SendApplyCertResponse(const aos::String& nodeID, const aos::Stri
std::string protoSerial;
aos::Error resultError = error;
if (error.IsNone()) {
Tie(protoSerial, resultError) = utils::ConvertSerialToProto(serial);
Tie(protoSerial, resultError) = aos::common::pbconvert::ConvertSerialToProto(serial);
if (!resultError.IsNone()) {
resultError = AOS_ERROR_WRAP(resultError);

Expand Down
11 changes: 1 addition & 10 deletions src/iamserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,4 @@ target_compile_options(${TARGET} PRIVATE -Wstack-usage=${AOS_STACK_USAGE})
# Libraries
# ######################################################################################################################

target_link_libraries(
${TARGET}
PUBLIC aoscommon
aosiam
aosutils
aospbconvert
aoscoreapi-gen-iam
Poco::Util
utils
)
target_link_libraries(${TARGET} PUBLIC aoscommon aosiam aosutils aospbconvert aoscoreapi-gen-iam Poco::Util)
19 changes: 9 additions & 10 deletions src/iamserver/nodecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "logger/logmodule.hpp"
#include "nodecontroller.hpp"
#include "utils/convert.hpp"

/***********************************************************************************************************************
* NodeStreamHandler
Expand Down Expand Up @@ -102,7 +101,7 @@
incoming.mutable_get_cert_types_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 104 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L104

Added line #L104 was not covered by tests
}

if (!outgoing.has_cert_types_response()) {
Expand All @@ -124,7 +123,7 @@
incoming.mutable_start_provisioning_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);
}

if (!outgoing.has_start_provisioning_response()) {
Expand All @@ -146,7 +145,7 @@
incoming.mutable_finish_provisioning_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 148 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L148

Added line #L148 was not covered by tests
}

if (!outgoing.has_finish_provisioning_response()) {
Expand All @@ -168,7 +167,7 @@
incoming.mutable_deprovision_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 170 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L170

Added line #L170 was not covered by tests
}

if (!outgoing.has_deprovision_response()) {
Expand All @@ -190,7 +189,7 @@
incoming.mutable_pause_node_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 192 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L192

Added line #L192 was not covered by tests
}

if (!outgoing.has_pause_node_response()) {
Expand All @@ -212,7 +211,7 @@
incoming.mutable_resume_node_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 214 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L214

Added line #L214 was not covered by tests
}

if (!outgoing.has_resume_node_response()) {
Expand All @@ -234,7 +233,7 @@
incoming.mutable_create_key_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 236 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L236

Added line #L236 was not covered by tests
}

if (!outgoing.has_create_key_response()) {
Expand All @@ -256,7 +255,7 @@
incoming.mutable_apply_cert_request()->CopyFrom(*request);

if (auto err = SendMessage(incoming, outgoing, responseTimeout); !err.IsNone()) {
return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 258 in src/iamserver/nodecontroller.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/nodecontroller.cpp#L258

Added line #L258 was not covered by tests
}

if (!outgoing.has_apply_cert_response()) {
Expand Down Expand Up @@ -405,7 +404,7 @@

Remove(handler);

return utils::ConvertAosErrorToGrpcStatus(ret);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(ret);
}

NodeStreamHandler::Ptr NodeController::GetNodeStreamHandler(const std::string& nodeID)
Expand Down
34 changes: 18 additions & 16 deletions src/iamserver/protectedmessagehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include <aos/iam/certhandler.hpp>

#include <pbconvert/common.hpp>
#include <pbconvert/iam.hpp>

#include "logger/logmodule.hpp"
#include "protectedmessagehandler.hpp"
#include "utils/convert.hpp"

/***********************************************************************************************************************
* Constants
Expand Down Expand Up @@ -101,7 +101,7 @@
if (auto status = RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 104 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L104

Added line #L104 was not covered by tests
}

return handler->PauseNode(request, response, cDefaultTimeout);
Expand Down Expand Up @@ -131,7 +131,7 @@
if (auto status = RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 134 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L134

Added line #L134 was not covered by tests
}

return handler->ResumeNode(request, response, cDefaultTimeout);
Expand Down Expand Up @@ -165,7 +165,7 @@
return RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 168 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L168

Added line #L168 was not covered by tests
}

return handler->GetCertTypes(request, response, cDefaultTimeout);
Expand All @@ -179,10 +179,12 @@
if (!err.IsNone()) {
LOG_ERR() << "Get certificate types error: " << AOS_ERROR_WRAP(err);

return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
}

utils::ConvertToProto(certTypes, *response->mutable_types());
for (const auto& type : certTypes) {
response->add_types(type.CStr());
}

return grpc::Status::OK;
}
Expand All @@ -198,7 +200,7 @@
return RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 203 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L203

Added line #L203 was not covered by tests
}

return handler->StartProvisioning(request, response, cProvisioningTimeout);
Expand All @@ -225,7 +227,7 @@
if (auto status = RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 230 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L230

Added line #L230 was not covered by tests
}

return handler->FinishProvisioning(request, response, cProvisioningTimeout);
Expand Down Expand Up @@ -263,7 +265,7 @@
if (auto status = RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 268 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L268

Added line #L268 was not covered by tests
}

return handler->Deprovision(request, response, cProvisioningTimeout);
Expand Down Expand Up @@ -331,7 +333,7 @@
return RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 336 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L336

Added line #L336 was not covered by tests
}

iamproto::CreateKeyRequest keyRequest = *request;
Expand Down Expand Up @@ -375,7 +377,7 @@
return RequestWithRetry([&]() {
auto handler = GetNodeController()->GetNodeStreamHandler(nodeID);
if (!handler) {
return utils::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(cStreamNotFoundError);

Check warning on line 380 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L380

Added line #L380 was not covered by tests
}

return handler->ApplyCert(request, response, cDefaultTimeout);
Expand All @@ -397,7 +399,7 @@
aos::Error err;
std::string serial;

Tie(serial, err) = utils::ConvertSerialToProto(certInfo.mSerial);
Tie(serial, err) = aos::common::pbconvert::ConvertSerialToProto(certInfo.mSerial);
if (!err.IsNone()) {
LOG_ERR() << "Convert serial failed: error=" << err;

Expand Down Expand Up @@ -432,7 +434,7 @@
if (err = aosPermissions->EmplaceBack(); !err.IsNone()) {
LOG_ERR() << "Failed to push back permissions: error=" << err;

return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);
}

aos::FunctionServicePermissions& servicePerm = aosPermissions->Back();
Expand All @@ -442,7 +444,7 @@
if (err = servicePerm.mPermissions.PushBack({key.c_str(), val.c_str()}); !err.IsNone()) {
LOG_ERR() << "Failed to push back permissions: error=" << err;

return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);

Check warning on line 447 in src/iamserver/protectedmessagehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/iamserver/protectedmessagehandler.cpp#L447

Added line #L447 was not covered by tests
}
}
}
Expand All @@ -453,7 +455,7 @@
if (!err.IsNone()) {
LOG_ERR() << "Register instance failed: error=" << err;

return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);
}

response->set_secret(secret.CStr());
Expand All @@ -472,7 +474,7 @@
if (auto err = GetPermHandler()->UnregisterInstance(instance); !err.IsNone()) {
LOG_ERR() << "Unregister instance failed: error=" << err;

return utils::ConvertAosErrorToGrpcStatus(err);
return aos::common::pbconvert::ConvertAosErrorToGrpcStatus(err);
}

return grpc::Status::OK;
Expand Down
Loading