2024-03-11 18:26:55 -04:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* 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.
*
**/
# include <aws/acm/ACMClient.h>
# include <aws/acm/model/ListCertificatesRequest.h>
# include "acm_samples.h"
// snippet-start:[cpp.example_code.acm.ListCertificates]
//! List the AWS Certificate Manager (ACM) certificates in an account.
/*!
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc : : ACM : : listCertificates (
const Aws : : Client : : ClientConfiguration & clientConfiguration ) {
Aws : : ACM : : ACMClient acmClient ( clientConfiguration ) ;
Aws : : ACM : : Model : : ListCertificatesRequest request ;
2024-04-24 14:30:38 -04:00
Aws : : Vector < Aws : : ACM : : Model : : CertificateSummary > allCertificates ;
Aws : : String nextToken ;
do {
if ( ! nextToken . empty ( ) ) {
request . SetNextToken ( nextToken ) ;
}
2024-03-11 18:26:55 -04:00
2024-04-24 14:30:38 -04:00
Aws : : ACM : : Model : : ListCertificatesOutcome outcome =
acmClient . ListCertificates ( request ) ;
2024-03-11 18:26:55 -04:00
2024-04-24 14:30:38 -04:00
if ( ! outcome . IsSuccess ( ) ) {
std : : cerr < < " Error: ListCertificates: " < <
outcome . GetError ( ) . GetMessage ( ) < < std : : endl ;
2024-03-11 18:26:55 -04:00
2024-04-24 14:30:38 -04:00
return false ;
}
else {
const Aws : : ACM : : Model : : ListCertificatesResult & result = outcome . GetResult ( ) ;
2024-03-11 18:26:55 -04:00
2024-04-24 14:30:38 -04:00
const Aws : : Vector < Aws : : ACM : : Model : : CertificateSummary > & certificates =
result . GetCertificateSummaryList ( ) ;
allCertificates . insert ( allCertificates . end ( ) , certificates . begin ( ) ,
certificates . end ( ) ) ;
2024-03-11 18:26:55 -04:00
2024-04-24 14:30:38 -04:00
nextToken = result . GetNextToken ( ) ;
2024-03-11 18:26:55 -04:00
}
2024-04-24 14:30:38 -04:00
} while ( ! nextToken . empty ( ) ) ;
if ( ! allCertificates . empty ( ) ) {
for ( const Aws : : ACM : : Model : : CertificateSummary & certificate : allCertificates ) {
std : : cout < < " Certificate ARN: " < <
certificate . GetCertificateArn ( ) < < std : : endl ;
std : : cout < < " Domain name: " < <
certificate . GetDomainName ( ) < < std : : endl < < std : : endl ;
2024-03-11 18:26:55 -04:00
}
}
2024-04-24 14:30:38 -04:00
else {
std : : cout < < " No available certificates found in account. "
< < std : : endl ;
}
return true ;
2024-03-11 18:26:55 -04:00
}
// snippet-end:[cpp.example_code.acm.ListCertificates]
/*
*
* main function
*
* Usage: 'run_list_certificates'
*
*/
# ifndef TESTING_BUILD
int main ( int argc , char * * argv ) {
Aws : : SDKOptions options ;
Aws : : InitAPI ( options ) ;
{
Aws : : Client : : ClientConfiguration clientConfig ;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
AwsDoc : : ACM : : listCertificates ( clientConfig ) ;
}
Aws : : ShutdownAPI ( options ) ;
return 0 ;
}
# endif // TESTING_BUILD