Add database URL. (#365)

* Add database URL.

This allows specification of either a file://, env://, or other string.
If it starts with file:// or env:// the actual value will be read from
those resources.

* Tidy up the KMS output

* Also run migrations in test mode when specifying the URL
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-16 09:28:39 -04:00
1 parent c2b49dbc7d
commit c4e2b88022
5 files changed
+83 -7

No files matched your search

+21 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/hashicorp/boundary/sdk/strutil"
"github.com/hashicorp/boundary/sdk/wrapper"
@@ -304,10 +305,29 @@ func (c *Command) Run(args []string) int {
}
}
if err := c.CreateDevDatabase("postgres", opts...); err != nil {
c.UI.Error(fmt.Errorf("Error creating dev database container: %s", err.Error()).Error())
c.UI.Error(fmt.Errorf("Error creating dev database container: %w", err).Error())
return 1
}
c.ShutdownFuncs = append(c.ShutdownFuncs, c.DestroyDevDatabase)
} else {
if c.Config.Database == nil || c.Config.Database.Url == "" {
c.UI.Error(`"url" not specified in "database" config block"`)
return 1
}
dbaseUrl, err := config.ParseAddress(c.Config.Database.Url)
if err != nil && err != config.ErrNotAUrl {
c.UI.Error(fmt.Errorf("Error parsing database url: %w", err).Error())
return 1
}
c.DatabaseUrl = strings.TrimSpace(dbaseUrl)
if err := db.InitStore("postgres", nil, c.DatabaseUrl); err != nil {
c.UI.Error(fmt.Errorf("Error running database migrations: %w", err).Error())
return 1
}
if err := c.ConnectToDatabase("postgres"); err != nil {
c.UI.Error(fmt.Errorf("Error connecting to database: %w", err).Error())
return 1
}
}
defer func() {