From 546e42cd85cec7df1714827e79da2a2555c72f3b Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:57:01 +0100 Subject: [PATCH 01/18] test: Add some some helpers for our tests --- test/helpers_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/helpers_test.go diff --git a/test/helpers_test.go b/test/helpers_test.go new file mode 100644 index 0000000..6be6072 --- /dev/null +++ b/test/helpers_test.go @@ -0,0 +1,36 @@ +package aztx_test + +import ( + "fmt" + "path/filepath" + "reflect" + "runtime" + "testing" +) + +// assert fails the test if the condition is false. +func assert(tb testing.TB, condition bool, msg string, v ...interface{}) { + if !condition { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) + tb.FailNow() + } +} + +// ok fails the test if an err is not nil. +func ok(tb testing.TB, err error) { + if err != nil { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) + tb.FailNow() + } +} + +// equals fails the test if exp is not equal to act. +func equals(tb testing.TB, exp, act interface{}) { + if !reflect.DeepEqual(exp, act) { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) + tb.FailNow() + } +} From 2f68a84f23cf1065dd59a02aa66144e32a7de216 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:57:19 +0100 Subject: [PATCH 02/18] test: Add some sample data to work with --- test/azureProfile.json | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/azureProfile.json diff --git a/test/azureProfile.json b/test/azureProfile.json new file mode 100644 index 0000000..e97e14a --- /dev/null +++ b/test/azureProfile.json @@ -0,0 +1,47 @@ +{ + "installationId": "e960b7cc-c5d9-11ea-a6f5-00155d82a4f4", + "subscriptions": [ + { + "id": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", + "name": "Test Subscription 1", + "state": "Enabled", + "user": { + "name": "First Last", + "type": "user" + }, + "isDefault": false, + "tenantId": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", + "environmentName": "AzureCloud", + "homeTenantId": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", + "managedByTenants": [] + }, + { + "id": "9bb28eee-ebaa-442a-83ba-5511810fb151", + "name": "Test Subscription 2", + "state": "Enabled", + "user": { + "name": "First Last", + "type": "user" + }, + "isDefault": false, + "tenantId": "9bb28eee-ebaa-442a-83ba-5511810fb151", + "environmentName": "AzureCloud", + "homeTenantId": "9bb28eee-ebaa-442a-83ba-5511810fb151", + "managedByTenants": [] + }, + { + "id": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", + "name": "Test Subscription 3", + "state": "Enabled", + "user": { + "name": "First Last", + "type": "user" + }, + "isDefault": false, + "tenantId": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", + "environmentName": "AzureCloud", + "homeTenantId": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", + "managedByTenants": [] + } + ] +} From 506f7f56b90ab51a8b00fa7e753f441b1d129613 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:57:44 +0100 Subject: [PATCH 03/18] test: Functional testing --- test/aztx_function_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/aztx_function_test.go diff --git a/test/aztx_function_test.go b/test/aztx_function_test.go new file mode 100644 index 0000000..873e3e1 --- /dev/null +++ b/test/aztx_function_test.go @@ -0,0 +1,29 @@ +// +build !integration + +package aztx_test + +import ( + "testing" + + "github.com/google/uuid" + "github.com/riweston/aztx/cmd/aztx" +) + +func TestReadFile(t *testing.T) { + value := aztx.ReadAzureProfile("azureProfile.json") + equals(t, "Test Subscription 1", value.Subscriptions[0].Name) +} + +func TestWriteFile(t *testing.T) { + inputFile := aztx.ReadAzureProfile("azureProfile.json") + uuid, err := uuid.Parse("9e7969ef-4cb8-4a2d-959f-bfdaae452a3d") + if err != nil { + panic(err) + } + outFile := aztx.WriteAzureProfile(inputFile, uuid, "azureProfile_test.json") + ok(t, outFile) + value := aztx.ReadAzureProfile("azureProfile_test.json") + equals(t, true, value.Subscriptions[0].IsDefault) + equals(t, false, value.Subscriptions[1].IsDefault) + equals(t, false, value.Subscriptions[2].IsDefault) +} From b07263d4cc827822f4bbabf519e7875f1ce2bbd6 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:58:44 +0100 Subject: [PATCH 04/18] feat: Updated the scruct type to allow us to work with the file directly --- cmd/aztx/contexts.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 713c819..f3d3b50 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -21,24 +21,30 @@ import ( "fmt" "os/exec" + "github.com/google/uuid" "github.com/ktr0731/go-fuzzyfinder" ) -type Account struct { - CloudName string `json:"cloudName"` - HomeTenantID string `json:"homeTenantId"` - ID string `json:"id"` - IsDefault bool `json:"isDefault"` - ManagedByTenants []string `json:"managedByTenants"` - Name string `json:"name"` - State string `json:"state"` - TenantID string `json:"tenantId"` +type Subscription struct { + CloudName string `json:"cloudName"` + HomeTenantID uuid.UUID `json:"homeTenantId"` + ID uuid.UUID `json:"id"` + IsDefault bool `json:"isDefault"` + ManagedByTenants []string `json:"managedByTenants"` + Name string `json:"name"` + State string `json:"state"` + TenantID uuid.UUID `json:"tenantId"` User struct { Name string `json:"name"` AccountType string `json:"type"` } `json:"user"` } +type File struct { + InstallationID uuid.UUID `json:"installationId"` + Subscriptions []Subscription +} + func GetAzureAccounts() []byte { binary, errLook := exec.LookPath("az") if errLook != nil { @@ -72,7 +78,7 @@ func SetAzureAccountContext(accountname string) { func SelectAzureAccountsDisplayName() { d := GetAzureAccounts() - var Accounts []Account + var Accounts []Subscription err := json.Unmarshal(d, &Accounts) if err != nil { panic(err) From 9347abd5bc301cec93675b6bee294f7550ca7903 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:59:19 +0100 Subject: [PATCH 05/18] feat: Add the function to allow us to read the data --- cmd/aztx/contexts.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index f3d3b50..4c2e805 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -19,6 +19,8 @@ package aztx import ( "encoding/json" "fmt" + "io/ioutil" + "os" "os/exec" "github.com/google/uuid" @@ -94,3 +96,19 @@ func SelectAzureAccountsDisplayName() { SetAzureAccountContext(Accounts[idx].Name) fmt.Print(Accounts[idx].Name, "\n", Accounts[idx].ID, "\n") } + +func ReadAzureProfile(file string) File { + jsonFile, err := os.Open(file) + if err != nil { + fmt.Println(err) + } + byteValue, _ := ioutil.ReadAll(jsonFile) + var jsonData File + errJson := json.Unmarshal(byteValue, &jsonData) + if errJson != nil { + fmt.Println(err) + } + + return jsonData +} + From b6ec1700923cf4f42235c542bd90849eaab32ca0 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:59:34 +0100 Subject: [PATCH 06/18] feat: Add the function to write out our data --- cmd/aztx/contexts.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 4c2e805..e6de8e4 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -112,3 +112,18 @@ func ReadAzureProfile(file string) File { return jsonData } +func WriteAzureProfile(file File, id uuid.UUID, outFile string) error { + for idx, _ := range file.Subscriptions { + if file.Subscriptions[idx].ID == id { + file.Subscriptions[idx].IsDefault = true + } + } + + byteValue, err := json.Marshal(&file) + if err != nil { + return err + } + + err = ioutil.WriteFile(outFile, byteValue, 0666) + return err +} From 884cfe42fd42b17826cd31e2d4447c20f6417a43 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 10:59:49 +0100 Subject: [PATCH 07/18] chore: Update go required packages --- go.mod | 6 +++++- go.sum | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 128462f..4a6edbd 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,8 @@ module github.com/riweston/aztx go 1.16 -require github.com/ktr0731/go-fuzzyfinder v0.4.0 +require ( + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/ktr0731/go-fuzzyfinder v0.4.0 +) diff --git a/go.sum b/go.sum index 05b35e8..acfbee8 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,7 @@ github.com/Azure/go-autorest/autorest/validation v0.3.1/go.mod h1:yhLgjC0Wda5DYX github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= @@ -372,6 +373,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= From 40e2e59d17fa91a1f84eac83513fe8219a9fe745 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 11:58:37 +0100 Subject: [PATCH 08/18] fix: Strict type --- cmd/aztx/contexts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index e6de8e4..6553f61 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -76,6 +76,8 @@ func SetAzureAccountContext(accountname string) { if err != nil { panic(err.Error()) } + InstallationID uuid.UUID `json:"installationId"` + Subscriptions []Subscription `json:"subscriptions"` } func SelectAzureAccountsDisplayName() { From 6e7e1149a89c3166eed7eaa966f1795d6a4ab535 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 11:59:01 +0100 Subject: [PATCH 09/18] fix: Dodgy bug with formatting of azureProfile file --- cmd/aztx/contexts.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 6553f61..1544842 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -105,6 +105,7 @@ func ReadAzureProfile(file string) File { fmt.Println(err) } byteValue, _ := ioutil.ReadAll(jsonFile) + byteValue = bytes.TrimPrefix(byteValue, []byte("\xef\xbb\xbf")) var jsonData File errJson := json.Unmarshal(byteValue, &jsonData) if errJson != nil { From 2afd4558eecaebf42c8aa874ef9ea862a8942ddd Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 11:59:34 +0100 Subject: [PATCH 10/18] refactor: Stripped old az binary commands to manipulate only the file --- cmd/aztx/contexts.go | 56 +++++++++----------------------------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 1544842..5b7200e 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -17,11 +17,11 @@ limitations under the License. package aztx import ( + "bytes" "encoding/json" "fmt" "io/ioutil" "os" - "os/exec" "github.com/google/uuid" "github.com/ktr0731/go-fuzzyfinder" @@ -43,60 +43,26 @@ type Subscription struct { } type File struct { - InstallationID uuid.UUID `json:"installationId"` - Subscriptions []Subscription -} - -func GetAzureAccounts() []byte { - binary, errLook := exec.LookPath("az") - if errLook != nil { - panic(errLook) - } - - args := []string{"account", "list", "-o", "json"} - - out, err := exec.Command(binary, args...).CombinedOutput() - // TODO: This currently breaks when selecting context - if err != nil { - panic(err) - } - - return out -} - -func SetAzureAccountContext(accountname string) { - binary, errLook := exec.LookPath("az") - if errLook != nil { - panic(errLook) - } - - args := []string{"account", "set", "--subscription", accountname} - - _, err := exec.Command(binary, args...).Output() - if err != nil { - panic(err.Error()) - } InstallationID uuid.UUID `json:"installationId"` Subscriptions []Subscription `json:"subscriptions"` } func SelectAzureAccountsDisplayName() { - d := GetAzureAccounts() - var Accounts []Subscription - err := json.Unmarshal(d, &Accounts) - if err != nil { - panic(err) - } + home, _ := os.UserHomeDir() + azureProfile := home + "/.azure/azureProfile.json" + d := ReadAzureProfile(azureProfile) + idx, errFind := fuzzyfinder.Find( - Accounts, + d.Subscriptions, func(i int) string { - return Accounts[i].Name + return d.Subscriptions[i].Name }) - if errFind != nil { + if errFind == nil { panic(errFind) } - SetAzureAccountContext(Accounts[idx].Name) - fmt.Print(Accounts[idx].Name, "\n", Accounts[idx].ID, "\n") + + WriteAzureProfile(d, d.Subscriptions[idx].ID, azureProfile) + fmt.Print(d.Subscriptions[idx].Name, "\n", d.Subscriptions[idx].ID, "\n") } func ReadAzureProfile(file string) File { From 32b177fae9781289f129f57639c5db99bd5e20d8 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 12:01:26 +0100 Subject: [PATCH 11/18] docs: Add install instructions for brew --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 3af6edc..ae8c3f9 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,19 @@ ## Install +### Source + ```sh go install github.com/riweston/aztx ``` +### brew + +```sh +brew tap riweston/aztx +brew install aztx +``` + ## Usage ```sh From 5215131114164d42f9a4fc4af7f7fd4ab9158f6b Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 12:09:38 +0100 Subject: [PATCH 12/18] test: Update type on the helper function --- test/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers_test.go b/test/helpers_test.go index 6be6072..19adf7f 100644 --- a/test/helpers_test.go +++ b/test/helpers_test.go @@ -27,7 +27,7 @@ func ok(tb testing.TB, err error) { } // equals fails the test if exp is not equal to act. -func equals(tb testing.TB, exp, act interface{}) { +func equals(tb testing.TB, exp interface{}, act interface{}) { if !reflect.DeepEqual(exp, act) { _, file, line, _ := runtime.Caller(1) fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) From 7b1b79a90bec717f0d677ea6947573d252d2e675 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 12:23:04 +0100 Subject: [PATCH 13/18] ci: Ignore our helpers --- .github/workflows/ci.lint_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.lint_test.yml b/.github/workflows/ci.lint_test.yml index b650e7f..0f8978c 100644 --- a/.github/workflows/ci.lint_test.yml +++ b/.github/workflows/ci.lint_test.yml @@ -25,6 +25,7 @@ jobs: DEFAULT_BRANCH: master GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_GO: true + FILTER_REGEX_EXCLUDE: test/helpers_test.go Test: name: "CI: Go Tests" From 705811b17c62e76accd8fbc0e4371f3666a3ecb1 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 17:38:01 +0100 Subject: [PATCH 14/18] fix: Wrong keyname in this scruct --- cmd/aztx/contexts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 5b7200e..86e014e 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -28,7 +28,7 @@ import ( ) type Subscription struct { - CloudName string `json:"cloudName"` + EnvironmentName string `json:"environmentName"` HomeTenantID uuid.UUID `json:"homeTenantId"` ID uuid.UUID `json:"id"` IsDefault bool `json:"isDefault"` From 0d1bd92e2318ccac456e210965e54b46a12ef142 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 17:38:54 +0100 Subject: [PATCH 15/18] refactor: Clearing linting errors --- .github/workflows/ci.lint_test.yml | 2 +- cmd/aztx/contexts.go | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.lint_test.yml b/.github/workflows/ci.lint_test.yml index 0f8978c..867817e 100644 --- a/.github/workflows/ci.lint_test.yml +++ b/.github/workflows/ci.lint_test.yml @@ -25,7 +25,7 @@ jobs: DEFAULT_BRANCH: master GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_GO: true - FILTER_REGEX_EXCLUDE: test/helpers_test.go + FILTER_REGEX_EXCLUDE: ".*test/.*" Test: name: "CI: Go Tests" diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 86e014e..511ed7d 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -48,7 +48,10 @@ type File struct { } func SelectAzureAccountsDisplayName() { - home, _ := os.UserHomeDir() + home, errHome := os.UserHomeDir() + if errHome != nil { + panic(errHome) + } azureProfile := home + "/.azure/azureProfile.json" d := ReadAzureProfile(azureProfile) @@ -57,11 +60,14 @@ func SelectAzureAccountsDisplayName() { func(i int) string { return d.Subscriptions[i].Name }) - if errFind == nil { + if errFind != nil { panic(errFind) } - WriteAzureProfile(d, d.Subscriptions[idx].ID, azureProfile) + errWrite := WriteAzureProfile(d, d.Subscriptions[idx].ID, azureProfile) + if errWrite != nil { + panic(errWrite) + } fmt.Print(d.Subscriptions[idx].Name, "\n", d.Subscriptions[idx].ID, "\n") } @@ -70,11 +76,14 @@ func ReadAzureProfile(file string) File { if err != nil { fmt.Println(err) } - byteValue, _ := ioutil.ReadAll(jsonFile) + byteValue, errByte := ioutil.ReadAll(jsonFile) + if errByte != nil { + fmt.Println(errByte) + } byteValue = bytes.TrimPrefix(byteValue, []byte("\xef\xbb\xbf")) var jsonData File - errJson := json.Unmarshal(byteValue, &jsonData) - if errJson != nil { + errJSON := json.Unmarshal(byteValue, &jsonData) + if errJSON != nil { fmt.Println(err) } @@ -82,7 +91,7 @@ func ReadAzureProfile(file string) File { } func WriteAzureProfile(file File, id uuid.UUID, outFile string) error { - for idx, _ := range file.Subscriptions { + for idx := range file.Subscriptions { if file.Subscriptions[idx].ID == id { file.Subscriptions[idx].IsDefault = true } @@ -93,6 +102,6 @@ func WriteAzureProfile(file File, id uuid.UUID, outFile string) error { return err } - err = ioutil.WriteFile(outFile, byteValue, 0666) + err = ioutil.WriteFile(outFile, byteValue, 0644) return err } From be2ad49c66f8165dabc3d3fa235142660808e307 Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 17:39:17 +0100 Subject: [PATCH 16/18] fix: Required else to santise the default account --- cmd/aztx/contexts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 511ed7d..542a51d 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -94,6 +94,8 @@ func WriteAzureProfile(file File, id uuid.UUID, outFile string) error { for idx := range file.Subscriptions { if file.Subscriptions[idx].ID == id { file.Subscriptions[idx].IsDefault = true + } else { + file.Subscriptions[idx].IsDefault = false } } From 6b325e66652e6589fa8e7365a179fd2500fed10c Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 17:53:15 +0100 Subject: [PATCH 17/18] ci: Testing with v4 image to clear compile error --- .github/workflows/ci.lint_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.lint_test.yml b/.github/workflows/ci.lint_test.yml index 867817e..15d5edf 100644 --- a/.github/workflows/ci.lint_test.yml +++ b/.github/workflows/ci.lint_test.yml @@ -19,7 +19,7 @@ jobs: fetch-depth: 0 - name: Lint Code Base - uses: docker://ghcr.io/github/super-linter:slim-v4 + uses: docker://ghcr.io/github/super-linter:v4 env: VALIDATE_ALL_CODEBASE: true DEFAULT_BRANCH: master From fa6546a788bc73161fa1542cfa94d268c2b50e5c Mon Sep 17 00:00:00 2001 From: Richard Weston Date: Sun, 1 Aug 2021 17:59:01 +0100 Subject: [PATCH 18/18] fix: Lower permissions to clear golint sec warning --- cmd/aztx/contexts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/aztx/contexts.go b/cmd/aztx/contexts.go index 542a51d..7810347 100644 --- a/cmd/aztx/contexts.go +++ b/cmd/aztx/contexts.go @@ -104,6 +104,6 @@ func WriteAzureProfile(file File, id uuid.UUID, outFile string) error { return err } - err = ioutil.WriteFile(outFile, byteValue, 0644) + err = ioutil.WriteFile(outFile, byteValue, 0600) return err }