Add -database-url to dev mode (#459)
Create default dev mode login name of "admin" and password of "password"
This commit is contained in:
1 parent
e7e28313ba
commit
bec3d702fb
6 files changed
+79
-52
No files matched your search
@@ -51,6 +51,7 @@ type Command struct {
|
||||
flagWorkerPublicAddr string
|
||||
flagPassthroughDirectory string
|
||||
flagRecoveryKey string
|
||||
flagDatabaseUrl string
|
||||
flagDisableDatabaseDestruction bool
|
||||
}
|
||||
|
||||
@@ -102,17 +103,19 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "password",
|
||||
Target: &c.flagPassword,
|
||||
EnvVar: "BOUNDARY_DEV_PASSWORD",
|
||||
Usage: "Initial login password.",
|
||||
Name: "password",
|
||||
Target: &c.flagPassword,
|
||||
Default: "password",
|
||||
EnvVar: "BOUNDARY_DEV_PASSWORD",
|
||||
Usage: "Initial login password.",
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "login-name",
|
||||
Target: &c.flagLoginName,
|
||||
EnvVar: "BOUNDARY_DEV_LOGIN_NAME",
|
||||
Usage: "Initial admin login name.",
|
||||
Name: "login-name",
|
||||
Target: &c.flagLoginName,
|
||||
Default: "admin",
|
||||
EnvVar: "BOUNDARY_DEV_LOGIN_NAME",
|
||||
Usage: "Initial admin login name.",
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
@@ -199,6 +202,12 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
Usage: "Specifies the base64'd 256-bit AES key to use for recovery operations",
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "database-url",
|
||||
Target: &c.flagDatabaseUrl,
|
||||
Usage: `If set, specifies the URL used to connect to the database for initialization (otherwise a Docker container will be started). This can refer to a file on disk (file://) from which a URL will be read; an env var (env://) from which the URL will be read; or a direct database URL.`,
|
||||
})
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
@@ -358,16 +367,30 @@ func (c *Command) Run(args []string) int {
|
||||
}
|
||||
}()
|
||||
|
||||
var opts []base.Option
|
||||
if c.flagDisableDatabaseDestruction {
|
||||
opts = append(opts, base.WithSkipDatabaseDestruction())
|
||||
}
|
||||
if err := c.CreateDevDatabase("postgres", opts...); err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error creating dev database container: %w", err).Error())
|
||||
return 1
|
||||
}
|
||||
if !c.flagDisableDatabaseDestruction {
|
||||
c.ShutdownFuncs = append(c.ShutdownFuncs, c.DestroyDevDatabase)
|
||||
switch c.flagDatabaseUrl {
|
||||
case "":
|
||||
var opts []base.Option
|
||||
if c.flagDisableDatabaseDestruction {
|
||||
opts = append(opts, base.WithSkipDatabaseDestruction())
|
||||
}
|
||||
if err := c.CreateDevDatabase("postgres", opts...); err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error creating dev database container: %w", err).Error())
|
||||
return 1
|
||||
}
|
||||
if !c.flagDisableDatabaseDestruction {
|
||||
c.ShutdownFuncs = append(c.ShutdownFuncs, c.DestroyDevDatabase)
|
||||
}
|
||||
default:
|
||||
dbaseUrl, err := config.ParseAddress(c.flagDatabaseUrl)
|
||||
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 := c.CreateDevDatabase("postgres"); err != nil {
|
||||
c.UI.Error(fmt.Errorf("Error connecting to database: %w", err).Error())
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
c.PrintInfo(c.UI)
|
||||
|
||||
Reference in new issue
Block a user