From 0530b3b9e42d359e7e782b7c604c6f10be02bbbf Mon Sep 17 00:00:00 2001 From: Jeet Parekh Date: Mon, 15 Apr 2019 23:35:25 +0530 Subject: [PATCH] started work for source connection checking --- cmd/abc/appbase_import.go | 6 ++++++ cmd/abc/verify_connections.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 cmd/abc/verify_connections.go diff --git a/cmd/abc/appbase_import.go b/cmd/abc/appbase_import.go index 3deac0b..4f667e7 100644 --- a/cmd/abc/appbase_import.go +++ b/cmd/abc/appbase_import.go @@ -66,6 +66,8 @@ func runImport(args []string) error { transformFile := flagset.String("transform_file", "", "transform file to use") + verify := flagset.Bool("verify", false, "verify the source and destination connections") + // use external config config := flagset.String("config", "", "Path to external config file, if specified, only that is used") @@ -75,6 +77,10 @@ func runImport(args []string) error { return err } + if *verify { + return verifyConnections(*srcType, *srcURL, *ssl) + } + // use the config file if *config != "" { file, err := genPipelineFromEnv(*config) diff --git a/cmd/abc/verify_connections.go b/cmd/abc/verify_connections.go new file mode 100644 index 0000000..d7d10f8 --- /dev/null +++ b/cmd/abc/verify_connections.go @@ -0,0 +1,34 @@ +// +build !oss + +package main + +import ( + "database/sql" + + _ "github.com/lib/pq" +) + +func verifyConnections(srcType string, srcURL string, ssl bool) error { + switch srcType { + case "postgres": + if !ssl { + srcURL = srcURL + "?sslmode=disable" + } + + conn, err := sql.Open("postgres", srcURL) + if err != nil { + return err + } + + err = conn.Ping() + if err != nil { + return err + } + + conn.Close() + + default: + return nil + } + return nil +} -- GitLab