Skip to content

Commit

Permalink
Hotfix: update the logic to get path of access tokens. (#198)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
metacpp authored and marstr committed Nov 17, 2017
1 parent ab56713 commit 0b0c957
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 12 additions & 1 deletion autorest/azure/cli/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b0c957

Please sign in to comment.