Implement token request with Azure CLI. Inspired from the Azure C++ SDK's `AzureCliCredential`, this credential type attempts to run the Azure CLI in a shell and parse the token from its output. This is meant for development purposes, where a user has already installed the Azure CLI and logged in with their user account. Pass the following environment to the process: * PATH * HOME * AZURE_CONFIG_DIR Add a token factory to construct a token from the process output. Unlike in Azure Entra and IMDS, the CLI's JSON output does not contain 'expires_in', and the token key is in camel case. Signed-off-by: Nikos Dragazis <nikolaos.dragazis@scylladb.com>
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
/*
|
|
* Copyright (C) 2025 ScyllaDB
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "utils/rjson.hh"
|
|
#include "credentials.hh"
|
|
|
|
namespace azure {
|
|
|
|
class azure_cli_credentials : public credentials {
|
|
static constexpr char NAME[] = "AzureCliCredentials";
|
|
|
|
std::string_view get_name() const override { return NAME; };
|
|
static std::vector<sstring> make_env();
|
|
future<> refresh(const resource_type& resource_uri) override;
|
|
future<> do_refresh(const resource_type& resource_uri);
|
|
access_token make_token(const rjson::value&, const resource_type&);
|
|
public:
|
|
azure_cli_credentials(const sstring& logctx = "");
|
|
};
|
|
|
|
}
|
|
|
|
template <>
|
|
struct fmt::formatter<azure::azure_cli_credentials> {
|
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
|
auto format(const azure::azure_cli_credentials& creds, fmt::format_context& ctxt) const {
|
|
return fmt::format_to(ctxt.out(), "{}", *dynamic_cast<const azure::credentials*>(&creds));
|
|
}
|
|
}; |