mirror of https://github.com/gophish/gophish
Add ability to provide initial API key on service standup (#1883)
parent
bf76f86ea4
commit
afa00e2a9c
|
@ -34,6 +34,11 @@ const DefaultAdminUsername = "admin"
|
||||||
// randomly
|
// randomly
|
||||||
const InitialAdminPassword = "GOPHISH_INITIAL_ADMIN_PASSWORD"
|
const InitialAdminPassword = "GOPHISH_INITIAL_ADMIN_PASSWORD"
|
||||||
|
|
||||||
|
// InitialAdminApiToken is the environment variable that specifies the
|
||||||
|
// API token to seed the initial root login instead of generating one
|
||||||
|
// randomly
|
||||||
|
const InitialAdminApiToken = "GOPHISH_INITIAL_ADMIN_API_TOKEN"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CampaignInProgress string = "In progress"
|
CampaignInProgress string = "In progress"
|
||||||
CampaignQueued string = "Queued"
|
CampaignQueued string = "Queued"
|
||||||
|
@ -208,7 +213,13 @@ func Setup(c *config.Config) error {
|
||||||
RoleID: adminRole.ID,
|
RoleID: adminRole.ID,
|
||||||
PasswordChangeRequired: true,
|
PasswordChangeRequired: true,
|
||||||
}
|
}
|
||||||
adminUser.ApiKey = auth.GenerateSecureKey(auth.APIKeyLength)
|
|
||||||
|
if envToken := os.Getenv(InitialAdminApiToken); envToken != "" {
|
||||||
|
adminUser.ApiKey = envToken
|
||||||
|
} else {
|
||||||
|
adminUser.ApiKey = auth.GenerateSecureKey(auth.APIKeyLength)
|
||||||
|
}
|
||||||
|
|
||||||
err = db.Save(&adminUser).Error
|
err = db.Save(&adminUser).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|
Loading…
Reference in New Issue