Skip to content

Commit f32fc37

Browse files
Sslmode (#37)
* Replace dep with go.mod * Add URI option * Use URI when available If postgres uri is given then use that to make a connection instead of database arguments * Update README.md * bump the version number
1 parent 6d64560 commit f32fc37

File tree

8 files changed

+387
-354
lines changed

8 files changed

+387
-354
lines changed

Gopkg.lock

Lines changed: 0 additions & 289 deletions
This file was deleted.

Gopkg.toml

Lines changed: 0 additions & 62 deletions
This file was deleted.

README.md

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Flags:
9292
-w, --password string Password for the user to connect to database
9393
-p, --port int Port number of the postgres database
9494
-r, --rows int Total rows to be faked or mocked (default 10)
95+
--uri string Postgres connection URI, eg. postgres://user:pass@host:=port/db?sslmode=disable
9596
-u, --username string Username to connect to the database
9697
-v, --verbose Enable verbose or debug logging
9798
--version version for mock

cmd.go

100644100755
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Command struct {
2626
DontPrompt bool
2727
SchemaName string
2828
File string
29+
Uri string
2930
}
3031

3132
// Database command line options
@@ -62,6 +63,16 @@ var rootCmd = &cobra.Command{
6263
Fatalf("Argument Error: minimum row cannot be less than 1")
6364
}
6465

66+
// There can only be one option either uri or database connection values
67+
isDatabaseArgumentsSet := !IsStringEmpty(cmdOptions.Database) ||
68+
!IsStringEmpty(cmdOptions.Hostname) || !IsStringEmpty(cmdOptions.Username) ||
69+
!IsStringEmpty(cmdOptions.Password) || cmdOptions.Port > 0
70+
71+
if !IsStringEmpty(cmdOptions.Uri) && isDatabaseArgumentsSet {
72+
Warnf("Database Uri are given preference for database connection, when used along with database " +
73+
"connection arguments, using URI to connect to database")
74+
}
75+
6576
// Ensure we can make a successful connection to the database
6677
// by printing the version of the database we are going to mock
6778
dbVersion()
@@ -209,6 +220,8 @@ func init() {
209220
10, "Total rows to be faked or mocked")
210221
rootCmd.PersistentFlags().IntVarP(&cmdOptions.Port, "port", "p",
211222
viper.GetInt("PGPORT"), "Port number of the postgres database")
223+
rootCmd.PersistentFlags().StringVar(&cmdOptions.Uri, "uri",
224+
"", "Postgres connection URI, eg. postgres://user:pass@host:=port/db?sslmode=disable")
212225
rootCmd.PersistentFlags().StringVarP(&cmdOptions.Hostname, "address", "a",
213226
viper.GetString("PGHOSTADDR"), "Hostname where the postgres database lives")
214227
rootCmd.PersistentFlags().StringVarP(&cmdOptions.Username, "username", "u",

0 commit comments

Comments
 (0)