diff --git a/settings/settings.go b/settings/settings.go index ae6e0d88a..0c25084f4 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" @@ -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") @@ -534,13 +534,27 @@ 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 } } - newVariables := Variables{{k, v}} + var vs string + switch vt := v.(type) { + case string: + vs = vt + default: + // Re-encode complex types as JSON. + 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) settings.Airflow.Variables = append(settings.Airflow.Variables, newVariables...) } @@ -559,7 +573,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