pgweb/pkg/bookmarks/bookmarks.go
Dan Sosedoff 69233cd769
Establish connections using bookmark ID only (#619)
* Establish connections using bookmark ID only
* Refactor specs
* Extra tests
* Fix homedir assertion for bookmarks path
* Fix newline in the warning message
* Check for bookmark file existence before reading
* Connect code restructure
2022-12-19 12:33:13 -06:00

38 lines
1.1 KiB
Go

package bookmarks
import (
"github.com/sosedoff/pgweb/pkg/command"
"github.com/sosedoff/pgweb/pkg/shared"
)
// Bookmark contains information about bookmarked database connection
type Bookmark struct {
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
}
// SSHInfoIsEmpty returns true if ssh configuration is not provided
func (b Bookmark) SSHInfoIsEmpty() bool {
return b.SSH == nil || b.SSH.User == "" && b.SSH.Host == "" && b.SSH.Port == ""
}
// ConvertToOptions returns an options struct from connection details
func (b Bookmark) ConvertToOptions() command.Options {
return command.Options{
URL: b.URL,
Host: b.Host,
Port: b.Port,
User: b.User,
Pass: b.Password,
DbName: b.Database,
SSLMode: b.SSLMode,
}
}