From 0b0c957209c80f4d85eb337a4d1c3bd74a038e89 Mon Sep 17 00:00:00 2001 From: Su Shi <1684739+metacpp@users.noreply.github.com> Date: Fri, 17 Nov 2017 12:57:28 -0800 Subject: [PATCH] Hotfix: update the logic to get path of access tokens. (#198) * Hotfix: update the logic to get path of access tokens. 1. Add logic to read path of access tokens through environment variable. 2. Add fallback logic to default one. Notice: this is short-term fix and require user to use latest version of provider in Cloud Shell. * add missed package caused by Go extension in VS Code. * Update TODO with issue# and update the changelog.md. --- CHANGELOG.md | 7 +++++++ autorest/azure/cli/token.go | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbfd85fbe..fe7b24f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## v9.4.1 + +### Bug Fixes + +- Update the AccessTokensPath() to read access tokens path through AZURE_ACCESS_TOKEN_FILE. If this +environment variable is not set, it will fall back to use default path set by Azure CLI. + ## v9.4.0 ### New Features diff --git a/autorest/azure/cli/token.go b/autorest/azure/cli/token.go index b80b8e3fa..83b81c34b 100644 --- a/autorest/azure/cli/token.go +++ b/autorest/azure/cli/token.go @@ -62,8 +62,19 @@ func (t Token) ToADALToken() (converted adal.Token, err error) { } // AccessTokensPath returns the path where access tokens are stored from the Azure CLI +// TODO(#199): add unit test. func AccessTokensPath() (string, error) { - return homedir.Expand("~/.azure/accessTokens.json") + // Azure-CLI allows user to customize the path of access tokens thorugh environment variable. + var accessTokenPath = os.Getenv("AZURE_ACCESS_TOKEN_FILE") + var err error + + // Fallback logic to default path on non-cloud-shell environment. + // TODO(#200): remove the dependency on hard-coding path. + if accessTokenPath == "" { + accessTokenPath, err = homedir.Expand("~/.azure/accessTokens.json") + } + + return accessTokenPath, err } // ParseExpirationDate parses either a Azure CLI or CloudShell date into a time object