Update the workload identity credential sample to work with required environment variables that need to be set. (#4924)

* Update the workload identity credential sample to work with required environment variables that need to be set.

* Fix clang format.
This commit is contained in:
Ahson Khan 2023-09-06 10:25:26 -07:00 committed by GitHub
parent 0ad52a028c
commit f7452cc233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,10 +9,19 @@
// The following environment variables must be set before running the sample.
// * AZURE_TENANT_ID: Tenant ID for the Azure account.
// * AZURE_CLIENT_ID: The Client ID to authenticate the request.
// * AZURE_CLIENT_CERTIFICATE_PATH: The path to a client certificate.
// * AZURE_FEDERATED_TOKEN_FILE: The path of a file containing a Kubernetes service account token.
std::string GetTenantId() { return std::getenv("AZURE_TENANT_ID"); }
std::string GetClientId() { return std::getenv("AZURE_CLIENT_ID"); }
std::string GetTokenFilePath() { return std::getenv("AZURE_FEDERATED_TOKEN_FILE"); }
std::string GetTokenFilePath()
{
char const* const tokenFilePath{std::getenv("AZURE_FEDERATED_TOKEN_FILE")};
if (tokenFilePath == nullptr)
{
std::cerr << "Missing environment variable AZURE_FEDERATED_TOKEN_FILE" << std::endl;
return std::string();
}
return tokenFilePath;
}
int main()
{