Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Jul 12, 2024
1 parent 67f2331 commit c9775a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
24 changes: 9 additions & 15 deletions samples/fleet_provisioning/fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/**
* A sample application demonstrating usage of AWS IoT Fleet provisioning.
*
* In a real world application you probably don't want to enforce synchronous behavior. But this is a sample console
* application, so all actions, like creating a certificate or registering a thing, are performed in synchronous manner.
* It's easier to follow a synchronous workflow, when events happen one after another. For that reason, this sample
* performs all actions, like connecting to a server or registering a thing, in synchronous manner.
*/

#include <aws/crt/Api.h>
Expand All @@ -34,12 +34,12 @@
using namespace Aws::Crt;
using namespace Aws::Iotidentity;

static std::string getFileData(std::string const &fileName)
static String getFileData(const String &fileName)
{
std::ifstream ifs(fileName);
std::ifstream ifs(fileName.c_str());
std::string str;
getline(ifs, str, (char)ifs.eof());
return str;
return str.c_str();
}

/**
Expand Down Expand Up @@ -437,8 +437,6 @@ int main(int argc, char *argv[])

// Do the global initialization for the API
ApiHandle apiHandle;
// Variables for the sample
String csrFile;

/**
* cmdData is the arguments/input from the command line placed into a single struct for
Expand All @@ -447,11 +445,6 @@ int main(int argc, char *argv[])
*/
Utils::cmdData cmdData = Utils::parseSampleInputFleetProvisioning(argc, argv, &apiHandle);

if (cmdData.input_csrPath != "")
{
csrFile = getFileData(cmdData.input_csrPath.c_str()).c_str();
}

ConnectionContext connectionContext;
auto connection = createConnection(cmdData, connectionContext);

Expand All @@ -474,13 +467,14 @@ int main(int argc, char *argv[])

// Create certificate.
CreateCertificateContext certificateContext;
if (csrFile.empty())
if (cmdData.input_csrPath != "")
{
createKeysAndCertificate(identityClient, certificateContext);
auto csrFile = getFileData(cmdData.input_csrPath);
createCertificateFromCsr(identityClient, certificateContext, csrFile);
}
else
{
createCertificateFromCsr(identityClient, certificateContext, csrFile);
createKeysAndCertificate(identityClient, certificateContext);
}

// After certificate is obtained, it's time to register a thing.
Expand Down
29 changes: 15 additions & 14 deletions samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

/**
* A sample application demonstrating usage of AWS IoT Fleet provisioning with MQTT5 client.
*
* It's easier to follow a synchronous workflow, when events happen one after another. For that reason, this sample
* performs all actions, like connecting to a server or registering a thing, in synchronous manner.
*/

#include <aws/crt/Api.h>
#include <aws/crt/JsonObject.h>
#include <aws/crt/mqtt/Mqtt5Packets.h>
Expand All @@ -27,12 +35,12 @@
using namespace Aws::Crt;
using namespace Aws::Iotidentity;

static std::string getFileData(std::string const &fileName)
static String getFileData(const String &fileName)
{
std::ifstream ifs(fileName);
std::ifstream ifs(fileName.c_str());
std::string str;
getline(ifs, str, (char)ifs.eof());
return str;
return str.c_str();
}

/**
Expand Down Expand Up @@ -421,9 +429,6 @@ int main(int argc, char *argv[])

// Do the global initialization for the API
ApiHandle apiHandle;
// Variables for the sample
String csrFile;
RegisterThingResponse registerThingResponse;

/**
* cmdData is the arguments/input from the command line placed into a single struct for
Expand All @@ -432,11 +437,6 @@ int main(int argc, char *argv[])
*/
Utils::cmdData cmdData = Utils::parseSampleInputFleetProvisioning(argc, argv, &apiHandle);

if (cmdData.input_csrPath != "")
{
csrFile = getFileData(cmdData.input_csrPath.c_str()).c_str();
}

Mqtt5ClientContext mqtt5ClientContext;
auto client = createMqtt5Client(mqtt5ClientContext, cmdData);

Expand All @@ -459,13 +459,14 @@ int main(int argc, char *argv[])

// Create certificate.
CreateCertificateContext certificateContext;
if (csrFile.empty())
if (cmdData.input_csrPath != "")
{
createKeysAndCertificate(identityClient, certificateContext);
auto csrFile = getFileData(cmdData.input_csrPath);
createCertificateFromCsr(identityClient, certificateContext, csrFile);
}
else
{
createCertificateFromCsr(identityClient, certificateContext, csrFile);
createKeysAndCertificate(identityClient, certificateContext);
}

// After certificate is obtained, it's time to register a thing.
Expand Down

0 comments on commit c9775a5

Please sign in to comment.