2019-05-24 06:04:58 +00:00
|
|
|
package bolt
|
|
|
|
|
2020-06-16 07:58:16 +00:00
|
|
|
import (
|
2020-08-15 22:54:50 +00:00
|
|
|
"github.com/gofrs/uuid"
|
2020-06-16 07:58:16 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2020-07-07 21:57:52 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
2020-06-16 07:58:16 +00:00
|
|
|
)
|
2019-05-24 06:04:58 +00:00
|
|
|
|
|
|
|
// Init creates the default data set.
|
|
|
|
func (store *Store) Init() error {
|
2020-08-15 22:54:50 +00:00
|
|
|
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()
|
2020-07-07 21:57:52 +00:00
|
|
|
if err == errors.ErrObjectNotFound {
|
2020-04-16 00:22:08 +00:00
|
|
|
defaultSettings := &portainer.Settings{
|
|
|
|
AuthenticationMethod: portainer.AuthenticationInternal,
|
|
|
|
BlackListedLabels: make([]portainer.Pair, 0),
|
|
|
|
LDAPSettings: portainer.LDAPSettings{
|
|
|
|
AnonymousMode: true,
|
|
|
|
AutoCreateUsers: true,
|
|
|
|
TLSConfig: portainer.TLSConfiguration{},
|
|
|
|
SearchSettings: []portainer.LDAPSearchSettings{
|
|
|
|
portainer.LDAPSearchSettings{},
|
|
|
|
},
|
|
|
|
GroupSearchSettings: []portainer.LDAPGroupSearchSettings{
|
|
|
|
portainer.LDAPGroupSearchSettings{},
|
|
|
|
},
|
|
|
|
},
|
2021-02-09 08:09:06 +00:00
|
|
|
OAuthSettings: portainer.OAuthSettings{},
|
|
|
|
|
|
|
|
EdgeAgentCheckinInterval: portainer.DefaultEdgeAgentCheckinIntervalInSeconds,
|
|
|
|
TemplatesURL: portainer.DefaultTemplatesURL,
|
|
|
|
UserSessionTimeout: portainer.DefaultUserSessionTimeout,
|
2020-04-16 00:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = store.SettingsService.UpdateSettings(defaultSettings)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = store.DockerHubService.DockerHub()
|
2020-07-07 21:57:52 +00:00
|
|
|
if err == errors.ErrObjectNotFound {
|
2020-04-16 00:22:08 +00:00
|
|
|
defaultDockerHub := &portainer.DockerHub{
|
|
|
|
Authentication: false,
|
|
|
|
Username: "",
|
|
|
|
Password: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := store.DockerHubService.UpdateDockerHub(defaultDockerHub)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-24 06:04:58 +00:00
|
|
|
groups, err := store.EndpointGroupService.EndpointGroups()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(groups) == 0 {
|
|
|
|
unassignedGroup := &portainer.EndpointGroup{
|
|
|
|
Name: "Unassigned",
|
|
|
|
Description: "Unassigned endpoints",
|
|
|
|
Labels: []portainer.Pair{},
|
|
|
|
UserAccessPolicies: portainer.UserAccessPolicies{},
|
|
|
|
TeamAccessPolicies: portainer.TeamAccessPolicies{},
|
2020-03-29 09:54:14 +00:00
|
|
|
TagIDs: []portainer.TagID{},
|
2019-05-24 06:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = store.EndpointGroupService.CreateEndpointGroup(unassignedGroup)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|