refactor(core/db): refactor instance ID init

pull/4224/head
Anthony Lapenna 4 years ago
parent 9733d32551
commit 1ef78c0fdf

@ -1,13 +1,30 @@
package bolt
import (
"github.com/gofrs/uuid"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt/errors"
)
// Init creates the default data set.
func (store *Store) Init() error {
_, err := store.SettingsService.Settings()
instanceID, err := store.VersionService.InstanceID()
if err == errors.ErrObjectNotFound {
uid, err := uuid.NewV4()
if err != nil {
return err
}
instanceID = uid.String()
err = store.VersionService.StoreInstanceID(instanceID)
if err != nil {
return err
}
} else if err != nil {
return err
}
_, err = store.SettingsService.Settings()
if err == errors.ErrObjectNotFound {
defaultSettings := &portainer.Settings{
AuthenticationMethod: portainer.AuthenticationInternal,

@ -6,10 +6,6 @@ import (
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/portainer/portainer/api/bolt/errors"
"github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt"
"github.com/portainer/portainer/api/chisel"
@ -344,23 +340,6 @@ func main() {
dataStore := initDataStore(*flags.Data, fileService)
defer dataStore.Close()
instanceID, err := dataStore.Version().InstanceID()
if err == errors.ErrObjectNotFound {
uid, err := uuid.NewV4()
if err != nil {
log.Fatal(err)
}
instanceID = uid.String()
err = dataStore.Version().StoreInstanceID(instanceID)
if err != nil {
log.Fatal(err)
}
} else if err != nil {
log.Fatal(err)
}
jwtService, err := initJWTService(dataStore)
if err != nil {
log.Fatal(err)
@ -383,6 +362,11 @@ func main() {
reverseTunnelService := chisel.NewService(dataStore)
instanceID, err := dataStore.Version().InstanceID()
if err != nil {
log.Fatal(err)
}
dockerClientFactory := initDockerClientFactory(digitalSignatureService, reverseTunnelService)
kubernetesClientFactory := initKubernetesClientFactory(digitalSignatureService, reverseTunnelService, instanceID)

Loading…
Cancel
Save