// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #include #include #include #include #include #include "codebuild_samples.h" /** * 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. */ bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); Aws::CodeBuild::Model::ListProjectsRequest listProjectsRequest; listProjectsRequest.SetSortOrder(sortType); Aws::String nextToken; // Next token for pagination. Aws::Vector allProjects; do { if (!nextToken.empty()) { listProjectsRequest.SetNextToken(nextToken); } Aws::CodeBuild::Model::ListProjectsOutcome outcome = codeBuildClient.ListProjects( listProjectsRequest); if (outcome.IsSuccess()) { const Aws::Vector &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; } return true; } // snippet-end:[cpp.example_code.codebuild.ListProjects] /* * * main function * * Usage: 'Usage: run_list_projects ' * */ #ifndef TESTING_BUILD int main(int argc, char **argv) { if (argc != 2) { std::cout << "Usage: run_list_projects "; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { 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"; AwsDoc::CodeBuild::listProjects(sortType, clientConfig); } Aws::ShutdownAPI(options); return 0; } #endif // TESTING_BUILD