2021-11-15 13:15:43 +00:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
# include <aws/core/Aws.h>
# include <aws/codebuild/CodeBuildClient.h>
# include <aws/codebuild/model/ListProjectsRequest.h>
# include <aws/codebuild/model/ListProjectsResult.h>
# include <iostream>
2024-05-01 11:03:07 -04:00
# include "codebuild_samples.h"
2021-11-15 13:15:43 +00:00
/**
2024-05-01 11:03:07 -04:00
* 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.codebuild.ListProjects]
//! List the CodeBuild projects.
/*!
\param sortType: 'SortOrderType' type.
\param clientConfiguration: AWS client configuration.
\return bool: Function succeeded.
2021-11-15 13:15:43 +00:00
*/
2024-05-01 11:03:07 -04:00
bool AwsDoc : : CodeBuild : : listProjects ( Aws : : CodeBuild : : Model : : SortOrderType sortType ,
const Aws : : Client : : ClientConfiguration & clientConfiguration ) {
Aws : : CodeBuild : : CodeBuildClient codeBuildClient ( clientConfiguration ) ;
2021-11-15 13:15:43 +00:00
2024-05-01 11:03:07 -04:00
Aws : : CodeBuild : : Model : : ListProjectsRequest listProjectsRequest ;
listProjectsRequest . SetSortOrder ( sortType ) ;
Aws : : String nextToken ; // Next token for pagination.
Aws : : Vector < Aws : : String > allProjects ;
do {
if ( ! nextToken . empty ( ) ) {
listProjectsRequest . SetNextToken ( nextToken ) ;
}
Aws : : CodeBuild : : Model : : ListProjectsOutcome outcome = codeBuildClient . ListProjects (
listProjectsRequest ) ;
if ( outcome . IsSuccess ( ) ) {
const Aws : : Vector < Aws : : String > & projects = outcome . GetResult ( ) . GetProjects ( ) ;
allProjects . insert ( allProjects . end ( ) , projects . begin ( ) , projects . end ( ) ) ;
nextToken = outcome . GetResult ( ) . GetNextToken ( ) ;
}
else {
std : : cerr < < " Error listing projects " < < outcome . GetError ( ) . GetMessage ( )
< < std : : endl ;
}
} while ( ! nextToken . empty ( ) ) ;
std : : cout < < allProjects . size ( ) < < " project(s) found. " < < std : : endl ;
for ( auto project : allProjects ) {
std : : cout < < project < < std : : endl ;
2021-11-15 13:15:43 +00:00
}
2024-05-01 11:03:07 -04:00
return true ;
}
// snippet-end:[cpp.example_code.codebuild.ListProjects]
/*
*
* main function
*
* Usage: 'Usage: run_list_projects <ASCENDING | DESCENDING>'
*
*/
2021-11-15 13:15:43 +00:00
2024-05-01 11:03:07 -04:00
# ifndef TESTING_BUILD
int main ( int argc , char * * argv ) {
if ( argc ! = 2 ) {
std : : cout < < " Usage: run_list_projects <ASCENDING | DESCENDING> " ;
return 1 ;
2021-11-15 13:15:43 +00:00
}
2024-05-01 11:03:07 -04:00
Aws : : SDKOptions options ;
Aws : : InitAPI ( options ) ;
2021-11-15 13:15:43 +00:00
{
2024-05-01 11:03:07 -04:00
Aws : : String sortOrderType = argv [ 1 ] ;
Aws : : CodeBuild : : Model : : SortOrderType sortType = Aws : : CodeBuild : : Model : : SortOrderType : : NOT_SET ;
if ( Aws : : Utils : : StringUtils : : CaselessCompare ( argv [ 1 ] , " ASCENDING " ) ) {
sortType = Aws : : CodeBuild : : Model : : SortOrderType : : ASCENDING ;
}
else if ( Aws : : Utils : : StringUtils : : CaselessCompare ( argv [ 1 ] , " DESCENDING " ) ) {
sortType = Aws : : CodeBuild : : Model : : SortOrderType : : DESCENDING ;
}
else {
std : : cout < < " Invalid sort order type. " < < std : : endl ;
}
Aws : : Client : : ClientConfiguration clientConfig ;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
2021-11-15 13:15:43 +00:00
2024-05-01 11:03:07 -04:00
AwsDoc : : CodeBuild : : listProjects ( sortType , clientConfig ) ;
}
Aws : : ShutdownAPI ( options ) ;
return 0 ;
2021-11-15 13:15:43 +00:00
}
2024-05-01 11:03:07 -04:00
# endif // TESTING_BUILD