2015-04-30 11:47:07 -05:00
|
|
|
package bookmarks
|
2014-12-02 22:19:38 -06:00
|
|
|
|
|
|
|
import (
|
2016-11-10 01:22:16 -05:00
|
|
|
"github.com/sosedoff/pgweb/pkg/command"
|
2016-01-14 19:50:01 -06:00
|
|
|
"github.com/sosedoff/pgweb/pkg/shared"
|
2014-12-02 22:19:38 -06:00
|
|
|
)
|
|
|
|
|
2019-11-02 13:00:23 -05:00
|
|
|
// Bookmark contains information about bookmarked database connection
|
2014-12-02 22:19:38 -06:00
|
|
|
type Bookmark struct {
|
2022-12-19 12:33:13 -06:00
|
|
|
ID string // ID generated from the filename
|
|
|
|
URL string // Postgres connection URL
|
|
|
|
Host string // Server hostname
|
|
|
|
Port int // Server port
|
|
|
|
User string // Database user
|
|
|
|
Password string // User password
|
|
|
|
Database string // Database name
|
|
|
|
SSLMode string // Connection SSL mode
|
|
|
|
SSH *shared.SSHInfo // SSH tunnel config
|
2014-12-02 22:19:38 -06:00
|
|
|
}
|
|
|
|
|
2022-12-12 15:09:12 -06:00
|
|
|
// SSHInfoIsEmpty returns true if ssh configuration is not provided
|
2016-11-10 01:21:49 -05:00
|
|
|
func (b Bookmark) SSHInfoIsEmpty() bool {
|
2019-11-02 13:00:23 -05:00
|
|
|
return b.SSH == nil || b.SSH.User == "" && b.SSH.Host == "" && b.SSH.Port == ""
|
2016-11-10 01:21:49 -05:00
|
|
|
}
|
2016-11-10 01:22:16 -05:00
|
|
|
|
2019-11-02 13:00:23 -05:00
|
|
|
// ConvertToOptions returns an options struct from connection details
|
2016-11-15 22:03:32 -05:00
|
|
|
func (b Bookmark) ConvertToOptions() command.Options {
|
2016-11-10 01:22:16 -05:00
|
|
|
return command.Options{
|
2022-11-23 16:21:30 -06:00
|
|
|
URL: b.URL,
|
|
|
|
Host: b.Host,
|
|
|
|
Port: b.Port,
|
|
|
|
User: b.User,
|
|
|
|
Pass: b.Password,
|
|
|
|
DbName: b.Database,
|
|
|
|
SSLMode: b.SSLMode,
|
2016-11-15 22:03:32 -05:00
|
|
|
}
|
2016-11-10 01:22:16 -05:00
|
|
|
}
|