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

Sonar CI fix #501

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
89000cd
Modified condition to create default sample shadow directory
Oct 17, 2024
43159e9
Merge branch 'awslabs:main' into main
ig15 Nov 6, 2024
bbeb386
Updated versions in build.yml for aws credential fetch
ig15 Nov 6, 2024
f995850
Merge pull request #1 from ig15/ig15-update-version-for-aws-credentials
ig15 Nov 6, 2024
219900d
Updated build.yml to revert version of configure-aws-credentials to v1
ig15 Nov 6, 2024
01630a7
Updated aws-credentials fetching mechanism version in build.yml
ig15 Nov 6, 2024
8adb376
Merge branch 'awslabs:main' into main
ig15 Nov 6, 2024
047be94
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Nov 11, 2024
ddc87c6
Add job document comparator to ignore pre-signed difference in s3 url
Nov 11, 2024
8235bd3
Merge branch 'main' of https://github.com/ig15/ishangg-aws-iot-device…
Nov 11, 2024
8fad21a
Remove unit test for the compareJobsDocument and make it private
Nov 12, 2024
31044e7
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Nov 14, 2024
412a0da
Refactor compareJobDocuments comments
Nov 14, 2024
9b266d6
Merge branch 'awslabs:main' into main
ig15 Nov 14, 2024
4b587d6
Merge branch 'awslabs:main' into main
ig15 Nov 15, 2024
0942527
Fix clang-format in multiple files
Nov 20, 2024
0772be2
Merge branch 'main' of https://github.com/ig15/ishangg-aws-iot-device…
Nov 20, 2024
06f7fc7
Merge branch 'main' of https://github.com/ig15/ishangg-aws-iot-device…
Nov 20, 2024
0358776
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Nov 21, 2024
7abec1c
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Nov 26, 2024
abd2d5c
Merge branch 'main' of https://github.com/ig15/ishangg-aws-iot-device…
Mar 3, 2025
2070848
Send data from local service to the IOT tunnel in chunks
Mar 5, 2025
bbd61bd
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Mar 18, 2025
ebe72d5
Merge branch 'awslabs:main' into main
ig15 Mar 19, 2025
ae5e926
Merge branch 'main' of https://github.com/ig15/ishangg-aws-iot-device…
Mar 19, 2025
0acb956
Add new field in Config test
Mar 19, 2025
a8b5ee9
Merge branch 'main' of https://github.com/awslabs/aws-iot-device-client
Mar 20, 2025
079db0c
Remove Run coverage job
Mar 20, 2025
b526cb5
Install gcc and g++9
Mar 20, 2025
41a9a60
Suppress the warning related to the use of the unique_ptr with the f…
Mar 20, 2025
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
Prev Previous commit
Next Next commit
Fix clang-format in multiple files
Ubuntu committed Nov 20, 2024
commit 0942527332d201888c09300c86a50258e36bf16d
8 changes: 6 additions & 2 deletions source/config/Config.cpp
Original file line number Diff line number Diff line change
@@ -1773,13 +1773,17 @@ bool PlainConfig::SampleShadow::LoadFromCliArgs(const CliArgs &cliArgs)
.c_str();
}

// setting `shadowOutputFile` value to default if no value was passed by user via CLI or JSON config, provided sample shadow feature is enabled.
// setting `shadowOutputFile` value to default if no value was passed by user via CLI or JSON config, provided
// sample shadow feature is enabled.
if (enabled && ((!shadowOutputFile.has_value() || shadowOutputFile->empty()) && !createShadowOutputFile()))
{
return false;
}

LOGM_INFO(Config::TAG, "Not creating directory %s since sample shadow is disabled", Config::DEFAULT_SAMPLE_SHADOW_OUTPUT_DIR);
LOGM_INFO(
Config::TAG,
"Not creating directory %s since sample shadow is disabled",
Config::DEFAULT_SAMPLE_SHADOW_OUTPUT_DIR);
return true;
}

57 changes: 37 additions & 20 deletions source/fleetprovisioning/FleetProvisioning.cpp
Original file line number Diff line number Diff line change
@@ -60,8 +60,7 @@ bool FleetProvisioning::WriteKeyAndCertToDirectory(CreateKeysAndCertificateRespo
if (FileUtils::StoreValueInFile(response->CertificatePem->c_str(), certPath.c_str()) &&
FileUtils::StoreValueInFile(response->PrivateKey->c_str(), keyPath.c_str()))
{
LOGM_INFO(
TAG, "Stored certificate and private key in %s and %s files", certPath.c_str(), keyPath.c_str());
LOGM_INFO(TAG, "Stored certificate and private key in %s and %s files", certPath.c_str(), keyPath.c_str());

LOG_INFO(TAG, "Attempting to set permissions for certificate and private key...");
chmod(certPath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -121,7 +120,8 @@ bool FleetProvisioning::WriteCSRCertToDirectory(CreateCertificateFromCsrResponse
bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient identityClient)
{
LOG_INFO(TAG, "Provisioning new device certificate and private key using CreateKeysAndCertificate API");
auto onKeysAcceptedSubAck = [this](int ioErr) {
auto onKeysAcceptedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -133,7 +133,8 @@ bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient i
keysAcceptedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onKeysRejectedSubAck = [this](int ioErr) {
auto onKeysRejectedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -145,7 +146,8 @@ bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient i
keysRejectedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onKeysPublishSubAck = [this](int ioErr) {
auto onKeysPublishSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -157,13 +159,15 @@ bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient i
keysPublishCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onKeysAccepted = [this](CreateKeysAndCertificateResponse *response, int ioErr) {
auto onKeysAccepted = [this](CreateKeysAndCertificateResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_INFO(TAG, "CreateKeysAndCertificateResponse certificateId: %s.", response->CertificateId->c_str());
certificateOwnershipToken = *response->CertificateOwnershipToken;
Aws::Crt::String certificateID = response->CertificateId->c_str();
bool writeSucceeded = WriteKeyAndCertToDirectory(response, certificateID.c_str()) && WriteKeyAndCertToDirectory(response, "active");
bool writeSucceeded = WriteKeyAndCertToDirectory(response, certificateID.c_str()) &&
WriteKeyAndCertToDirectory(response, "active");
keysCreationCompletedPromise.set_value(writeSucceeded);
}
else
@@ -177,7 +181,8 @@ bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient i
}
};

auto onKeysRejected = [this](ErrorResponse *error, int ioErr) {
auto onKeysRejected = [this](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -252,7 +257,8 @@ bool FleetProvisioning::CreateCertificateAndKey(Iotidentity::IotIdentityClient i
bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient identityClient)
{
LOG_INFO(TAG, "Provisioning new device certificate using CreateCertificateFromCsr API");
auto onCsrAcceptedSubAck = [this](int ioErr) {
auto onCsrAcceptedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -264,7 +270,8 @@ bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient
csrAcceptedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onCsrRejectedSubAck = [this](int ioErr) {
auto onCsrRejectedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -276,7 +283,8 @@ bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient
csrRejectedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onCsrPublishSubAck = [this](int ioErr) {
auto onCsrPublishSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -288,13 +296,15 @@ bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient
csrPublishCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onCsrAccepted = [this](CreateCertificateFromCsrResponse *response, int ioErr) {
auto onCsrAccepted = [this](CreateCertificateFromCsrResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_INFO(TAG, "CreateCertificateFromCsrResponse certificateId: %s. ***", response->CertificateId->c_str());
certificateOwnershipToken = *response->CertificateOwnershipToken;
Aws::Crt::String certificateID = response->CertificateId->c_str();
bool writeSucceeded = WriteCSRCertToDirectory(response, certificateID.c_str()) && WriteCSRCertToDirectory(response, "active");
bool writeSucceeded =
WriteCSRCertToDirectory(response, certificateID.c_str()) && WriteCSRCertToDirectory(response, "active");
csrCreationCompletedPromise.set_value(writeSucceeded);
}
else
@@ -308,7 +318,8 @@ bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient
}
};

auto onCsrRejected = [this](ErrorResponse *error, int ioErr) {
auto onCsrRejected = [this](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -386,7 +397,8 @@ bool FleetProvisioning::CreateCertificateUsingCSR(Iotidentity::IotIdentityClient
}
bool FleetProvisioning::RegisterThing(Iotidentity::IotIdentityClient identityClient)
{
auto onRegisterAcceptedSubAck = [this](int ioErr) {
auto onRegisterAcceptedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -398,7 +410,8 @@ bool FleetProvisioning::RegisterThing(Iotidentity::IotIdentityClient identityCli
registerAcceptedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onRegisterRejectedSubAck = [this](int ioErr) {
auto onRegisterRejectedSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -410,7 +423,8 @@ bool FleetProvisioning::RegisterThing(Iotidentity::IotIdentityClient identityCli
registerRejectedCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onRegisterPublishSubAck = [this](int ioErr) {
auto onRegisterPublishSubAck = [this](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -422,7 +436,8 @@ bool FleetProvisioning::RegisterThing(Iotidentity::IotIdentityClient identityCli
registerPublishCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onRegisterAccepted = [this](RegisterThingResponse *response, int ioErr) {
auto onRegisterAccepted = [this](RegisterThingResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_INFO(TAG, "RegisterThingResponse ThingName: %s.", response->ThingName->c_str());
@@ -437,7 +452,8 @@ bool FleetProvisioning::RegisterThing(Iotidentity::IotIdentityClient identityCli
registerThingCompletedPromise.set_value(ioErr == AWS_OP_SUCCESS);
};

auto onRegisterRejected = [this](ErrorResponse *error, int ioErr) {
auto onRegisterRejected = [this](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
LOGM_ERROR(
@@ -529,7 +545,8 @@ bool FleetProvisioning::ProvisionDevice(shared_ptr<SharedCrtResourceManager> fpC
LOG_INFO(TAG, "Fleet Provisioning Feature has been started.");
collectSystemInformation = config.fleetProvisioning.collectSystemInformation;

bool didSetup = FileUtils::CreateDirectoryWithPermissions(keyDir.c_str(), S_IRWXU) && FileUtils::CreateDirectoryWithPermissions(
bool didSetup = FileUtils::CreateDirectoryWithPermissions(keyDir.c_str(), S_IRWXU) &&
FileUtils::CreateDirectoryWithPermissions(
Config::DEFAULT_CONFIG_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH | S_IXOTH);
if (!didSetup)
{
12 changes: 8 additions & 4 deletions source/fleetprovisioning/FleetProvisioning.h
Original file line number Diff line number Diff line change
@@ -172,15 +172,19 @@ namespace Aws
* @param response from IotIdentity CreateKeysAndCertificate call
* @return returns true if successfully written to directory
*/
bool WriteKeyAndCertToDirectory(Iotidentity::CreateKeysAndCertificateResponse *response, std::string fileName);
bool WriteKeyAndCertToDirectory(
Iotidentity::CreateKeysAndCertificateResponse *response,
std::string fileName);

/**
* \brief writes contents of the cert from CSR to the device client config directory.
*
* @param response from IotIdentity CreateCertificateFromCsrResponse call
* @return returns true if successfully written to directory
*/
bool WriteCSRCertToDirectory(Iotidentity::CreateCertificateFromCsrResponse *response, std::string fileName);
bool WriteCSRCertToDirectory(
Iotidentity::CreateCertificateFromCsrResponse *response,
std::string fileName);

/**
* \brief creates a new certificate and private key using the AWS certificate authority
@@ -274,6 +278,6 @@ namespace Aws
bool ObtainCertificateSerialID(const char *certPath);
};
} // namespace FleetProvisioningNS
} // namespace DeviceClient
} // namespace Iot
} // namespace DeviceClient
} // namespace Iot
} // namespace Aws
38 changes: 22 additions & 16 deletions source/jobs/JobsFeature.cpp
Original file line number Diff line number Diff line change
@@ -425,7 +425,8 @@ void JobsFeature::publishUpdateJobExecutionStatusWithRetry(
retryConfig.needStopFlag = nullptr;
}

auto publishLambda = [this, data, statusInfo, statusDetails]() -> bool {
auto publishLambda = [this, data, statusInfo, statusDetails]() -> bool
{
// We first need to make sure that we haven't previously leaked any promises into our map
unique_lock<mutex> leakLock(updateJobExecutionPromisesLock);
for (auto keyPromise = updateJobExecutionPromises.cbegin(); keyPromise != updateJobExecutionPromises.cend();
@@ -513,9 +514,9 @@ void JobsFeature::publishUpdateJobExecutionStatusWithRetry(
this->updateJobExecutionPromises.erase(clientToken.c_str());
return finished;
};
std::thread updateJobExecutionThread([retryConfig, publishLambda, onCompleteCallback] {
Retry::exponentialBackoff(retryConfig, publishLambda, onCompleteCallback);
});
std::thread updateJobExecutionThread(
[retryConfig, publishLambda, onCompleteCallback]
{ Retry::exponentialBackoff(retryConfig, publishLambda, onCompleteCallback); });
updateJobExecutionThread.detach();
}

@@ -527,23 +528,25 @@ void JobsFeature::copyJobsNotification(Iotjobs::JobExecutionData job)
latestJobsNotification.ExecutionNumber = job.ExecutionNumber.value();
}


bool JobsFeature::compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aws::Crt::JsonObject& job2) {
bool JobsFeature::compareJobDocuments(const Aws::Crt::JsonObject &job1, const Aws::Crt::JsonObject &job2)
{
std::string str1 = job1.View().WriteCompact().c_str();
std::string str2 = job2.View().WriteCompact().c_str();

// Regular expression to match S3 URLs and capture the non-presigned parts
std::regex s3UrlRegex(R"((https://[^.\s"]+\.s3[.-](?:[^.\s"]+\.)?amazonaws\.com/[^?\s"]+)(\?[^"\s]+)?)");

// Function to replace only the pre-signed portion of S3 URLs
auto processPresignedUrls = [&s3UrlRegex](std::string& s) -> int {
auto processPresignedUrls = [&s3UrlRegex](std::string &s) -> int
{
int count = 0;
std::string result;
std::sregex_iterator it(s.begin(), s.end(), s3UrlRegex);
std::sregex_iterator end;

size_t lastPos = 0;
for (; it != end; ++it) {
for (; it != end; ++it)
{
count++;

// Adding the rest of the job document before the s3 URL
@@ -553,7 +556,7 @@ bool JobsFeature::compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aw
result += it->str(1);

// Replace only the presigned portion with the placeholder
result += "?aws:iot:s3-presigned-suffix:PLACEHOLDER";
result += "?aws:iot:s3-presigned-suffix:PLACEHOLDER";
lastPos = it->position() + it->length();
}
result += s.substr(lastPos);
@@ -566,7 +569,8 @@ bool JobsFeature::compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aw
int count2 = processPresignedUrls(str2);

// If the number of pre-signed URLs differs, the documents are different
if (count1 != count2) {
if (count1 != count2)
{
return false;
}
return str1 == str2;
@@ -588,9 +592,8 @@ bool JobsFeature::isDuplicateNotification(JobExecutionData job)
return false;
}

if (!compareJobDocuments(
job.JobDocument.value(),
latestJobsNotification.JobDocument.value())) {
if (!compareJobDocuments(job.JobDocument.value(), latestJobsNotification.JobDocument.value()))
{
LOG_DEBUG(TAG, "Job document differs");
return false;
}
@@ -607,7 +610,8 @@ bool JobsFeature::isDuplicateNotification(JobExecutionData job)

void JobsFeature::initJob(const JobExecutionData &job)
{
auto shutdownHandler = [this]() -> void {
auto shutdownHandler = [this]() -> void
{
handlingJob.store(false);
if (needStop.load())
{
@@ -638,7 +642,8 @@ void JobsFeature::executeJob(const Iotjobs::JobExecutionData &job, const PlainJo
{
LOGM_INFO(TAG, "Executing job: %s", job.JobId->c_str());

auto shutdownHandler = [this]() -> void {
auto shutdownHandler = [this]() -> void
{
handlingJob.store(false);
if (needStop.load())
{
@@ -647,7 +652,8 @@ void JobsFeature::executeJob(const Iotjobs::JobExecutionData &job, const PlainJo
}
};
// TODO: Add support for checking condition
auto runJob = [this, job, jobDocument, shutdownHandler]() {
auto runJob = [this, job, jobDocument, shutdownHandler]()
{
auto engine = createJobEngine();
// execute all action steps in sequence as provided in job document
int executionStatus = engine->exec_steps(jobDocument, jobHandlerDir);
7 changes: 3 additions & 4 deletions source/jobs/JobsFeature.h
Original file line number Diff line number Diff line change
@@ -322,8 +322,7 @@ namespace Aws
* @return true if the documents are equivalent (ignoring pre-signed URLs), false otherwise
*/

bool compareJobDocuments(const Aws::Crt::JsonObject& job1, const Aws::Crt::JsonObject& job2);

bool compareJobDocuments(const Aws::Crt::JsonObject &job1, const Aws::Crt::JsonObject &job2);

/**
* \brief Stores information about a job notification
@@ -340,8 +339,8 @@ namespace Aws
virtual std::shared_ptr<JobEngine> createJobEngine();
};
} // namespace Jobs
} // namespace DeviceClient
} // namespace Iot
} // namespace DeviceClient
} // namespace Iot
} // namespace Aws

#endif // DEVICE_CLIENT_JOBSFEATURE_H
2 changes: 1 addition & 1 deletion test/jobs/TestJobsFeature.cpp
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <aws/crt/Api.h>
#include <aws/iotjobs/RejectedError.h>
#include <aws/iotjobs/StartNextJobExecutionResponse.h>
#include <aws/iotjobs/UpdateJobExecutionResponse.h>
#include <aws/crt/Api.h>

using namespace std;
using namespace testing;