Skip to content

Request response samples format #782

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

Draft
wants to merge 8 commits into
base: RequestResponseSamples
Choose a base branch
from
Draft
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
17 changes: 16 additions & 1 deletion format-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,34 @@

# create file containing list of all files to format
filepaths_file = NamedTemporaryFile(delete=False)

# SDK libraries
subs = ['devicedefender', 'discovery', 'eventstream_rpc', 'greengrass_ipc', 'identity', 'iotdevicecommon', 'jobs', 'secure_tunneling', 'shadow']
for subdir in subs:
for dirpath, dirnames, filenames in os.walk(subdir):
for filename in filenames:
# our regexes expect filepath to use forward slash
filepath = Path(dirpath, filename).as_posix()
print(f"Checking {filepath}")
if not INCLUDE_REGEX.match(filepath):
continue
if EXCLUDE_REGEX.match(filepath):
continue

filepaths_file.write(f"{filepath}\n".encode())

# SDK samples
SAMPLE_INCLUDE_REGEX = re.compile(r'^.*\.(cpp|h)$')
for dirpath, dirnames, filenames in os.walk("samples"):
for filename in filenames:
# our regexes expect filepath to use forward slash
filepath = Path(dirpath, filename).as_posix()
if not SAMPLE_INCLUDE_REGEX.match(filepath):
continue
if EXCLUDE_REGEX.match(filepath):
continue

filepaths_file.write(f"{filepath}\n".encode())

filepaths_file.close()

# use pipx to run clang-format from PyPI
Expand Down
51 changes: 34 additions & 17 deletions samples/deprecated/fleet_provisioning/fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ std::shared_ptr<Mqtt::MqttConnection> createConnection(const Utils::cmdData &cmd
*/

// Invoked when a MQTT connect has completed or failed
auto onConnectionCompleted = [&ctx](Mqtt::MqttConnection &, int errorCode, Mqtt::ReturnCode returnCode, bool) {
auto onConnectionCompleted = [&ctx](Mqtt::MqttConnection &, int errorCode, Mqtt::ReturnCode returnCode, bool)
{
if (errorCode)
{
fprintf(stdout, "Connection failed with error %s\n", ErrorDebugString(errorCode));
Expand All @@ -98,7 +99,8 @@ std::shared_ptr<Mqtt::MqttConnection> createConnection(const Utils::cmdData &cmd
};

// Invoked when a disconnect has been completed
auto onDisconnect = [&ctx](Mqtt::MqttConnection & /*conn*/) {
auto onDisconnect = [&ctx](Mqtt::MqttConnection & /*conn*/)
{
{
fprintf(stdout, "Disconnect completed\n");
ctx.connectionClosedPromise.set_value();
Expand Down Expand Up @@ -150,7 +152,8 @@ std::shared_ptr<Mqtt::MqttConnection> createConnection(const Utils::cmdData &cmd
*/
void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertificateContext &ctx)
{
auto onKeysPublishPubAck = [&ctx](int ioErr) {
auto onKeysPublishPubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error publishing to CreateKeysAndCertificate: %s\n", ErrorDebugString(ioErr));
Expand All @@ -159,7 +162,8 @@ void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertifica
ctx.pubAckPromise.set_value();
};

auto onKeysAcceptedSubAck = [&ctx](int ioErr) {
auto onKeysAcceptedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to CreateKeysAndCertificate accepted: %s\n", ErrorDebugString(ioErr));
Expand All @@ -168,7 +172,8 @@ void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertifica
ctx.acceptedSubAckPromise.set_value();
};

auto onKeysRejectedSubAck = [&ctx](int ioErr) {
auto onKeysRejectedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to CreateKeysAndCertificate rejected: %s\n", ErrorDebugString(ioErr));
Expand All @@ -177,7 +182,8 @@ void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertifica
ctx.rejectedSubAckPromise.set_value();
};

auto onKeysAccepted = [&ctx](CreateKeysAndCertificateResponse *response, int ioErr) {
auto onKeysAccepted = [&ctx](CreateKeysAndCertificateResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(stdout, "CreateKeysAndCertificateResponse certificateId: %s.\n", response->CertificateId->c_str());
Expand All @@ -190,7 +196,8 @@ void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertifica
}
};

auto onKeysRejected = [](ErrorResponse *error, int ioErr) {
auto onKeysRejected = [](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(
Expand Down Expand Up @@ -236,7 +243,8 @@ void createKeysAndCertificate(IotIdentityClient &identityClient, CreateCertifica
*/
void createCertificateFromCsr(IotIdentityClient &identityClient, CreateCertificateContext &ctx, const String &csrFile)
{
auto onCsrPublishPubAck = [&ctx](int ioErr) {
auto onCsrPublishPubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error publishing to CreateCertificateFromCsr: %s\n", ErrorDebugString(ioErr));
Expand All @@ -245,7 +253,8 @@ void createCertificateFromCsr(IotIdentityClient &identityClient, CreateCertifica
ctx.pubAckPromise.set_value();
};

auto onCsrAcceptedSubAck = [&ctx](int ioErr) {
auto onCsrAcceptedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to CreateCertificateFromCsr accepted: %s\n", ErrorDebugString(ioErr));
Expand All @@ -254,7 +263,8 @@ void createCertificateFromCsr(IotIdentityClient &identityClient, CreateCertifica
ctx.acceptedSubAckPromise.set_value();
};

auto onCsrRejectedSubAck = [&ctx](int ioErr) {
auto onCsrRejectedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to CreateCertificateFromCsr rejected: %s\n", ErrorDebugString(ioErr));
Expand All @@ -263,7 +273,8 @@ void createCertificateFromCsr(IotIdentityClient &identityClient, CreateCertifica
ctx.rejectedSubAckPromise.set_value();
};

auto onCsrAccepted = [&ctx](CreateCertificateFromCsrResponse *response, int ioErr) {
auto onCsrAccepted = [&ctx](CreateCertificateFromCsrResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(stdout, "CreateCertificateFromCsrResponse certificateId: %s.\n", response->CertificateId->c_str());
Expand All @@ -276,7 +287,8 @@ void createCertificateFromCsr(IotIdentityClient &identityClient, CreateCertifica
}
};

auto onCsrRejected = [](ErrorResponse *error, int ioErr) {
auto onCsrRejected = [](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(
Expand Down Expand Up @@ -325,7 +337,8 @@ void registerThing(
const Utils::cmdData &cmdData,
const String &token)
{
auto onRegisterAcceptedSubAck = [&ctx](int ioErr) {
auto onRegisterAcceptedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to RegisterThing accepted: %s\n", ErrorDebugString(ioErr));
Expand All @@ -334,7 +347,8 @@ void registerThing(
ctx.acceptedSubAckPromise.set_value();
};

auto onRegisterRejectedSubAck = [&ctx](int ioErr) {
auto onRegisterRejectedSubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error subscribing to RegisterThing rejected: %s\n", ErrorDebugString(ioErr));
Expand All @@ -343,7 +357,8 @@ void registerThing(
ctx.rejectedSubAckPromise.set_value();
};

auto onRegisterAccepted = [&ctx](RegisterThingResponse *response, int ioErr) {
auto onRegisterAccepted = [&ctx](RegisterThingResponse *response, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(stdout, "RegisterThingResponse ThingName: %s.\n", response->ThingName->c_str());
Expand All @@ -356,7 +371,8 @@ void registerThing(
}
};

auto onRegisterRejected = [](ErrorResponse *error, int ioErr) {
auto onRegisterRejected = [](ErrorResponse *error, int ioErr)
{
if (ioErr == AWS_OP_SUCCESS)
{
fprintf(
Expand All @@ -373,7 +389,8 @@ void registerThing(
}
};

auto onRegisterPublishPubAck = [&ctx](int ioErr) {
auto onRegisterPublishPubAck = [&ctx](int ioErr)
{
if (ioErr != AWS_OP_SUCCESS)
{
fprintf(stderr, "Error publishing to RegisterThing: %s\n", ErrorDebugString(ioErr));
Expand Down
Loading
Loading