From 7602c8bb02f0c95203322ed4bd3ea20a2d09d403 Mon Sep 17 00:00:00 2001 From: Victor Shih Date: Tue, 4 Jun 2024 08:10:08 -0700 Subject: [PATCH 1/3] Spelling. --- settings/settings.go | 6 +++--- settings/settings_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index ae6e0d88a..1ad60cf19 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -42,7 +42,7 @@ var ( const ( airflowConnectionList = "airflow connections list -o yaml" - ariflowPoolsList = "airflow pools list -o yaml" + airflowPoolsList = "airflow pools list -o yaml" airflowConnExport = "airflow connections export tmp.connections --file-format env" airflowVarExport = "airflow variables export tmp.var" catVarFile = "cat tmp.var" @@ -534,7 +534,7 @@ func ExportVariables(id string) error { for j := range settings.Airflow.Variables { if settings.Airflow.Variables[j].VariableName == k { fmt.Println("Updating Pool: " + k) - // Remove variable if it already exits + // Remove variable if it already exists settings.Airflow.Variables = append(settings.Airflow.Variables[:j], settings.Airflow.Variables[j+1:]...) break } @@ -559,7 +559,7 @@ func ExportVariables(id string) error { func ExportPools(id string) error { // Setup airflow command to export pools - airflowCommand := ariflowPoolsList + airflowCommand := airflowPoolsList out := execAirflowCommand(id, airflowCommand) logrus.Debugf("Export Pools logs:\n" + out) diff --git a/settings/settings_test.go b/settings/settings_test.go index dcbef3828..58bc8f104 100644 --- a/settings/settings_test.go +++ b/settings/settings_test.go @@ -329,7 +329,7 @@ func (s *Suite) TestExport() { return `{ "myvar": "myval" }` - case ariflowPoolsList: + case airflowPoolsList: return ` - description: Default pool pool: default_pool From 1c43c69984e22dd830143c2ac2117aa2199178c7 Mon Sep 17 00:00:00 2001 From: Victor Shih Date: Tue, 4 Jun 2024 08:04:13 -0700 Subject: [PATCH 2/3] Dump JSON values properly. --- settings/settings.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index 1ad60cf19..338015807 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -524,7 +524,7 @@ func ExportVariables(id string) error { // get variables created by the airflow command out = execAirflowCommand(id, catVarFile) - m := map[string]string{} + var m map[string]interface{} err := json.Unmarshal([]byte(out), &m) if err != nil { fmt.Println("variable json decode unsuccessful") @@ -540,7 +540,16 @@ func ExportVariables(id string) error { } } - newVariables := Variables{{k, v}} + var vs string + switch vt := v.(type) { + case string: + vs = vt + default: + // Re-encode complex types as JSON. + b, _ := json.Marshal(v) + vs = string(b) + } + newVariables := Variables{{k, vs}} fmt.Println("Exporting Variable: " + k) settings.Airflow.Variables = append(settings.Airflow.Variables, newVariables...) } From 9b81e3bf325675a4196bd9af6c8353c713711f7c Mon Sep 17 00:00:00 2001 From: Victor Shih Date: Thu, 21 Nov 2024 09:29:26 -0800 Subject: [PATCH 3/3] Error handling for JSON encoding. --- settings/settings.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index 338015807..0c25084f4 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -546,8 +546,13 @@ func ExportVariables(id string) error { vs = vt default: // Re-encode complex types as JSON. - b, _ := json.Marshal(v) - vs = string(b) + b, err := json.Marshal(v) + if err == nil { + vs = string(b) + } else { + fmt.Println("variable json encode unsuccessful") + vs = v + } } newVariables := Variables{{k, vs}} fmt.Println("Exporting Variable: " + k)