fix(az): use platform specific folder

resolves #1567
This commit is contained in:
Jan De Dobbeleer 2022-01-13 20:25:24 +01:00 committed by Jan De Dobbeleer
parent f37a36aad1
commit b1c427abaa
2 changed files with 16 additions and 11 deletions

View file

@ -96,20 +96,24 @@ func (a *az) init(props Properties, env Environment) {
a.env = env
}
func (a *az) getFileContentWithoutBom(file string) string {
const ByteOrderMark = "\ufeff"
file = filepath.Join(a.env.homeDir(), file)
config := a.env.getFileContent(file)
return strings.TrimLeft(config, ByteOrderMark)
}
func (a *az) enabled() bool {
return a.getAzureProfile() || a.getAzureRmContext()
}
func (a *az) getFileContentWithoutBom(file string) string {
azFolder := ".azure"
if a.env.getRuntimeGOOS() == linuxPlatform {
azFolder = ".Azure"
}
file = filepath.Join(a.env.homeDir(), azFolder, file)
config := a.env.getFileContent(file)
const ByteOrderMark = "\ufeff"
return strings.TrimLeft(config, ByteOrderMark)
}
func (a *az) getAzureProfile() bool {
var content string
if content = a.getFileContentWithoutBom(".azure/azureProfile.json"); len(content) == 0 {
if content = a.getFileContentWithoutBom("azureProfile.json"); len(content) == 0 {
return false
}
var config AzureConfig
@ -127,7 +131,7 @@ func (a *az) getAzureProfile() bool {
func (a *az) getAzureRmContext() bool {
var content string
if content = a.getFileContentWithoutBom(".azure/AzureRmContext.json"); len(content) == 0 {
if content = a.getFileContentWithoutBom("AzureRmContext.json"); len(content) == 0 {
return false
}
var config AzurePowerShellConfig

View file

@ -57,8 +57,9 @@ func TestAzSegment(t *testing.T) {
content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
azureRmContext = string(content)
}
env.On("getFileContent", filepath.Join(home, ".azure/azureProfile.json")).Return(azureProfile)
env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext)
env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
env.On("getFileContent", filepath.Join(home, ".Azure", "azureProfile.json")).Return(azureProfile)
env.On("getFileContent", filepath.Join(home, ".Azure", "AzureRmContext.json")).Return(azureRmContext)
env.onTemplate()
props := properties{
SegmentTemplate: tc.Template,