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

Issue 1320 - Add Conn Description as Parameter #1361

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cmd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
upgrade-test*
7 changes: 6 additions & 1 deletion settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@
connections = AppendEnvironmentConnections(connections, envConns)

baseCmd := "airflow connections "
var baseAddCmd, baseRmCmd, baseListCmd, connIDArg, connTypeArg, connURIArg, connExtraArg, connHostArg, connLoginArg, connPasswordArg, connSchemaArg, connPortArg string
var baseAddCmd, baseRmCmd, baseListCmd, connIDArg, connDescriptionArg, connTypeArg, connURIArg, connExtraArg, connHostArg, connLoginArg, connPasswordArg, connSchemaArg, connPortArg string
if version >= AirflowVersionTwo {
// Airflow 2.0.0 command
// based on https://airflow.apache.org/docs/apache-airflow/2.0.0/cli-and-env-variables-ref.html
baseAddCmd = baseCmd + "add "
baseRmCmd = baseCmd + "delete "
baseListCmd = baseCmd + "list -o plain"
connIDArg = ""
connDescriptionArg = "--conn-description"
connTypeArg = "--conn-type"
connURIArg = "--conn-uri"
connExtraArg = "--conn-extra"
Expand Down Expand Up @@ -194,6 +195,10 @@
}

airflowCommand = fmt.Sprintf("%s %s '%s' ", baseAddCmd, connIDArg, conn.ConnID)
if objectValidator(0, conn.ConnDescription) {
airflowCommand += fmt.Sprintf("%s '%s' ", connDescriptionArg, conn.ConnDescription)
j++

Check warning on line 200 in settings/settings.go

View check run for this annotation

Codecov / codecov/patch

settings/settings.go#L199-L200

Added lines #L199 - L200 were not covered by tests
}
if objectValidator(0, conn.ConnType) {
airflowCommand += fmt.Sprintf("%s '%s' ", connTypeArg, conn.ConnType)
j++
Expand Down
1 change: 1 addition & 0 deletions settings/testfiles/airflow_settings_export.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
airflow:
connections:
- conn_id: local_postgres
conn_description: ""
conn_type: postgres
conn_host: example.db.example.com
conn_schema: schema
Expand Down
19 changes: 10 additions & 9 deletions settings/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ type Connections []Connection

// Connection contains structure of airflow connection
type Connection struct {
ConnID string `mapstructure:"conn_id" yaml:"conn_id"`
ConnType string `mapstructure:"conn_type" yaml:"conn_type"`
ConnHost string `mapstructure:"conn_host" yaml:"conn_host"`
ConnSchema string `mapstructure:"conn_schema" yaml:"conn_schema"`
ConnLogin string `mapstructure:"conn_login" yaml:"conn_login"`
ConnPassword string `mapstructure:"conn_password" yaml:"conn_password"`
ConnPort int `mapstructure:"conn_port" yaml:"conn_port"`
ConnURI string `mapstructure:"conn_uri" yaml:"conn_uri"`
ConnExtra interface{} `mapstructure:"conn_extra" yaml:"conn_extra"`
ConnID string `mapstructure:"conn_id" yaml:"conn_id"`
ConnDescription string `mapstructure:"conn_description" yaml:"conn_description"`
ConnType string `mapstructure:"conn_type" yaml:"conn_type"`
ConnHost string `mapstructure:"conn_host" yaml:"conn_host"`
ConnSchema string `mapstructure:"conn_schema" yaml:"conn_schema"`
ConnLogin string `mapstructure:"conn_login" yaml:"conn_login"`
ConnPassword string `mapstructure:"conn_password" yaml:"conn_password"`
ConnPort int `mapstructure:"conn_port" yaml:"conn_port"`
ConnURI string `mapstructure:"conn_uri" yaml:"conn_uri"`
ConnExtra interface{} `mapstructure:"conn_extra" yaml:"conn_extra"`
}

// Pools contains structure of airflow pools
Expand Down