Skip to content

Commit

Permalink
C++:Cloudtrail legacy cleanup. (awsdocs#6377)
Browse files Browse the repository at this point in the history
* Cloudtrail update
  • Loading branch information
meyertst-aws authored Apr 29, 2024
1 parent ac774c4 commit 1a8b968
Show file tree
Hide file tree
Showing 20 changed files with 965 additions and 156 deletions.
42 changes: 41 additions & 1 deletion .doc_gen/metadata/cloudtrail_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ cloudtrail_CreateTrail:
- description:
snippet_tags:
- cloudtrail.Ruby.createTrail
C++:
versions:
- sdk_version: 1
github: cpp/example_code/cloudtrail
excerpts:
- description:
snippet_tags:
- cpp.example_code.cloudtrail.CreateTrail
services:
cloudtrail: {CreateTrail}
cloudtrail_ListTrailEvents:
cloudtrail_LookupEvents:
title: List &CT; trail events using an &AWS; SDK
title_abbrev: List trail events
synopsis: list &CTlong; trail events.
Expand All @@ -48,6 +56,14 @@ cloudtrail_ListTrailEvents:
- description:
snippet_tags:
- cloudtrail.Ruby.lookupEvents
C++:
versions:
- sdk_version: 1
github: cpp/example_code/cloudtrail
excerpts:
- description:
snippet_tags:
- cpp.example_code.cloudtrail.LookupEvents
services:
cloudtrail: {LookupEvents}
cloudtrail_DeleteTrail:
Expand All @@ -65,5 +81,29 @@ cloudtrail_DeleteTrail:
- description:
snippet_tags:
- cloudtrail.Ruby.deleteTrail
C++:
versions:
- sdk_version: 1
github: cpp/example_code/cloudtrail
excerpts:
- description:
snippet_tags:
- cpp.example_code.cloudtrail.DeleteTrail
services:
cloudtrail: {DeleteTrail}
cloudtrail_DescribeTrail:
title: Describe &CT; trails using an &AWS; SDK
title_abbrev: Describe trails
synopsis: describe &CTlong; trails.
category:
languages:
C++:
versions:
- sdk_version: 1
github: cpp/example_code/cloudtrail
excerpts:
- description:
snippet_tags:
- cpp.example_code.cloudtrail.DescribeTrails
services:
cloudtrail: {DescribeTrail}
89 changes: 64 additions & 25 deletions cpp/example_code/cloudtrail/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,67 @@
# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# This file is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of
# the License is located at
# http://aws.amazon.com/apache2.0/
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# Set the minimum required version of CMake for this project.
cmake_minimum_required(VERSION 3.13)
project(cloudtrail-examples)
set (CMAKE_CXX_STANDARD 11)

# Locate the aws sdk for c++ package.
find_package(AWSSDK REQUIRED COMPONENTS cloudtrail)

set(EXAMPLES "")
list(APPEND EXAMPLES "create_trail")
list(APPEND EXAMPLES "delete_trail")
list(APPEND EXAMPLES "describe_trails")
list(APPEND EXAMPLES "lookup_events")

# The executables to build.
foreach(EXAMPLE IN LISTS EXAMPLES)
add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
target_link_libraries(${EXAMPLE} ${AWSSDK_LINK_LIBRARIES})
endforeach()

set(SERVICE_NAME cloudtrail)
set(SERVICE_COMPONENTS cloudtrail)

# Set this project's name.
project("${SERVICE_NAME}-examples")

# Build shared libraries by default.
set(BUILD_SHARED_LIBS ON)

# Set the C++ standard to use to build this target.
set(CMAKE_CXX_STANDARD 11)

# Use the MSVC variable to determine if this is a Windows build.
set(WINDOWS_BUILD ${MSVC})

# Set the location of where Windows can find the installed libraries of the SDK.
if (WINDOWS_BUILD)
string(REPLACE ";" "/aws-cpp-sdk-all;" SYSTEM_MODULE_PATH "${CMAKE_SYSTEM_PREFIX_PATH}/aws-cpp-sdk-all")
list(APPEND CMAKE_PREFIX_PATH ${SYSTEM_MODULE_PATH})
endif ()

# Find the AWS SDK for C++ package.
find_package(AWSSDK REQUIRED COMPONENTS ${SERVICE_COMPONENTS})


if (WINDOWS_BUILD)
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.

# set(BIN_SUB_DIR "/Debug") # If you are building from the command line, you may need to uncomment this
# and set the proper subdirectory to the executables' location.

AWSSDK_CPY_DYN_LIBS(SERVICE_COMPONENTS "" ${CMAKE_CURRENT_BINARY_DIR} ${BIN_SUB_DIR})
endif ()


# AWSDOC_SOURCE can be defined in the command line to limit the files in a build. For example,
# you can limit files to one action.
if (NOT DEFINED AWSDOC_SOURCE)
file(GLOB AWSDOC_SOURCE
"*.cpp"
)
endif ()

foreach (file ${AWSDOC_SOURCE})
get_filename_component(EXAMPLE ${file} NAME_WE)

# Build the code example executables.
set(EXAMPLE_EXE run_${EXAMPLE})

add_executable(${EXAMPLE_EXE} ${file})

target_link_libraries(${EXAMPLE_EXE} ${AWSSDK_LINK_LIBRARIES}
${AWSSDK_PLATFORM_DEPS})

endforeach ()


if (BUILD_TESTS)
add_subdirectory(tests)
endif ()

10 changes: 10 additions & 0 deletions cpp/example_code/cloudtrail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ Next, for information on code example structures and how to build and run the ex
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Single actions

Code excerpts that show you how to call individual service functions.

- [Create trails](create_trail.cpp#L24) (`CreateTrail`)
- [Delete trail](delete_trail.cpp#L24) (`DeleteTrail`)
- [Describe trails](describe_trails.cpp#L23) (`DescribeTrail`)
- [List trail events](lookup_events.cpp#L23) (`LookupEvents`)


<!--custom.examples.start-->
<!--custom.examples.end-->

Expand Down
48 changes: 48 additions & 0 deletions cpp/example_code/cloudtrail/cloudtrail_samples.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0


#pragma once
#ifndef CLOUDTRAIL_EXAMPLES_CLOUDTRAIL_SAMPLES_H
#define CLOUDTRAIL_EXAMPLES_CLOUDTRAIL_SAMPLES_H

#include <aws/core/client/ClientConfiguration.h>

namespace AwsDoc {
namespace CloudTrail {
// Routine which creates an AWS CloudTrail trail.
/*!
\param trailName: The name of the CloudTrail trail.
\param bucketName: The Amazon S3 bucket designate for publishing logs.
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool createTrail(const Aws::String trailName, const Aws::String bucketName,
const Aws::Client::ClientConfiguration &clientConfig);

// Routine which deletes a CloudTrail trail.
/*!
\param trailName: The name of the CloudTrail trail.
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool deleteTrail(const Aws::String trailName,
const Aws::Client::ClientConfiguration &clientConfig);

// Routine which describes the CloudTrail trails in an account.
/*!
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool describeTrails(const Aws::Client::ClientConfiguration &clientConfig);

// Routine which looks up events captured by CloudTrail.
/*!
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool lookupEvents(const Aws::Client::ClientConfiguration &clientConfig);
} // CloudTrail
} // AwsDoc

#endif //CLOUDTRAIL_EXAMPLES_CLOUDTRAIL_SAMPLES_H
104 changes: 71 additions & 33 deletions cpp/example_code/cloudtrail/create_trail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,82 @@
#include <aws/cloudtrail/model/CreateTrailRequest.h>
#include <aws/cloudtrail/model/CreateTrailResult.h>
#include <iostream>
#include "cloudtrail_samples.h"

/**
* Creates a cloud trail on command line input
*/

int main(int argc, char **argv)
{
if (argc != 3)
{
std::cout << "Usage: create_trail <trail_name> <bucket_name>";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::String trail_name(argv[1]);
Aws::String bucket_name(argv[2]);

Aws::CloudTrail::CloudTrailClient ct;

Aws::CloudTrail::Model::CreateTrailRequest ct_req;
ct_req.SetName(trail_name);
ct_req.SetS3BucketName(bucket_name);

auto ct_out = ct.CreateTrail(ct_req);

if (ct_out.IsSuccess())
{
std::cout << "Successfully created cloud trail" << std::endl;
* Before running this C++ code example, set up your development environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*
* For information on the structure of the code examples and how to build and run the examples, see
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html.
*
**/

// snippet-start:[cpp.example_code.cloudtrail.CreateTrail]
// Routine which creates an AWS CloudTrail trail.
/*!
\param trailName: The name of the CloudTrail trail.
\param bucketName: The Amazon S3 bucket designate for publishing logs.
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc::CloudTrail::createTrail(const Aws::String trailName,
const Aws::String bucketName,
const Aws::Client::ClientConfiguration &clientConfig) {
Aws::CloudTrail::CloudTrailClient trailClient(clientConfig);
Aws::CloudTrail::Model::CreateTrailRequest request;
request.SetName(trailName);
request.SetS3BucketName(bucketName);

Aws::CloudTrail::Model::CreateTrailOutcome outcome = trailClient.CreateTrail(
request);
if (outcome.IsSuccess()) {
std::cout << "Successfully created trail " << trailName << std::endl;
}
else {
std::cerr << "Failed to create trail " << trailName <<
": " << outcome.GetError().GetMessage() << std::endl;
}

return outcome.IsSuccess();
}
// snippet-end:[cpp.example_code.cloudtrail.CreateTrail]

else
/*
*
* main function
*
* Usage: 'run_create_trail <trail_name> <bucket_name>'
*
* Prerequisites: An existing Amazon S3 bucket.
*
*/

#ifndef TESTING_BUILD

int main(int argc, char **argv) {
if (argc != 3) {
std::cout << "Usage: 'run_create_trail <trail_name> <bucket_name>'";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
std::cout << "Error creating cloud trail " << ct_out.GetError().GetMessage()
<< std::endl;
Aws::String trailName(argv[1]);
Aws::String bucketName(argv[2]);

Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";

AwsDoc::CloudTrail::createTrail(trailName, bucketName, clientConfig);
}
}

Aws::ShutdownAPI(options);
return 0;
Aws::ShutdownAPI(options);
return 0;
}

#endif // TESTING_BUILD
Loading

0 comments on commit 1a8b968

Please sign in to comment.