Make sample service an object library (#3728)

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2022-06-08 16:25:45 -07:00 коммит произвёл GitHub
Родитель 99f45a5f18
Коммит 6aac5aba17
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 39 добавлений и 29 удалений

Просмотреть файл

@ -10,8 +10,11 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(
service
INTERFACE
OBJECT
inc/azure/service/client.hpp
)
src/client.cpp
)
target_include_directories(service INTERFACE inc)
target_link_libraries(service PUBLIC azure-core)
target_include_directories(service PUBLIC inc)

Просмотреть файл

@ -3,9 +3,11 @@
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/credentials/credentials.hpp>
#include <memory>
#include <string>
#include <utility>
namespace Azure { namespace Service {
@ -26,32 +28,13 @@ namespace Azure { namespace Service {
static_cast<void>(serviceUrl); // to suppress the "unused variable" warning.
}
void DoSomething(const Core::Context& context) const
{
static_cast<void>(context); // to suppress the "unused variable" warning.
// This method does nothing, because the purpose of this class is to demonstrate
// how Azure::Identity classes can be used with a generic Azure SDK service client.
// If we have code here that gets the token, it would be up to the user to set it up to be
// valid enough to get a token, which is not critical for the intended demonstration purposes.
// And if user runs this, and authentication is unsuccessful, it may draw an unnecessary
// attention to an irrelevant (to the demo) point.
// But an oversimplified logic of what a typical Azure SDK client does is below:
#if (0)
// Every client has its own scope. We use management.azure.com here as an example.
Core::Credentials::TokenRequestContext azureServiceClientContext;
azureServiceClientContext.Scopes = {"https://management.azure.com/"};
auto authenticationToken = m_credential->GetToken(azureServiceClientContext, context);
// Now that it has a token, Client can authorize and DoSomething().
// ...
// ...
static_cast<void>(authenticationToken); // to suppress the "unused variable" warning.
#endif
}
// This method does nothing, because the purpose of this class is to demonstrate how
// Azure::Identity classes can be used with a generic Azure SDK service client. If we have code
// here that gets the token, it would be up to the user to set it up to be valid enough to get a
// token, which is not critical for the intended demonstration purposes. And if user runs this,
// and authentication is unsuccessful, it may draw an unnecessary attention to an irrelevant (to
// the demo) point.
void DoSomething(const Core::Context& context) const;
};
}} // namespace Azure::Service

Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/service/client.hpp"
void Azure::Service::Client::DoSomething(const Azure::Core::Context& context) const
{
static_cast<void>(context); // to suppress the "unused variable" warning.
// An oversimplified logic of what a typical Azure SDK client does is below:
#if (0)
// Every client has its own scope. We use management.azure.com here as an example.
Core::Credentials::TokenRequestContext azureServiceClientContext;
azureServiceClientContext.Scopes = {"https://management.azure.com/"};
auto authenticationToken = m_credential->GetToken(azureServiceClientContext, context);
// Now that it has a token, Client can authorize and DoSomething().
// ...
// ...
static_cast<void>(authenticationToken); // to suppress the "unused variable" warning.
#endif
}