From 25b8d9eaf8f1e65de8a879a2c3e4e82a2d348b84 Mon Sep 17 00:00:00 2001 From: Matthew Broomfield Date: Wed, 28 Nov 2018 11:18:48 -0800 Subject: [PATCH] Fix source-config command. Closes #62 --- src/omg-cli/go.mod | 6 +---- src/omg-cli/go.sum | 12 ++------- src/omg-cli/omg/commands/source_config.go | 13 ++------- .../omg/commands/source_config_test.go | 27 +++++++++++++++++++ src/omg-tf/init.sh | 22 ++++++++++++++- 5 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 src/omg-cli/omg/commands/source_config_test.go diff --git a/src/omg-cli/go.mod b/src/omg-cli/go.mod index 7a979783..0d07c43a 100644 --- a/src/omg-cli/go.mod +++ b/src/omg-cli/go.mod @@ -2,10 +2,6 @@ module omg-cli require ( cloud.google.com/go/compute/metadata v0.0.0-20181109222614-193e596dec49 // indirect - code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c - code.cloudfoundry.org/lager v2.0.0+incompatible - code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d // indirect - code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82 github.com/PuerkitoBio/goquery v1.4.1 // indirect github.com/alecthomas/kingpin v2.2.6+incompatible github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect @@ -17,10 +13,10 @@ require ( github.com/cloudfoundry/bosh-utils v0.0.0-20181109230347-f1d51d8b54a5 // indirect github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd + github.com/iancoleman/strcase v0.0.0-20181128000000-3605ed457bf7 github.com/imdario/mergo v0.3.6 github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/olekukonko/tablewriter v0.0.1 // indirect diff --git a/src/omg-cli/go.sum b/src/omg-cli/go.sum index b611f968..15cc4814 100644 --- a/src/omg-cli/go.sum +++ b/src/omg-cli/go.sum @@ -1,13 +1,5 @@ cloud.google.com/go/compute/metadata v0.0.0-20181109222614-193e596dec49 h1:wK/qe2zvtL/3B8DGX8ItISY8vxwrQRmC6EXLPGeZ0Ek= cloud.google.com/go/compute/metadata v0.0.0-20181109222614-193e596dec49/go.mod h1:bDzgiyYlSneEi8ypjdQR5QS9yAMUX2nlrSb6UVd6Ghk= -code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c h1:5eeuG0BHx1+DHeT3AP+ISKZ2ht1UjGhm581ljqYpVeQ= -code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8= -code.cloudfoundry.org/lager v2.0.0+incompatible h1:WZwDKDB2PLd/oL+USK4b4aEjUymIej9My2nUQ9oWEwQ= -code.cloudfoundry.org/lager v2.0.0+incompatible/go.mod h1:O2sS7gKP3HM2iemG+EnwvyNQK7pTSC6Foi4QiMp9sSk= -code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d h1:1I5BueV2nNkvIV40CQ0JQgmD/ijouF0QlLLOz0KMkRo= -code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d/go.mod h1:KAH6N5nwHViCZsOgmApk6nj8TDuqRGb9R06Hk461Uwc= -code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82 h1:qUuXU4x4xcL3OCtqdLcxELBmLr4RFp0agNgXzv1uQRE= -code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82/go.mod h1:RPJxhL74iNXTSTQf9EDtdAXJ5fLVAmkVsFtZRHEbgk0= github.com/PuerkitoBio/goquery v1.4.1 h1:smcIRGdYm/w7JSbcdeLHEMzxmsBQvl8lhf0dSw2nzMI= github.com/PuerkitoBio/goquery v1.4.1/go.mod h1:T9ezsOHcCrDCgA8aF1Cqr3sSYbO/xgdy8/R/XiIMAhA= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f h1:5ZfJxyXo8KyX8DgGXC5B7ILL8y51fci/qYz2B4j8iLY= @@ -32,8 +24,6 @@ github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c h1:L6Qwcfk/qeD github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c/go.mod h1:67a7aIi94FHDZdoeGSJRRFDp66l9MhaAG1yGxpUoFD8= 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/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= @@ -50,6 +40,8 @@ github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd h1:1e+0Z+T4t1mKL5xxv github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/iancoleman/strcase v0.0.0-20181128000000-3605ed457bf7 h1:xaEaXiQ2EzvQHzFrbPkX0MhxmG7eXUDLw4BP9gi7IA4= +github.com/iancoleman/strcase v0.0.0-20181128000000-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= diff --git a/src/omg-cli/omg/commands/source_config.go b/src/omg-cli/omg/commands/source_config.go index 7b180e7e..d970ce23 100644 --- a/src/omg-cli/omg/commands/source_config.go +++ b/src/omg-cli/omg/commands/source_config.go @@ -19,12 +19,11 @@ package commands import ( "encoding/json" "log" - "regexp" - "strings" "omg-cli/config" "github.com/alecthomas/kingpin" + "github.com/iancoleman/strcase" ) // SourceConfigCommand outputs the quickstart's config. @@ -40,16 +39,8 @@ func (cmd *SourceConfigCommand) register(app *kingpin.Application) { registerEnvConfigFlag(c, &cmd.envDir) } -var camel = regexp.MustCompile("(^[^A-Z0-9]*|[A-Z0-9]*)([A-Z0-9][^A-Z]+|$)") - func nameToEnv(name string) string { - var words []string - for _, part := range camel.FindAllStringSubmatch(name, -1) { - if part[0] != "" { - words = append(words, part[0]) - } - } - return strings.ToUpper(strings.Join(words, "_")) + return strcase.ToScreamingSnake(name) } func (cmd *SourceConfigCommand) run(c *kingpin.ParseContext) error { diff --git a/src/omg-cli/omg/commands/source_config_test.go b/src/omg-cli/omg/commands/source_config_test.go new file mode 100644 index 00000000..89b77a49 --- /dev/null +++ b/src/omg-cli/omg/commands/source_config_test.go @@ -0,0 +1,27 @@ +package commands + +import "testing" + +func TestNameToEnv(t *testing.T) { + + cases := []struct { + name string + envName string + } { + { + name: "DNSZoneName", + envName: "DNS_ZONE_NAME", + }, + { + name: "HappyCloud", + envName: "HAPPY_CLOUD", + }, + } + + for _, tc := range cases { + actual := nameToEnv(tc.name) + if tc.envName != actual { + t.Fatalf("unexpected env name. wanted %s but got %s", tc.envName, actual) + } + } +} \ No newline at end of file diff --git a/src/omg-tf/init.sh b/src/omg-tf/init.sh index 455c5f4c..a95a9d6e 100755 --- a/src/omg-tf/init.sh +++ b/src/omg-tf/init.sh @@ -35,6 +35,26 @@ if [ -z ${DNS_ZONE_NAME+x} ]; then exit 1 fi +if [ -z ${ZONE_1+x} ]; then + echo "ZONE_1 required" + exit 1 +fi + +if [ -z ${ZONE_2+x} ]; then + echo "ZONE_2 required" + exit 1 +fi + +if [ -z ${ZONE_3+x} ]; then + echo "ZONE_3 required" + exit 1 +fi + +if [ -z ${REGION+x} ]; then + echo "REGION required" + exit 1 +fi + if [ -z ${PROJECT_ID+x} ]; then export PROJECT_ID=${PROJECT_ID-`gcloud config get-value project 2> /dev/null`} echo "PROJECT_ID unset, using: ${PROJECT_ID}" @@ -111,7 +131,7 @@ jumpbox_machine_type="${jumpbox_machine_type}" ops_manager_password = "${OPSMAN_ADMIN_PASSWORD:-}" ops_manager_skip_ssl_verify = "true" region = "${REGION}" -zones = ["${ZONE1}", "${ZONE2}", "${ZONE3}"] +zones = ["${ZONE_1}", "${ZONE_2}", "${ZONE_3}"] external_database = "${external_database}" ssl_cert = <