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 package bolt
import ( import (
"github.com/gofrs/uuid"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/bolt/errors" "github.com/portainer/portainer/api/bolt/errors"
) )
// Init creates the default data set. // Init creates the default data set.
func (store *Store) Init() error { 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 { if err == errors.ErrObjectNotFound {
defaultSettings := &portainer.Settings{ defaultSettings := &portainer.Settings{
AuthenticationMethod: portainer.AuthenticationInternal, AuthenticationMethod: portainer.AuthenticationInternal,

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

Loading…
Cancel
Save