From ce03c376f9049d6e017394c3b28324ef5810290f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 14 Nov 2024 09:19:53 -0500 Subject: [PATCH 01/76] adding basic go skele --- go.mod | 3 +++ main.go | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f9b234a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/GSA-TTS/gitlab-runner-cloudgov + +go 1.23.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..da29a2c --- /dev/null +++ b/main.go @@ -0,0 +1,4 @@ +package main + +func main() { +} From 2a2abc6d49d09f155603694dc8bc496953f1c222 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 14 Nov 2024 09:20:51 -0500 Subject: [PATCH 02/76] adding simple makefile --- Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..45c8ea4 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.DEFAULT_GOAL := build + +.PHONY:fmt vet build +fmt: + go fmt ./... + +vet: fmt + go vet ./... + +build: vet + go build From b5895ef8c52b831eba0aa07363bd7e5746ae267a Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 14 Nov 2024 17:36:42 -0500 Subject: [PATCH 03/76] feat: parse VCAP & use to connect with cloud.gov Also added a silly little test that does nothind --- go.mod | 14 ++++++++++++++ go.sum | 24 ++++++++++++++++++++++++ main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ main_test.go | 20 ++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 go.sum create mode 100644 main_test.go diff --git a/go.mod b/go.mod index f9b234a..edb24d3 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,17 @@ module github.com/GSA-TTS/gitlab-runner-cloudgov go 1.23.3 + +require github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 + +require ( + github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect + github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect + github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.9.0 // indirect + golang.org/x/oauth2 v0.21.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d350760 --- /dev/null +++ b/go.sum @@ -0,0 +1,24 @@ +github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 h1:HK3+nJEPgwlhc5H74aw/V4mVowqWaTKGjHONdVQQ2Vw= +github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9/go.mod h1:eUjFfpsU3lRv388wKlXMmkQfsJ9pveUHZEia7AoBCPY= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk= +github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= +github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 h1:YFh+sjyJTMQSYjKwM4dFKhJPJC/wfo98tPUc17HdoYw= +github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index da29a2c..3926773 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,47 @@ package main +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cloudfoundry/go-cfclient/v3/client" + "github.com/cloudfoundry/go-cfclient/v3/config" +) + +var vcap = []byte(`{"cloud-gov-service-account":[{"label":"cloud-gov-service-account","provider":null,"plan":"space-deployer","name":"zjr-gl-runner-svc","tags":["gitlab-service-account"],"instance_guid":"aaaa","instance_name":"zjr-gl-runner-svc","binding_guid":"c55db941-d3eb-482c-af75-62a37503bc88","binding_name":null,"credentials":{"password":"REDACTED","username":"REDACTED"}}]}`) + +type VCapData struct { + CloudGovServiceAccount []struct { + Label string + Credentials struct { + Username string + Password string + } + } `json:"cloud-gov-service-account"` +} + func main() { + var vcapData VCapData + + err := json.Unmarshal(vcap, &vcapData) + if err != nil { + fmt.Println("error:", err) + return + } + + credentials := vcapData.CloudGovServiceAccount[0].Credentials + + cfConfig, _ := config.New("https://api.fr.cloud.gov", config.UserPassword( + credentials.Username, + credentials.Password, + )) + cf, _ := client.New(cfConfig) + + fmt.Printf("%+v", vcapData) + + apps, _ := cf.Applications.ListAll(context.Background(), nil) + for _, app := range apps { + fmt.Printf("Application %s is %s\n", app.Name, app.State) + } } diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..641f3bd --- /dev/null +++ b/main_test.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "testing" +) + +func Test_main(t *testing.T) { + tests := []struct { + name string + }{ + {name: "scoobie"}, + } + for _, tt := range tests { + fmt.Println(tt.name) + t.Run(tt.name, func(t *testing.T) { + main() + }) + } +} From c7fc20b33ec9fb977f1e1a578cd4a60923fd40d8 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 15 Nov 2024 10:51:58 -0500 Subject: [PATCH 04/76] feat: parse creds from VCAP_SERVICES env var --- main.go | 32 ++++++++++++++++++-------------- main_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 3926773..ba75907 100644 --- a/main.go +++ b/main.go @@ -4,41 +4,45 @@ import ( "context" "encoding/json" "fmt" + "os" "github.com/cloudfoundry/go-cfclient/v3/client" "github.com/cloudfoundry/go-cfclient/v3/config" ) -var vcap = []byte(`{"cloud-gov-service-account":[{"label":"cloud-gov-service-account","provider":null,"plan":"space-deployer","name":"zjr-gl-runner-svc","tags":["gitlab-service-account"],"instance_guid":"aaaa","instance_name":"zjr-gl-runner-svc","binding_guid":"c55db941-d3eb-482c-af75-62a37503bc88","binding_name":null,"credentials":{"password":"REDACTED","username":"REDACTED"}}]}`) +type Credentials struct { + Username string + Password string +} -type VCapData struct { +type VcapData struct { CloudGovServiceAccount []struct { - Label string - Credentials struct { - Username string - Password string - } + Credentials Credentials } `json:"cloud-gov-service-account"` } -func main() { - var vcapData VCapData +func GetCredentials() (*Credentials, error) { + var data VcapData + vcapServices := os.Getenv("VCAP_SERVICES") - err := json.Unmarshal(vcap, &vcapData) + err := json.Unmarshal([]byte(vcapServices), &data) if err != nil { fmt.Println("error:", err) - return + return nil, err } - credentials := vcapData.CloudGovServiceAccount[0].Credentials + return &data.CloudGovServiceAccount[0].Credentials, nil +} + +func main() { + credentials, _ := GetCredentials() cfConfig, _ := config.New("https://api.fr.cloud.gov", config.UserPassword( credentials.Username, credentials.Password, )) - cf, _ := client.New(cfConfig) - fmt.Printf("%+v", vcapData) + cf, _ := client.New(cfConfig) apps, _ := cf.Applications.ListAll(context.Background(), nil) for _, app := range apps { diff --git a/main_test.go b/main_test.go index 641f3bd..5f6015f 100644 --- a/main_test.go +++ b/main_test.go @@ -5,6 +5,32 @@ import ( "testing" ) +func Test_GetCredentials(t *testing.T) { + username := "tjefferson" + password := "p4ssw0rdz1" + + json := fmt.Sprintf( + `{"cloud-gov-service-account":[{"credentials":{"password":"%s","username":"%s"}}]}`, + password, + username, + ) + + t.Setenv("VCAP_SERVICES", json) + + t.Run("Get credentials from VCAP_SERVICES", func(t *testing.T) { + credentials, err := GetCredentials() + if err != nil { + t.Error(err) + } + if credentials.Username != username { + t.Errorf("credentials.Username = %s; want %s", credentials.Username, username) + } + if credentials.Password != password { + t.Errorf("credentials.Password = %s; want %s", credentials.Password, password) + } + }) +} + func Test_main(t *testing.T) { tests := []struct { name string From 8c407b51e50ccc9b589610e3b9e9bdc860793004 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 15 Nov 2024 11:59:15 -0500 Subject: [PATCH 05/76] refactor: simplify GetCredentials test --- main_test.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/main_test.go b/main_test.go index 5f6015f..e8d0b5c 100644 --- a/main_test.go +++ b/main_test.go @@ -17,18 +17,16 @@ func Test_GetCredentials(t *testing.T) { t.Setenv("VCAP_SERVICES", json) - t.Run("Get credentials from VCAP_SERVICES", func(t *testing.T) { - credentials, err := GetCredentials() - if err != nil { - t.Error(err) - } - if credentials.Username != username { - t.Errorf("credentials.Username = %s; want %s", credentials.Username, username) - } - if credentials.Password != password { - t.Errorf("credentials.Password = %s; want %s", credentials.Password, password) - } - }) + credentials, err := GetCredentials() + if err != nil { + t.Error(err) + } + if credentials.Username != username { + t.Errorf("credentials.Username = %s; want %s", credentials.Username, username) + } + if credentials.Password != password { + t.Errorf("credentials.Password = %s; want %s", credentials.Password, password) + } } func Test_main(t *testing.T) { From ab70e74840140b5528cf46e3a7138316c49c35c4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Tue, 19 Nov 2024 10:10:35 -0500 Subject: [PATCH 06/76] refactor: better error handling --- main.go | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ba75907..034dad4 100644 --- a/main.go +++ b/main.go @@ -27,24 +27,58 @@ func GetCredentials() (*Credentials, error) { err := json.Unmarshal([]byte(vcapServices), &data) if err != nil { - fmt.Println("error:", err) - return nil, err + return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) } return &data.CloudGovServiceAccount[0].Credentials, nil } +func GetCfClient() (_ *client.Client, err error) { + defer func() { + if err != nil { + err = fmt.Errorf("error getting cf client: %w", err) + } + }() + + creds, err := GetCredentials() + if err != nil { + return nil, err + } + + cfConfig, err := config.New( + "https://api.fr.cloud.gov", + config.UserPassword(creds.Username, creds.Password), + ) + if err != nil { + return nil, err + } + + return client.New(cfConfig) +} + func main() { - credentials, _ := GetCredentials() + var err error - cfConfig, _ := config.New("https://api.fr.cloud.gov", config.UserPassword( - credentials.Username, - credentials.Password, - )) + defer func() { + if err != nil { + fmt.Println(fmt.Errorf("in main: %w", err)) + } - cf, _ := client.New(cfConfig) + if v := recover(); v != nil { + fmt.Println(v) + } + }() + + cf, err := GetCfClient() + if err != nil { + return + } + + apps, err := cf.Applications.ListAll(context.Background(), nil) + if err != nil { + return + } - apps, _ := cf.Applications.ListAll(context.Background(), nil) for _, app := range apps { fmt.Printf("Application %s is %s\n", app.Name, app.State) } From 50eaa2a1adec691df94cf8fabdcf4922000a2d66 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Tue, 19 Nov 2024 10:14:03 -0500 Subject: [PATCH 07/76] refactor: slightly better read flow for getting config --- main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 034dad4..2b51ad8 100644 --- a/main.go +++ b/main.go @@ -45,10 +45,9 @@ func GetCfClient() (_ *client.Client, err error) { return nil, err } - cfConfig, err := config.New( - "https://api.fr.cloud.gov", - config.UserPassword(creds.Username, creds.Password), - ) + apiRootUrl := "https://api.fr.cloud.gov" + configOpts := config.UserPassword(creds.Username, creds.Password) + cfConfig, err := config.New(apiRootUrl, configOpts) if err != nil { return nil, err } From 32f98a4e24cbd58612bdad52a02b54a507cca8f9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Tue, 19 Nov 2024 10:33:16 -0500 Subject: [PATCH 08/76] chore: add standard ignores for Go --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2802610..9f5e01b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ override.tf.json # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* + From bfea6b85493e3d525927e2d7252d9b3ff80d016a Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 21 Nov 2024 11:53:03 -0500 Subject: [PATCH 09/76] chore: move go code into its proper place --- go.mod => runner/cf-executor/go.mod | 2 +- go.sum => runner/cf-executor/go.sum | 0 main.go => runner/cf-executor/main.go | 0 main_test.go => runner/cf-executor/main_test.go | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename go.mod => runner/cf-executor/go.mod (90%) rename go.sum => runner/cf-executor/go.sum (100%) rename main.go => runner/cf-executor/main.go (100%) rename main_test.go => runner/cf-executor/main_test.go (100%) diff --git a/go.mod b/runner/cf-executor/go.mod similarity index 90% rename from go.mod rename to runner/cf-executor/go.mod index edb24d3..854b616 100644 --- a/go.mod +++ b/runner/cf-executor/go.mod @@ -1,4 +1,4 @@ -module github.com/GSA-TTS/gitlab-runner-cloudgov +module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-executor go 1.23.3 diff --git a/go.sum b/runner/cf-executor/go.sum similarity index 100% rename from go.sum rename to runner/cf-executor/go.sum diff --git a/main.go b/runner/cf-executor/main.go similarity index 100% rename from main.go rename to runner/cf-executor/main.go diff --git a/main_test.go b/runner/cf-executor/main_test.go similarity index 100% rename from main_test.go rename to runner/cf-executor/main_test.go From d6be17bc65829c4a1204a5df7bed762e24dbdaba Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 09:27:53 -0500 Subject: [PATCH 10/76] refactor: simplify error check for json.Unmarshal --- runner/cf-executor/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index 2b51ad8..e0a11ee 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -25,8 +25,7 @@ func GetCredentials() (*Credentials, error) { var data VcapData vcapServices := os.Getenv("VCAP_SERVICES") - err := json.Unmarshal([]byte(vcapServices), &data) - if err != nil { + if err := json.Unmarshal([]byte(vcapServices), &data); err != nil { return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) } From e749436a74a1f1707ddbffd4cd97259ae07f0e79 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 09:31:56 -0500 Subject: [PATCH 11/76] test: more robust testing of GetCredentials - validate failure with bad data - uses go-cmp for struct comparison - uses table structure to make additional cases easier to add --- runner/cf-executor/go.mod | 1 + runner/cf-executor/go.sum | 2 ++ runner/cf-executor/main_test.go | 58 +++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/runner/cf-executor/go.mod b/runner/cf-executor/go.mod index 854b616..b44fb6f 100644 --- a/runner/cf-executor/go.mod +++ b/runner/cf-executor/go.mod @@ -8,6 +8,7 @@ require ( github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect + github.com/google/go-cmp v0.6.0 github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/runner/cf-executor/go.sum b/runner/cf-executor/go.sum index d350760..e93de21 100644 --- a/runner/cf-executor/go.sum +++ b/runner/cf-executor/go.sum @@ -7,6 +7,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 h1:YFh+sjyJTMQSYjKwM4dFKhJPJC/wfo98tPUc17HdoYw= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index e8d0b5c..dd3d124 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -1,31 +1,53 @@ package main import ( + "encoding/json" + "errors" "fmt" "testing" -) -func Test_GetCredentials(t *testing.T) { - username := "tjefferson" - password := "p4ssw0rdz1" + "github.com/cloudfoundry/go-cfclient/v3/client" + "github.com/google/go-cmp/cmp" +) - json := fmt.Sprintf( - `{"cloud-gov-service-account":[{"credentials":{"password":"%s","username":"%s"}}]}`, - password, - username, - ) +var syntaxError *json.SyntaxError - t.Setenv("VCAP_SERVICES", json) +func getVcapJson(u string, p string) string { + return fmt.Sprintf(`{"cloud-gov-service-account":[{"credentials":{"username":"%s","password":"%s"}}]}`, u, p) +} - credentials, err := GetCredentials() - if err != nil { - t.Error(err) - } - if credentials.Username != username { - t.Errorf("credentials.Username = %s; want %s", credentials.Username, username) +func TestGetCredentials(t *testing.T) { + tests := []struct { + name string + json string + want *Credentials + wantErr interface{} + }{ + {"fails with no JSON", "", nil, &syntaxError}, + {"fails with malformed JSON", `{"foo": [{"bar": false}}`, nil, &syntaxError}, + {"pulls credentials from JSON", getVcapJson("aa", "bb"), &Credentials{"aa", "bb"}, nil}, } - if credentials.Password != password { - t.Errorf("credentials.Password = %s; want %s", credentials.Password, password) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("VCAP_SERVICES", tt.json) + + have, err := GetCredentials() + + if (err == nil) != (tt.wantErr == nil) { + t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if err != nil && !errors.As(err, tt.wantErr) { + t.Errorf("GetCredentials() bad error type: have %T, want %T", err, tt.wantErr) + return + } + + if diff := cmp.Diff(tt.want, have); diff != "" { + t.Error(diff) + } + }) } } From 49d3151099ebe20d7465ae11b006d917c5eab74b Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 09:38:46 -0500 Subject: [PATCH 12/76] test: skip Test_main because it's just meant for experiments right now --- runner/cf-executor/main_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index dd3d124..0525a6b 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -52,6 +52,19 @@ func TestGetCredentials(t *testing.T) { } func Test_main(t *testing.T) { + t.Skip("Test_main is just for experiments right now") + + tests := []struct{ name string }{{name: "run main"}} + + for _, tt := range tests { + fmt.Println(tt.name) + t.Run(tt.name, func(t *testing.T) { + main() + }) + } +} + +func TestGetCfClient(t *testing.T) { tests := []struct { name string }{ From 5fb7f30105cec9276a56d7cb1f2887edaa566768 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 11:13:44 -0500 Subject: [PATCH 13/76] refactor: decouple GetCfClient from GetCredentials --- runner/cf-executor/main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index e0a11ee..91d2f57 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -32,20 +32,16 @@ func GetCredentials() (*Credentials, error) { return &data.CloudGovServiceAccount[0].Credentials, nil } -func GetCfClient() (_ *client.Client, err error) { +func GetCfClient(creds *Credentials) (_ *client.Client, err error) { defer func() { if err != nil { err = fmt.Errorf("error getting cf client: %w", err) } }() - creds, err := GetCredentials() - if err != nil { - return nil, err - } - apiRootUrl := "https://api.fr.cloud.gov" configOpts := config.UserPassword(creds.Username, creds.Password) + cfConfig, err := config.New(apiRootUrl, configOpts) if err != nil { return nil, err @@ -67,7 +63,12 @@ func main() { } }() - cf, err := GetCfClient() + creds, err := GetCredentials() + if err != nil { + return + } + + cf, err := GetCfClient(creds) if err != nil { return } From 67d8249e8e03911a06bd105c7f7b77569b6c327e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 15:45:55 -0500 Subject: [PATCH 14/76] feat: allow explicit config of CF user/pass w/ envvars --- runner/cf-executor/main.go | 7 ++++ runner/cf-executor/main_test.go | 59 ++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index 91d2f57..9f16793 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -22,6 +22,13 @@ type VcapData struct { } func GetCredentials() (*Credentials, error) { + cfUser := os.Getenv("CF_USERNAME") + cfPass := os.Getenv("CF_PASSWORD") + + if cfUser != "" && cfPass != "" { + return &Credentials{cfUser, cfPass}, nil + } + var data VcapData vcapServices := os.Getenv("VCAP_SERVICES") diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index 0525a6b..4154f46 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -19,18 +19,67 @@ func getVcapJson(u string, p string) string { func TestGetCredentials(t *testing.T) { tests := []struct { name string - json string + env map[string]string want *Credentials wantErr interface{} }{ - {"fails with no JSON", "", nil, &syntaxError}, - {"fails with malformed JSON", `{"foo": [{"bar": false}}`, nil, &syntaxError}, - {"pulls credentials from JSON", getVcapJson("aa", "bb"), &Credentials{"aa", "bb"}, nil}, + { + "fails with no JSON", + nil, nil, &syntaxError, + }, + { + "fails with malformed JSON", + map[string]string{ + "VCAP_SERVICES": `{"foo": [{"bar": false}}`, + }, + nil, &syntaxError, + }, + { + "fails with incorrectly defined VCAP envvar", + map[string]string{ + "VCAP_SURGICES": getVcapJson("aa", "bb"), + }, + nil, &syntaxError, + }, + { + "pulls credentials from JSON", + map[string]string{ + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Credentials{"aa", "bb"}, nil, + }, + { + "pulls credentials from JSON when only user available", + map[string]string{ + "CF_USERNAME": "Klaus", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Credentials{"aa", "bb"}, nil, + }, + { + "pulls credentials from JSON when only pass available", + map[string]string{ + "CF_PASSWORD": "tulip-cat-cupcake", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Credentials{"aa", "bb"}, nil, + }, + { + "pulls credentials from specifically defined envvars if available", + map[string]string{ + "CF_USERNAME": "Klaus", + "CF_PASSWORD": "tulip-cat-cupcake", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Credentials{"Klaus", "tulip-cat-cupcake"}, nil, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - t.Setenv("VCAP_SERVICES", tt.json) + for key, val := range tt.env { + t.Setenv(key, val) + } have, err := GetCredentials() From 18f9f3f299ead6f5e3ea97fc9b096ab3da0f0859 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 15:48:01 -0500 Subject: [PATCH 15/76] fix: move & comment out the CfClient test that snuck in --- runner/cf-executor/main_test.go | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index 4154f46..869cfa9 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -100,6 +100,26 @@ func TestGetCredentials(t *testing.T) { } } +// func TestGetCfClient(t *testing.T) { +// tests := []struct { +// name string +// want *client.Client +// wantErr bool +// }{{}} +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// got, err := GetCfClient() +// if (err != nil) != tt.wantErr { +// t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) +// return +// } +// if !reflect.DeepEqual(got, tt.want) { +// t.Errorf("GetCfClient() = %v, want %v", got, tt.want) +// } +// }) +// } +// } + func Test_main(t *testing.T) { t.Skip("Test_main is just for experiments right now") @@ -112,17 +132,3 @@ func Test_main(t *testing.T) { }) } } - -func TestGetCfClient(t *testing.T) { - tests := []struct { - name string - }{ - {name: "scoobie"}, - } - for _, tt := range tests { - fmt.Println(tt.name) - t.Run(tt.name, func(t *testing.T) { - main() - }) - } -} From b76d62feb10abcd073e00b309c435ae8f8dce36b Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 15:52:07 -0500 Subject: [PATCH 16/76] refactor: Credentials -> CfCredentials for specificity --- runner/cf-executor/main.go | 12 ++++++------ runner/cf-executor/main_test.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index 9f16793..b0d82f3 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -10,23 +10,23 @@ import ( "github.com/cloudfoundry/go-cfclient/v3/config" ) -type Credentials struct { +type CfCredentials struct { Username string Password string } type VcapData struct { CloudGovServiceAccount []struct { - Credentials Credentials + Credentials CfCredentials } `json:"cloud-gov-service-account"` } -func GetCredentials() (*Credentials, error) { +func GetCfCredentials() (*CfCredentials, error) { cfUser := os.Getenv("CF_USERNAME") cfPass := os.Getenv("CF_PASSWORD") if cfUser != "" && cfPass != "" { - return &Credentials{cfUser, cfPass}, nil + return &CfCredentials{cfUser, cfPass}, nil } var data VcapData @@ -39,7 +39,7 @@ func GetCredentials() (*Credentials, error) { return &data.CloudGovServiceAccount[0].Credentials, nil } -func GetCfClient(creds *Credentials) (_ *client.Client, err error) { +func GetCfClient(creds *CfCredentials) (_ *client.Client, err error) { defer func() { if err != nil { err = fmt.Errorf("error getting cf client: %w", err) @@ -70,7 +70,7 @@ func main() { } }() - creds, err := GetCredentials() + creds, err := GetCfCredentials() if err != nil { return } diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index 869cfa9..5173281 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -16,11 +16,11 @@ func getVcapJson(u string, p string) string { return fmt.Sprintf(`{"cloud-gov-service-account":[{"credentials":{"username":"%s","password":"%s"}}]}`, u, p) } -func TestGetCredentials(t *testing.T) { +func TestGetCfCredentials(t *testing.T) { tests := []struct { name string env map[string]string - want *Credentials + want *CfCredentials wantErr interface{} }{ { @@ -46,7 +46,7 @@ func TestGetCredentials(t *testing.T) { map[string]string{ "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Credentials{"aa", "bb"}, nil, + &CfCredentials{"aa", "bb"}, nil, }, { "pulls credentials from JSON when only user available", @@ -54,7 +54,7 @@ func TestGetCredentials(t *testing.T) { "CF_USERNAME": "Klaus", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Credentials{"aa", "bb"}, nil, + &CfCredentials{"aa", "bb"}, nil, }, { "pulls credentials from JSON when only pass available", @@ -62,7 +62,7 @@ func TestGetCredentials(t *testing.T) { "CF_PASSWORD": "tulip-cat-cupcake", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Credentials{"aa", "bb"}, nil, + &CfCredentials{"aa", "bb"}, nil, }, { "pulls credentials from specifically defined envvars if available", @@ -71,7 +71,7 @@ func TestGetCredentials(t *testing.T) { "CF_PASSWORD": "tulip-cat-cupcake", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Credentials{"Klaus", "tulip-cat-cupcake"}, nil, + &CfCredentials{"Klaus", "tulip-cat-cupcake"}, nil, }, } @@ -81,7 +81,7 @@ func TestGetCredentials(t *testing.T) { t.Setenv(key, val) } - have, err := GetCredentials() + have, err := GetCfCredentials() if (err == nil) != (tt.wantErr == nil) { t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) From 13151dd2c3559c7fd657c8a2a01ae5c95fc37b0b Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 25 Nov 2024 17:45:13 -0500 Subject: [PATCH 17/76] refactor: move Makefile & go gitignore --- .gitignore | 1 - runner/cf-executor/.gitignore | 22 ++++++++++++++++++++++ Makefile => runner/cf-executor/Makefile | 0 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 runner/cf-executor/.gitignore rename Makefile => runner/cf-executor/Makefile (100%) diff --git a/.gitignore b/.gitignore index 9f5e01b..2802610 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,3 @@ override.tf.json # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* - diff --git a/runner/cf-executor/.gitignore b/runner/cf-executor/.gitignore new file mode 100644 index 0000000..e6f7deb --- /dev/null +++ b/runner/cf-executor/.gitignore @@ -0,0 +1,22 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env diff --git a/Makefile b/runner/cf-executor/Makefile similarity index 100% rename from Makefile rename to runner/cf-executor/Makefile From d59e1dd03aa006d521f9d4c3c2a30db7c68bbdb9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 4 Dec 2024 11:57:51 -0500 Subject: [PATCH 18/76] feat: add godotenv, load in main --- runner/cf-executor/go.mod | 1 + runner/cf-executor/go.sum | 2 ++ runner/cf-executor/main.go | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/runner/cf-executor/go.mod b/runner/cf-executor/go.mod index b44fb6f..d4bc0ab 100644 --- a/runner/cf-executor/go.mod +++ b/runner/cf-executor/go.mod @@ -9,6 +9,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect github.com/google/go-cmp v0.6.0 + github.com/joho/godotenv v1.5.1 github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/runner/cf-executor/go.sum b/runner/cf-executor/go.sum index e93de21..40a4b5c 100644 --- a/runner/cf-executor/go.sum +++ b/runner/cf-executor/go.sum @@ -9,6 +9,8 @@ github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iauee github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 h1:YFh+sjyJTMQSYjKwM4dFKhJPJC/wfo98tPUc17HdoYw= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index b0d82f3..f5489c9 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -4,10 +4,12 @@ import ( "context" "encoding/json" "fmt" + "log" "os" "github.com/cloudfoundry/go-cfclient/v3/client" "github.com/cloudfoundry/go-cfclient/v3/config" + "github.com/joho/godotenv" ) type CfCredentials struct { @@ -70,6 +72,10 @@ func main() { } }() + if err := godotenv.Load(); err != nil { + log.Fatal("error loading .env file") + } + creds, err := GetCfCredentials() if err != nil { return From 4c601488320ff9701a7f093638566327e07bb9be Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 4 Dec 2024 14:47:17 -0500 Subject: [PATCH 19/76] refactor: wrapping cfclient poc --- runner/cf-executor/main.go | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index f5489c9..bc9fedb 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -41,7 +41,44 @@ func GetCfCredentials() (*CfCredentials, error) { return &data.CloudGovServiceAccount[0].Credentials, nil } -func GetCfClient(creds *CfCredentials) (_ *client.Client, err error) { +type CfInter interface { + GetClient(config *cfConfig) (*cfClient, error) + GetConfig(apiRootURL string, options ...config.Option) (*cfConfig, error) + UserPassword(username string, password string) config.Option +} + +type ( + cfClient client.Client + cfConfig config.Config +) + +func (c cfClient) GetClient(cfg *cfConfig) (*cfClient, error) { + extCfg := config.Config(*cfg) + + extCli, err := client.New(&extCfg) + if err != nil { + return nil, err + } + + cli := cfClient(*extCli) + return &cli, nil +} + +func (c cfClient) GetConfig(apiRootURL string, options ...config.Option) (*cfConfig, error) { + extCfg, err := config.New(apiRootURL, options...) + if err != nil { + return nil, err + } + + cfg := cfConfig(*extCfg) + return &cfg, nil +} + +func (c cfClient) UserPassword(username string, password string) config.Option { + return config.UserPassword(username, password) +} + +func GetCfClient(cf CfInter, creds *CfCredentials) (_ *cfClient, err error) { defer func() { if err != nil { err = fmt.Errorf("error getting cf client: %w", err) @@ -49,14 +86,14 @@ func GetCfClient(creds *CfCredentials) (_ *client.Client, err error) { }() apiRootUrl := "https://api.fr.cloud.gov" - configOpts := config.UserPassword(creds.Username, creds.Password) + configOpts := cf.UserPassword(creds.Username, creds.Password) - cfConfig, err := config.New(apiRootUrl, configOpts) + cfg, err := cf.GetConfig(apiRootUrl, configOpts) if err != nil { return nil, err } - return client.New(cfConfig) + return cf.GetClient((*cfConfig)(cfg)) } func main() { @@ -81,7 +118,7 @@ func main() { return } - cf, err := GetCfClient(creds) + cf, err := GetCfClient(cfClient{}, creds) if err != nil { return } From 0aac409731cbb296fb8ec766d987bea22eaecd8c Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 6 Dec 2024 16:57:11 -0500 Subject: [PATCH 20/76] refactor: move relevant cloud.gov logic w/ adapter for cf-goclient --- runner/cf-executor/cg/cf.go | 49 +++++++++++++++ runner/cf-executor/cg/cg.go | 120 ++++++++++++++++++++++++++++++++++++ runner/cf-executor/main.go | 111 +++------------------------------ 3 files changed, 178 insertions(+), 102 deletions(-) create mode 100644 runner/cf-executor/cg/cf.go create mode 100644 runner/cf-executor/cg/cg.go diff --git a/runner/cf-executor/cg/cf.go b/runner/cf-executor/cg/cf.go new file mode 100644 index 0000000..c680802 --- /dev/null +++ b/runner/cf-executor/cg/cf.go @@ -0,0 +1,49 @@ +package cg + +import ( + "context" + + "github.com/cloudfoundry/go-cfclient/v3/client" + "github.com/cloudfoundry/go-cfclient/v3/config" +) + +type GoCFClientAdapter struct { + _con *client.Client +} + +func (cf *GoCFClientAdapter) connect(url string, creds *Creds) error { + cfg, err := config.New(url, config.UserPassword(creds.Username, creds.Password)) + if err != nil { + return err + } + + con, err := client.New(cfg) + if err != nil { + return err + } + + cf._con = con + + return nil +} + +func (cf *GoCFClientAdapter) conn() *client.Client { + if cf._con != nil { + return cf._con + } + panic("not connected") +} + +func (cf *GoCFClientAdapter) getApps() ([]*App, error) { + apps, err := cf.conn().Applications.ListAll(context.Background(), nil) + if err != nil { + return nil, err + } + + Apps := make([]*App, len(apps)) + for idx, app := range apps { + Apps[idx] = &(App{app.GUID, app.Name, app.State}) + } + + return Apps, nil +} diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go new file mode 100644 index 0000000..e7d21b4 --- /dev/null +++ b/runner/cf-executor/cg/cg.go @@ -0,0 +1,120 @@ +package cg + +import ( + "encoding/json" + "errors" + "fmt" + "os" +) + +type App struct { + Id string + Name string + State string +} + +type Creds struct { + Username string + Password string +} + +func (cr *Creds) isEmpty() bool { + return cr.Username == "" && cr.Password == "" +} + +type vcapData struct { + CGSrvAct []struct{ Creds Creds } `json:"cloud-gov-service-account"` +} + +func getCreds() (*Creds, error) { + creds := &Creds{} + + // Check if credentials are supplied through environment + creds.Username = os.Getenv("CF_USERNAME") + creds.Password = os.Getenv("CF_PASSWORD") + if !creds.isEmpty() { + return creds, nil + } + + // Check for credentials in VCAP_SERVICES JSON + var vcd vcapData + vSrv := os.Getenv("VCAP_SERVICES") + if err := json.Unmarshal([]byte(vSrv), &vcd); err != nil { + return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) + } + + // If creds are still empty we fail + creds = &vcd.CGSrvAct[0].Creds + if creds.isEmpty() { + return nil, errors.New("could not establish credentials") + } + + return creds, nil +} + +type Adapter interface { + getApps() (apps []*App, err error) + + connect(url string, creds *Creds) error + + // Stuff + // + // mapRoute() + // + // addNetworkPolicy() + // removeNetworkPolicy() + // + // appGet() + // appCmd() + // appPush() + // appDelete() +} + +type CG struct { + Adapter + Opts +} + +type Opts struct { + Creds Creds + APIRootURL string +} + +var apiRootURLDefault = "https://api.fr.cloud.gov" + +func New(a Adapter, o *Opts) (*CG, error) { + if o == nil { + o = &Opts{} + } + cg := &CG{a, *o} + return cg.Connect() +} + +func (c *CG) apiRootURL() string { + if c.APIRootURL == "" { + return apiRootURLDefault + } + return c.APIRootURL +} + +func (c *CG) creds() (*Creds, error) { + if c.Creds.isEmpty() { + return getCreds() + } + return &c.Creds, nil +} + +func (c *CG) Connect() (*CG, error) { + creds, err := c.creds() + if err != nil { + return nil, err + } + if err := c.connect(c.apiRootURL(), creds); err != nil { + return nil, err + } + return c, nil +} + +func (c *CG) GetApps() ([]*App, error) { + return c.getApps() +} diff --git a/runner/cf-executor/main.go b/runner/cf-executor/main.go index bc9fedb..552bed7 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-executor/main.go @@ -1,134 +1,41 @@ package main import ( - "context" - "encoding/json" "fmt" "log" - "os" - "github.com/cloudfoundry/go-cfclient/v3/client" - "github.com/cloudfoundry/go-cfclient/v3/config" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-executor/cg" "github.com/joho/godotenv" ) -type CfCredentials struct { - Username string - Password string -} - -type VcapData struct { - CloudGovServiceAccount []struct { - Credentials CfCredentials - } `json:"cloud-gov-service-account"` -} - -func GetCfCredentials() (*CfCredentials, error) { - cfUser := os.Getenv("CF_USERNAME") - cfPass := os.Getenv("CF_PASSWORD") - - if cfUser != "" && cfPass != "" { - return &CfCredentials{cfUser, cfPass}, nil - } - - var data VcapData - vcapServices := os.Getenv("VCAP_SERVICES") - - if err := json.Unmarshal([]byte(vcapServices), &data); err != nil { - return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) - } - - return &data.CloudGovServiceAccount[0].Credentials, nil -} - -type CfInter interface { - GetClient(config *cfConfig) (*cfClient, error) - GetConfig(apiRootURL string, options ...config.Option) (*cfConfig, error) - UserPassword(username string, password string) config.Option -} - -type ( - cfClient client.Client - cfConfig config.Config -) - -func (c cfClient) GetClient(cfg *cfConfig) (*cfClient, error) { - extCfg := config.Config(*cfg) - - extCli, err := client.New(&extCfg) - if err != nil { - return nil, err - } - - cli := cfClient(*extCli) - return &cli, nil -} - -func (c cfClient) GetConfig(apiRootURL string, options ...config.Option) (*cfConfig, error) { - extCfg, err := config.New(apiRootURL, options...) - if err != nil { - return nil, err - } - - cfg := cfConfig(*extCfg) - return &cfg, nil -} - -func (c cfClient) UserPassword(username string, password string) config.Option { - return config.UserPassword(username, password) -} - -func GetCfClient(cf CfInter, creds *CfCredentials) (_ *cfClient, err error) { - defer func() { - if err != nil { - err = fmt.Errorf("error getting cf client: %w", err) - } - }() - - apiRootUrl := "https://api.fr.cloud.gov" - configOpts := cf.UserPassword(creds.Username, creds.Password) - - cfg, err := cf.GetConfig(apiRootUrl, configOpts) - if err != nil { - return nil, err - } - - return cf.GetClient((*cfConfig)(cfg)) -} - func main() { var err error defer func() { if err != nil { - fmt.Println(fmt.Errorf("in main: %w", err)) + log.Println(fmt.Errorf("in main: %w", err)) } if v := recover(); v != nil { - fmt.Println(v) + log.Println(v) } }() if err := godotenv.Load(); err != nil { - log.Fatal("error loading .env file") - } - - creds, err := GetCfCredentials() - if err != nil { - return + panic("error loading .env file") } - cf, err := GetCfClient(cfClient{}, creds) + cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) if err != nil { - return + panic(err) } - apps, err := cf.Applications.ListAll(context.Background(), nil) + apps, err := cgClient.GetApps() if err != nil { - return + panic(err) } for _, app := range apps { - fmt.Printf("Application %s is %s\n", app.Name, app.State) + log.Printf("Application %s is %s\n", app.Name, app.State) } } From 450af8997aa3443801f06e47135bed7166bc7938 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 6 Dec 2024 17:01:09 -0500 Subject: [PATCH 21/76] refactor: move creds code into its own file --- runner/cf-executor/cg/cg.go | 70 ++++++---------------------------- runner/cf-executor/cg/creds.go | 47 +++++++++++++++++++++++ 2 files changed, 58 insertions(+), 59 deletions(-) create mode 100644 runner/cf-executor/cg/creds.go diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index e7d21b4..7dcc43a 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -1,73 +1,25 @@ package cg -import ( - "encoding/json" - "errors" - "fmt" - "os" -) - type App struct { Id string Name string State string } -type Creds struct { - Username string - Password string -} - -func (cr *Creds) isEmpty() bool { - return cr.Username == "" && cr.Password == "" -} - -type vcapData struct { - CGSrvAct []struct{ Creds Creds } `json:"cloud-gov-service-account"` -} - -func getCreds() (*Creds, error) { - creds := &Creds{} - - // Check if credentials are supplied through environment - creds.Username = os.Getenv("CF_USERNAME") - creds.Password = os.Getenv("CF_PASSWORD") - if !creds.isEmpty() { - return creds, nil - } - - // Check for credentials in VCAP_SERVICES JSON - var vcd vcapData - vSrv := os.Getenv("VCAP_SERVICES") - if err := json.Unmarshal([]byte(vSrv), &vcd); err != nil { - return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) - } - - // If creds are still empty we fail - creds = &vcd.CGSrvAct[0].Creds - if creds.isEmpty() { - return nil, errors.New("could not establish credentials") - } - - return creds, nil -} - +// Stuff we'll need to implement, for ref +// +// mapRoute() +// +// addNetworkPolicy() +// removeNetworkPolicy() +// +// appGet() +// appCmd() +// appPush() +// appDelete() type Adapter interface { getApps() (apps []*App, err error) - connect(url string, creds *Creds) error - - // Stuff - // - // mapRoute() - // - // addNetworkPolicy() - // removeNetworkPolicy() - // - // appGet() - // appCmd() - // appPush() - // appDelete() } type CG struct { diff --git a/runner/cf-executor/cg/creds.go b/runner/cf-executor/cg/creds.go new file mode 100644 index 0000000..babb924 --- /dev/null +++ b/runner/cf-executor/cg/creds.go @@ -0,0 +1,47 @@ +package cg + +import ( + "encoding/json" + "errors" + "fmt" + "os" +) + +type Creds struct { + Username string + Password string +} + +func (cr *Creds) isEmpty() bool { + return cr.Username == "" && cr.Password == "" +} + +type vcapData struct { + CGSrvAct []struct{ Creds Creds } `json:"cloud-gov-service-account"` +} + +func getCreds() (*Creds, error) { + creds := &Creds{} + + // Check if credentials are supplied through environment + creds.Username = os.Getenv("CF_USERNAME") + creds.Password = os.Getenv("CF_PASSWORD") + if !creds.isEmpty() { + return creds, nil + } + + // Check for credentials in VCAP_SERVICES JSON + var vcd vcapData + vSrv := os.Getenv("VCAP_SERVICES") + if err := json.Unmarshal([]byte(vSrv), &vcd); err != nil { + return nil, fmt.Errorf("error unmarshaling VCAP_SERVICES: %w", err) + } + + // If creds are still empty we fail + creds = &vcd.CGSrvAct[0].Creds + if creds.isEmpty() { + return nil, errors.New("could not establish credentials") + } + + return creds, nil +} From e5a7e5535bc622f3a2a0aab28647f7cbb02e3be8 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 6 Dec 2024 17:01:38 -0500 Subject: [PATCH 22/76] chore: add launch.json for debug config --- runner/cf-executor/.vscode/launch.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 runner/cf-executor/.vscode/launch.json diff --git a/runner/cf-executor/.vscode/launch.json b/runner/cf-executor/.vscode/launch.json new file mode 100644 index 0000000..ea3fa7e --- /dev/null +++ b/runner/cf-executor/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug main.go", + "type": "go", + "request": "launch", + "program": "main.go" + } + ] +} From f74cfd5e47a7037da04816762425d5704b9eed12 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 9 Dec 2024 11:35:52 -0500 Subject: [PATCH 23/76] refactor: colocate creds tests and fix names --- runner/cf-executor/cg/creds_test.go | 100 ++++++++++++++++++++++++++++ runner/cf-executor/main_test.go | 95 -------------------------- 2 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 runner/cf-executor/cg/creds_test.go diff --git a/runner/cf-executor/cg/creds_test.go b/runner/cf-executor/cg/creds_test.go new file mode 100644 index 0000000..7fcad54 --- /dev/null +++ b/runner/cf-executor/cg/creds_test.go @@ -0,0 +1,100 @@ +package cg + +import ( + "encoding/json" + "errors" + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" +) + +var syntaxError *json.SyntaxError + +func getVcapJson(u string, p string) string { + return fmt.Sprintf(`{"cloud-gov-service-account":[{"credentials":{"username":"%s","password":"%s"}}]}`, u, p) +} + +func Test_getCreds(t *testing.T) { + tests := []struct { + name string + env map[string]string + want *Creds + wantErr interface{} + }{ + { + "fails with no JSON", + nil, nil, &syntaxError, + }, + { + "fails with malformed JSON", + map[string]string{ + "VCAP_SERVICES": `{"foo": [{"bar": false}}`, + }, + nil, &syntaxError, + }, + { + "fails with incorrectly defined VCAP envvar", + map[string]string{ + "VCAP_SURGICES": getVcapJson("aa", "bb"), + }, + nil, &syntaxError, + }, + { + "pulls credentials from JSON", + map[string]string{ + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Creds{Username: "aa", Password: "bb"}, nil, + }, + { + "pulls credentials from JSON when only user available", + map[string]string{ + "CF_USERNAME": "Klaus", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Creds{Username: "aa", Password: "bb"}, nil, + }, + { + "pulls credentials from JSON when only pass available", + map[string]string{ + "CF_PASSWORD": "tulip-cat-cupcake", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Creds{Username: "aa", Password: "bb"}, nil, + }, + { + "pulls credentials from specifically defined envvars if available", + map[string]string{ + "CF_USERNAME": "Klaus", + "CF_PASSWORD": "tulip-cat-cupcake", + "VCAP_SERVICES": getVcapJson("aa", "bb"), + }, + &Creds{Username: "Klaus", Password: "tulip-cat-cupcake"}, nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + for key, val := range tt.env { + t.Setenv(key, val) + } + + have, err := getCreds() + + if (err == nil) != (tt.wantErr == nil) { + t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if err != nil && !errors.As(err, tt.wantErr) { + t.Errorf("GetCredentials() bad error type: have %T, want %T", err, tt.wantErr) + return + } + + if diff := cmp.Diff(tt.want, have); diff != "" { + t.Error(diff) + } + }) + } +} diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index 5173281..a711db2 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -1,105 +1,10 @@ package main import ( - "encoding/json" - "errors" "fmt" "testing" - - "github.com/cloudfoundry/go-cfclient/v3/client" - "github.com/google/go-cmp/cmp" ) -var syntaxError *json.SyntaxError - -func getVcapJson(u string, p string) string { - return fmt.Sprintf(`{"cloud-gov-service-account":[{"credentials":{"username":"%s","password":"%s"}}]}`, u, p) -} - -func TestGetCfCredentials(t *testing.T) { - tests := []struct { - name string - env map[string]string - want *CfCredentials - wantErr interface{} - }{ - { - "fails with no JSON", - nil, nil, &syntaxError, - }, - { - "fails with malformed JSON", - map[string]string{ - "VCAP_SERVICES": `{"foo": [{"bar": false}}`, - }, - nil, &syntaxError, - }, - { - "fails with incorrectly defined VCAP envvar", - map[string]string{ - "VCAP_SURGICES": getVcapJson("aa", "bb"), - }, - nil, &syntaxError, - }, - { - "pulls credentials from JSON", - map[string]string{ - "VCAP_SERVICES": getVcapJson("aa", "bb"), - }, - &CfCredentials{"aa", "bb"}, nil, - }, - { - "pulls credentials from JSON when only user available", - map[string]string{ - "CF_USERNAME": "Klaus", - "VCAP_SERVICES": getVcapJson("aa", "bb"), - }, - &CfCredentials{"aa", "bb"}, nil, - }, - { - "pulls credentials from JSON when only pass available", - map[string]string{ - "CF_PASSWORD": "tulip-cat-cupcake", - "VCAP_SERVICES": getVcapJson("aa", "bb"), - }, - &CfCredentials{"aa", "bb"}, nil, - }, - { - "pulls credentials from specifically defined envvars if available", - map[string]string{ - "CF_USERNAME": "Klaus", - "CF_PASSWORD": "tulip-cat-cupcake", - "VCAP_SERVICES": getVcapJson("aa", "bb"), - }, - &CfCredentials{"Klaus", "tulip-cat-cupcake"}, nil, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - for key, val := range tt.env { - t.Setenv(key, val) - } - - have, err := GetCfCredentials() - - if (err == nil) != (tt.wantErr == nil) { - t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) - return - } - - if err != nil && !errors.As(err, tt.wantErr) { - t.Errorf("GetCredentials() bad error type: have %T, want %T", err, tt.wantErr) - return - } - - if diff := cmp.Diff(tt.want, have); diff != "" { - t.Error(diff) - } - }) - } -} - // func TestGetCfClient(t *testing.T) { // tests := []struct { // name string From 7cc5d7c64ebe0717da033355e2c1c99d32727c9c Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 9 Dec 2024 11:36:21 -0500 Subject: [PATCH 24/76] fix: add json tag for CGSrvAct.Creds, make isEmpty an OR --- runner/cf-executor/cg/creds.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runner/cf-executor/cg/creds.go b/runner/cf-executor/cg/creds.go index babb924..1dc7108 100644 --- a/runner/cf-executor/cg/creds.go +++ b/runner/cf-executor/cg/creds.go @@ -12,12 +12,14 @@ type Creds struct { Password string } -func (cr *Creds) isEmpty() bool { - return cr.Username == "" && cr.Password == "" +type vcapData struct { + CGSrvAct []struct { + Creds `json:"credentials"` + } `json:"cloud-gov-service-account"` } -type vcapData struct { - CGSrvAct []struct{ Creds Creds } `json:"cloud-gov-service-account"` +func (cr *Creds) isEmpty() bool { + return cr.Username == "" || cr.Password == "" } func getCreds() (*Creds, error) { From 6e4723547e8af349a02d894f3f9da45b21f17819 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Tue, 10 Dec 2024 08:59:13 -0500 Subject: [PATCH 25/76] chore: rearrange Test_getCreds fields for better data alignment --- runner/cf-executor/cg/creds_test.go | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/runner/cf-executor/cg/creds_test.go b/runner/cf-executor/cg/creds_test.go index 7fcad54..10ba91f 100644 --- a/runner/cf-executor/cg/creds_test.go +++ b/runner/cf-executor/cg/creds_test.go @@ -17,60 +17,60 @@ func getVcapJson(u string, p string) string { func Test_getCreds(t *testing.T) { tests := []struct { - name string - env map[string]string want *Creds wantErr interface{} + env map[string]string + name string }{ { - "fails with no JSON", - nil, nil, &syntaxError, + name: "fails with no JSON", + wantErr: &syntaxError, }, { - "fails with malformed JSON", - map[string]string{ + name: "fails with malformed JSON", + wantErr: &syntaxError, + env: map[string]string{ "VCAP_SERVICES": `{"foo": [{"bar": false}}`, }, - nil, &syntaxError, }, { - "fails with incorrectly defined VCAP envvar", - map[string]string{ + name: "fails with incorrectly defined VCAP envvar", + wantErr: &syntaxError, + env: map[string]string{ "VCAP_SURGICES": getVcapJson("aa", "bb"), }, - nil, &syntaxError, }, { - "pulls credentials from JSON", - map[string]string{ + name: "pulls credentials from JSON", + want: &Creds{Username: "aa", Password: "bb"}, + env: map[string]string{ "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Creds{Username: "aa", Password: "bb"}, nil, }, { - "pulls credentials from JSON when only user available", - map[string]string{ + name: "pulls credentials from JSON when only user available", + want: &Creds{Username: "aa", Password: "bb"}, + env: map[string]string{ "CF_USERNAME": "Klaus", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Creds{Username: "aa", Password: "bb"}, nil, }, { - "pulls credentials from JSON when only pass available", - map[string]string{ + name: "pulls credentials from JSON when only pass available", + want: &Creds{Username: "aa", Password: "bb"}, + env: map[string]string{ "CF_PASSWORD": "tulip-cat-cupcake", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Creds{Username: "aa", Password: "bb"}, nil, }, { - "pulls credentials from specifically defined envvars if available", - map[string]string{ + name: "pulls credentials from specifically defined envvars if available", + want: &Creds{Username: "Klaus", Password: "tulip-cat-cupcake"}, + env: map[string]string{ "CF_USERNAME": "Klaus", "CF_PASSWORD": "tulip-cat-cupcake", "VCAP_SERVICES": getVcapJson("aa", "bb"), }, - &Creds{Username: "Klaus", Password: "tulip-cat-cupcake"}, nil, }, } From 59bb4680e6087b7d70f9f3e219790a3479ca3717 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Tue, 10 Dec 2024 11:40:38 -0500 Subject: [PATCH 26/76] test: add tests & test stubs for CG --- runner/cf-executor/cg/cg.go | 20 ++- runner/cf-executor/cg/cg_test.go | 197 ++++++++++++++++++++++++++++ runner/cf-executor/cg/creds.go | 4 +- runner/cf-executor/cg/creds_test.go | 2 +- 4 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 runner/cf-executor/cg/cg_test.go diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index 7dcc43a..cab2ade 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -22,23 +22,29 @@ type Adapter interface { connect(url string, creds *Creds) error } -type CG struct { - Adapter - Opts +type CredI interface { + getCreds() (*Creds, error) } type Opts struct { - Creds Creds + CredI + Creds Creds + APIRootURL string } +type CG struct { + Adapter + *Opts +} + var apiRootURLDefault = "https://api.fr.cloud.gov" func New(a Adapter, o *Opts) (*CG, error) { if o == nil { - o = &Opts{} + o = &Opts{CredI: EnvCredsGetter{}} } - cg := &CG{a, *o} + cg := &CG{a, o} return cg.Connect() } @@ -51,7 +57,7 @@ func (c *CG) apiRootURL() string { func (c *CG) creds() (*Creds, error) { if c.Creds.isEmpty() { - return getCreds() + return c.getCreds() } return &c.Creds, nil } diff --git a/runner/cf-executor/cg/cg_test.go b/runner/cf-executor/cg/cg_test.go new file mode 100644 index 0000000..c975dc5 --- /dev/null +++ b/runner/cf-executor/cg/cg_test.go @@ -0,0 +1,197 @@ +package cg + +import ( + "errors" + "testing" + + "github.com/google/go-cmp/cmp" +) + +type adapterStub struct { + Adapter +} + +func (adapterStub) getApps() (apps []*App, err error) { + panic("getApps not implemented") // TODO: Implement +} + +func (adapterStub) connect(url string, creds *Creds) (_ error) { + return nil +} + +type credIStub struct{} + +func (credIStub) getCreds() (*Creds, error) { + return &Creds{"", ""}, nil +} + +var ( + optsStub *Opts = &Opts{CredI: credIStub{}} + cgStub *CG = &CG{adapterStub{}, optsStub} +) + +func TestNew(t *testing.T) { + tests := []struct { + want *CG + opts *Opts + wantErr interface{} + name string + }{ + {name: "fails using default credential getter", wantErr: &syntaxError}, + {name: "returns adapted CG struct", want: cgStub, opts: optsStub}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + have, err := New(adapterStub{}, tt.opts) + + if (err == nil) != (tt.wantErr == nil) { + t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if err != nil && !errors.As(err, tt.wantErr) { + t.Errorf("GetCredentials() bad error type: have %T, want %T", err, tt.wantErr) + return + } + + if diff := cmp.Diff(tt.want, have); diff != "" { + t.Error(diff) + } + }) + } +} + +func TestCG_apiRootURL(t *testing.T) { + type fields struct { + Adapter Adapter + Opts *Opts + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "gets default root API URL", + want: apiRootURLDefault, + fields: fields{ + Adapter: adapterStub{}, + Opts: &Opts{CredI: credIStub{}}, + }, + }, + { + name: "updates root API URL", + want: "foo", + fields: fields{ + Adapter: adapterStub{}, + Opts: &Opts{CredI: credIStub{}, APIRootURL: "foo"}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &CG{ + Adapter: tt.fields.Adapter, + Opts: tt.fields.Opts, + } + got := c.apiRootURL() + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Error(diff) + } + }) + } +} + +func TestCG_creds(t *testing.T) { + type fields struct { + Adapter Adapter + Opts *Opts + } + tests := []struct { + fields fields + want *Creds + name string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &CG{ + Adapter: tt.fields.Adapter, + Opts: tt.fields.Opts, + } + got, err := c.creds() + if (err != nil) != tt.wantErr { + t.Errorf("CG.creds() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Error(diff) + } + }) + } +} + +func TestCG_Connect(t *testing.T) { + type fields struct { + Adapter Adapter + Opts *Opts + } + tests := []struct { + fields fields + want *CG + name string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &CG{ + Adapter: tt.fields.Adapter, + Opts: tt.fields.Opts, + } + got, err := c.Connect() + if (err != nil) != tt.wantErr { + t.Errorf("CG.Connect() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Error(diff) + } + }) + } +} + +func TestCG_GetApps(t *testing.T) { + type fields struct { + Adapter Adapter + Opts *Opts + } + tests := []struct { + name string + fields fields + want []*App + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &CG{ + Adapter: tt.fields.Adapter, + Opts: tt.fields.Opts, + } + got, err := c.GetApps() + if (err != nil) != tt.wantErr { + t.Errorf("CG.GetApps() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Error(diff) + } + }) + } +} diff --git a/runner/cf-executor/cg/creds.go b/runner/cf-executor/cg/creds.go index 1dc7108..d87118f 100644 --- a/runner/cf-executor/cg/creds.go +++ b/runner/cf-executor/cg/creds.go @@ -22,7 +22,9 @@ func (cr *Creds) isEmpty() bool { return cr.Username == "" || cr.Password == "" } -func getCreds() (*Creds, error) { +type EnvCredsGetter struct{} + +func (e EnvCredsGetter) getCreds() (*Creds, error) { creds := &Creds{} // Check if credentials are supplied through environment diff --git a/runner/cf-executor/cg/creds_test.go b/runner/cf-executor/cg/creds_test.go index 10ba91f..813bee7 100644 --- a/runner/cf-executor/cg/creds_test.go +++ b/runner/cf-executor/cg/creds_test.go @@ -80,7 +80,7 @@ func Test_getCreds(t *testing.T) { t.Setenv(key, val) } - have, err := getCreds() + have, err := EnvCredsGetter{}.getCreds() if (err == nil) != (tt.wantErr == nil) { t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) From 1b705bcaa828f35f2b9ef25d3b013caf490ae99e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 11 Dec 2024 15:56:10 -0500 Subject: [PATCH 27/76] test: adding tests for rest of the CG stubs --- runner/cf-executor/cg/cg.go | 4 +- runner/cf-executor/cg/cg_test.go | 151 +++++++++++++++++++++++++------ 2 files changed, 125 insertions(+), 30 deletions(-) diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index cab2ade..31c87c0 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -28,7 +28,7 @@ type CredI interface { type Opts struct { CredI - Creds Creds + Creds *Creds APIRootURL string } @@ -59,7 +59,7 @@ func (c *CG) creds() (*Creds, error) { if c.Creds.isEmpty() { return c.getCreds() } - return &c.Creds, nil + return c.Creds, nil } func (c *CG) Connect() (*CG, error) { diff --git a/runner/cf-executor/cg/cg_test.go b/runner/cf-executor/cg/cg_test.go index c975dc5..ab736fb 100644 --- a/runner/cf-executor/cg/cg_test.go +++ b/runner/cf-executor/cg/cg_test.go @@ -9,28 +9,51 @@ import ( type adapterStub struct { Adapter + + StCreds *Creds + StURL string + StApps []*App + + FailGetApps bool + FailConnect bool } -func (adapterStub) getApps() (apps []*App, err error) { - panic("getApps not implemented") // TODO: Implement +func (a *adapterStub) getApps() (apps []*App, err error) { + if a.FailGetApps { + return nil, errors.New("fail") + } + return a.StApps, nil } -func (adapterStub) connect(url string, creds *Creds) (_ error) { +func (a *adapterStub) connect(url string, creds *Creds) (_ error) { + if a.FailConnect { + return errors.New("fail") + } + a.StURL = url + a.StCreds = creds return nil } -type credIStub struct{} - -func (credIStub) getCreds() (*Creds, error) { - return &Creds{"", ""}, nil +type credIStub struct { + U string + P string + Fail bool } -var ( - optsStub *Opts = &Opts{CredI: credIStub{}} - cgStub *CG = &CG{adapterStub{}, optsStub} -) +func (c credIStub) getCreds() (*Creds, error) { + if c.Fail { + return nil, errors.New("fail") + } + return &Creds{c.U, c.P}, nil +} func TestNew(t *testing.T) { + optsStub := &Opts{CredI: credIStub{"a", "b", false}} + cgStub := &CG{&adapterStub{ + StURL: apiRootURLDefault, + StCreds: &Creds{"a", "b"}, + }, optsStub} + tests := []struct { want *CG opts *Opts @@ -43,20 +66,17 @@ func TestNew(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - have, err := New(adapterStub{}, tt.opts) - + got, err := New(&adapterStub{}, tt.opts) if (err == nil) != (tt.wantErr == nil) { t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) return } - if err != nil && !errors.As(err, tt.wantErr) { - t.Errorf("GetCredentials() bad error type: have %T, want %T", err, tt.wantErr) + t.Errorf("GetCredentials() bad error type: got %T, want %T", err, tt.wantErr) return } - - if diff := cmp.Diff(tt.want, have); diff != "" { - t.Error(diff) + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Errorf("mismatch (-got +want):\n%s", diff) } }) } @@ -76,7 +96,7 @@ func TestCG_apiRootURL(t *testing.T) { name: "gets default root API URL", want: apiRootURLDefault, fields: fields{ - Adapter: adapterStub{}, + Adapter: &adapterStub{}, Opts: &Opts{CredI: credIStub{}}, }, }, @@ -84,7 +104,7 @@ func TestCG_apiRootURL(t *testing.T) { name: "updates root API URL", want: "foo", fields: fields{ - Adapter: adapterStub{}, + Adapter: &adapterStub{}, Opts: &Opts{CredI: credIStub{}, APIRootURL: "foo"}, }, }, @@ -97,7 +117,7 @@ func TestCG_apiRootURL(t *testing.T) { } got := c.apiRootURL() if diff := cmp.Diff(got, tt.want); diff != "" { - t.Error(diff) + t.Errorf("mismatch (-got +want):\n%s", diff) } }) } @@ -108,14 +128,31 @@ func TestCG_creds(t *testing.T) { Adapter Adapter Opts *Opts } + tests := []struct { fields fields want *Creds name string wantErr bool }{ - // TODO: Add test cases. + { + name: "returns creds when they already exist", + want: &Creds{"a", "b"}, + fields: fields{ + Adapter: &adapterStub{}, + Opts: &Opts{Creds: &Creds{"a", "b"}}, + }, + }, + { + name: "returns creds from getter when not supplied", + want: &Creds{"foo", "bar"}, + fields: fields{ + Adapter: &adapterStub{}, + Opts: &Opts{CredI: credIStub{U: "foo", P: "bar"}}, + }, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ @@ -128,7 +165,7 @@ func TestCG_creds(t *testing.T) { return } if diff := cmp.Diff(got, tt.want); diff != "" { - t.Error(diff) + t.Errorf("mismatch (-got +want):\n%s", diff) } }) } @@ -139,45 +176,103 @@ func TestCG_Connect(t *testing.T) { Adapter Adapter Opts *Opts } + tests := []struct { fields fields want *CG + cmpGet func(c *CG) any name string + checks []string wantErr bool }{ - // TODO: Add test cases. + { + name: "fails with creds() err", + wantErr: true, + fields: fields{ + Adapter: &adapterStub{}, + Opts: &Opts{CredI: &credIStub{Fail: true}}, + }, + }, + { + name: "connect sets URL & creds", + want: &CG{ + Adapter: &adapterStub{ + StURL: "butter", + StCreds: &Creds{Username: "corn", Password: "cob"}, + }, + }, + fields: fields{ + Adapter: &adapterStub{}, + Opts: &Opts{ + APIRootURL: "butter", + Creds: &Creds{Username: "corn", Password: "cob"}, + }, + }, + cmpGet: func(c *CG) any { + return c.Adapter + }, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ Adapter: tt.fields.Adapter, Opts: tt.fields.Opts, } + got, err := c.Connect() + if (err != nil) != tt.wantErr { t.Errorf("CG.Connect() error = %v, wantErr %v", err, tt.wantErr) return } - if diff := cmp.Diff(got, tt.want); diff != "" { - t.Error(diff) + + if tt.cmpGet == nil { + tt.cmpGet = func(c *CG) any { + return c + } + } + + if diff := cmp.Diff(tt.cmpGet(got), tt.cmpGet(tt.want)); diff != "" { + t.Errorf("mismatch (-got +want):\n%s", diff) } }) } } func TestCG_GetApps(t *testing.T) { + testApps := []*App{{Id: "1", Name: "foo"}} + type fields struct { Adapter Adapter Opts *Opts } + tests := []struct { name string fields fields want []*App wantErr bool }{ - // TODO: Add test cases. + { + name: "reports errors", + wantErr: true, + fields: fields{ + Adapter: &adapterStub{StApps: testApps, FailGetApps: true}, + Opts: &Opts{CredI: &credIStub{}}, + }, + }, + { + name: "returns available apps list", + want: testApps, + fields: fields{ + Adapter: &adapterStub{StApps: testApps}, + Opts: &Opts{CredI: &credIStub{}}, + }, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ @@ -190,7 +285,7 @@ func TestCG_GetApps(t *testing.T) { return } if diff := cmp.Diff(got, tt.want); diff != "" { - t.Error(diff) + t.Errorf("mismatch (-got +want):\n%s", diff) } }) } From a110cb7082efd7ae52c16cd692286b58fc49880e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 11 Dec 2024 15:56:33 -0500 Subject: [PATCH 28/76] fix: issue with nil creds --- runner/cf-executor/cg/creds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-executor/cg/creds.go b/runner/cf-executor/cg/creds.go index d87118f..0129221 100644 --- a/runner/cf-executor/cg/creds.go +++ b/runner/cf-executor/cg/creds.go @@ -19,7 +19,7 @@ type vcapData struct { } func (cr *Creds) isEmpty() bool { - return cr.Username == "" || cr.Password == "" + return cr == nil || cr.Username == "" || cr.Password == "" } type EnvCredsGetter struct{} From b2ae777ef72e249b8095fd710c44a065a4670e3e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 11 Dec 2024 16:03:21 -0500 Subject: [PATCH 29/76] chore: delete commented out stub test from main_test.go --- runner/cf-executor/main_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/runner/cf-executor/main_test.go b/runner/cf-executor/main_test.go index a711db2..cbd2b8d 100644 --- a/runner/cf-executor/main_test.go +++ b/runner/cf-executor/main_test.go @@ -5,26 +5,6 @@ import ( "testing" ) -// func TestGetCfClient(t *testing.T) { -// tests := []struct { -// name string -// want *client.Client -// wantErr bool -// }{{}} -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// got, err := GetCfClient() -// if (err != nil) != tt.wantErr { -// t.Errorf("GetCfClient() error = %v, wantErr %v", err, tt.wantErr) -// return -// } -// if !reflect.DeepEqual(got, tt.want) { -// t.Errorf("GetCfClient() = %v, want %v", got, tt.want) -// } -// }) -// } -// } - func Test_main(t *testing.T) { t.Skip("Test_main is just for experiments right now") From 97f35aa4e2398550e0d23591399283e974d469d4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 14:54:58 -0500 Subject: [PATCH 30/76] refactor: Adapter -> CloudI, more descriptive and fun --- runner/cf-executor/cg/cg.go | 6 +-- runner/cf-executor/cg/cg_test.go | 69 ++++++++++++++++---------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index 31c87c0..0c95d1e 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -17,7 +17,7 @@ type App struct { // appCmd() // appPush() // appDelete() -type Adapter interface { +type CloudI interface { getApps() (apps []*App, err error) connect(url string, creds *Creds) error } @@ -34,13 +34,13 @@ type Opts struct { } type CG struct { - Adapter + CloudI *Opts } var apiRootURLDefault = "https://api.fr.cloud.gov" -func New(a Adapter, o *Opts) (*CG, error) { +func New(a CloudI, o *Opts) (*CG, error) { if o == nil { o = &Opts{CredI: EnvCredsGetter{}} } diff --git a/runner/cf-executor/cg/cg_test.go b/runner/cf-executor/cg/cg_test.go index ab736fb..8ba5b6b 100644 --- a/runner/cf-executor/cg/cg_test.go +++ b/runner/cf-executor/cg/cg_test.go @@ -8,7 +8,7 @@ import ( ) type adapterStub struct { - Adapter + CloudI StCreds *Creds StURL string @@ -84,9 +84,10 @@ func TestNew(t *testing.T) { func TestCG_apiRootURL(t *testing.T) { type fields struct { - Adapter Adapter - Opts *Opts + CloudI + Opts *Opts } + tests := []struct { name string fields fields @@ -96,24 +97,24 @@ func TestCG_apiRootURL(t *testing.T) { name: "gets default root API URL", want: apiRootURLDefault, fields: fields{ - Adapter: &adapterStub{}, - Opts: &Opts{CredI: credIStub{}}, + CloudI: &adapterStub{}, + Opts: &Opts{CredI: credIStub{}}, }, }, { name: "updates root API URL", want: "foo", fields: fields{ - Adapter: &adapterStub{}, - Opts: &Opts{CredI: credIStub{}, APIRootURL: "foo"}, + CloudI: &adapterStub{}, + Opts: &Opts{CredI: credIStub{}, APIRootURL: "foo"}, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ - Adapter: tt.fields.Adapter, - Opts: tt.fields.Opts, + CloudI: tt.fields.CloudI, + Opts: tt.fields.Opts, } got := c.apiRootURL() if diff := cmp.Diff(got, tt.want); diff != "" { @@ -125,8 +126,8 @@ func TestCG_apiRootURL(t *testing.T) { func TestCG_creds(t *testing.T) { type fields struct { - Adapter Adapter - Opts *Opts + CloudI + Opts *Opts } tests := []struct { @@ -139,16 +140,16 @@ func TestCG_creds(t *testing.T) { name: "returns creds when they already exist", want: &Creds{"a", "b"}, fields: fields{ - Adapter: &adapterStub{}, - Opts: &Opts{Creds: &Creds{"a", "b"}}, + CloudI: &adapterStub{}, + Opts: &Opts{Creds: &Creds{"a", "b"}}, }, }, { name: "returns creds from getter when not supplied", want: &Creds{"foo", "bar"}, fields: fields{ - Adapter: &adapterStub{}, - Opts: &Opts{CredI: credIStub{U: "foo", P: "bar"}}, + CloudI: &adapterStub{}, + Opts: &Opts{CredI: credIStub{U: "foo", P: "bar"}}, }, }, } @@ -156,8 +157,8 @@ func TestCG_creds(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ - Adapter: tt.fields.Adapter, - Opts: tt.fields.Opts, + CloudI: tt.fields.CloudI, + Opts: tt.fields.Opts, } got, err := c.creds() if (err != nil) != tt.wantErr { @@ -173,8 +174,8 @@ func TestCG_creds(t *testing.T) { func TestCG_Connect(t *testing.T) { type fields struct { - Adapter Adapter - Opts *Opts + CloudI + Opts *Opts } tests := []struct { @@ -189,27 +190,27 @@ func TestCG_Connect(t *testing.T) { name: "fails with creds() err", wantErr: true, fields: fields{ - Adapter: &adapterStub{}, - Opts: &Opts{CredI: &credIStub{Fail: true}}, + CloudI: &adapterStub{}, + Opts: &Opts{CredI: &credIStub{Fail: true}}, }, }, { name: "connect sets URL & creds", want: &CG{ - Adapter: &adapterStub{ + CloudI: &adapterStub{ StURL: "butter", StCreds: &Creds{Username: "corn", Password: "cob"}, }, }, fields: fields{ - Adapter: &adapterStub{}, + CloudI: &adapterStub{}, Opts: &Opts{ APIRootURL: "butter", Creds: &Creds{Username: "corn", Password: "cob"}, }, }, cmpGet: func(c *CG) any { - return c.Adapter + return c.CloudI }, }, } @@ -217,8 +218,8 @@ func TestCG_Connect(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ - Adapter: tt.fields.Adapter, - Opts: tt.fields.Opts, + CloudI: tt.fields.CloudI, + Opts: tt.fields.Opts, } got, err := c.Connect() @@ -245,8 +246,8 @@ func TestCG_GetApps(t *testing.T) { testApps := []*App{{Id: "1", Name: "foo"}} type fields struct { - Adapter Adapter - Opts *Opts + CloudI + Opts *Opts } tests := []struct { @@ -259,16 +260,16 @@ func TestCG_GetApps(t *testing.T) { name: "reports errors", wantErr: true, fields: fields{ - Adapter: &adapterStub{StApps: testApps, FailGetApps: true}, - Opts: &Opts{CredI: &credIStub{}}, + CloudI: &adapterStub{StApps: testApps, FailGetApps: true}, + Opts: &Opts{CredI: &credIStub{}}, }, }, { name: "returns available apps list", want: testApps, fields: fields{ - Adapter: &adapterStub{StApps: testApps}, - Opts: &Opts{CredI: &credIStub{}}, + CloudI: &adapterStub{StApps: testApps}, + Opts: &Opts{CredI: &credIStub{}}, }, }, } @@ -276,8 +277,8 @@ func TestCG_GetApps(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &CG{ - Adapter: tt.fields.Adapter, - Opts: tt.fields.Opts, + CloudI: tt.fields.CloudI, + Opts: tt.fields.Opts, } got, err := c.GetApps() if (err != nil) != tt.wantErr { From 9a3c0c40c36a71b92d79dab65790561c7d8b633e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:12:35 -0500 Subject: [PATCH 31/76] chore: better error msg for go-cfclient.conn() --- runner/cf-executor/cg/cf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-executor/cg/cf.go b/runner/cf-executor/cg/cf.go index c680802..7bc621b 100644 --- a/runner/cf-executor/cg/cf.go +++ b/runner/cf-executor/cg/cf.go @@ -31,7 +31,7 @@ func (cf *GoCFClientAdapter) conn() *client.Client { if cf._con != nil { return cf._con } - panic("not connected") + panic("go-cfclient adapter is not connected") } func (cf *GoCFClientAdapter) getApps() ([]*App, error) { From 34fe7a5edd459178989dc67e709e9706d9fc8a5e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:23:29 -0500 Subject: [PATCH 32/76] refactor: extract the cf-client adapter's app casting --- runner/cf-executor/cg/cf.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/runner/cf-executor/cg/cf.go b/runner/cf-executor/cg/cf.go index 7bc621b..56585a7 100644 --- a/runner/cf-executor/cg/cf.go +++ b/runner/cf-executor/cg/cf.go @@ -5,6 +5,7 @@ import ( "github.com/cloudfoundry/go-cfclient/v3/client" "github.com/cloudfoundry/go-cfclient/v3/config" + "github.com/cloudfoundry/go-cfclient/v3/resource" ) type GoCFClientAdapter struct { @@ -23,7 +24,6 @@ func (cf *GoCFClientAdapter) connect(url string, creds *Creds) error { } cf._con = con - return nil } @@ -34,16 +34,18 @@ func (cf *GoCFClientAdapter) conn() *client.Client { panic("go-cfclient adapter is not connected") } -func (cf *GoCFClientAdapter) getApps() ([]*App, error) { - apps, err := cf.conn().Applications.ListAll(context.Background(), nil) - if err != nil { - return nil, err - } - +func castApps(apps []*resource.App) []*App { Apps := make([]*App, len(apps)) for idx, app := range apps { Apps[idx] = &(App{app.GUID, app.Name, app.State}) } + return Apps +} - return Apps, nil +func (cf *GoCFClientAdapter) getApps() ([]*App, error) { + apps, err := cf.conn().Applications.ListAll(context.Background(), nil) + if err != nil { + return nil, err + } + return castApps(apps), nil } From fcda405e423465cdc99b52acc1b8ff0a37959e34 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:32:00 -0500 Subject: [PATCH 33/76] style: indirect deps should be in own require block --- runner/cf-executor/go.mod | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runner/cf-executor/go.mod b/runner/cf-executor/go.mod index d4bc0ab..2f7175a 100644 --- a/runner/cf-executor/go.mod +++ b/runner/cf-executor/go.mod @@ -2,14 +2,16 @@ module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-executor go 1.23.3 -require github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 +require ( + github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 + github.com/google/go-cmp v0.6.0 + github.com/joho/godotenv v1.5.1 +) require ( github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect - github.com/google/go-cmp v0.6.0 - github.com/joho/godotenv v1.5.1 github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect From 8ad38f7e882fb94ac86700806ba829ae7c9054a6 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:33:36 -0500 Subject: [PATCH 34/76] refactor: more descriptive name for cf_adapter file --- runner/cf-executor/cg/{cf.go => cf_adapter.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename runner/cf-executor/cg/{cf.go => cf_adapter.go} (100%) diff --git a/runner/cf-executor/cg/cf.go b/runner/cf-executor/cg/cf_adapter.go similarity index 100% rename from runner/cf-executor/cg/cf.go rename to runner/cf-executor/cg/cf_adapter.go From c9ed52e2b6fb69e565c41c68575633ae1bd1e9d4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:40:58 -0500 Subject: [PATCH 35/76] style: the default root url should prob be a const --- runner/cf-executor/cg/cg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index 0c95d1e..6c7492b 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -38,7 +38,7 @@ type CG struct { *Opts } -var apiRootURLDefault = "https://api.fr.cloud.gov" +const apiRootURLDefault = "https://api.fr.cloud.gov" func New(a CloudI, o *Opts) (*CG, error) { if o == nil { From f1ccccf227258853a0773a1a4a519b8f65bcee43 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 12 Dec 2024 15:42:22 -0500 Subject: [PATCH 36/76] style: short CloudI shoulda been `i` --- runner/cf-executor/cg/cg.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-executor/cg/cg.go index 6c7492b..082436d 100644 --- a/runner/cf-executor/cg/cg.go +++ b/runner/cf-executor/cg/cg.go @@ -40,11 +40,11 @@ type CG struct { const apiRootURLDefault = "https://api.fr.cloud.gov" -func New(a CloudI, o *Opts) (*CG, error) { +func New(i CloudI, o *Opts) (*CG, error) { if o == nil { o = &Opts{CredI: EnvCredsGetter{}} } - cg := &CG{a, o} + cg := &CG{i, o} return cg.Connect() } From 8ebc0b418511a46ecdef1efb0404e9fea2ff7a99 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 13 Dec 2024 10:01:17 -0500 Subject: [PATCH 37/76] feat: add test target to Makefile --- runner/cf-executor/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runner/cf-executor/Makefile b/runner/cf-executor/Makefile index 45c8ea4..6e07fdd 100644 --- a/runner/cf-executor/Makefile +++ b/runner/cf-executor/Makefile @@ -7,5 +7,8 @@ fmt: vet: fmt go vet ./... +test: vet + go test ./... + build: vet go build From ab56585d79045967c77a933bf3d46e8ee58deaf4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 13 Dec 2024 17:12:45 -0500 Subject: [PATCH 38/76] fix: clear tested env vars before testing creds.go See issue #67 --- runner/cf-executor/cg/creds_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runner/cf-executor/cg/creds_test.go b/runner/cf-executor/cg/creds_test.go index 813bee7..153bb47 100644 --- a/runner/cf-executor/cg/creds_test.go +++ b/runner/cf-executor/cg/creds_test.go @@ -74,6 +74,15 @@ func Test_getCreds(t *testing.T) { }, } + // Todo (zjrgov): it could also make sense to get ENV vars outside this + // code, but I'm not exactly sure what the end implementation will look + // like and don't want to get ahead of myself. + // + // See https://github.com/GSA-TTS/gitlab-runner-cloudgov/issues/67 + for _, k := range []string{"CF_USERNAME", "CF_PASSWORD", "VCAP_SERVICES"} { + t.Setenv(k, "") + } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { for key, val := range tt.env { From d93675762246aa4ecc5062e60eccc218f9e18f5d Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 16 Dec 2024 14:41:57 -0500 Subject: [PATCH 39/76] docs: add README.md to the go driver with info RE deps & testing --- runner/cf-executor/README.md | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 runner/cf-executor/README.md diff --git a/runner/cf-executor/README.md b/runner/cf-executor/README.md new file mode 100644 index 0000000..26d7520 --- /dev/null +++ b/runner/cf-executor/README.md @@ -0,0 +1,51 @@ +# CloudFoundry (cloud.gov) driver + +This is a _driver_ developed for use with `gitlab-runner`’s [Custom executor](https://docs.gitlab.com/runner/executors/custom.html) to prepare, run, and clean up runner managers, workers, and services. + +## Go setup + +### Install Go + +You can use Homebrew to install Go on MacOS (it is generally unnecessary to use a version manager). You could also download Go packages for Linux, Mac, and Windows from [Go's website](https://go.dev/doc/install). + +```sh +brew install go +``` + +### Manage dependencies + +Manage project dependencies with `go` & `go mod`. Go programs are divided first into _modules_ and then into _packages_. Dependencies are listed in `./go.mod`. + +#### To download dependencies + +To download deps as listed in `./go.mod`, run: + +```sh +go mod download +``` + +Or, to walk the project and as needed install & remove modules while updating `./go.mod` & `./go.sum` accordingly: + +```sh +go mod tidy +``` + +#### To `get` new dependencies + +While `go mod tidy` can install dependencies you've already imported in your packages, you can also install them explicitly: + +```sh +go get github.com/google/some-mod/pkg +``` + +## Running tests + +The simplest way to run tests—or the one with the least typing, at least—is with `make`. + +```sh +make test +``` + +## Builds + +You can also run a build with `make` (`make build`, or simply `make`), but it won't do you much good because we aren't set up to do anything with an executable yet. From 53c7af58799907dad850837d0e95824291fc7832 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 16 Dec 2024 14:43:30 -0500 Subject: [PATCH 40/76] chore: update the go.sum --- runner/cf-executor/go.sum | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runner/cf-executor/go.sum b/runner/cf-executor/go.sum index 40a4b5c..a99c489 100644 --- a/runner/cf-executor/go.sum +++ b/runner/cf-executor/go.sum @@ -18,11 +18,14 @@ github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwU github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 6da90b15443758ed79d777db16ca4ab9e858d098 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Mon, 16 Dec 2024 14:47:27 -0500 Subject: [PATCH 41/76] chore: executor should be driver! --- runner/{cf-executor => cf-driver-go}/.gitignore | 0 runner/{cf-executor => cf-driver-go}/.vscode/launch.json | 0 runner/{cf-executor => cf-driver-go}/Makefile | 0 runner/{cf-executor => cf-driver-go}/README.md | 0 runner/{cf-executor => cf-driver-go}/cg/cf_adapter.go | 0 runner/{cf-executor => cf-driver-go}/cg/cg.go | 0 runner/{cf-executor => cf-driver-go}/cg/cg_test.go | 0 runner/{cf-executor => cf-driver-go}/cg/creds.go | 0 runner/{cf-executor => cf-driver-go}/cg/creds_test.go | 0 runner/{cf-executor => cf-driver-go}/go.mod | 2 +- runner/{cf-executor => cf-driver-go}/go.sum | 0 runner/{cf-executor => cf-driver-go}/main.go | 2 +- runner/{cf-executor => cf-driver-go}/main_test.go | 0 13 files changed, 2 insertions(+), 2 deletions(-) rename runner/{cf-executor => cf-driver-go}/.gitignore (100%) rename runner/{cf-executor => cf-driver-go}/.vscode/launch.json (100%) rename runner/{cf-executor => cf-driver-go}/Makefile (100%) rename runner/{cf-executor => cf-driver-go}/README.md (100%) rename runner/{cf-executor => cf-driver-go}/cg/cf_adapter.go (100%) rename runner/{cf-executor => cf-driver-go}/cg/cg.go (100%) rename runner/{cf-executor => cf-driver-go}/cg/cg_test.go (100%) rename runner/{cf-executor => cf-driver-go}/cg/creds.go (100%) rename runner/{cf-executor => cf-driver-go}/cg/creds_test.go (100%) rename runner/{cf-executor => cf-driver-go}/go.mod (91%) rename runner/{cf-executor => cf-driver-go}/go.sum (100%) rename runner/{cf-executor => cf-driver-go}/main.go (89%) rename runner/{cf-executor => cf-driver-go}/main_test.go (100%) diff --git a/runner/cf-executor/.gitignore b/runner/cf-driver-go/.gitignore similarity index 100% rename from runner/cf-executor/.gitignore rename to runner/cf-driver-go/.gitignore diff --git a/runner/cf-executor/.vscode/launch.json b/runner/cf-driver-go/.vscode/launch.json similarity index 100% rename from runner/cf-executor/.vscode/launch.json rename to runner/cf-driver-go/.vscode/launch.json diff --git a/runner/cf-executor/Makefile b/runner/cf-driver-go/Makefile similarity index 100% rename from runner/cf-executor/Makefile rename to runner/cf-driver-go/Makefile diff --git a/runner/cf-executor/README.md b/runner/cf-driver-go/README.md similarity index 100% rename from runner/cf-executor/README.md rename to runner/cf-driver-go/README.md diff --git a/runner/cf-executor/cg/cf_adapter.go b/runner/cf-driver-go/cg/cf_adapter.go similarity index 100% rename from runner/cf-executor/cg/cf_adapter.go rename to runner/cf-driver-go/cg/cf_adapter.go diff --git a/runner/cf-executor/cg/cg.go b/runner/cf-driver-go/cg/cg.go similarity index 100% rename from runner/cf-executor/cg/cg.go rename to runner/cf-driver-go/cg/cg.go diff --git a/runner/cf-executor/cg/cg_test.go b/runner/cf-driver-go/cg/cg_test.go similarity index 100% rename from runner/cf-executor/cg/cg_test.go rename to runner/cf-driver-go/cg/cg_test.go diff --git a/runner/cf-executor/cg/creds.go b/runner/cf-driver-go/cg/creds.go similarity index 100% rename from runner/cf-executor/cg/creds.go rename to runner/cf-driver-go/cg/creds.go diff --git a/runner/cf-executor/cg/creds_test.go b/runner/cf-driver-go/cg/creds_test.go similarity index 100% rename from runner/cf-executor/cg/creds_test.go rename to runner/cf-driver-go/cg/creds_test.go diff --git a/runner/cf-executor/go.mod b/runner/cf-driver-go/go.mod similarity index 91% rename from runner/cf-executor/go.mod rename to runner/cf-driver-go/go.mod index 2f7175a..5a6cd5a 100644 --- a/runner/cf-executor/go.mod +++ b/runner/cf-driver-go/go.mod @@ -1,4 +1,4 @@ -module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-executor +module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver go 1.23.3 diff --git a/runner/cf-executor/go.sum b/runner/cf-driver-go/go.sum similarity index 100% rename from runner/cf-executor/go.sum rename to runner/cf-driver-go/go.sum diff --git a/runner/cf-executor/main.go b/runner/cf-driver-go/main.go similarity index 89% rename from runner/cf-executor/main.go rename to runner/cf-driver-go/main.go index 552bed7..0c7f0aa 100644 --- a/runner/cf-executor/main.go +++ b/runner/cf-driver-go/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-executor/cg" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cg" "github.com/joho/godotenv" ) diff --git a/runner/cf-executor/main_test.go b/runner/cf-driver-go/main_test.go similarity index 100% rename from runner/cf-executor/main_test.go rename to runner/cf-driver-go/main_test.go From 5c5d7a0265d543443b1c73eabb311995ecbe7df9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 09:52:56 -0500 Subject: [PATCH 42/76] feat: add basic CI workflow for cf-driver-go --- .github/workflows/cf-driver-go.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/cf-driver-go.yml diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml new file mode 100644 index 0000000..73d4bb3 --- /dev/null +++ b/.github/workflows/cf-driver-go.yml @@ -0,0 +1,29 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: "CF Driver: Go Build & Test" + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: "./runner/cf-driver-go/go.mod" + + - name: Format + run: go fmt ./... + + - name: Vet + run: go vet ./... + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From de7b06f8b3b9f73275ea82fe96095cd43d6a7e48 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 09:59:36 -0500 Subject: [PATCH 43/76] fix: using the right file path would help --- .github/workflows/cf-driver-go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 73d4bb3..374cf33 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -17,13 +17,13 @@ jobs: go-version-file: "./runner/cf-driver-go/go.mod" - name: Format - run: go fmt ./... + run: go fmt ./runner/cf-driver-go/... - name: Vet - run: go vet ./... + run: go vet ./runner/cf-driver-go/... - name: Build - run: go build -v ./... + run: go build -v ./runner/cf-driver-go/... - name: Test - run: go test -v ./... + run: go test -v ./runner/cf-driver-go/... From c04918caf1e4bac53704d1865fd97e0e10bc9794 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:04:16 -0500 Subject: [PATCH 44/76] fix: how about setting a working directory --- .github/workflows/cf-driver-go.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 374cf33..377fc5d 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -5,6 +5,10 @@ name: "CF Driver: Go Build & Test" on: [pull_request] +defaults: + run: + working-directory: runner/cf-driver-go + jobs: build: runs-on: ubuntu-latest @@ -17,13 +21,13 @@ jobs: go-version-file: "./runner/cf-driver-go/go.mod" - name: Format - run: go fmt ./runner/cf-driver-go/... + run: go fmt ./... - name: Vet - run: go vet ./runner/cf-driver-go/... + run: go vet ./... - name: Build - run: go build -v ./runner/cf-driver-go/... + run: go build -v ./... - name: Test - run: go test -v ./runner/cf-driver-go/... + run: go test -v ./... From 07a2d087654831a26cfea9d4cf75824eb95d59b2 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:10:42 -0500 Subject: [PATCH 45/76] feat: have the go fmt step check for diffs --- .github/workflows/cf-driver-go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 377fc5d..2efd485 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -20,8 +20,8 @@ jobs: with: go-version-file: "./runner/cf-driver-go/go.mod" - - name: Format - run: go fmt ./... + - name: Check formatting + run: test -z $(gofmt -l ./...) - name: Vet run: go vet ./... From 6e2ff19def9633817d5581b90cacffc2f853b8cb Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:13:30 -0500 Subject: [PATCH 46/76] chore: spec a go version in case GitHub likes that better --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 2efd485..5501124 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version-file: "./runner/cf-driver-go/go.mod" + go-version: "1.23.x" - name: Check formatting run: test -z $(gofmt -l ./...) From 45e2b16db4455be120727afcc66e59c0d6c14f5d Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:14:54 -0500 Subject: [PATCH 47/76] chore: set a specific step to install deps This isolates dependency problems, could help caching --- .github/workflows/cf-driver-go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 5501124..e39e4b2 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -20,6 +20,9 @@ jobs: with: go-version: "1.23.x" + - name: Install dependencies + run: go get . + - name: Check formatting run: test -z $(gofmt -l ./...) From 3cfa5d2a28f05cdbe6e15d0fb049a0068d592e66 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:17:26 -0500 Subject: [PATCH 48/76] fix: supply setup-go w/ go.sum path It was _not_ using the default working-directory --- .github/workflows/cf-driver-go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index e39e4b2..c9242bf 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: "1.23.x" + cache-dependency-path: runner/cf-driver-go/go.sum - name: Install dependencies run: go get . From 64dcab365401510658b4a9e864a5cf5a7a25cef4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:19:53 -0500 Subject: [PATCH 49/76] chore: test failing go fmt --- runner/cf-driver-go/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/main.go b/runner/cf-driver-go/main.go index 0c7f0aa..83f2991 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cf-driver-go/main.go @@ -22,7 +22,7 @@ func main() { }() if err := godotenv.Load(); err != nil { - panic("error loading .env file") + panic("error loading .env file") } cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) From dda1a50cf321a906b408dd7821057387cadaa6dc Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:27:35 -0500 Subject: [PATCH 50/76] fix: gofmt doesn't take the ./... style arg --- .github/workflows/cf-driver-go.yml | 2 +- runner/cf-driver-go/cg/cg.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index c9242bf..cb302b4 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -25,7 +25,7 @@ jobs: run: go get . - name: Check formatting - run: test -z $(gofmt -l ./...) + run: test -z $(gofmt -l .) - name: Vet run: go vet ./... diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..65cb974 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -2,7 +2,7 @@ package cg type App struct { Id string - Name string + Name string State string } From 629f28d5a6dc3f27a2a8bc30d87247f07d6dc248 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:30:55 -0500 Subject: [PATCH 51/76] fix: foiled by quoting! --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index cb302b4..f035b23 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -25,7 +25,7 @@ jobs: run: go get . - name: Check formatting - run: test -z $(gofmt -l .) + run: test -z "$(gofmt -l .)" - name: Vet run: go vet ./... From 4436697d0fe1239188546126997315aea51d19b9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:32:09 -0500 Subject: [PATCH 52/76] chore: fix the formatting --- runner/cf-driver-go/cg/cg.go | 2 +- runner/cf-driver-go/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 65cb974..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -2,7 +2,7 @@ package cg type App struct { Id string - Name string + Name string State string } diff --git a/runner/cf-driver-go/main.go b/runner/cf-driver-go/main.go index 83f2991..0c7f0aa 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cf-driver-go/main.go @@ -22,7 +22,7 @@ func main() { }() if err := godotenv.Load(); err != nil { - panic("error loading .env file") + panic("error loading .env file") } cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) From f2e842e4c01fb4d74759d93a2dd6d3b0e3d507e9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:37:41 -0500 Subject: [PATCH 53/76] chore: validate that go vet will fail --- runner/cf-driver-go/cg/cg.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..5002a42 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -1,5 +1,7 @@ package cg +import "fmt" + type App struct { Id string Name string @@ -46,6 +48,8 @@ func New(i CloudI, o *Opts) (*CG, error) { } cg := &CG{i, o} return cg.Connect() + + fmt.Println("I am unreachable code!!") } func (c *CG) apiRootURL() string { From e1ba6198a92cfa16271060c2c2c80bc2b5fa1225 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:38:29 -0500 Subject: [PATCH 54/76] chore: remove my go vet break --- runner/cf-driver-go/cg/cg.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 5002a42..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -1,7 +1,5 @@ package cg -import "fmt" - type App struct { Id string Name string @@ -48,8 +46,6 @@ func New(i CloudI, o *Opts) (*CG, error) { } cg := &CG{i, o} return cg.Connect() - - fmt.Println("I am unreachable code!!") } func (c *CG) apiRootURL() string { From d87eb3d19998bbaad0df06de39f2413ccfcb37a6 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:40:29 -0500 Subject: [PATCH 55/76] chore: add a bug to validate test failure --- runner/cf-driver-go/cg/cg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..cd2a7d8 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -50,7 +50,7 @@ func New(i CloudI, o *Opts) (*CG, error) { func (c *CG) apiRootURL() string { if c.APIRootURL == "" { - return apiRootURLDefault + return "cookies" } return c.APIRootURL } From 7f8ba86d8c61f9e39c5b905c72e7566c75b80925 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:41:58 -0500 Subject: [PATCH 56/76] Revert "chore: add a bug to validate test failure" This reverts commit 9cc8c15044137b448e8544b77377e281d5e5e94f. --- runner/cf-driver-go/cg/cg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index cd2a7d8..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -50,7 +50,7 @@ func New(i CloudI, o *Opts) (*CG, error) { func (c *CG) apiRootURL() string { if c.APIRootURL == "" { - return "cookies" + return apiRootURLDefault } return c.APIRootURL } From ec98588385d82036b911a2dcb9ef57f135800059 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:55:26 -0500 Subject: [PATCH 57/76] feat: upgrade setup-go to v5 --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index f035b23..a17526d 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.23.x" cache-dependency-path: runner/cf-driver-go/go.sum From 287cbb45e0e71bda66049f1796b661547759cb27 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 11:00:13 -0500 Subject: [PATCH 58/76] feat: get go version for action from go.mod --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index a17526d..1a147f2 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.23.x" + go-version-file: runner/cf-driver-go/go.mod cache-dependency-path: runner/cf-driver-go/go.sum - name: Install dependencies From e717240f917b8800bc521ddb61af36e7d63a8ac7 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 11:12:50 -0500 Subject: [PATCH 59/76] chore: not necessary to pin a patch version for go --- runner/cf-driver-go/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/go.mod b/runner/cf-driver-go/go.mod index 5a6cd5a..bb6b4f1 100644 --- a/runner/cf-driver-go/go.mod +++ b/runner/cf-driver-go/go.mod @@ -1,6 +1,6 @@ module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver -go 1.23.3 +go 1.23 require ( github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 From 6e69483497c18585143cfa38e1770332d9679588 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 17:50:36 -0500 Subject: [PATCH 60/76] feat: add integration test for go driver's CG --- .gitignore | 3 + runner/cf-driver-go/Makefile | 5 +- runner/cf-driver-go/cg/cg_integration_test.go | 76 +++++++++++++++++++ runner/cf-driver-go/cg/cg_test.go | 2 + runner/cf-driver-go/cg/creds_test.go | 2 + .../cf-driver-go/cg/testdata/.cg_creds.sample | 7 ++ runner/cf-driver-go/main_test.go | 2 + 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 runner/cf-driver-go/cg/cg_integration_test.go create mode 100644 runner/cf-driver-go/cg/testdata/.cg_creds.sample diff --git a/.gitignore b/.gitignore index 2802610..dd0b887 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ override.tf.json # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* + +**/testdata/.* +!**/testdata/.*.sample diff --git a/runner/cf-driver-go/Makefile b/runner/cf-driver-go/Makefile index 6e07fdd..185575a 100644 --- a/runner/cf-driver-go/Makefile +++ b/runner/cf-driver-go/Makefile @@ -1,6 +1,6 @@ .DEFAULT_GOAL := build -.PHONY:fmt vet build +.PHONY:fmt vet build test integration fmt: go fmt ./... @@ -10,5 +10,8 @@ vet: fmt test: vet go test ./... +integration: vet + go test --tags=integration ./... + build: vet go build diff --git a/runner/cf-driver-go/cg/cg_integration_test.go b/runner/cf-driver-go/cg/cg_integration_test.go new file mode 100644 index 0000000..d31a421 --- /dev/null +++ b/runner/cf-driver-go/cg/cg_integration_test.go @@ -0,0 +1,76 @@ +//go:build integration + +package cg_integration + +import ( + "bufio" + "encoding/json" + "os" + "testing" + + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cg" + "github.com/google/go-cmp/cmp" +) + +func Test_CFAdapter_GetApps(t *testing.T) { + var u, p, want string + var l int + + f, err := os.Open("./testdata/.cg_creds") + if err != nil { + t.Errorf("Error opening testdata file = %v", err) + } + defer f.Close() + + scanner := bufio.NewScanner(f) + +scanning: + for scanner.Scan() { + text := scanner.Text() + + if text[0] == '#' { + continue + } + + switch l { + case 0: + u = text + case 1: + p = text + case 2: + want = text + break scanning + } + + l++ + } + + if err := scanner.Err(); err != nil { + t.Errorf("Error scanning testdata file = %v", err) + } + + if u == "" || p == "" || want == "" { + t.Error("Could not load variables from testdata") + } + + cgClient, err := cg.New(&cg.GoCFClientAdapter{}, &cg.Opts{ + Creds: &cg.Creds{Username: u, Password: p}, + }) + if err != nil { + t.Errorf("Error getting cgClient = %v", err) + } + + apps, err := cgClient.GetApps() + if err != nil { + t.Errorf("Error running GetApps() = %v", err) + } + + got, err := json.Marshal(apps) + if err != nil { + t.Errorf("Error marshalling apps to json = %v", err) + } + + if diff := cmp.Diff(string(got), want); diff != "" { + t.Errorf("mismatch (-got +want):\n%s", diff) + } +} diff --git a/runner/cf-driver-go/cg/cg_test.go b/runner/cf-driver-go/cg/cg_test.go index 8ba5b6b..787936e 100644 --- a/runner/cf-driver-go/cg/cg_test.go +++ b/runner/cf-driver-go/cg/cg_test.go @@ -1,3 +1,5 @@ +//go:build !integration + package cg import ( diff --git a/runner/cf-driver-go/cg/creds_test.go b/runner/cf-driver-go/cg/creds_test.go index 153bb47..a31168e 100644 --- a/runner/cf-driver-go/cg/creds_test.go +++ b/runner/cf-driver-go/cg/creds_test.go @@ -1,3 +1,5 @@ +//go:build !integration + package cg import ( diff --git a/runner/cf-driver-go/cg/testdata/.cg_creds.sample b/runner/cf-driver-go/cg/testdata/.cg_creds.sample new file mode 100644 index 0000000..4095dca --- /dev/null +++ b/runner/cf-driver-go/cg/testdata/.cg_creds.sample @@ -0,0 +1,7 @@ +# For simple integration test with cg_integration_test.go +# 1. copy this file to `.cg_creds` +# 2. replace with real credentials +# 3. replace with real output +username-1234-asdf +password-asdf-1234 +I am the expected output! diff --git a/runner/cf-driver-go/main_test.go b/runner/cf-driver-go/main_test.go index cbd2b8d..b0a6641 100644 --- a/runner/cf-driver-go/main_test.go +++ b/runner/cf-driver-go/main_test.go @@ -1,3 +1,5 @@ +//go:build !integration + package main import ( From c31c6f2fafe78b65908cf63cfcc52b39c29b0988 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 19 Dec 2024 09:49:05 -0500 Subject: [PATCH 61/76] fix: have to name package pkgname_test --- runner/cf-driver-go/cg/cg_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/cg/cg_integration_test.go b/runner/cf-driver-go/cg/cg_integration_test.go index d31a421..dab4c2c 100644 --- a/runner/cf-driver-go/cg/cg_integration_test.go +++ b/runner/cf-driver-go/cg/cg_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package cg_integration +package cg_test import ( "bufio" From 874c440326372aad5a762957de85ad3acffafd13 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 19 Dec 2024 10:21:27 -0500 Subject: [PATCH 62/76] fix: forgot t.Error/t.Fail doesn't exit --- runner/cf-driver-go/cg/cg_integration_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runner/cf-driver-go/cg/cg_integration_test.go b/runner/cf-driver-go/cg/cg_integration_test.go index dab4c2c..b65ed12 100644 --- a/runner/cf-driver-go/cg/cg_integration_test.go +++ b/runner/cf-driver-go/cg/cg_integration_test.go @@ -47,10 +47,12 @@ scanning: if err := scanner.Err(); err != nil { t.Errorf("Error scanning testdata file = %v", err) + return } if u == "" || p == "" || want == "" { t.Error("Could not load variables from testdata") + return } cgClient, err := cg.New(&cg.GoCFClientAdapter{}, &cg.Opts{ @@ -58,19 +60,23 @@ scanning: }) if err != nil { t.Errorf("Error getting cgClient = %v", err) + return } apps, err := cgClient.GetApps() if err != nil { t.Errorf("Error running GetApps() = %v", err) + return } got, err := json.Marshal(apps) if err != nil { t.Errorf("Error marshalling apps to json = %v", err) + return } if diff := cmp.Diff(string(got), want); diff != "" { t.Errorf("mismatch (-got +want):\n%s", diff) + return } } From ac02ee56ecfc03538701275f0953fd909b836299 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 19 Dec 2024 10:21:50 -0500 Subject: [PATCH 63/76] docs: note about integration test in readme, helpful error message --- runner/cf-driver-go/README.md | 11 +++++++++++ runner/cf-driver-go/cg/cg_integration_test.go | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/runner/cf-driver-go/README.md b/runner/cf-driver-go/README.md index 26d7520..9865c90 100644 --- a/runner/cf-driver-go/README.md +++ b/runner/cf-driver-go/README.md @@ -40,12 +40,23 @@ go get github.com/google/some-mod/pkg ## Running tests +### Unit tests + The simplest way to run tests—or the one with the least typing, at least—is with `make`. ```sh make test ``` +### Integration tests + +We only have one integration test right now, and to get it running you'll need to do a bit of local setup. + +1. You will need to first get a username & password for some space on cloud.gov that has at least one app. +1. Then you can add those credentials to `./cg/testdata/.cg_creds` in the style of the `.cg_creds.sample` file there. +1. Run the test with `make integration`, which should give you an error and, in its output, show you what the resulting JSON looks like. +1. Copy that JSON result over to the last line of your `.cg_creds` file and run `make integration` again, this time it should succeed. + ## Builds You can also run a build with `make` (`make build`, or simply `make`), but it won't do you much good because we aren't set up to do anything with an executable yet. diff --git a/runner/cf-driver-go/cg/cg_integration_test.go b/runner/cf-driver-go/cg/cg_integration_test.go index b65ed12..699e230 100644 --- a/runner/cf-driver-go/cg/cg_integration_test.go +++ b/runner/cf-driver-go/cg/cg_integration_test.go @@ -16,9 +16,14 @@ func Test_CFAdapter_GetApps(t *testing.T) { var u, p, want string var l int - f, err := os.Open("./testdata/.cg_creds") + path := "./testdata/.cg_creds" + f, err := os.Open(path) if err != nil { - t.Errorf("Error opening testdata file = %v", err) + t.Errorf( + "Error opening testdata file = %v\n\033[1;33mDid you forget to create `%v`?\033[0m", + err, path, + ) + return } defer f.Close() From 4b6dc62f896ddc996069318ed2d78101334ff174 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 19 Dec 2024 10:24:55 -0500 Subject: [PATCH 64/76] fix: prevent caching integration test which defeats the purpose --- runner/cf-driver-go/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/Makefile b/runner/cf-driver-go/Makefile index 185575a..28732e0 100644 --- a/runner/cf-driver-go/Makefile +++ b/runner/cf-driver-go/Makefile @@ -11,7 +11,7 @@ test: vet go test ./... integration: vet - go test --tags=integration ./... + go test -count=1 --tags=integration ./... build: vet go build From f6e41b11398d2f1545b3444dc242592af4bae874 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 26 Dec 2024 12:06:38 -0500 Subject: [PATCH 65/76] feat: structure as CLI tool, with `drive` subcmd for each stage Also includes some long command descriptions that are mostly lifted from GitLabs Custom executor documentation. --- runner/cf-driver-go/cmd/drive/cleanup.go | 37 +++++++++++++ runner/cf-driver-go/cmd/drive/config.go | 22 ++++++++ runner/cf-driver-go/cmd/drive/drive.go | 50 ++++++++++++++++++ runner/cf-driver-go/cmd/drive/prepare.go | 34 ++++++++++++ runner/cf-driver-go/cmd/drive/run.go | 61 +++++++++++++++++++++ runner/cf-driver-go/cmd/root.go | 30 +++++++++++ runner/cf-driver-go/go.mod | 27 ++++++++-- runner/cf-driver-go/go.sum | 67 ++++++++++++++++++++++-- runner/cf-driver-go/main.go | 16 +----- runner/cf-driver-go/main_test.go | 21 -------- 10 files changed, 324 insertions(+), 41 deletions(-) create mode 100644 runner/cf-driver-go/cmd/drive/cleanup.go create mode 100644 runner/cf-driver-go/cmd/drive/config.go create mode 100644 runner/cf-driver-go/cmd/drive/drive.go create mode 100644 runner/cf-driver-go/cmd/drive/prepare.go create mode 100644 runner/cf-driver-go/cmd/drive/run.go create mode 100644 runner/cf-driver-go/cmd/root.go delete mode 100644 runner/cf-driver-go/main_test.go diff --git a/runner/cf-driver-go/cmd/drive/cleanup.go b/runner/cf-driver-go/cmd/drive/cleanup.go new file mode 100644 index 0000000..428eea0 --- /dev/null +++ b/runner/cf-driver-go/cmd/drive/cleanup.go @@ -0,0 +1,37 @@ +package drive + +import ( + "log" + + "github.com/spf13/cobra" +) + +var cleanupCmd = &cobra.Command{ + Use: "cleanup", + Short: "Cleans up resources, containers, etc. at job completion", + Long: `The Cleanup stage is executed by "cleanup_exec". + +This final stage is executed even if one of the previous stages failed. +The main goal for this stage is to clean up any of the environments that +might have been set up. For example, turning off VMs or deleting +containers. + +The result of cleanup_exec does not affect job statuses. For example, a +job will be marked as successful even if the following occurs: + + Both prepare_exec and run_exec are successful. + cleanup_exec fails. + +The user can set cleanup_exec_timeout if they want to set some kind of +deadline of how long GitLab Runner should wait to clean up the +environment before terminating the process. + +The STDOUT of this executable will be printed to GitLab Runner logs at a +DEBUG level. The STDERR will be printed to the logs at a WARN level. + +Read more in GitLab's documentation: +https://docs.gitlab.com/runner/executors/custom.html#cleanup`, + Run: func(cmd *cobra.Command, args []string) { + log.Println("cleaning up...") + }, +} diff --git a/runner/cf-driver-go/cmd/drive/config.go b/runner/cf-driver-go/cmd/drive/config.go new file mode 100644 index 0000000..f89c83e --- /dev/null +++ b/runner/cf-driver-go/cmd/drive/config.go @@ -0,0 +1,22 @@ +package drive + +import ( + "log" + + "github.com/spf13/cobra" +) + +var configCmd = &cobra.Command{ + Use: "config", + Short: "Configure various jobs settings before they run", + Long: `The Config stage is executed by "config_exec". + +Sometimes you might want to set some settings during execution time. For +example, setting a build directory depending on the project ID. + +For a detailed list of settings that can be configured, read more at: +https://docs.gitlab.com/runner/executors/custom.html#config.`, + Run: func(cmd *cobra.Command, args []string) { + log.Println("configuring...") + }, +} diff --git a/runner/cf-driver-go/cmd/drive/drive.go b/runner/cf-driver-go/cmd/drive/drive.go new file mode 100644 index 0000000..1b715ac --- /dev/null +++ b/runner/cf-driver-go/cmd/drive/drive.go @@ -0,0 +1,50 @@ +package drive + +import ( + "github.com/spf13/cobra" +) + +func init() { + cobra.EnableCommandSorting = false + DriveCmd.AddCommand(configCmd, prepareCmd, runCmd, cleanupCmd) +} + +var DriveCmd = &cobra.Command{ + Use: "drive", + Short: "Drive stages requested by gitlab-runner's executor", + Long: `Drive holds subcommands to run each of executor's stages. + +The Custom executor provides the stages for you to configure some +details of the job, prepare and clean up the environment and run the job +script within it. Each stage is responsible for specific things and has +different things to keep in mind. + +Each stage executed by the Custom executor is executed at the time a +builtin GitLab Runner executor would execute them. + +For each step that will be executed, specific environment variables are +exposed to the executable, which can be used to get information about the +specific Job that is running. All stages will have the following +environment variables available to them: + + - Standard CI/CD environment variables, including predefined variables. + - All environment variables provided by the Custom executor Runner host + system. + - All services and their available settings. Exposed in JSON format as + CUSTOM_ENV_CI_JOB_SERVICES. + +Both CI/CD environment variables and predefined variables are prefixed +with CUSTOM_ENV_ to prevent conflicts with system environment variables. +For example, CI_BUILDS_DIR will be available as CUSTOM_ENV_CI_BUILDS_DIR. + +The stages run in the following sequence: + + 1. config_exec + 2. prepare_exec + 3. run_exec + 4. cleanup_exec + +Read more in GitLab's documentation: +https://docs.gitlab.com/runner/executors/custom.html#stages + `, +} diff --git a/runner/cf-driver-go/cmd/drive/prepare.go b/runner/cf-driver-go/cmd/drive/prepare.go new file mode 100644 index 0000000..c917188 --- /dev/null +++ b/runner/cf-driver-go/cmd/drive/prepare.go @@ -0,0 +1,34 @@ +package drive + +import ( + "log" + + "github.com/spf13/cobra" +) + +var prepareCmd = &cobra.Command{ + Use: "prepare", + Short: "Prepare for jobs by starting containers, services, etc.", + Long: `The Prepare stage is executed by "prepare_exec". + +At this point, GitLab Runner knows everything about the job (where and +how it’s going to run). The only thing left is for the environment to be +set up so the job can run. Prepare will execute the steps necessary to +create that environment. + +This is responsible for setting up the environment (for example, +creating the virtual machine or container, services or anything else). +After this is done, we expect that the environment is ready to run the +job. + +This stage is executed only once in a job execution. + +The STDOUT and STDERR returned from this executable will print to the +job log. + +Read more in GitLab's documentation: +https://docs.gitlab.com/runner/executors/custom.html#prepare`, + Run: func(cmd *cobra.Command, args []string) { + log.Println("preparing...") + }, +} diff --git a/runner/cf-driver-go/cmd/drive/run.go b/runner/cf-driver-go/cmd/drive/run.go new file mode 100644 index 0000000..073991d --- /dev/null +++ b/runner/cf-driver-go/cmd/drive/run.go @@ -0,0 +1,61 @@ +package drive + +import ( + "log" + + "github.com/spf13/cobra" +) + +var runCmd = &cobra.Command{ + Use: "run", + Short: "Executes substages (e.g., cache download) and job steps", + Long: `The Run stage is executed by "run_exec". + +The STDOUT and STDERR returned from this executable will print to the job +log. + +Unlike the other stages, the run_exec stage is executed multiple times, +since it’s split into sub stages listed below in sequential order: + + prepare_script + get_sources + restore_cache + download_artifacts + step_* + build_script + step_* + after_script + archive_cache OR archive_cache_on_failure + upload_artifacts_on_success OR upload_artifacts_on_failure + cleanup_file_variables + +In GitLab Runner 14.0 and later, build_script will be replaced with +step_script. For more information, see this issue. + +For each stage mentioned above, the run_exec executable will be executed +with (1) the path to the script that GitLab Runner creates for the Custom +executor to run, and (2) the name of the stage. + +This executable should be responsible for executing the scripts that are +specified in the first argument. They contain all the scripts any GitLab +Runner executor would run normally to clone, download artifacts, run +user scripts and all the other steps described below. The scripts can be +of the following shells: + + Bash + PowerShell Desktop + PowerShell Core + Batch (deprecated) + +We generate the script using the shell configured by shell inside of +[[runners]]. If none is provided the defaults for the OS platform are used. + +The table below is a detailed explanation of what each script does and +what the main goal of that script is. + +Read more in GitLab's documentation: +https://docs.gitlab.com/runner/executors/custom.html#run`, + Run: func(cmd *cobra.Command, args []string) { + log.Println("running...") + }, +} diff --git a/runner/cf-driver-go/cmd/root.go b/runner/cf-driver-go/cmd/root.go new file mode 100644 index 0000000..0b1b209 --- /dev/null +++ b/runner/cf-driver-go/cmd/root.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cmd/drive" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(drive.DriveCmd) +} + +var rootCmd = &cobra.Command{ + Use: "cfd", + Short: "CloudFoundry Driver", + Long: `This is CloudFoundry Driver for the GitLab Custom executor. + +The gitlab-runner service should run cfd with it's "drive" subcommands, +e.g., "cfd drive prepare".`, +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/runner/cf-driver-go/go.mod b/runner/cf-driver-go/go.mod index bb6b4f1..601fbf8 100644 --- a/runner/cf-driver-go/go.mod +++ b/runner/cf-driver-go/go.mod @@ -5,17 +5,38 @@ go 1.23 require ( github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 github.com/google/go-cmp v0.6.0 - github.com/joho/godotenv v1.5.1 + github.com/spf13/cobra v1.8.1 + github.com/spf13/viper v1.19.0 ) require ( github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/joho/godotenv v1.5.1 + github.com/magiconair/properties v1.8.7 // indirect github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.9.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/runner/cf-driver-go/go.sum b/runner/cf-driver-go/go.sum index a99c489..748cf02 100644 --- a/runner/cf-driver-go/go.sum +++ b/runner/cf-driver-go/go.sum @@ -2,30 +2,91 @@ github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 h1:HK3+nJEPgwlhc5H74aw/V4m github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9/go.mod h1:eUjFfpsU3lRv388wKlXMmkQfsJ9pveUHZEia7AoBCPY= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 h1:YFh+sjyJTMQSYjKwM4dFKhJPJC/wfo98tPUc17HdoYw= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/runner/cf-driver-go/main.go b/runner/cf-driver-go/main.go index 0c7f0aa..f3afe35 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cf-driver-go/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cg" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cmd" "github.com/joho/godotenv" ) @@ -25,17 +25,5 @@ func main() { panic("error loading .env file") } - cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) - if err != nil { - panic(err) - } - - apps, err := cgClient.GetApps() - if err != nil { - panic(err) - } - - for _, app := range apps { - log.Printf("Application %s is %s\n", app.Name, app.State) - } + cmd.Execute() } diff --git a/runner/cf-driver-go/main_test.go b/runner/cf-driver-go/main_test.go deleted file mode 100644 index b0a6641..0000000 --- a/runner/cf-driver-go/main_test.go +++ /dev/null @@ -1,21 +0,0 @@ -//go:build !integration - -package main - -import ( - "fmt" - "testing" -) - -func Test_main(t *testing.T) { - t.Skip("Test_main is just for experiments right now") - - tests := []struct{ name string }{{name: "run main"}} - - for _, tt := range tests { - fmt.Println(tt.name) - t.Run(tt.name, func(t *testing.T) { - main() - }) - } -} From aea1f0a3cec1c8b69f7596d2dcb6b800cec3f7bb Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 26 Dec 2024 12:12:55 -0500 Subject: [PATCH 66/76] chore: should have run `tidy` --- runner/cf-driver-go/go.mod | 23 ++++--------------- runner/cf-driver-go/go.sum | 47 ++------------------------------------ 2 files changed, 7 insertions(+), 63 deletions(-) diff --git a/runner/cf-driver-go/go.mod b/runner/cf-driver-go/go.mod index 601fbf8..d4a79e7 100644 --- a/runner/cf-driver-go/go.mod +++ b/runner/cf-driver-go/go.mod @@ -6,37 +6,24 @@ require ( github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9 github.com/google/go-cmp v0.6.0 github.com/spf13/cobra v1.8.1 - github.com/spf13/viper v1.19.0 +) + +require ( + github.com/kr/pretty v0.3.1 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) require ( github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab // indirect - github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/joho/godotenv v1.5.1 - github.com/magiconair/properties v1.8.7 // indirect github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/sagikazarmark/locafero v0.4.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/sourcegraph/conc v0.3.0 // indirect - github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.9.0 // indirect - github.com/subosito/gotenv v1.6.0 // indirect - go.uber.org/atomic v1.9.0 // indirect - go.uber.org/multierr v1.9.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/runner/cf-driver-go/go.sum b/runner/cf-driver-go/go.sum index 748cf02..b25180c 100644 --- a/runner/cf-driver-go/go.sum +++ b/runner/cf-driver-go/go.sum @@ -3,20 +3,14 @@ github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9/go.mod h1:eUjFfpsU3lRv388w github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= @@ -25,68 +19,31 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 h1:YFh+sjyJTMQSYjKwM4dFKhJPJC/wfo98tPUc17HdoYw= github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= -github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= -github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= -github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= -go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= -go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From e35c5d9065e1c6ff778ba5a166343d0a85f68373 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 27 Dec 2024 09:25:20 -0500 Subject: [PATCH 67/76] chore: trigger pr workflow From fa02c7396649eb9edf3728b51455589bb4dab9ce Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 27 Dec 2024 10:03:29 -0500 Subject: [PATCH 68/76] refactor: rename cf-driver to cfd --- runner/{cf-driver-go => cfd}/.gitignore | 0 runner/{cf-driver-go => cfd}/.vscode/launch.json | 0 runner/{cf-driver-go => cfd}/Makefile | 0 runner/{cf-driver-go => cfd}/README.md | 0 runner/{cf-driver-go => cfd}/cg/cf_adapter.go | 0 runner/{cf-driver-go => cfd}/cg/cg.go | 0 runner/{cf-driver-go => cfd}/cg/cg_integration_test.go | 2 +- runner/{cf-driver-go => cfd}/cg/cg_test.go | 0 runner/{cf-driver-go => cfd}/cg/creds.go | 0 runner/{cf-driver-go => cfd}/cg/creds_test.go | 0 runner/{cf-driver-go => cfd}/cg/testdata/.cg_creds.sample | 0 runner/{cf-driver-go => cfd}/cmd/drive/cleanup.go | 0 runner/{cf-driver-go => cfd}/cmd/drive/config.go | 0 runner/{cf-driver-go => cfd}/cmd/drive/drive.go | 0 runner/{cf-driver-go => cfd}/cmd/drive/prepare.go | 0 runner/{cf-driver-go => cfd}/cmd/drive/run.go | 0 runner/{cf-driver-go => cfd}/cmd/root.go | 2 +- runner/{cf-driver-go => cfd}/go.mod | 2 +- runner/{cf-driver-go => cfd}/go.sum | 0 runner/{cf-driver-go => cfd}/main.go | 2 +- 20 files changed, 4 insertions(+), 4 deletions(-) rename runner/{cf-driver-go => cfd}/.gitignore (100%) rename runner/{cf-driver-go => cfd}/.vscode/launch.json (100%) rename runner/{cf-driver-go => cfd}/Makefile (100%) rename runner/{cf-driver-go => cfd}/README.md (100%) rename runner/{cf-driver-go => cfd}/cg/cf_adapter.go (100%) rename runner/{cf-driver-go => cfd}/cg/cg.go (100%) rename runner/{cf-driver-go => cfd}/cg/cg_integration_test.go (95%) rename runner/{cf-driver-go => cfd}/cg/cg_test.go (100%) rename runner/{cf-driver-go => cfd}/cg/creds.go (100%) rename runner/{cf-driver-go => cfd}/cg/creds_test.go (100%) rename runner/{cf-driver-go => cfd}/cg/testdata/.cg_creds.sample (100%) rename runner/{cf-driver-go => cfd}/cmd/drive/cleanup.go (100%) rename runner/{cf-driver-go => cfd}/cmd/drive/config.go (100%) rename runner/{cf-driver-go => cfd}/cmd/drive/drive.go (100%) rename runner/{cf-driver-go => cfd}/cmd/drive/prepare.go (100%) rename runner/{cf-driver-go => cfd}/cmd/drive/run.go (100%) rename runner/{cf-driver-go => cfd}/cmd/root.go (86%) rename runner/{cf-driver-go => cfd}/go.mod (93%) rename runner/{cf-driver-go => cfd}/go.sum (100%) rename runner/{cf-driver-go => cfd}/main.go (83%) diff --git a/runner/cf-driver-go/.gitignore b/runner/cfd/.gitignore similarity index 100% rename from runner/cf-driver-go/.gitignore rename to runner/cfd/.gitignore diff --git a/runner/cf-driver-go/.vscode/launch.json b/runner/cfd/.vscode/launch.json similarity index 100% rename from runner/cf-driver-go/.vscode/launch.json rename to runner/cfd/.vscode/launch.json diff --git a/runner/cf-driver-go/Makefile b/runner/cfd/Makefile similarity index 100% rename from runner/cf-driver-go/Makefile rename to runner/cfd/Makefile diff --git a/runner/cf-driver-go/README.md b/runner/cfd/README.md similarity index 100% rename from runner/cf-driver-go/README.md rename to runner/cfd/README.md diff --git a/runner/cf-driver-go/cg/cf_adapter.go b/runner/cfd/cg/cf_adapter.go similarity index 100% rename from runner/cf-driver-go/cg/cf_adapter.go rename to runner/cfd/cg/cf_adapter.go diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cfd/cg/cg.go similarity index 100% rename from runner/cf-driver-go/cg/cg.go rename to runner/cfd/cg/cg.go diff --git a/runner/cf-driver-go/cg/cg_integration_test.go b/runner/cfd/cg/cg_integration_test.go similarity index 95% rename from runner/cf-driver-go/cg/cg_integration_test.go rename to runner/cfd/cg/cg_integration_test.go index 699e230..722ba85 100644 --- a/runner/cf-driver-go/cg/cg_integration_test.go +++ b/runner/cfd/cg/cg_integration_test.go @@ -8,7 +8,7 @@ import ( "os" "testing" - "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cg" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cfd/cg" "github.com/google/go-cmp/cmp" ) diff --git a/runner/cf-driver-go/cg/cg_test.go b/runner/cfd/cg/cg_test.go similarity index 100% rename from runner/cf-driver-go/cg/cg_test.go rename to runner/cfd/cg/cg_test.go diff --git a/runner/cf-driver-go/cg/creds.go b/runner/cfd/cg/creds.go similarity index 100% rename from runner/cf-driver-go/cg/creds.go rename to runner/cfd/cg/creds.go diff --git a/runner/cf-driver-go/cg/creds_test.go b/runner/cfd/cg/creds_test.go similarity index 100% rename from runner/cf-driver-go/cg/creds_test.go rename to runner/cfd/cg/creds_test.go diff --git a/runner/cf-driver-go/cg/testdata/.cg_creds.sample b/runner/cfd/cg/testdata/.cg_creds.sample similarity index 100% rename from runner/cf-driver-go/cg/testdata/.cg_creds.sample rename to runner/cfd/cg/testdata/.cg_creds.sample diff --git a/runner/cf-driver-go/cmd/drive/cleanup.go b/runner/cfd/cmd/drive/cleanup.go similarity index 100% rename from runner/cf-driver-go/cmd/drive/cleanup.go rename to runner/cfd/cmd/drive/cleanup.go diff --git a/runner/cf-driver-go/cmd/drive/config.go b/runner/cfd/cmd/drive/config.go similarity index 100% rename from runner/cf-driver-go/cmd/drive/config.go rename to runner/cfd/cmd/drive/config.go diff --git a/runner/cf-driver-go/cmd/drive/drive.go b/runner/cfd/cmd/drive/drive.go similarity index 100% rename from runner/cf-driver-go/cmd/drive/drive.go rename to runner/cfd/cmd/drive/drive.go diff --git a/runner/cf-driver-go/cmd/drive/prepare.go b/runner/cfd/cmd/drive/prepare.go similarity index 100% rename from runner/cf-driver-go/cmd/drive/prepare.go rename to runner/cfd/cmd/drive/prepare.go diff --git a/runner/cf-driver-go/cmd/drive/run.go b/runner/cfd/cmd/drive/run.go similarity index 100% rename from runner/cf-driver-go/cmd/drive/run.go rename to runner/cfd/cmd/drive/run.go diff --git a/runner/cf-driver-go/cmd/root.go b/runner/cfd/cmd/root.go similarity index 86% rename from runner/cf-driver-go/cmd/root.go rename to runner/cfd/cmd/root.go index 0b1b209..c535dc9 100644 --- a/runner/cf-driver-go/cmd/root.go +++ b/runner/cfd/cmd/root.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cmd/drive" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cfd/cmd/drive" "github.com/spf13/cobra" ) diff --git a/runner/cf-driver-go/go.mod b/runner/cfd/go.mod similarity index 93% rename from runner/cf-driver-go/go.mod rename to runner/cfd/go.mod index d4a79e7..92b6d46 100644 --- a/runner/cf-driver-go/go.mod +++ b/runner/cfd/go.mod @@ -1,4 +1,4 @@ -module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver +module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cfd go 1.23 diff --git a/runner/cf-driver-go/go.sum b/runner/cfd/go.sum similarity index 100% rename from runner/cf-driver-go/go.sum rename to runner/cfd/go.sum diff --git a/runner/cf-driver-go/main.go b/runner/cfd/main.go similarity index 83% rename from runner/cf-driver-go/main.go rename to runner/cfd/main.go index f3afe35..9d780f7 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cfd/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver/cmd" + "github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cfd/cmd" "github.com/joho/godotenv" ) From 899d25abf65b5f4418d92d8c79432bc7e4b999dd Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Fri, 27 Dec 2024 10:23:40 -0500 Subject: [PATCH 69/76] fix: forgot to update path in GH action --- .github/workflows/cf-driver-go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 1a147f2..197020a 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -7,7 +7,7 @@ on: [pull_request] defaults: run: - working-directory: runner/cf-driver-go + working-directory: runner/cfd jobs: build: @@ -18,8 +18,8 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version-file: runner/cf-driver-go/go.mod - cache-dependency-path: runner/cf-driver-go/go.sum + go-version-file: runner/cfd/go.mod + cache-dependency-path: runner/cfd/go.sum - name: Install dependencies run: go get . From 4e789fbdd5fc4e2d95986062ee9d32bcf2c8444f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 15 Jan 2025 11:55:04 -0500 Subject: [PATCH 70/76] feat: add types & functions to parse env config --- runner/cfd/cmd/drive/read_env.go | 130 ++++++++++++++++++ runner/cfd/cmd/drive/read_env_test.go | 127 +++++++++++++++++ .../drive/testdata/sample_job_response.json | 26 ++++ 3 files changed, 283 insertions(+) create mode 100644 runner/cfd/cmd/drive/read_env.go create mode 100644 runner/cfd/cmd/drive/read_env_test.go create mode 100644 runner/cfd/cmd/drive/testdata/sample_job_response.json diff --git a/runner/cfd/cmd/drive/read_env.go b/runner/cfd/cmd/drive/read_env.go new file mode 100644 index 0000000..ed71229 --- /dev/null +++ b/runner/cfd/cmd/drive/read_env.go @@ -0,0 +1,130 @@ +package drive + +import ( + "encoding/json" + "fmt" + "os" + "reflect" +) + +type EnvCfg struct { + *JobResData + *VcapAppData + *ServicesData + + JobResFile string `env:"JOB_RESPONSE_FILE"` + VcapAppJSON string `env:"VCAP_APPLICATION"` + ServicesJSON string `env:"CUSTOM_ENV_CI_JOB_SERVICES"` + + ContainerId string `env:"CONTAINER_ID"` + + RegUser string `env:"CUSTOM_ENV_CI_REGISTRY_USER"` + RegPass string `env:"CUSTOM_ENV_CI_REGISTRY_PASSWORD"` + JobImg string `env:"CUSTOM_ENV_CI_JOB_IMAGE"` + + DockerToken string `env:"DOCKER_HUB_TOKEN"` + DockerUser string `env:"DOCKER_HUB_USER"` + DockerPass string `env:"CF_DOCKER_PASSWORD"` + + WorkerMem string `env:"WORKER_MEMORY"` + WorkerDisk string `env:"WORKER_DISK_SIZE"` +} + +type JobResData struct { + Image JobResImg + Variables JobResVars + Services []JobResSvcs +} +type JobResImg struct { + Name string + Alias string + Command []string + Entrypoint []string +} +type JobResVars []struct { + Key string + Value string +} +type JobResSvcs struct { + JobResImg + Variables JobResVars +} + +type VcapAppData struct { + OrgName string `json:"organization_name"` + SpaceName string `json:"space_name"` +} + +type ServicesData []struct { + Name string + Alias string + Entrypoint []string + Command []string +} + +func parseCfgJSON[R any](j []byte, r *R) (*R, error) { + if len(j) < 1 { + return nil, nil + } + if err := json.Unmarshal(j, r); err != nil { + return nil, fmt.Errorf("error parsing %t: %w", r, err) + } + return r, nil +} + +func (c *EnvCfg) parseJobResFile() (err error) { + if c.JobResFile == "" { + return nil + } + + j, err := os.ReadFile(c.JobResFile) + if err != nil { + return fmt.Errorf("error reading JobResFile: %w", err) + } + + c.JobResData, err = parseCfgJSON(j, &JobResData{}) + return err +} + +func (c *EnvCfg) parseVcapAppJSON() (err error) { + c.VcapAppData, err = parseCfgJSON([]byte(c.VcapAppJSON), &VcapAppData{}) + return err +} + +func (c *EnvCfg) parseServicesJSON() (err error) { + c.ServicesData, err = parseCfgJSON([]byte(c.ServicesJSON), &ServicesData{}) + return err +} + +// This is a pretty simple implementation, if our needs get more +// complex we should use one of several existing packages to do this. +// e.g., https://pkg.go.dev/github.com/caarlos0/env/v11 +func (c *EnvCfg) parseEnv() *EnvCfg { + ct := reflect.TypeOf(*c) + ce := reflect.ValueOf(c).Elem() + + for i := 0; i < ct.NumField(); i++ { + field := ce.Field(i) + fieldTag := ct.Field(i).Tag.Get("env") + if fieldTag == "" || field.Kind() != reflect.String { + continue + } + field.SetString(os.Getenv(fieldTag)) + } + + return c +} + +func getEnvCfg() *EnvCfg { + cfg := (&EnvCfg{}).parseEnv() + if err := cfg.parseJobResFile(); err != nil { + panic(err) + } + if err := cfg.parseVcapAppJSON(); err != nil { + panic(err) + } + if err := cfg.parseServicesJSON(); err != nil { + panic(err) + } + return cfg +} diff --git a/runner/cfd/cmd/drive/read_env_test.go b/runner/cfd/cmd/drive/read_env_test.go new file mode 100644 index 0000000..d4a6aa0 --- /dev/null +++ b/runner/cfd/cmd/drive/read_env_test.go @@ -0,0 +1,127 @@ +package drive + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +// TODO: can replace this and the other tests with one nice table test, +// but I think it'll be easier to manage if parsing a file and want to +// think about that later. +func Test_getEnvCfg(t *testing.T) { + cfgWant := &EnvCfg{ + ContainerId: "1234", + RegUser: "foo", + RegPass: "bar", + JobImg: "bookworm", + DockerToken: "1234", + DockerUser: "foo", + DockerPass: "bar", + WorkerMem: "1024M", + WorkerDisk: "1024M", + JobResFile: "", + VcapAppJSON: "", + ServicesJSON: "", + } + + envWant := map[string]string{ + "CONTAINER_ID": cfgWant.ContainerId, + "JOB_RESPONSE_FILE": cfgWant.JobResFile, + "CUSTOM_ENV_CI_REGISTRY_USER": cfgWant.RegUser, + "CUSTOM_ENV_CI_REGISTRY_PASSWORD": cfgWant.RegPass, + "CUSTOM_ENV_CI_JOB_IMAGE": cfgWant.JobImg, + "DOCKER_HUB_TOKEN": cfgWant.DockerToken, + "DOCKER_HUB_USER": cfgWant.DockerUser, + "CF_DOCKER_PASSWORD": cfgWant.DockerPass, + "WORKER_MEMORY": cfgWant.WorkerMem, + "WORKER_DISK_SIZE": cfgWant.WorkerDisk, + "VCAP_APPLICATION": cfgWant.VcapAppJSON, + "CUSTOM_ENV_CI_JOB_SERVICES": cfgWant.ServicesJSON, + } + + for k, v := range envWant { + t.Setenv(k, v) + } + parsedCfg := getEnvCfg() + if diff := cmp.Diff(cfgWant, parsedCfg); diff != "" { + t.Error(diff) + } + + t.Setenv("CONTAINER_ID", "fail") + parsedCfg = getEnvCfg() + if diff := cmp.Diff("fail", parsedCfg.ContainerId); diff != "" { + t.Error(diff) + } + + parsedCfg.ContainerId = "1234" + if diff := cmp.Diff(cfgWant, parsedCfg); diff != "" { + t.Error(diff) + } +} + +func Test_parseJobResFile(t *testing.T) { + t.Setenv("JOB_RESPONSE_FILE", "./testdata/sample_job_response.json") + + wanted := &JobResData{ + Image: JobResImg{ + Command: []string{"a", "b", "c"}, + Entrypoint: []string{"d", "e", "f"}, + }, + Services: []JobResSvcs{{ + JobResImg: JobResImg{ + Name: "postgres:wormy", + Alias: "my-pg-service", + Command: []string{"g", "h", "i"}, + Entrypoint: []string{"j", "k", "l"}, + }, + Variables: JobResVars{{Key: "bazz", Value: "buzz"}}, + }}, + Variables: JobResVars{{Key: "foo", Value: "bar"}}, + } + + cfg := getEnvCfg() + + if diff := cmp.Diff(wanted, cfg.JobResData); diff != "" { + t.Error(diff) + } +} + +func Test_parseVcapAppJSON(t *testing.T) { + sample := `{"cf_api":"https://api.fr.cloud.gov","limits":{"fds":16384,"mem":128,"disk":1024},"application_name":"gitlab-runner","application_uris":[],"name":"gitlab-runner","space_name":"zjr-gl-test","space_id":"8969a4b6-01aa-431d-9790-77cc4c47e3e7","organization_id":"f0a46189-6f64-43fb-99c3-0719cf9ee255","organization_name":"gsa-tts-devtools-prototyping","uris":[],"process_id":"e905fbb9-aea0-44aa-ba10-f76aed1668d1","process_type":"web","application_id":"e905fbb9-aea0-44aa-ba10-f76aed1668d1","version":"f115779a-17a3-4700-9941-aae3fe81a4c8","application_version":"f115779a-17a3-4700-9941-aae3fe81a4c8"}` + t.Setenv("VCAP_APPLICATION", sample) + + wanted := &VcapAppData{ + OrgName: "gsa-tts-devtools-prototyping", + SpaceName: "zjr-gl-test", + } + + cfg := getEnvCfg() + + if diff := cmp.Diff(wanted, cfg.VcapAppData); diff != "" { + t.Error(diff) + } +} + +func Test_parseServicesJSON(t *testing.T) { + sample := `[{"name":"redis:latest","alias":"","entrypoint":null,"command":null},{"name":"my-postgres:9.4","alias":"pg","entrypoint":["path","to","entrypoint"],"command":["path","to","cmd"]}]` + t.Setenv("CUSTOM_ENV_CI_JOB_SERVICES", sample) + + wanted := &ServicesData{ + { + Name: "redis:latest", + }, + { + Name: "my-postgres:9.4", + Alias: "pg", + Entrypoint: []string{"path", "to", "entrypoint"}, + Command: []string{"path", "to", "cmd"}, + }, + } + + cfg := getEnvCfg() + + if diff := cmp.Diff(wanted, cfg.ServicesData); diff != "" { + t.Error(diff) + } +} diff --git a/runner/cfd/cmd/drive/testdata/sample_job_response.json b/runner/cfd/cmd/drive/testdata/sample_job_response.json new file mode 100644 index 0000000..1ff1be5 --- /dev/null +++ b/runner/cfd/cmd/drive/testdata/sample_job_response.json @@ -0,0 +1,26 @@ +{ + "image": { + "command": ["a", "b", "c"], + "entrypoint": ["d", "e", "f"] + }, + "services": [ + { + "alias": "my-pg-service", + "name": "postgres:wormy", + "command": ["g", "h", "i"], + "entrypoint": ["j", "k", "l"], + "variables": [ + { + "key": "bazz", + "value": "buzz" + } + ] + } + ], + "variables": [ + { + "key": "foo", + "value": "bar" + } + ] +} From f12009b2c2c290f93118df159891a591815f270f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 15 Jan 2025 16:14:06 -0500 Subject: [PATCH 71/76] refactor: should have used pointers --- runner/cfd/cmd/drive/read_env.go | 10 +++++----- runner/cfd/cmd/drive/read_env_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/runner/cfd/cmd/drive/read_env.go b/runner/cfd/cmd/drive/read_env.go index ed71229..f78149a 100644 --- a/runner/cfd/cmd/drive/read_env.go +++ b/runner/cfd/cmd/drive/read_env.go @@ -31,9 +31,9 @@ type EnvCfg struct { } type JobResData struct { - Image JobResImg - Variables JobResVars - Services []JobResSvcs + Image *JobResImg + Variables *JobResVars + Services []*JobResSvcs } type JobResImg struct { Name string @@ -46,8 +46,8 @@ type JobResVars []struct { Value string } type JobResSvcs struct { - JobResImg - Variables JobResVars + *JobResImg + Variables *JobResVars } type VcapAppData struct { diff --git a/runner/cfd/cmd/drive/read_env_test.go b/runner/cfd/cmd/drive/read_env_test.go index d4a6aa0..8cc04b5 100644 --- a/runner/cfd/cmd/drive/read_env_test.go +++ b/runner/cfd/cmd/drive/read_env_test.go @@ -64,20 +64,20 @@ func Test_parseJobResFile(t *testing.T) { t.Setenv("JOB_RESPONSE_FILE", "./testdata/sample_job_response.json") wanted := &JobResData{ - Image: JobResImg{ + Image: &JobResImg{ Command: []string{"a", "b", "c"}, Entrypoint: []string{"d", "e", "f"}, }, - Services: []JobResSvcs{{ - JobResImg: JobResImg{ + Services: []*JobResSvcs{{ + JobResImg: &JobResImg{ Name: "postgres:wormy", Alias: "my-pg-service", Command: []string{"g", "h", "i"}, Entrypoint: []string{"j", "k", "l"}, }, - Variables: JobResVars{{Key: "bazz", Value: "buzz"}}, + Variables: &JobResVars{{Key: "bazz", Value: "buzz"}}, }}, - Variables: JobResVars{{Key: "foo", Value: "bar"}}, + Variables: &JobResVars{{Key: "foo", Value: "bar"}}, } cfg := getEnvCfg() From 736d2f0634eaa9e8f0b56ac44babcd761e3a5bf9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 16 Jan 2025 11:00:40 -0500 Subject: [PATCH 72/76] refactor: use more descriptive variable names --- runner/cfd/cmd/drive/read_env.go | 34 +++++++++++------------ runner/cfd/cmd/drive/read_env_test.go | 40 +++++++++++++-------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/runner/cfd/cmd/drive/read_env.go b/runner/cfd/cmd/drive/read_env.go index f78149a..d781d0a 100644 --- a/runner/cfd/cmd/drive/read_env.go +++ b/runner/cfd/cmd/drive/read_env.go @@ -7,7 +7,7 @@ import ( "reflect" ) -type EnvCfg struct { +type EnvConfig struct { *JobResData *VcapAppData *ServicesData @@ -18,22 +18,22 @@ type EnvCfg struct { ContainerId string `env:"CONTAINER_ID"` - RegUser string `env:"CUSTOM_ENV_CI_REGISTRY_USER"` - RegPass string `env:"CUSTOM_ENV_CI_REGISTRY_PASSWORD"` - JobImg string `env:"CUSTOM_ENV_CI_JOB_IMAGE"` + JobImg string `env:"CUSTOM_ENV_CI_JOB_IMAGE"` + DockerPass string `env:"CF_DOCKER_PASSWORD"` + CIRegistryUser string `env:"CUSTOM_ENV_CI_REGISTRY_USER"` + CIRegistryPass string `env:"CUSTOM_ENV_CI_REGISTRY_PASSWORD"` - DockerToken string `env:"DOCKER_HUB_TOKEN"` - DockerUser string `env:"DOCKER_HUB_USER"` - DockerPass string `env:"CF_DOCKER_PASSWORD"` + DockerHubUser string `env:"DOCKER_HUB_USER"` + DockerHubToken string `env:"DOCKER_HUB_TOKEN"` - WorkerMem string `env:"WORKER_MEMORY"` - WorkerDisk string `env:"WORKER_DISK_SIZE"` + WorkerMemory string `env:"WORKER_MEMORY"` + WorkerDiskSize string `env:"WORKER_DISK_SIZE"` } type JobResData struct { Image *JobResImg Variables *JobResVars - Services []*JobResSvcs + Services []*JobResServices } type JobResImg struct { Name string @@ -45,7 +45,7 @@ type JobResVars []struct { Key string Value string } -type JobResSvcs struct { +type JobResServices struct { *JobResImg Variables *JobResVars } @@ -72,7 +72,7 @@ func parseCfgJSON[R any](j []byte, r *R) (*R, error) { return r, nil } -func (c *EnvCfg) parseJobResFile() (err error) { +func (c *EnvConfig) parseJobResFile() (err error) { if c.JobResFile == "" { return nil } @@ -86,12 +86,12 @@ func (c *EnvCfg) parseJobResFile() (err error) { return err } -func (c *EnvCfg) parseVcapAppJSON() (err error) { +func (c *EnvConfig) parseVcapAppJSON() (err error) { c.VcapAppData, err = parseCfgJSON([]byte(c.VcapAppJSON), &VcapAppData{}) return err } -func (c *EnvCfg) parseServicesJSON() (err error) { +func (c *EnvConfig) parseServicesJSON() (err error) { c.ServicesData, err = parseCfgJSON([]byte(c.ServicesJSON), &ServicesData{}) return err } @@ -99,7 +99,7 @@ func (c *EnvCfg) parseServicesJSON() (err error) { // This is a pretty simple implementation, if our needs get more // complex we should use one of several existing packages to do this. // e.g., https://pkg.go.dev/github.com/caarlos0/env/v11 -func (c *EnvCfg) parseEnv() *EnvCfg { +func (c *EnvConfig) parseEnv() *EnvConfig { ct := reflect.TypeOf(*c) ce := reflect.ValueOf(c).Elem() @@ -115,8 +115,8 @@ func (c *EnvCfg) parseEnv() *EnvCfg { return c } -func getEnvCfg() *EnvCfg { - cfg := (&EnvCfg{}).parseEnv() +func getEnvCfg() *EnvConfig { + cfg := (&EnvConfig{}).parseEnv() if err := cfg.parseJobResFile(); err != nil { panic(err) } diff --git a/runner/cfd/cmd/drive/read_env_test.go b/runner/cfd/cmd/drive/read_env_test.go index 8cc04b5..c8e9485 100644 --- a/runner/cfd/cmd/drive/read_env_test.go +++ b/runner/cfd/cmd/drive/read_env_test.go @@ -10,32 +10,32 @@ import ( // but I think it'll be easier to manage if parsing a file and want to // think about that later. func Test_getEnvCfg(t *testing.T) { - cfgWant := &EnvCfg{ - ContainerId: "1234", - RegUser: "foo", - RegPass: "bar", - JobImg: "bookworm", - DockerToken: "1234", - DockerUser: "foo", - DockerPass: "bar", - WorkerMem: "1024M", - WorkerDisk: "1024M", - JobResFile: "", - VcapAppJSON: "", - ServicesJSON: "", + cfgWant := &EnvConfig{ + ContainerId: "1234", + CIRegistryUser: "foo", + CIRegistryPass: "bar", + JobImg: "bookworm", + DockerPass: "bar", + DockerHubUser: "foo", + DockerHubToken: "1234", + WorkerMemory: "1024M", + WorkerDiskSize: "1024M", + JobResFile: "", + VcapAppJSON: "", + ServicesJSON: "", } envWant := map[string]string{ "CONTAINER_ID": cfgWant.ContainerId, "JOB_RESPONSE_FILE": cfgWant.JobResFile, - "CUSTOM_ENV_CI_REGISTRY_USER": cfgWant.RegUser, - "CUSTOM_ENV_CI_REGISTRY_PASSWORD": cfgWant.RegPass, + "CUSTOM_ENV_CI_REGISTRY_USER": cfgWant.CIRegistryUser, + "CUSTOM_ENV_CI_REGISTRY_PASSWORD": cfgWant.CIRegistryPass, "CUSTOM_ENV_CI_JOB_IMAGE": cfgWant.JobImg, - "DOCKER_HUB_TOKEN": cfgWant.DockerToken, - "DOCKER_HUB_USER": cfgWant.DockerUser, + "DOCKER_HUB_TOKEN": cfgWant.DockerHubToken, + "DOCKER_HUB_USER": cfgWant.DockerHubUser, "CF_DOCKER_PASSWORD": cfgWant.DockerPass, - "WORKER_MEMORY": cfgWant.WorkerMem, - "WORKER_DISK_SIZE": cfgWant.WorkerDisk, + "WORKER_MEMORY": cfgWant.WorkerMemory, + "WORKER_DISK_SIZE": cfgWant.WorkerDiskSize, "VCAP_APPLICATION": cfgWant.VcapAppJSON, "CUSTOM_ENV_CI_JOB_SERVICES": cfgWant.ServicesJSON, } @@ -68,7 +68,7 @@ func Test_parseJobResFile(t *testing.T) { Command: []string{"a", "b", "c"}, Entrypoint: []string{"d", "e", "f"}, }, - Services: []*JobResSvcs{{ + Services: []*JobResServices{{ JobResImg: &JobResImg{ Name: "postgres:wormy", Alias: "my-pg-service", From c2abd968f11f0721f263f140518dc050f8bd7f52 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 16 Jan 2025 15:31:00 -0500 Subject: [PATCH 73/76] chore: delete unused parse for CF_DOCKER_PASSWORD --- runner/cfd/cmd/drive/read_env.go | 1 - 1 file changed, 1 deletion(-) diff --git a/runner/cfd/cmd/drive/read_env.go b/runner/cfd/cmd/drive/read_env.go index d781d0a..7ce55bd 100644 --- a/runner/cfd/cmd/drive/read_env.go +++ b/runner/cfd/cmd/drive/read_env.go @@ -19,7 +19,6 @@ type EnvConfig struct { ContainerId string `env:"CONTAINER_ID"` JobImg string `env:"CUSTOM_ENV_CI_JOB_IMAGE"` - DockerPass string `env:"CF_DOCKER_PASSWORD"` CIRegistryUser string `env:"CUSTOM_ENV_CI_REGISTRY_USER"` CIRegistryPass string `env:"CUSTOM_ENV_CI_REGISTRY_PASSWORD"` From 2c65099c01986b969d4fc070e3691d024c20f73e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 16 Jan 2025 15:50:05 -0500 Subject: [PATCH 74/76] chore: delete unused parse for CF_DOCKER_PASSWORD, Pt II This is what I get for my hubris --- runner/cfd/cmd/drive/read_env_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/runner/cfd/cmd/drive/read_env_test.go b/runner/cfd/cmd/drive/read_env_test.go index c8e9485..246582d 100644 --- a/runner/cfd/cmd/drive/read_env_test.go +++ b/runner/cfd/cmd/drive/read_env_test.go @@ -15,7 +15,6 @@ func Test_getEnvCfg(t *testing.T) { CIRegistryUser: "foo", CIRegistryPass: "bar", JobImg: "bookworm", - DockerPass: "bar", DockerHubUser: "foo", DockerHubToken: "1234", WorkerMemory: "1024M", @@ -33,7 +32,6 @@ func Test_getEnvCfg(t *testing.T) { "CUSTOM_ENV_CI_JOB_IMAGE": cfgWant.JobImg, "DOCKER_HUB_TOKEN": cfgWant.DockerHubToken, "DOCKER_HUB_USER": cfgWant.DockerHubUser, - "CF_DOCKER_PASSWORD": cfgWant.DockerPass, "WORKER_MEMORY": cfgWant.WorkerMemory, "WORKER_DISK_SIZE": cfgWant.WorkerDiskSize, "VCAP_APPLICATION": cfgWant.VcapAppJSON, From 9d31e9b0770ebd38636606da6d6be162eef8fe8e Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 16 Jan 2025 16:18:14 -0500 Subject: [PATCH 75/76] chore: forgot the runner dir moved! --- {runner => runner-manager}/cfd/.gitignore | 0 {runner => runner-manager}/cfd/.vscode/launch.json | 0 {runner => runner-manager}/cfd/Makefile | 0 {runner => runner-manager}/cfd/README.md | 0 {runner => runner-manager}/cfd/cg/cf_adapter.go | 0 {runner => runner-manager}/cfd/cg/cg.go | 0 {runner => runner-manager}/cfd/cg/cg_integration_test.go | 0 {runner => runner-manager}/cfd/cg/cg_test.go | 0 {runner => runner-manager}/cfd/cg/creds.go | 0 {runner => runner-manager}/cfd/cg/creds_test.go | 0 {runner => runner-manager}/cfd/cg/testdata/.cg_creds.sample | 0 {runner => runner-manager}/cfd/cmd/drive/cleanup.go | 0 {runner => runner-manager}/cfd/cmd/drive/config.go | 0 {runner => runner-manager}/cfd/cmd/drive/drive.go | 0 {runner => runner-manager}/cfd/cmd/drive/prepare.go | 0 {runner => runner-manager}/cfd/cmd/drive/read_env.go | 0 {runner => runner-manager}/cfd/cmd/drive/read_env_test.go | 0 {runner => runner-manager}/cfd/cmd/drive/run.go | 0 .../cfd/cmd/drive/testdata/sample_job_response.json | 0 {runner => runner-manager}/cfd/cmd/root.go | 0 {runner => runner-manager}/cfd/go.mod | 0 {runner => runner-manager}/cfd/go.sum | 0 {runner => runner-manager}/cfd/main.go | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename {runner => runner-manager}/cfd/.gitignore (100%) rename {runner => runner-manager}/cfd/.vscode/launch.json (100%) rename {runner => runner-manager}/cfd/Makefile (100%) rename {runner => runner-manager}/cfd/README.md (100%) rename {runner => runner-manager}/cfd/cg/cf_adapter.go (100%) rename {runner => runner-manager}/cfd/cg/cg.go (100%) rename {runner => runner-manager}/cfd/cg/cg_integration_test.go (100%) rename {runner => runner-manager}/cfd/cg/cg_test.go (100%) rename {runner => runner-manager}/cfd/cg/creds.go (100%) rename {runner => runner-manager}/cfd/cg/creds_test.go (100%) rename {runner => runner-manager}/cfd/cg/testdata/.cg_creds.sample (100%) rename {runner => runner-manager}/cfd/cmd/drive/cleanup.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/config.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/drive.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/prepare.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/read_env.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/read_env_test.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/run.go (100%) rename {runner => runner-manager}/cfd/cmd/drive/testdata/sample_job_response.json (100%) rename {runner => runner-manager}/cfd/cmd/root.go (100%) rename {runner => runner-manager}/cfd/go.mod (100%) rename {runner => runner-manager}/cfd/go.sum (100%) rename {runner => runner-manager}/cfd/main.go (100%) diff --git a/runner/cfd/.gitignore b/runner-manager/cfd/.gitignore similarity index 100% rename from runner/cfd/.gitignore rename to runner-manager/cfd/.gitignore diff --git a/runner/cfd/.vscode/launch.json b/runner-manager/cfd/.vscode/launch.json similarity index 100% rename from runner/cfd/.vscode/launch.json rename to runner-manager/cfd/.vscode/launch.json diff --git a/runner/cfd/Makefile b/runner-manager/cfd/Makefile similarity index 100% rename from runner/cfd/Makefile rename to runner-manager/cfd/Makefile diff --git a/runner/cfd/README.md b/runner-manager/cfd/README.md similarity index 100% rename from runner/cfd/README.md rename to runner-manager/cfd/README.md diff --git a/runner/cfd/cg/cf_adapter.go b/runner-manager/cfd/cg/cf_adapter.go similarity index 100% rename from runner/cfd/cg/cf_adapter.go rename to runner-manager/cfd/cg/cf_adapter.go diff --git a/runner/cfd/cg/cg.go b/runner-manager/cfd/cg/cg.go similarity index 100% rename from runner/cfd/cg/cg.go rename to runner-manager/cfd/cg/cg.go diff --git a/runner/cfd/cg/cg_integration_test.go b/runner-manager/cfd/cg/cg_integration_test.go similarity index 100% rename from runner/cfd/cg/cg_integration_test.go rename to runner-manager/cfd/cg/cg_integration_test.go diff --git a/runner/cfd/cg/cg_test.go b/runner-manager/cfd/cg/cg_test.go similarity index 100% rename from runner/cfd/cg/cg_test.go rename to runner-manager/cfd/cg/cg_test.go diff --git a/runner/cfd/cg/creds.go b/runner-manager/cfd/cg/creds.go similarity index 100% rename from runner/cfd/cg/creds.go rename to runner-manager/cfd/cg/creds.go diff --git a/runner/cfd/cg/creds_test.go b/runner-manager/cfd/cg/creds_test.go similarity index 100% rename from runner/cfd/cg/creds_test.go rename to runner-manager/cfd/cg/creds_test.go diff --git a/runner/cfd/cg/testdata/.cg_creds.sample b/runner-manager/cfd/cg/testdata/.cg_creds.sample similarity index 100% rename from runner/cfd/cg/testdata/.cg_creds.sample rename to runner-manager/cfd/cg/testdata/.cg_creds.sample diff --git a/runner/cfd/cmd/drive/cleanup.go b/runner-manager/cfd/cmd/drive/cleanup.go similarity index 100% rename from runner/cfd/cmd/drive/cleanup.go rename to runner-manager/cfd/cmd/drive/cleanup.go diff --git a/runner/cfd/cmd/drive/config.go b/runner-manager/cfd/cmd/drive/config.go similarity index 100% rename from runner/cfd/cmd/drive/config.go rename to runner-manager/cfd/cmd/drive/config.go diff --git a/runner/cfd/cmd/drive/drive.go b/runner-manager/cfd/cmd/drive/drive.go similarity index 100% rename from runner/cfd/cmd/drive/drive.go rename to runner-manager/cfd/cmd/drive/drive.go diff --git a/runner/cfd/cmd/drive/prepare.go b/runner-manager/cfd/cmd/drive/prepare.go similarity index 100% rename from runner/cfd/cmd/drive/prepare.go rename to runner-manager/cfd/cmd/drive/prepare.go diff --git a/runner/cfd/cmd/drive/read_env.go b/runner-manager/cfd/cmd/drive/read_env.go similarity index 100% rename from runner/cfd/cmd/drive/read_env.go rename to runner-manager/cfd/cmd/drive/read_env.go diff --git a/runner/cfd/cmd/drive/read_env_test.go b/runner-manager/cfd/cmd/drive/read_env_test.go similarity index 100% rename from runner/cfd/cmd/drive/read_env_test.go rename to runner-manager/cfd/cmd/drive/read_env_test.go diff --git a/runner/cfd/cmd/drive/run.go b/runner-manager/cfd/cmd/drive/run.go similarity index 100% rename from runner/cfd/cmd/drive/run.go rename to runner-manager/cfd/cmd/drive/run.go diff --git a/runner/cfd/cmd/drive/testdata/sample_job_response.json b/runner-manager/cfd/cmd/drive/testdata/sample_job_response.json similarity index 100% rename from runner/cfd/cmd/drive/testdata/sample_job_response.json rename to runner-manager/cfd/cmd/drive/testdata/sample_job_response.json diff --git a/runner/cfd/cmd/root.go b/runner-manager/cfd/cmd/root.go similarity index 100% rename from runner/cfd/cmd/root.go rename to runner-manager/cfd/cmd/root.go diff --git a/runner/cfd/go.mod b/runner-manager/cfd/go.mod similarity index 100% rename from runner/cfd/go.mod rename to runner-manager/cfd/go.mod diff --git a/runner/cfd/go.sum b/runner-manager/cfd/go.sum similarity index 100% rename from runner/cfd/go.sum rename to runner-manager/cfd/go.sum diff --git a/runner/cfd/main.go b/runner-manager/cfd/main.go similarity index 100% rename from runner/cfd/main.go rename to runner-manager/cfd/main.go From 1647675e22b1808f02abea1029cc1d19e8a7d91f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Thu, 16 Jan 2025 16:20:14 -0500 Subject: [PATCH 76/76] fix: tell go driver workflow to look in runner-manager --- .github/workflows/cf-driver-go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 197020a..0e98f31 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -7,7 +7,7 @@ on: [pull_request] defaults: run: - working-directory: runner/cfd + working-directory: runner-manager/cfd jobs: build: @@ -18,8 +18,8 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version-file: runner/cfd/go.mod - cache-dependency-path: runner/cfd/go.sum + go-version-file: runner-manager/cfd/go.mod + cache-dependency-path: runner-manager/cfd/go.sum - name: Install dependencies run: go get .