Skip to content

Commit ded887b

Browse files
authored
fix(config): fix ssh connection through the config file (#273)
* fix(config): add missing fig struct tags * test(config): add missing ssh test assertions * docs: update docs to show example of the new fixes
1 parent be5c836 commit ded887b

File tree

7 files changed

+106
-8
lines changed

7 files changed

+106
-8
lines changed

.dblab.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,32 @@ database:
3434
db: "msdb"
3535
password: "5@klkbN#ABC"
3636
user: "SA"
37+
- name: "ssh-tunnel"
38+
host: "localhost"
39+
port: 5432
40+
db: "users"
41+
password: "password"
42+
user: "postgres"
43+
schema: "public"
44+
driver: "postgres"
45+
ssh-host: "example.com"
46+
ssh-port: 22
47+
ssh-user: "ssh-user"
48+
ssh-pass: "password"
49+
- name: "realistic-ssh-example"
50+
host: "rds-endpoint.region.rds.amazonaws.com"
51+
port: 5432
52+
db: "database_name"
53+
user: "db_user"
54+
password: "password"
55+
schema: "schema_name"
56+
driver: "postgres"
57+
ssl: "require"
58+
ssh-host: "bastion.host.ip"
59+
ssh-port: 22
60+
ssh-user: "ec2-user"
61+
ssh-key-file: "/path/to/ssh/key.pem"
62+
ssh-key-pass: "hiuwiewnc092"
3763
limit: 50
3864
keybindings:
3965
run-query: 'Ctrl-Space'

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ curl https://raw.githubusercontent.com/danvergara/dblab/master/scripts/install_u
8282
## Help
8383

8484
```
85-
dblab is a terminal UI based interactive database client for Postgres, MySQL and SQLite3.
85+
dblab is a terminal UI based interactive database client
8686
8787
Usage:
8888
dblab [flags]
@@ -320,6 +320,20 @@ database:
320320
ssh-port: 22
321321
ssh-user: "ssh-user"
322322
ssh-pass: "password"
323+
- name: "realistic-ssh-example"
324+
host: "rds-endpoint.region.rds.amazonaws.com"
325+
port: 5432
326+
db: "database_name"
327+
user: "db_user"
328+
password: "password"
329+
schema: "schema_name"
330+
driver: "postgres"
331+
ssl: "require"
332+
ssh-host: "bastion.host.ip"
333+
ssh-port: 22
334+
ssh-user: "ec2-user"
335+
ssh-key-file: "/path/to/ssh/key.pem"
336+
ssh-key-pass: "hiuwiewnc092"
323337
# should be greater than 0, otherwise the app will error out
324338
limit: 50
325339
keybindings:

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewRootCmd() *cobra.Command {
5858
return &cobra.Command{
5959
Use: "dblab",
6060
Short: "Interactive database client",
61-
Long: `dblab is a terminal UI based interactive database client for Postgres and MySQL.`,
61+
Long: `dblab is a terminal UI based interactive database client`,
6262
RunE: func(cmd *cobra.Command, args []string) error {
6363
var opts command.Options
6464
var err error

docs/usage.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ database:
338338
ssh-port: 22
339339
ssh-user: "ssh-user"
340340
ssh-pass: "password"
341+
- name: "realistic-ssh-example"
342+
host: "rds-endpoint.region.rds.amazonaws.com"
343+
port: 5432
344+
db: "database_name"
345+
user: "db_user"
346+
password: "password"
347+
schema: "schema_name"
348+
driver: "postgres"
349+
ssl: "require"
350+
ssh-host: "bastion.host.ip"
351+
ssh-port: 22
352+
ssh-user: "ec2-user"
353+
ssh-key-file: "/path/to/ssh/key.pem"
354+
ssh-key-pass: "hiuwiewnc092"
341355
# should be greater than 0, otherwise the app will error out
342356
limit: 50
343357
keybindings:

pkg/config/.dblab.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ database:
4848
ssh-port: 22
4949
ssh-user: "ssh-user"
5050
ssh-pass: "password"
51+
- name: "realistic-ssh-example"
52+
host: "rds-endpoint.region.rds.amazonaws.com"
53+
port: 5432
54+
db: "database_name"
55+
user: "db_user"
56+
password: "password"
57+
schema: "schema_name"
58+
driver: "postgres"
59+
ssl: "require"
60+
ssh-host: "bastion.host.ip"
61+
ssh-port: 22
62+
ssh-user: "ec2-user"
63+
ssh-key-file: "/path/to/ssh/key.pem"
64+
ssh-key-pass: "hiuwiewnc092"
5165
limit: 50
5266
keybindings:
5367
run-query: 'Ctrl-Space'

pkg/config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ type Database struct {
4646
Schema string
4747

4848
// SSH Tunnel.
49-
SSHHost string
50-
SSHPort string
51-
SSHUser string
52-
SSHPass string
53-
SSHKeyFile string
54-
SSHKeyPassphrase string
49+
SSHHost string `fig:"ssh-host"`
50+
SSHPort string `fig:"ssh-port"`
51+
SSHUser string `fig:"ssh-user"`
52+
SSHPass string `fig:"ssh-pass"`
53+
SSHKeyFile string `fig:"ssh-key-file"`
54+
SSHKeyPassphrase string `fig:"ssh-key-pass"`
5555

5656
// SSL connection params.
5757
SSL string `default:"disable"`

pkg/config/config_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func TestInit(t *testing.T) {
3131
sshPort string
3232
sshUser string
3333
sshPass string
34+
sshKeyFile string
35+
sshKeyPass string
3436
}
3537
var tests = []struct {
3638
name string
@@ -102,6 +104,26 @@ func TestInit(t *testing.T) {
102104
limit: 50,
103105
},
104106
},
107+
{
108+
name: "realistic example",
109+
input: "realistic-ssh-example",
110+
want: want{
111+
host: "rds-endpoint.region.rds.amazonaws.com",
112+
port: "5432",
113+
dbname: "database_name",
114+
user: "db_user",
115+
pass: "password",
116+
driver: "postgres",
117+
schema: "schema_name",
118+
ssl: "require",
119+
sshHost: "bastion.host.ip",
120+
sshPort: "22",
121+
sshUser: "ec2-user",
122+
sshKeyFile: "/path/to/ssh/key.pem",
123+
sshKeyPass: "hiuwiewnc092",
124+
limit: 50,
125+
},
126+
},
105127
{
106128
name: "oracle",
107129
input: "oracle",
@@ -139,6 +161,14 @@ func TestInit(t *testing.T) {
139161
assert.Equal(t, tt.want.sslkey, opts.SSLKey)
140162
assert.Equal(t, tt.want.sslpassword, opts.SSLPassword)
141163
assert.Equal(t, tt.want.sslrootcert, opts.SSLRootcert)
164+
165+
// SSH validations.
166+
assert.Equal(t, tt.want.sshHost, opts.SSHHost)
167+
assert.Equal(t, tt.want.sshPort, opts.SSHPort)
168+
assert.Equal(t, tt.want.sshUser, opts.SSHUser)
169+
assert.Equal(t, tt.want.sshPass, opts.SSHPass)
170+
assert.Equal(t, tt.want.sshPass, opts.SSHPass)
171+
assert.Equal(t, tt.want.sshKeyFile, opts.SSHKeyFile)
142172
})
143173
}
144174
}

0 commit comments

Comments
 (0)