-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom authorizer sample (#423)
Adds a new custom authorizer sample and support to the V2 C++ SDK * Added custom authorizer sample * Clang format fix * Update to use correct function naming * More clang-format fixes * Modified Codebuild custom authorizer name with better name * Added custom authorizer sample to README * Updated to use latest CRT release
- Loading branch information
1 parent
7ff4354
commit bca2450
Showing
9 changed files
with
195 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
env | ||
|
||
pushd $CODEBUILD_SRC_DIR/samples/mqtt/custom_authorizer_connect | ||
|
||
mkdir _build | ||
cd _build | ||
cmake -DCMAKE_PREFIX_PATH=/tmp/install .. | ||
make -j | ||
|
||
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') | ||
AUTH_NAME=$(aws secretsmanager get-secret-value --secret-id "unit-test/authorizer-name" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') | ||
AUTH_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "unit-test/authorizer-password" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') | ||
|
||
echo "Custom authorizer connect test" | ||
./custom-authorizer-connect --endpoint $ENDPOINT --custom_auth_authorizer_name $AUTH_NAME --custom_auth_password $AUTH_PASSWORD | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule aws-crt-cpp
updated
5 files
+13 −0 | .github/workflows/ci.yml | |
+1 −1 | CMakeLists.txt | |
+14 −0 | README.md | |
+55 −0 | include/aws/iot/MqttClient.h | |
+140 −4 | source/iot/MqttClient.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 | ||
project(custom-authorizer-connect CXX) | ||
|
||
file(GLOB SRC_FILES | ||
"*.cpp" | ||
"../../utils/CommandLineUtils.cpp" | ||
"../../utils/CommandLineUtils.h" | ||
) | ||
|
||
add_executable(${PROJECT_NAME} ${SRC_FILES}) | ||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
CXX_STANDARD 14) | ||
|
||
#set warnings | ||
if (MSVC) | ||
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068) | ||
else () | ||
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror) | ||
endif () | ||
|
||
find_package(aws-crt-cpp REQUIRED) | ||
|
||
target_link_libraries(${PROJECT_NAME} AWS::aws-crt-cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
#include <aws/crt/Api.h> | ||
#include <aws/crt/UUID.h> | ||
|
||
#include "../../utils/CommandLineUtils.h" | ||
|
||
using namespace Aws::Crt; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
|
||
/************************ Setup the Lib ****************************/ | ||
/* | ||
* Do the global initialization for the API. | ||
*/ | ||
ApiHandle apiHandle; | ||
|
||
/*********************** Parse Arguments ***************************/ | ||
Utils::CommandLineUtils cmdUtils = Utils::CommandLineUtils(); | ||
cmdUtils.RegisterProgramName("custom_authorizer_connect"); | ||
cmdUtils.AddCommonMQTTCommands(); | ||
cmdUtils.AddCommonCustomAuthorizerCommands(); | ||
cmdUtils.RegisterCommand("client_id", "<str>", "Client id to use (optional, default='test-*')"); | ||
const char **const_argv = (const char **)argv; | ||
cmdUtils.SendArguments(const_argv, const_argv + argc); | ||
|
||
// Make a MQTT client and create a connection through a custom authorizer | ||
// Note: The data for the connection is gotten from cmdUtils | ||
// (see BuildDirectMQTTConnectionWithCustomAuthorizer for implementation) | ||
Aws::Iot::MqttClient client = Aws::Iot::MqttClient(); | ||
std::shared_ptr<Aws::Crt::Mqtt::MqttConnection> connection = | ||
cmdUtils.BuildDirectMQTTConnectionWithCustomAuthorizer(&client); | ||
|
||
// Get the client ID to send with the connection | ||
String clientId = cmdUtils.GetCommandOrDefault("client_id", String("test-") + Aws::Crt::UUID().ToString()); | ||
|
||
// Connect and then disconnect using the connection we created | ||
// (see SampleConnectAndDisconnect for implementation) | ||
cmdUtils.SampleConnectAndDisconnect(connection, clientId); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters