Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump JSON values properly. #1660

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (

const (
airflowConnectionList = "airflow connections list -o yaml"
ariflowPoolsList = "airflow pools list -o yaml"
airflowPoolsList = "airflow pools list -o yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appreciate squashing typos, and leaving the code that much better 🙂

airflowConnExport = "airflow connections export tmp.connections --file-format env"
airflowVarExport = "airflow variables export tmp.var"
catVarFile = "cat tmp.var"
Expand Down Expand Up @@ -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")
Expand All @@ -534,13 +534,22 @@ 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, _ := json.Marshal(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add error handling here, just to be safe

vs = string(b)
}
newVariables := Variables{{k, vs}}
fmt.Println("Exporting Variable: " + k)
settings.Airflow.Variables = append(settings.Airflow.Variables, newVariables...)
}
Expand All @@ -559,7 +568,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)

Expand Down
2 changes: 1 addition & 1 deletion settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *Suite) TestExport() {
return `{
"myvar": "myval"
}`
case ariflowPoolsList:
case airflowPoolsList:
return `
- description: Default pool
pool: default_pool
Expand Down