From c4678c9a10f3b7f0bc9545f3a5a603da09820863 Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Thu, 17 Mar 2022 12:20:15 -0700 Subject: [PATCH] Add smoketest MVP (#3440) * initial setup * smoke sample * cleanup * typo * typo 2 * typo 3 * daniel's feedback --- CMakeLists.txt | 1 + .../vcpkg-all-smoke/CMakeLists.txt | 37 +++++++++++++ samples/integration/vcpkg-all-smoke/LICENSE | 21 ++++++++ samples/integration/vcpkg-all-smoke/README.md | 53 +++++++++++++++++++ .../integration/vcpkg-all-smoke/src/main.cpp | 46 ++++++++++++++++ samples/integration/vcpkg-keyvault/README.md | 4 +- 6 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 samples/integration/vcpkg-all-smoke/CMakeLists.txt create mode 100644 samples/integration/vcpkg-all-smoke/LICENSE create mode 100644 samples/integration/vcpkg-all-smoke/README.md create mode 100644 samples/integration/vcpkg-all-smoke/src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 735823d3d..f56c610fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,4 +103,5 @@ add_subdirectory(sdk/template) if(BUILD_SAMPLES) add_subdirectory(samples/integration/vcpkg-keyvault) + add_subdirectory(samples/integration/vcpkg-all-smoke) endif() diff --git a/samples/integration/vcpkg-all-smoke/CMakeLists.txt b/samples/integration/vcpkg-all-smoke/CMakeLists.txt new file mode 100644 index 000000000..ab28da2e4 --- /dev/null +++ b/samples/integration/vcpkg-all-smoke/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT + +# vcpkg integration. +if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "") +endif() +if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET) + set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "") +endif() + +# Project set up +cmake_minimum_required(VERSION 3.13) +project(smoketest-vcpkg LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +add_executable ( + smoketest-vcpkg + src/main +) + +# Link to Azure SDK +target_link_libraries(smoketest-vcpkg + PRIVATE + Azure::azure-security-keyvault-keys + Azure::azure-security-keyvault-certificates + Azure::azure-security-keyvault-secrets + Azure::azure-identity + get-env-helper +) + +# Add the sample to be run on CI. +# CI pipeline reads the {service}-samples.txt and runs the binaries listed there. +file(APPEND ${CMAKE_BINARY_DIR}/attestation-samples.txt "${CMAKE_CURRENT_BINARY_DIR}/smoketest-vcpkg\n") +file(APPEND ${CMAKE_BINARY_DIR}/keyvault-samples.txt "${CMAKE_CURRENT_BINARY_DIR}/smoketest-vcpkg\n") diff --git a/samples/integration/vcpkg-all-smoke/LICENSE b/samples/integration/vcpkg-all-smoke/LICENSE new file mode 100644 index 000000000..51b6a76e5 --- /dev/null +++ b/samples/integration/vcpkg-all-smoke/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) Microsoft Corporation. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --git a/samples/integration/vcpkg-all-smoke/README.md b/samples/integration/vcpkg-all-smoke/README.md new file mode 100644 index 000000000..c706e36c9 --- /dev/null +++ b/samples/integration/vcpkg-all-smoke/README.md @@ -0,0 +1,53 @@ +# Smoketest the Azure SDK for C++ into your application using vcpkg + +This application instantiates all the sdk clients, and call one API from each in order to check their side by side capabilities + +## Pre-requisites + +There are two options to set up the development environment: + +### Manual installation + +Install the [Azure SDK for C++ dependencies](https://github.com/Azure/azure-sdk-for-cpp/blob/main/CONTRIBUTING.md#third-party-dependencies). + +- CMake project (min version 3.13). +- C++ version 14 or greater. + +## Build + +### Linux terminal + +```bash +# +# Building the application. +# Instructions from application root directory. +# + +# Create build directory just the first time. +mkdir build +cd build + +# Generate and build +# This code assumes that the SDK dependencies were installed with vcpkg +# When using docker provided container, the TOOLCHAIN option is not required (cmake ..). +cmake -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/scripts/buildsystems/vcpkg.cmake .. +cmake -build . +``` + +### Windows VS + +If you are using Visual Studio, the toolchain to link vcpkg is set with `CMakeSettings.json`. Update this file and set the vcpkg toolchain file for vcpkg (VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake). After setting the toolchain, VS can generate and build the sample. Use VS to open the sample folder only. + +## Run application + +Review source code header for `environment variables` that must be set up before running the app. + +```bash +# +# Running the Application +# Instructions from inside the build directory. +# + +# Run binary (.exe on Windows) +./smoketest-vcpkg +``` diff --git a/samples/integration/vcpkg-all-smoke/src/main.cpp b/samples/integration/vcpkg-all-smoke/src/main.cpp new file mode 100644 index 000000000..a68af64a3 --- /dev/null +++ b/samples/integration/vcpkg-all-smoke/src/main.cpp @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @brief This sample provides smoke test for the sdks to ensure side by side works properly + * + * @remark The following environment variables must be set before running the sample. + * - AZURE_KEYVAULT_URL: To the Key Vault account URL. + * - AZURE_TENANT_ID: Tenant ID for the Azure account. + * - AZURE_CLIENT_ID: The Client ID to authenticate the request. + * - AZURE_CLIENT_SECRET: The client secret. + * + */ + +#include "get_env.hpp" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace Azure::Security::KeyVault::Keys; +using namespace Azure::Security::KeyVault::Secrets; +using namespace Azure::Security::KeyVault::Certificates; + +int main() +{ + auto tenantId = "tenant"; + auto clientId = "client"; + auto clientSecret = "secret"; + auto credential + = std::make_shared(tenantId, clientId, clientSecret); + + // instantiate the clients + KeyClient keyClient(std::getenv("AZURE_KEYVAULT_URL"), credential); + SecretClient secretClient(std::getenv("AZURE_KEYVAULT_URL"), credential); + CertificateClient certificateClient(std::getenv("AZURE_KEYVAULT_URL"), credential); + + return 0; +} diff --git a/samples/integration/vcpkg-keyvault/README.md b/samples/integration/vcpkg-keyvault/README.md index f5fa3c491..dd7e4b705 100644 --- a/samples/integration/vcpkg-keyvault/README.md +++ b/samples/integration/vcpkg-keyvault/README.md @@ -1,6 +1,6 @@ # Integrating the Azure SDK for C++ into your application using vcpkg -This application shows how to integrate the Azure SDK for C++ in your application. It uses vcpkg to adquire and build the Azure SDK for C++ client libraries. Your CMake project needs to link the libraries from vcpkg by setting the toolchain file to vcpkg (shown below). +This application shows how to integrate the Azure SDK for C++ in your application. It uses vcpkg to acquire and build the Azure SDK for C++ client libraries. Your CMake project needs to link the libraries from vcpkg by setting the toolchain file to vcpkg (shown below). ## Pre-requisites @@ -50,7 +50,7 @@ cmake -build . ### Windows VS -If you are using Visual Studio, the toolchain to link vcpkg is set with `CMakeSettings.json`. Upate this file and set the vcpkg toolchain file for vcpkg (VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake). After setting the toolchain, VS can generate and build the sample. Use VS to open the sample folder only. +If you are using Visual Studio, the toolchain to link vcpkg is set with `CMakeSettings.json`. Update this file and set the vcpkg toolchain file for vcpkg (VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake). After setting the toolchain, VS can generate and build the sample. Use VS to open the sample folder only. ## Run application