Skip to content

Commit 1e54e1a

Browse files
authored
Merge branch 'main' into corepyle/react-sqs
2 parents e70a2b4 + d98e3b6 commit 1e54e1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3521
-2609
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
# aws-doc-sdk-examples Pull Request
22

3-
Thank you for making a submission to the *aws-doc-sdk-examples* repository. For more information about submitting pull requests to this repository, see [Guidelines for contributing](/CONTRIBUTING.md).
3+
Thank you for making a submission to the *aws-doc-sdk-examples* repository. For more information about submitting pull requests to this repository, see [Guidelines for contributing](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/CONTRIBUTING.md).
44

5-
*NOTE:* This PR template contains three sections. Depending on the reason for your pull request, please fill out the section that applies to you and then remove the other two sections.
5+
*NOTE:* This pull request (PR) template contains two sections. Use the section that applies to your submission, and remove the section which doesn't apply.
6+
***
7+
## I'm submitting a new SDK code example
68

7-
## New SDK Code Example
9+
Confirm you have met the following minimum requirements:
810

9-
The submitter has:
11+
- [ ] Add the following copyright notice to the top of each file. See the [LICENSE agreement](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/LICENSE) for the terms of the copyright.
12+
>Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\
13+
>SPDX-License-Identifier: Apache-2.0
14+
- [ ] Create unit tests for all paths through the code, and confirm that the all the tests pass. For recommendations, see [How we test code examples](https://github.com/awsdocs/aws-doc-sdk-examples/wiki/Code-quality-guidelines---testing-and-linting#how-we-test-code-examples).
15+
- [ ] Run a linter against all code and implement the resulting suggestions. For recommendations, see [Linters run on check in](https://github.com/awsdocs/aws-doc-sdk-examples/wiki/Code-quality-guidelines---testing-and-linting#linters-run-on-check-in).
16+
- [ ] Add minimum usage documentation as comments in the code. For recommendations, see [Code comment guidelines](https://github.com/awsdocs/aws-doc-sdk-examples/wiki/Code-comment-guidelines).
17+
***
18+
## I'm resolving an issue with an existing code example
1019

11-
- [ ] Added the default copyright notice to all files.
12-
- [ ] Created unit tests for all paths through the code and they all pass.
13-
- [ ] Run a linter against all code and implemented the resulting suggestions.
14-
- [ ] Added minimum usage documentation as comments in the code.
15-
- [ ] Had comments and strings reviewed and incorporated suggested changes.
16-
- [ ] Had the code reviewed and implemented the reviewer's suggested changes.
20+
Describe the changes you have made here, including any issue numbers.
1721

18-
## Existing Example Update
22+
Confirm you have met the following minimum requirements:
1923

20-
The submitter has:
21-
22-
- [ ] Confirmed that the correct copyright is included in all files.
23-
- [ ] Major code changes have been reviewed, and the submitter has incorporated review comments.
24-
- [ ] Changed or added comments and strings have been reviewed, and the submitter has incorporated any and all suggested edits.
25-
26-
## Resolve Issue
27-
28-
Issue #
29-
30-
### Description of Changes
31-
32-
Please describe the changes you have made here.
33-
34-
- [ ] I have tested my changes and created unit tests for new code paths.
35-
- [ ] Changes have been reviewed, and all reviewer comments have been incorporated.
24+
- [ ] Test the changed code. For recommendations, see [How we test code examples](https://github.com/awsdocs/aws-doc-sdk-examples/wiki/Code-quality-guidelines---testing-and-linting#how-we-test-code-examples).
25+
- [ ] Run a linter against the changed code and implement the resulting suggestions. For recommendations, see [Linters run on check in](https://github.com/awsdocs/aws-doc-sdk-examples/wiki/Code-quality-guidelines---testing-and-linting#linters-run-on-check-in).
26+
***
27+
## Open source license adherence
3628

3729
_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license._

.github/workflows/cpp-lint.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
name: cpp lint check
1+
name: "cpp lint check"
22
on:
3-
push:
4-
paths:
5-
- 'cpp/**'
6-
branches:
7-
- main
8-
pull_request:
3+
pull_request_target:
94
paths:
105
- 'cpp/**'
116
workflow_dispatch:
@@ -19,7 +14,9 @@ jobs:
1914
runs-on: ubuntu-latest
2015
steps:
2116
- uses: actions/checkout@v3
22-
- name: Run clang-tidy check
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
- name: "Run clang-tidy check"
2320
uses: ./.github/cpp-linter
2421
with:
2522
config_file: ./.github/cpp-linter/clang-tidy-config.txt

cpp/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build/
22
cmake-build*/
3+
.vs/

cpp/example_code/s3/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ if(NOT BUILD_SHARED_LIBS)
2727
endif()
2828

2929
# Find the AWS SDK for C++ package.
30-
find_package(AWSSDK REQUIRED COMPONENTS s3 sts)
30+
find_package(AWSSDK REQUIRED COMPONENTS s3 sts iam)
3131

3232
# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
3333
# and building as shared libraries, then dynamically link to those shared libraries.
3434
if(MSVC AND BUILD_SHARED_LIBS)
3535
add_definitions(-DUSE_IMPORT_EXPORT)
3636
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
37-
list(APPEND SERVICE_LIST s3 sts)
37+
list(APPEND SERVICE_LIST s3 sts iam)
3838
#For IDE's like Xcode and Visual Studio, this line is ignored. This is because Release/Debug
3939
# is switched internally, but this is necessary for non-IDE builds.
4040
set(CMAKE_BUILD_TYPE Debug) #TODO: Set to your build type.
@@ -114,7 +114,7 @@ foreach(file ${AWSDOC_S3_SOURCE})
114114
set(EXAMPLE_TEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_${EXAMPLE}.cpp)
115115

116116
if(EXISTS ${EXAMPLE_TEST_FILE})
117-
add_executable(${EXAMPLE_TEST} ${EXAMPLE_TEST_FILE} )
117+
add_executable(${EXAMPLE_TEST} ${EXAMPLE_TEST_FILE} tests/test_utils.cpp)
118118

119119
target_include_directories(${EXAMPLE_TEST} PUBLIC
120120
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

cpp/example_code/s3/gtests/CMakeLists.txt

+45-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
# Set the minimum required version of CMake for this project.
55
cmake_minimum_required(VERSION 3.14)
66

7+
set(EXAMPLE_SERVICE_NAME "s3")
8+
set(CURRENT_TARGET "${EXAMPLE_SERVICE_NAME}_gtest")
9+
set(CURRENT_TARGET_AWS_DEPENDENCIES s3 sts)
10+
711
# Set this project's name.
8-
project("s3-examples-gtests")
12+
project("${EXAMPLE_SERVICE_NAME}-examples-gtests" )
913

1014
# Set the C++ standard to use to build this target.
1115
set(CMAKE_CXX_STANDARD 14)
@@ -31,36 +35,42 @@ if(NOT BUILD_SHARED_LIBS)
3135
set(BUILD_SHARED_LIBS ON)
3236
endif()
3337

38+
set(CMAKE_BUILD_TYPE Debug)
39+
3440
# Find the AWS SDK for C++ package.
35-
find_package(AWSSDK REQUIRED COMPONENTS s3 sts)
41+
find_package(AWSSDK REQUIRED COMPONENTS ${CURRENT_TARGET_AWS_DEPENDENCIES})
3642

3743
add_executable(
38-
s3_gtest
44+
${CURRENT_TARGET}
3945
)
4046

41-
4247
# If the compiler is some version of Microsoft Visual C++, or another compiler simulating C++,
4348
# and building as shared libraries, then dynamically link to those shared libraries.
4449
if(MSVC AND BUILD_SHARED_LIBS)
4550
add_definitions(-DUSE_IMPORT_EXPORT)
4651
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
47-
list(APPEND SERVICE_LIST s3 sts)
52+
list(APPEND SERVICE_LIST ${CURRENT_TARGET_AWS_DEPENDENCIES})
4853
#For IDE's like Xcode and Visual Studio this line will be ignored because Release/Debug
4954
# is switched internally, but this is necessary for non-IDE builds.
50-
set(CMAKE_BUILD_TYPE Debug) #TODO: Set to your build type.
55+
5156

5257
#TODO:Choose which of the following two lines to use to copy to the same folder where your executables are.
53-
AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) #Choose this line if your executables are in /build/Debug
54-
#AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}) #Choose this line for Visual Studio and possibly other IDEs.
58+
AWSSDK_CPY_DYN_LIBS(
59+
SERVICE_LIST
60+
""
61+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
62+
) #Choose this line if your executables are in /build/Debug
63+
5564
add_custom_command(
56-
TARGET s3_gtest POST_BUILD
65+
TARGET
66+
${CURRENT_TARGET}
67+
POST_BUILD
5768
COMMAND ${CMAKE_COMMAND} -E copy
58-
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/gtest_main.dll
59-
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/gtest.dll
60-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
69+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${CMAKE_BUILD_TYPE}/gtest.dll
70+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
71+
)
6172
endif()
6273

63-
6474
# Check whether the target system is Windows, including Win64.
6575
if(WIN32)
6676
# Check whether the compiler is some version of Microsoft Visual C++, or another compiler simulating C++.
@@ -72,8 +82,10 @@ endif()
7282

7383
enable_testing()
7484

75-
file(GLOB GTEST_SOURCE_FILES
76-
"gtest_*.cpp"
85+
file(
86+
GLOB
87+
GTEST_SOURCE_FILES
88+
"gtest_*.cpp"
7789
)
7890

7991
foreach(TEST_FILE ${GTEST_SOURCE_FILES})
@@ -83,29 +95,37 @@ foreach(TEST_FILE ${GTEST_SOURCE_FILES})
8395
else()
8496
message("Error: no associated source file found for ${TEST_FILE}")
8597
endif()
86-
8798
endforeach()
8899

89-
90100
target_sources(
91-
s3_gtest
101+
${CURRENT_TARGET}
92102
PUBLIC
93103
${GTEST_SOURCE}
104+
test_main.cpp
94105
)
95106

96-
target_include_directories(s3_gtest PUBLIC
107+
target_include_directories(
108+
${CURRENT_TARGET}
109+
PUBLIC
97110
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
98-
$<INSTALL_INTERFACE:../include>)
111+
$<INSTALL_INTERFACE:../include>
112+
)
99113

100-
target_compile_definitions(s3_gtest PUBLIC
101-
TESTING_BUILD)
114+
target_compile_definitions(
115+
${CURRENT_TARGET}
116+
PUBLIC
117+
TESTING_BUILD
118+
)
102119

103120
target_link_libraries(
104-
s3_gtest
105-
GTest::gtest_main
121+
${CURRENT_TARGET}
122+
GTest::gtest
106123
${AWSSDK_LINK_LIBRARIES}
107124
${AWSSDK_PLATFORM_DEPS}
108125
)
109126

110127
include(GoogleTest)
111-
gtest_discover_tests(s3_gtest)
128+
gtest_add_tests(
129+
TARGET
130+
${CURRENT_TARGET}
131+
)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "gtest/gtest.h"
7+
8+
int main(int argc, char **argv) {
9+
::testing::InitGoogleTest(&argc, argv);
10+
return RUN_ALL_TESTS();
11+
}

cpp/example_code/s3/include/awsdoc/s3/s3_examples.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ namespace AwsDoc
3636
AWSDOC_S3_API bool GetWebsiteConfig(const Aws::String& bucketName,
3737
const Aws::String& region = "");
3838
AWSDOC_S3_API bool ListBuckets();
39+
AWSDOC_S3_API bool ListBucketDisablingDnsCache( const Aws::String& region = "");
3940
AWSDOC_S3_API bool ListObjects(const Aws::String& bucketName,
4041
const Aws::String& region = "");
41-
AWSDOC_S3_API bool PutBucketAcl(const Aws::String& bucketName,
42-
const Aws::String& ownerID,
43-
const Aws::String& granteePermission,
42+
AWSDOC_S3_API bool PutBucketAcl(const Aws::String& bucketName,
43+
const Aws::String& ownerID,
44+
const Aws::String& granteePermission,
4445
const Aws::String& granteeType,
45-
const Aws::String& region,
46-
const Aws::String& granteeID = "",
46+
const Aws::String& granteeID,
47+
const Aws::String& region,
4748
const Aws::String& granteeDisplayName = "",
4849
const Aws::String& granteeEmailAddress = "",
4950
const Aws::String& granteeURI = "");

cpp/example_code/s3/list_buckets_disabling_dns_cache.cpp

+38-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <aws/core/client/ClientConfiguration.h>
2424
#include <aws/core/http/curl/CurlHttpClient.h> //This example is for Linux only. See top.
2525
#include <aws/s3/S3Client.h>
26+
#include "awsdoc/s3/s3_examples.h"
2627

2728
using namespace Aws;
2829
using namespace Aws::Http;
@@ -83,6 +84,38 @@ class MyHttpClientFactory : public Aws::Http::HttpClientFactory
8384
}
8485
};
8586

87+
bool AwsDoc::S3::ListBucketDisablingDnsCache( const Aws::String& region)
88+
{
89+
SetHttpClientFactory(Aws::MakeShared<MyHttpClientFactory>(ALLOCATION_TAG));
90+
Aws::Client::ClientConfiguration config;
91+
if (!region.empty())
92+
{
93+
config.region = region;
94+
}
95+
96+
Aws::S3::S3Client s3Client(config);
97+
auto listBucketsOutcome = s3Client.ListBuckets();
98+
if (listBucketsOutcome.IsSuccess())
99+
{
100+
std::cout << "Found " << listBucketsOutcome.GetResult().GetBuckets().size() << " buckets" << std::endl;
101+
for (auto&& bucket : listBucketsOutcome.GetResult().GetBuckets())
102+
{
103+
std::cout << " " << bucket.GetName() << std::endl;
104+
}
105+
}
106+
else
107+
{
108+
std::cout << "Failed to list buckets. Error details:" << std::endl;
109+
std::cout << listBucketsOutcome.GetError() << std::endl;
110+
}
111+
112+
// reset the http client factory
113+
CleanupHttp();
114+
InitHttp();
115+
116+
return listBucketsOutcome.IsSuccess();
117+
}
118+
86119
/**
87120
* With AWS SDK for C++ version 1.8, it's much easier to override the default HTTP client configuration with the virtual functions: OverrideOptionsOn*Handle()
88121
* In this example, we override the default HTTP client and disable DNS caching with some low level Curl APIs.
@@ -92,26 +125,13 @@ int main(int argc, char *argv[])
92125
SDKOptions options;
93126
options.loggingOptions.logLevel = Utils::Logging::LogLevel::Trace;
94127
InitAPI(options);
95-
{
96-
SetHttpClientFactory(Aws::MakeShared<MyHttpClientFactory>(ALLOCATION_TAG));
97128

98-
Aws::S3::S3Client s3Client;
99-
auto listBucketsOutcome = s3Client.ListBuckets();
100-
if (listBucketsOutcome.IsSuccess())
101-
{
102-
std::cout << "Found " << listBucketsOutcome.GetResult().GetBuckets().size() << " buckets" << std::endl;
103-
for (auto&& bucket : listBucketsOutcome.GetResult().GetBuckets())
104-
{
105-
std::cout << " " << bucket.GetName() << std::endl;
106-
}
107-
}
108-
else
109-
{
110-
std::cout << "Failed to list buckets. Error details:" << std::endl;
111-
std::cout << listBucketsOutcome.GetError() << std::endl;
112-
}
129+
int result = 0;
130+
if (!AwsDoc::S3::ListBucketDisablingDnsCache())
131+
{
132+
result = 1;
113133
}
114134

115135
ShutdownAPI(options);
116-
return 0;
136+
return result;
117137
}

cpp/example_code/s3/tests/test_delete_bucket_policy.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <aws/s3/model/PutBucketPolicyRequest.h>
1111
#include <aws/s3/model/DeleteBucketRequest.h>
1212
#include <awsdoc/s3/s3_examples.h>
13+
#include "test_utils.h"
1314

1415
int main()
1516
{
@@ -46,6 +47,12 @@ int main()
4647
return 1;
4748
}
4849

50+
Aws::String user_arn = AwsTest::TestUtils::getArnForUser(config);
51+
if (user_arn.empty())
52+
{
53+
return 1;
54+
}
55+
4956
// 2/4. Create the bucket policy, and then add the bucket policy
5057
// to the bucket.
5158
Aws::String policy_string =
@@ -55,7 +62,9 @@ int main()
5562
" {\n"
5663
" \"Sid\": \"1\",\n"
5764
" \"Effect\": \"Allow\",\n"
58-
" \"Principal\": {\"AWS\":\"*\"},\n"
65+
" \"Principal\": {\n"
66+
" \"AWS\": \"" + user_arn + "\"\n"
67+
" },\n"
5968
" \"Action\": [\"s3:GetObject\"],\n"
6069
" \"Resource\": [\"arn:aws:s3:::" + bucket_name + "/*\"]\n"
6170
" }]\n"
@@ -77,9 +86,9 @@ int main()
7786
{
7887
auto err = create_outcome.GetError();
7988
std::cout << "Error: DeleteBucketPolicy test setup: Add bucket policy '" <<
80-
policy_string << "' to bucket '" << bucket_name << "': " <<
89+
policy_string << "' to bucket '" << bucket_name << "': " <<
8190
err.GetExceptionName() << ": " << err.GetMessage() << std::endl;
82-
std::cout << "To clean up, you must delete the bucket '" <<
91+
std::cout << "To clean up, you must delete the bucket '" <<
8392
bucket_name << "' yourself. " << std::endl;
8493

8594
return 1;

0 commit comments

Comments
 (0)