pgweb/pkg/bookmarks/bookmarks.go

54 lines
1.5 KiB
Go
Raw Permalink Normal View History

2015-04-30 11:47:07 -05:00
package bookmarks
2014-12-02 22:19:38 -06:00
import (
"os"
"github.com/sosedoff/pgweb/pkg/command"
"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 {
ID string // ID generated from the filename
URL string // Postgres connection URL
Host string // Server hostname
Port int // Server port
User string // Database user
UserVar string // Database user environment variable
Password string // User password
PasswordVar string // User password environment variable
Database string // Database name
SSLMode string // Connection SSL mode
SSH *shared.SSHInfo // SSH tunnel config
ReadOnly bool // Enable read-only transaction mode
2014-12-02 22:19:38 -06:00
}
// SSHInfoIsEmpty returns true if ssh configuration is not provided
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 == ""
}
2019-11-02 13:00:23 -05:00
// ConvertToOptions returns an options struct from connection details
func (b Bookmark) ConvertToOptions() command.Options {
user := b.User
if b.User == "" {
user = os.Getenv(b.UserVar)
}
pass := b.Password
if b.Password == "" {
pass = os.Getenv(b.PasswordVar)
}
return command.Options{
URL: b.URL,
Host: b.Host,
Port: b.Port,
User: user,
Pass: pass,
DbName: b.Database,
SSLMode: b.SSLMode,
ReadOnly: b.ReadOnly,
}
}