fix(database): db migration improvements EE-2688 (#6662)

pull/6763/head
Prabhat Khera 3 years ago committed by GitHub
parent 85ad4e334a
commit e4241207cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1,2 @@
dist dist
api/datastore/test_data

@ -60,4 +60,5 @@ Example:
``` ```
eyJyZWdpc3RyeUlkIjoxfQ== eyJyZWdpc3RyeUlkIjoxfQ==
``` ```
**NOTE**: You can find more information on how to query the Docker API in the [Docker official documentation](https://docs.docker.com/engine/api/v1.30/) as well as in [this Portainer example](https://documentation.portainer.io/api/api-examples/). **NOTE**: You can find more information on how to query the Docker API in the [Docker official documentation](https://docs.docker.com/engine/api/v1.30/) as well as in [this Portainer example](https://documentation.portainer.io/api/api-examples/).

@ -20,7 +20,7 @@ func Test_SatisfiesAPIKeyServiceInterface(t *testing.T) {
func Test_GenerateApiKey(t *testing.T) { func Test_GenerateApiKey(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -74,7 +74,7 @@ func Test_GenerateApiKey(t *testing.T) {
func Test_GetAPIKey(t *testing.T) { func Test_GetAPIKey(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -94,7 +94,7 @@ func Test_GetAPIKey(t *testing.T) {
func Test_GetAPIKeys(t *testing.T) { func Test_GetAPIKeys(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -115,7 +115,7 @@ func Test_GetAPIKeys(t *testing.T) {
func Test_GetDigestUserAndKey(t *testing.T) { func Test_GetDigestUserAndKey(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -151,7 +151,7 @@ func Test_GetDigestUserAndKey(t *testing.T) {
func Test_UpdateAPIKey(t *testing.T) { func Test_UpdateAPIKey(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -199,7 +199,7 @@ func Test_UpdateAPIKey(t *testing.T) {
func Test_DeleteAPIKey(t *testing.T) { func Test_DeleteAPIKey(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())
@ -240,7 +240,7 @@ func Test_DeleteAPIKey(t *testing.T) {
func Test_InvalidateUserKeyCache(t *testing.T) { func Test_InvalidateUserKeyCache(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
service := NewAPIKeyService(store.APIKeyRepository(), store.User()) service := NewAPIKeyService(store.APIKeyRepository(), store.User())

@ -21,7 +21,7 @@ func (m mockKingpinSetting) SetValue(value kingpin.Value) {
func Test_enableFeaturesFromFlags(t *testing.T) { func Test_enableFeaturesFromFlags(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
tests := []struct { tests := []struct {
@ -76,7 +76,7 @@ func Test_optionalFeature(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// Enable the test feature // Enable the test feature

@ -161,7 +161,7 @@ func (connection *DbConnection) ExportRaw(filename string) error {
return fmt.Errorf("stat on %s failed: %s", databasePath, err) return fmt.Errorf("stat on %s failed: %s", databasePath, err)
} }
b, err := connection.exportJson(databasePath) b, err := connection.ExportJson(databasePath, true)
if err != nil { if err != nil {
return err return err
} }

@ -8,9 +8,30 @@ import (
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
) )
func backupMetadata(connection *bolt.DB) (map[string]interface{}, error) {
buckets := map[string]interface{}{}
err := connection.View(func(tx *bolt.Tx) error {
err := tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
bucketName := string(name)
bucket = tx.Bucket([]byte(bucketName))
seqId := bucket.Sequence()
buckets[bucketName] = int(seqId)
return nil
})
return err
})
return buckets, err
}
// ExportJSON creates a JSON representation from a DbConnection. You can include
// the database's metadata or ignore it. Ensure the database is closed before
// using this function
// inspired by github.com/konoui/boltdb-exporter (which has no license) // inspired by github.com/konoui/boltdb-exporter (which has no license)
// but very much simplified, based on how we use boltdb // but very much simplified, based on how we use boltdb
func (c *DbConnection) exportJson(databasePath string) ([]byte, error) { func (c *DbConnection) ExportJson(databasePath string, metadata bool) ([]byte, error) {
logrus.WithField("databasePath", databasePath).Infof("exportJson") logrus.WithField("databasePath", databasePath).Infof("exportJson")
connection, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second, ReadOnly: true}) connection, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second, ReadOnly: true})
@ -20,6 +41,13 @@ func (c *DbConnection) exportJson(databasePath string) ([]byte, error) {
defer connection.Close() defer connection.Close()
backup := make(map[string]interface{}) backup := make(map[string]interface{})
if metadata {
meta, err := backupMetadata(connection)
if err != nil {
logrus.WithError(err).Errorf("Failed exporting metadata: %v", err)
}
backup["__metadata"] = meta
}
err = connection.View(func(tx *bolt.Tx) error { err = connection.View(func(tx *bolt.Tx) error {
err = tx.ForEach(func(name []byte, bucket *bolt.Bucket) error { err = tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
@ -45,15 +73,20 @@ func (c *DbConnection) exportJson(databasePath string) ([]byte, error) {
} }
if bucketName == "version" { if bucketName == "version" {
backup[bucketName] = version backup[bucketName] = version
return nil
} }
if len(list) > 0 { if len(list) > 0 {
if bucketName == "ssl" || if bucketName == "ssl" ||
bucketName == "settings" || bucketName == "settings" ||
bucketName == "tunnel_server" { bucketName == "tunnel_server" {
backup[bucketName] = nil
if len(list) > 0 {
backup[bucketName] = list[0] backup[bucketName] = list[0]
}
return nil return nil
} }
backup[bucketName] = list backup[bucketName] = list
return nil
} }
return nil return nil

@ -29,7 +29,7 @@ func TestService_StackByWebhookID(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode. Normally takes ~1s to run.") t.Skip("skipping test in short mode. Normally takes ~1s to run.")
} }
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
b := stackBuilder{t: t, store: store} b := stackBuilder{t: t, store: store}
@ -87,7 +87,7 @@ func Test_RefreshableStacks(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode. Normally takes ~1s to run.") t.Skip("skipping test in short mode. Normally takes ~1s to run.")
} }
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
staticStack := portainer.Stack{ID: 1} staticStack := portainer.Stack{ID: 1}

@ -10,7 +10,7 @@ import (
func Test_teamByName(t *testing.T) { func Test_teamByName(t *testing.T) {
t.Run("When store is empty should return ErrObjectNotFound", func(t *testing.T) { t.Run("When store is empty should return ErrObjectNotFound", func(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
_, err := store.Team().TeamByName("name") _, err := store.Team().TeamByName("name")
@ -19,7 +19,7 @@ func Test_teamByName(t *testing.T) {
}) })
t.Run("When there is no object with the same name should return ErrObjectNotFound", func(t *testing.T) { t.Run("When there is no object with the same name should return ErrObjectNotFound", func(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
teamBuilder := teamBuilder{ teamBuilder := teamBuilder{
@ -35,7 +35,7 @@ func Test_teamByName(t *testing.T) {
}) })
t.Run("When there is an object with the same name should return the object", func(t *testing.T) { t.Run("When there is an object with the same name should return the object", func(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
teamBuilder := teamBuilder{ teamBuilder := teamBuilder{

@ -69,6 +69,11 @@ func getBackupRestoreOptions(backupDir string) *BackupOptions {
} }
} }
// Backup current database with default options
func (store *Store) Backup() (string, error) {
return store.backupWithOptions(nil)
}
func (store *Store) setupOptions(options *BackupOptions) *BackupOptions { func (store *Store) setupOptions(options *BackupOptions) *BackupOptions {
if options == nil { if options == nil {
options = &BackupOptions{} options = &BackupOptions{}

@ -10,7 +10,7 @@ import (
) )
func TestCreateBackupFolders(t *testing.T) { func TestCreateBackupFolders(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
connection := store.GetConnection() connection := store.GetConnection()
@ -27,7 +27,7 @@ func TestCreateBackupFolders(t *testing.T) {
} }
func TestStoreCreation(t *testing.T) { func TestStoreCreation(t *testing.T) {
_, store, teardown := MustNewTestStore(true) _, store, teardown := MustNewTestStore(true, true)
defer teardown() defer teardown()
if store == nil { if store == nil {
@ -40,7 +40,7 @@ func TestStoreCreation(t *testing.T) {
} }
func TestBackup(t *testing.T) { func TestBackup(t *testing.T) {
_, store, teardown := MustNewTestStore(true) _, store, teardown := MustNewTestStore(true, true)
connection := store.GetConnection() connection := store.GetConnection()
defer teardown() defer teardown()
@ -67,7 +67,7 @@ func TestBackup(t *testing.T) {
} }
func TestRemoveWithOptions(t *testing.T) { func TestRemoveWithOptions(t *testing.T) {
_, store, teardown := MustNewTestStore(true) _, store, teardown := MustNewTestStore(true, true)
defer teardown() defer teardown()
t.Run("successfully removes file if existent", func(t *testing.T) { t.Run("successfully removes file if existent", func(t *testing.T) {

@ -27,7 +27,7 @@ const (
// TestStoreFull an eventually comprehensive set of tests for the Store. // TestStoreFull an eventually comprehensive set of tests for the Store.
// The idea is what we write to the store, we should read back. // The idea is what we write to the store, we should read back.
func TestStoreFull(t *testing.T) { func TestStoreFull(t *testing.T) {
_, store, teardown := MustNewTestStore(true) _, store, teardown := MustNewTestStore(true, true)
defer teardown() defer teardown()
testCases := map[string]func(t *testing.T){ testCases := map[string]func(t *testing.T){

@ -28,10 +28,20 @@ func (slog *ScopedLog) Debug(message string) {
slog.print(DEBUG, fmt.Sprintf("[message: %s]", message)) slog.print(DEBUG, fmt.Sprintf("[message: %s]", message))
} }
func (slog *ScopedLog) Debugf(message string, vars ...interface{}) {
message = fmt.Sprintf(message, vars...)
slog.print(DEBUG, fmt.Sprintf("[message: %s]", message))
}
func (slog *ScopedLog) Info(message string) { func (slog *ScopedLog) Info(message string) {
slog.print(INFO, fmt.Sprintf("[message: %s]", message)) slog.print(INFO, fmt.Sprintf("[message: %s]", message))
} }
func (slog *ScopedLog) Infof(message string, vars ...interface{}) {
message = fmt.Sprintf(message, vars...)
slog.print(INFO, fmt.Sprintf("[message: %s]", message))
}
func (slog *ScopedLog) Error(message string, err error) { func (slog *ScopedLog) Error(message string, err error) {
slog.print(ERROR, fmt.Sprintf("[message: %s] [error: %s]", message, err)) slog.print(ERROR, fmt.Sprintf("[message: %s] [error: %s]", message, err))
} }

@ -9,6 +9,7 @@ import (
plog "github.com/portainer/portainer/api/datastore/log" plog "github.com/portainer/portainer/api/datastore/log"
"github.com/portainer/portainer/api/datastore/migrator" "github.com/portainer/portainer/api/datastore/migrator"
"github.com/portainer/portainer/api/internal/authorization" "github.com/portainer/portainer/api/internal/authorization"
"github.com/sirupsen/logrus"
werrors "github.com/pkg/errors" werrors "github.com/pkg/errors"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
@ -24,6 +25,12 @@ func (store *Store) MigrateData() error {
return err return err
} }
// Backup Database
backupPath, err := store.Backup()
if err != nil {
return werrors.Wrap(err, "while backing up db before migration")
}
migratorParams := &migrator.MigratorParameters{ migratorParams := &migrator.MigratorParameters{
DatabaseVersion: version, DatabaseVersion: version,
EndpointGroupService: store.EndpointGroupService, EndpointGroupService: store.EndpointGroupService,
@ -46,7 +53,27 @@ func (store *Store) MigrateData() error {
AuthorizationService: authorization.NewService(store), AuthorizationService: authorization.NewService(store),
} }
return store.connectionMigrateData(migratorParams) // restore on error
err = store.connectionMigrateData(migratorParams)
if err != nil {
logrus.Errorf("While DB migration %v. Restoring DB", err)
// Restore options
options := BackupOptions{
BackupPath: backupPath,
}
err := store.restoreWithOptions(&options)
if err != nil {
logrus.Fatalf(
"Failed restoring the backup. portainer database file needs to restored manually by "+
"replacing %s database file with recent backup %s. Error %v",
store.databasePath(),
options.BackupPath,
err,
)
}
}
return err
} }
// FailSafeMigrate backup and restore DB if migration fail // FailSafeMigrate backup and restore DB if migration fail

@ -1,13 +1,19 @@
package datastore package datastore
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"io"
"log" "log"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/database/boltdb"
) )
// testVersion is a helper which tests current store version against wanted version // testVersion is a helper which tests current store version against wanted version
@ -22,8 +28,32 @@ func testVersion(store *Store, versionWant int, t *testing.T) {
} }
func TestMigrateData(t *testing.T) { func TestMigrateData(t *testing.T) {
snapshotTests := []struct {
testName string
srcPath string
wantPath string
}{
{
testName: "migrate version 24 to 35",
srcPath: "test_data/input_24.json",
wantPath: "test_data/output_35.json",
},
}
for _, test := range snapshotTests {
t.Run(test.testName, func(t *testing.T) {
err := migrateDBTestHelper(t, test.srcPath, test.wantPath)
if err != nil {
t.Errorf(
"Failed migrating mock database %v: %v",
test.srcPath,
err,
)
}
})
}
t.Run("MigrateData for New Store & Re-Open Check", func(t *testing.T) { t.Run("MigrateData for New Store & Re-Open Check", func(t *testing.T) {
newStore, store, teardown := MustNewTestStore(false) newStore, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
if !newStore { if !newStore {
@ -50,7 +80,7 @@ func TestMigrateData(t *testing.T) {
{version: 21, expectedVersion: portainer.DBVersion}, {version: 21, expectedVersion: portainer.DBVersion},
} }
for _, tc := range tests { for _, tc := range tests {
_, store, teardown := MustNewTestStore(true) _, store, teardown := MustNewTestStore(true, true)
defer teardown() defer teardown()
// Setup data // Setup data
@ -75,7 +105,7 @@ func TestMigrateData(t *testing.T) {
} }
t.Run("Error in MigrateData should restore backup before MigrateData", func(t *testing.T) { t.Run("Error in MigrateData should restore backup before MigrateData", func(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
version := 17 version := 17
@ -87,7 +117,7 @@ func TestMigrateData(t *testing.T) {
}) })
t.Run("MigrateData should create backup file upon update", func(t *testing.T) { t.Run("MigrateData should create backup file upon update", func(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
store.VersionService.StoreDBVersion(0) store.VersionService.StoreDBVersion(0)
@ -101,7 +131,7 @@ func TestMigrateData(t *testing.T) {
}) })
t.Run("MigrateData should fail to create backup if database file is set to updating", func(t *testing.T) { t.Run("MigrateData should fail to create backup if database file is set to updating", func(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
store.VersionService.StoreIsUpdating(true) store.VersionService.StoreIsUpdating(true)
@ -116,7 +146,7 @@ func TestMigrateData(t *testing.T) {
}) })
t.Run("MigrateData should not create backup on startup if portainer version matches db", func(t *testing.T) { t.Run("MigrateData should not create backup on startup if portainer version matches db", func(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
store.MigrateData() store.MigrateData()
@ -131,7 +161,7 @@ func TestMigrateData(t *testing.T) {
} }
func Test_getBackupRestoreOptions(t *testing.T) { func Test_getBackupRestoreOptions(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
options := getBackupRestoreOptions(store.commonBackupDir()) options := getBackupRestoreOptions(store.commonBackupDir())
@ -150,7 +180,7 @@ func Test_getBackupRestoreOptions(t *testing.T) {
func TestRollback(t *testing.T) { func TestRollback(t *testing.T) {
t.Run("Rollback should restore upgrade after backup", func(t *testing.T) { t.Run("Rollback should restore upgrade after backup", func(t *testing.T) {
version := 21 version := 21
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
store.VersionService.StoreDBVersion(version) store.VersionService.StoreDBVersion(version)
@ -185,3 +215,250 @@ func isFileExist(path string) bool {
} }
return len(matches) > 0 return len(matches) > 0
} }
// migrateDBTestHelper loads a json representation of a bolt database from srcPath,
// parses it into a database, runs a migration on that database, and then
// compares it with an expected output database.
func migrateDBTestHelper(t *testing.T, srcPath, wantPath string) error {
srcJSON, err := os.ReadFile(srcPath)
if err != nil {
t.Fatalf("failed loading source JSON file %v: %v", srcPath, err)
}
// Parse source json to db.
_, store, teardown := MustNewTestStore(true, false)
defer teardown()
err = importJSON(t, bytes.NewReader(srcJSON), store)
if err != nil {
return err
}
// Run the actual migrations on our input database.
err = store.MigrateData()
if err != nil {
return err
}
// Assert that our database connection is using bolt so we can call
// exportJson rather than ExportRaw. The exportJson function allows us to
// strip out the metadata which we don't want for our tests.
// TODO: update connection interface in CE to allow us to use ExportRaw and pass meta false
err = store.connection.Close()
if err != nil {
t.Fatalf("err closing bolt connection: %v", err)
}
con, ok := store.connection.(*boltdb.DbConnection)
if !ok {
t.Fatalf("backing database is not using boltdb, but the migrations test requires it")
}
// Convert database back to json.
databasePath := con.GetDatabaseFilePath()
if _, err := os.Stat(databasePath); err != nil {
return fmt.Errorf("stat on %s failed: %s", databasePath, err)
}
gotJSON, err := con.ExportJson(databasePath, false)
if err != nil {
t.Logf(
"failed re-exporting database %s to JSON: %v",
databasePath,
err,
)
}
wantJSON, err := os.ReadFile(wantPath)
if err != nil {
t.Fatalf("failed loading want JSON file %v: %v", wantPath, err)
}
// Compare the result we got with the one we wanted.
if diff := cmp.Diff(wantJSON, gotJSON); diff != "" {
gotPath := filepath.Join(os.TempDir(), "portainer-migrator-test-fail.json")
os.WriteFile(
gotPath,
gotJSON,
0600,
)
t.Errorf(
"migrate data from %s to %s failed\nwrote migrated input to %s\nmismatch (-want +got):\n%s",
srcPath,
wantPath,
gotPath,
diff,
)
}
return nil
}
// importJSON reads input JSON and commits it to a portainer datastore.Store.
// Errors are logged with the testing package.
func importJSON(t *testing.T, r io.Reader, store *Store) error {
objects := make(map[string]interface{})
// Parse json into map of objects.
d := json.NewDecoder(r)
d.UseNumber()
err := d.Decode(&objects)
if err != nil {
return err
}
// Get database connection from store.
con := store.connection
for k, v := range objects {
switch k {
case "version":
versions, ok := v.(map[string]interface{})
if !ok {
t.Logf("failed casting %s to map[string]interface{}", k)
}
dbVersion, ok := versions["DB_VERSION"]
if !ok {
t.Logf("failed getting DB_VERSION from %s", k)
}
numDBVersion, ok := dbVersion.(json.Number)
if !ok {
t.Logf("failed parsing DB_VERSION as json number from %s", k)
}
intDBVersion, err := numDBVersion.Int64()
if err != nil {
t.Logf("failed casting %v to int: %v", numDBVersion, intDBVersion)
}
err = con.CreateObjectWithStringId(
k,
[]byte("DB_VERSION"),
int(intDBVersion),
)
if err != nil {
t.Logf("failed writing DB_VERSION in %s: %v", k, err)
}
instanceID, ok := versions["INSTANCE_ID"]
if !ok {
t.Logf("failed getting INSTANCE_ID from %s", k)
}
err = con.CreateObjectWithStringId(
k,
[]byte("INSTANCE_ID"),
instanceID,
)
if err != nil {
t.Logf("failed writing INSTANCE_ID in %s: %v", k, err)
}
case "dockerhub":
obj, ok := v.([]interface{})
if !ok {
t.Logf("failed to cast %s to []interface{}", k)
}
err := con.CreateObjectWithStringId(
k,
[]byte("DOCKERHUB"),
obj[0],
)
if err != nil {
t.Logf("failed writing DOCKERHUB in %s: %v", k, err)
}
case "ssl":
obj, ok := v.(map[string]interface{})
if !ok {
t.Logf("failed to case %s to map[string]interface{}", k)
}
err := con.CreateObjectWithStringId(
k,
[]byte("SSL"),
obj,
)
if err != nil {
t.Logf("failed writing SSL in %s: %v", k, err)
}
case "settings":
obj, ok := v.(map[string]interface{})
if !ok {
t.Logf("failed to case %s to map[string]interface{}", k)
}
err := con.CreateObjectWithStringId(
k,
[]byte("SETTINGS"),
obj,
)
if err != nil {
t.Logf("failed writing SETTINGS in %s: %v", k, err)
}
case "tunnel_server":
obj, ok := v.(map[string]interface{})
if !ok {
t.Logf("failed to case %s to map[string]interface{}", k)
}
err := con.CreateObjectWithStringId(
k,
[]byte("INFO"),
obj,
)
if err != nil {
t.Logf("failed writing INFO in %s: %v", k, err)
}
case "templates":
continue
default:
objlist, ok := v.([]interface{})
if !ok {
t.Logf("failed to cast %s to []interface{}", k)
}
for _, obj := range objlist {
value, ok := obj.(map[string]interface{})
if !ok {
t.Logf("failed to cast %v to map[string]interface{}", obj)
} else {
var ok bool
var id interface{}
switch k {
case "endpoint_relations":
// TODO: need to make into an int, then do that weird
// stringification
id, ok = value["EndpointID"]
default:
id, ok = value["Id"]
}
if !ok {
// endpoint_relations: EndpointID
t.Logf("missing Id field: %s", k)
id = "error"
}
n, ok := id.(json.Number)
if !ok {
t.Logf("failed to cast %v to json.Number in %s", id, k)
} else {
key, err := n.Int64()
if err != nil {
t.Logf("failed to cast %v to int in %s", n, k)
} else {
err := con.CreateObjectWithId(
k,
int(key),
value,
)
if err != nil {
t.Logf("failed writing %v in %s: %v", key, k, err)
}
}
}
}
}
}
}
return nil
}

@ -33,7 +33,7 @@ func setup(store *Store) error {
} }
func TestMigrateSettings(t *testing.T) { func TestMigrateSettings(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
err := setup(store) err := setup(store)

@ -10,7 +10,7 @@ import (
) )
func TestMigrateStackEntryPoint(t *testing.T) { func TestMigrateStackEntryPoint(t *testing.T) {
_, store, teardown := MustNewTestStore(false) _, store, teardown := MustNewTestStore(false, true)
defer teardown() defer teardown()
stackService := store.Stack() stackService := store.Stack()

@ -1,199 +1,127 @@
package migrator package migrator
import ( import (
"fmt" "errors"
"reflect"
"runtime"
werrors "github.com/pkg/errors" werrors "github.com/pkg/errors"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
) )
type migration struct {
dbversion int
migrate func() error
}
func migrationError(err error, context string) error { func migrationError(err error, context string) error {
return werrors.Wrap(err, "failed in "+context) return werrors.Wrap(err, "failed in "+context)
} }
// Migrate checks the database version and migrate the existing data to the most recent data model. func newMigration(dbversion int, migrate func() error) migration {
func (m *Migrator) Migrate() error { return migration{
// set DB to updating status dbversion: dbversion,
err := m.versionService.StoreIsUpdating(true) migrate: migrate,
if err != nil {
return migrationError(err, "StoreIsUpdating")
} }
if m.currentDBVersion < 17 {
return migrationError(err, "migrating from less than Portainer 1.21.0 is not supported, please contact Portainer support.")
} }
// Portainer 1.21.0 func dbTooOldError() error {
if m.currentDBVersion < 18 { return errors.New("migrating from less than Portainer 1.21.0 is not supported, please contact Portainer support.")
err := m.updateUsersToDBVersion18()
if err != nil {
return migrationError(err, "updateUsersToDBVersion18")
} }
err = m.updateEndpointsToDBVersion18() func GetFunctionName(i interface{}) string {
if err != nil { return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
return migrationError(err, "updateEndpointsToDBVersion18")
}
err = m.updateEndpointGroupsToDBVersion18()
if err != nil {
return migrationError(err, "updateEndpointGroupsToDBVersion18")
} }
err = m.updateRegistriesToDBVersion18() // Migrate checks the database version and migrate the existing data to the most recent data model.
func (m *Migrator) Migrate() error {
// set DB to updating status
err := m.versionService.StoreIsUpdating(true)
if err != nil { if err != nil {
return migrationError(err, "updateRegistriesToDBVersion18") return migrationError(err, "StoreIsUpdating")
}
} }
// Portainer 1.22.0 migrations := []migration{
if m.currentDBVersion < 19 { // Portainer < 1.21.0
err := m.updateSettingsToDBVersion19() newMigration(17, dbTooOldError),
if err != nil {
return migrationError(err, "updateSettingsToDBVersion19")
}
}
// Portainer 1.22.1 // Portainer 1.21.0
if m.currentDBVersion < 20 { newMigration(18, m.updateUsersToDBVersion18),
err := m.updateUsersToDBVersion20() newMigration(18, m.updateEndpointsToDBVersion18),
if err != nil { newMigration(18, m.updateEndpointGroupsToDBVersion18),
return migrationError(err, "updateUsersToDBVersion20") newMigration(18, m.updateRegistriesToDBVersion18),
}
err = m.updateSettingsToDBVersion20() // 1.22.0
if err != nil { newMigration(19, m.updateSettingsToDBVersion19),
return migrationError(err, "updateSettingsToDBVersion20")
}
err = m.updateSchedulesToDBVersion20() // 1.22.1
if err != nil { newMigration(20, m.updateUsersToDBVersion20),
return migrationError(err, "updateSchedulesToDBVersion20") newMigration(20, m.updateSettingsToDBVersion20),
} newMigration(20, m.updateSchedulesToDBVersion20),
}
// Portainer 1.23.0 // Portainer 1.23.0
// DBVersion 21 is missing as it was shipped as via hotfix 1.22.2 // DBVersion 21 is missing as it was shipped as via hotfix 1.22.2
if m.currentDBVersion < 22 { newMigration(22, m.updateResourceControlsToDBVersion22),
err := m.updateResourceControlsToDBVersion22() newMigration(22, m.updateUsersAndRolesToDBVersion22),
if err != nil {
return migrationError(err, "updateResourceControlsToDBVersion22")
}
err = m.updateUsersAndRolesToDBVersion22()
if err != nil {
return migrationError(err, "updateUsersAndRolesToDBVersion22")
}
}
// Portainer 1.24.0 // Portainer 1.24.0
if m.currentDBVersion < 23 { newMigration(23, m.updateTagsToDBVersion23),
migrateLog.Info("Migrating to DB 23") newMigration(23, m.updateEndpointsAndEndpointGroupsToDBVersion23),
err := m.updateTagsToDBVersion23()
if err != nil {
return migrationError(err, "updateTagsToDBVersion23")
}
err = m.updateEndpointsAndEndpointGroupsToDBVersion23()
if err != nil {
return migrationError(err, "updateEndpointsAndEndpointGroupsToDBVersion23")
}
}
// Portainer 1.24.1 // Portainer 1.24.1
if m.currentDBVersion < 24 { newMigration(24, m.updateSettingsToDB24),
migrateLog.Info("Migrating to DB 24")
err := m.updateSettingsToDB24()
if err != nil {
return migrationError(err, "updateSettingsToDB24")
}
}
// Portainer 2.0.0 // Portainer 2.0.0
if m.currentDBVersion < 25 { newMigration(25, m.updateSettingsToDB25),
migrateLog.Info("Migrating to DB 25") newMigration(25, m.updateStacksToDB24), // yes this looks odd. Don't be tempted to move it
err := m.updateSettingsToDB25()
if err != nil {
return migrationError(err, "updateSettingsToDB25")
}
err = m.updateStacksToDB24()
if err != nil {
return migrationError(err, "updateStacksToDB24")
}
}
// Portainer 2.1.0 // Portainer 2.1.0
if m.currentDBVersion < 26 { newMigration(26, m.updateEndpointSettingsToDB25),
migrateLog.Info("Migrating to DB 26")
err := m.updateEndpointSettingsToDB25()
if err != nil {
return migrationError(err, "updateEndpointSettingsToDB25")
}
}
// Portainer 2.2.0 // Portainer 2.2.0
if m.currentDBVersion < 27 { newMigration(27, m.updateStackResourceControlToDB27),
migrateLog.Info("Migrating to DB 27")
err := m.updateStackResourceControlToDB27()
if err != nil {
return migrationError(err, "updateStackResourceControlToDB27")
}
}
// Portainer 2.6.0 // Portainer 2.6.0
if m.currentDBVersion < 30 { newMigration(30, m.migrateDBVersionToDB30),
migrateLog.Info("Migrating to DB 30")
err := m.migrateDBVersionToDB30()
if err != nil {
return migrationError(err, "migrateDBVersionToDB30")
}
}
// Portainer 2.9.0 // Portainer 2.9.0
if m.currentDBVersion < 32 { newMigration(32, m.migrateDBVersionToDB32),
err := m.migrateDBVersionToDB32()
if err != nil {
return migrationError(err, "migrateDBVersionToDB32")
}
}
// Portainer 2.9.1, 2.9.2 // Portainer 2.9.1, 2.9.2
if m.currentDBVersion < 33 { newMigration(33, m.migrateDBVersionToDB33),
migrateLog.Info("Migrating to DB 33")
err := m.migrateDBVersionToDB33()
if err != nil {
return migrationError(err, "migrateDBVersionToDB33")
}
}
// Portainer 2.10 // Portainer 2.10
if m.currentDBVersion < 34 { newMigration(34, m.migrateDBVersionToDB34),
migrateLog.Info("Migrating to DB 34")
if err := m.migrateDBVersionToDB34(); err != nil {
return migrationError(err, "migrateDBVersionToDB34")
}
}
// Portainer 2.9.3 (yep out of order, but 2.10 is EE only) // Portainer 2.9.3 (yep out of order, but 2.10 is EE only)
if m.currentDBVersion < 35 { newMigration(35, m.migrateDBVersionToDB35),
migrateLog.Info("Migrating to DB 35")
if err := m.migrateDBVersionToDB35(); err != nil { newMigration(36, m.migrateDBVersionToDB36),
return migrationError(err, "migrateDBVersionToDB35")
} }
var lastDbVersion int
for _, migration := range migrations {
if m.currentDBVersion < migration.dbversion {
// Print the next line only when the version changes
if migration.dbversion > lastDbVersion {
migrateLog.Infof("Migrating DB to version %d", migration.dbversion)
} }
if m.currentDBVersion < 36 { err := migration.migrate()
migrateLog.Info("Migrating to DB 36") if err != nil {
if err := m.migrateDBVersionToDB36(); err != nil { return migrationError(err, GetFunctionName(migration.migrate))
return migrationError(err, "migrateDBVersionToDB36")
} }
} }
lastDbVersion = migration.dbversion
}
migrateLog.Infof("Setting DB version to %d", portainer.DBVersion)
err = m.versionService.StoreDBVersion(portainer.DBVersion) err = m.versionService.StoreDBVersion(portainer.DBVersion)
if err != nil { if err != nil {
return migrationError(err, "StoreDBVersion") return migrationError(err, "StoreDBVersion")
} }
migrateLog.Info(fmt.Sprintf("Updated DB version to %d", portainer.DBVersion)) migrateLog.Infof("Updated DB version to %d", portainer.DBVersion)
// reset DB updating status // reset DB updating status
return m.versionService.StoreIsUpdating(false) return m.versionService.StoreIsUpdating(false)

@ -5,6 +5,7 @@ import (
) )
func (m *Migrator) updateUsersToDBVersion18() error { func (m *Migrator) updateUsersToDBVersion18() error {
migrateLog.Info("- updating users")
legacyUsers, err := m.userService.Users() legacyUsers, err := m.userService.Users()
if err != nil { if err != nil {
return err return err
@ -39,6 +40,7 @@ func (m *Migrator) updateUsersToDBVersion18() error {
} }
func (m *Migrator) updateEndpointsToDBVersion18() error { func (m *Migrator) updateEndpointsToDBVersion18() error {
migrateLog.Info("- updating endpoints")
legacyEndpoints, err := m.endpointService.Endpoints() legacyEndpoints, err := m.endpointService.Endpoints()
if err != nil { if err != nil {
return err return err
@ -69,6 +71,7 @@ func (m *Migrator) updateEndpointsToDBVersion18() error {
} }
func (m *Migrator) updateEndpointGroupsToDBVersion18() error { func (m *Migrator) updateEndpointGroupsToDBVersion18() error {
migrateLog.Info("- updating endpoint groups")
legacyEndpointGroups, err := m.endpointGroupService.EndpointGroups() legacyEndpointGroups, err := m.endpointGroupService.EndpointGroups()
if err != nil { if err != nil {
return err return err
@ -99,6 +102,7 @@ func (m *Migrator) updateEndpointGroupsToDBVersion18() error {
} }
func (m *Migrator) updateRegistriesToDBVersion18() error { func (m *Migrator) updateRegistriesToDBVersion18() error {
migrateLog.Info("- updating registries")
legacyRegistries, err := m.registryService.Registries() legacyRegistries, err := m.registryService.Registries()
if err != nil { if err != nil {
return err return err

@ -3,6 +3,7 @@ package migrator
import portainer "github.com/portainer/portainer/api" import portainer "github.com/portainer/portainer/api"
func (m *Migrator) updateSettingsToDBVersion19() error { func (m *Migrator) updateSettingsToDBVersion19() error {
migrateLog.Info("- updating settings")
legacySettings, err := m.settingsService.Settings() legacySettings, err := m.settingsService.Settings()
if err != nil { if err != nil {
return err return err

@ -7,6 +7,7 @@ import (
const scheduleScriptExecutionJobType = 1 const scheduleScriptExecutionJobType = 1
func (m *Migrator) updateUsersToDBVersion20() error { func (m *Migrator) updateUsersToDBVersion20() error {
migrateLog.Info("- updating user authentication")
return m.authorizationService.UpdateUsersAuthorizations() return m.authorizationService.UpdateUsersAuthorizations()
} }
@ -22,6 +23,7 @@ func (m *Migrator) updateSettingsToDBVersion20() error {
} }
func (m *Migrator) updateSchedulesToDBVersion20() error { func (m *Migrator) updateSchedulesToDBVersion20() error {
migrateLog.Info("- updating schedules")
legacySchedules, err := m.scheduleService.Schedules() legacySchedules, err := m.scheduleService.Schedules()
if err != nil { if err != nil {
return err return err

@ -6,6 +6,7 @@ import (
) )
func (m *Migrator) updateResourceControlsToDBVersion22() error { func (m *Migrator) updateResourceControlsToDBVersion22() error {
migrateLog.Info("- updating resource controls")
legacyResourceControls, err := m.resourceControlService.ResourceControls() legacyResourceControls, err := m.resourceControlService.ResourceControls()
if err != nil { if err != nil {
return err return err
@ -24,6 +25,7 @@ func (m *Migrator) updateResourceControlsToDBVersion22() error {
} }
func (m *Migrator) updateUsersAndRolesToDBVersion22() error { func (m *Migrator) updateUsersAndRolesToDBVersion22() error {
migrateLog.Info("- updating users and roles")
legacyUsers, err := m.userService.Users() legacyUsers, err := m.userService.Users()
if err != nil { if err != nil {
return err return err

@ -3,7 +3,7 @@ package migrator
import portainer "github.com/portainer/portainer/api" import portainer "github.com/portainer/portainer/api"
func (m *Migrator) updateTagsToDBVersion23() error { func (m *Migrator) updateTagsToDBVersion23() error {
migrateLog.Info("Updating tags") migrateLog.Info("- Updating tags")
tags, err := m.tagService.Tags() tags, err := m.tagService.Tags()
if err != nil { if err != nil {
return err return err
@ -21,7 +21,7 @@ func (m *Migrator) updateTagsToDBVersion23() error {
} }
func (m *Migrator) updateEndpointsAndEndpointGroupsToDBVersion23() error { func (m *Migrator) updateEndpointsAndEndpointGroupsToDBVersion23() error {
migrateLog.Info("Updating endpoints and endpoint groups") migrateLog.Info("- updating endpoints and endpoint groups")
tags, err := m.tagService.Tags() tags, err := m.tagService.Tags()
if err != nil { if err != nil {
return err return err

@ -3,7 +3,7 @@ package migrator
import portainer "github.com/portainer/portainer/api" import portainer "github.com/portainer/portainer/api"
func (m *Migrator) updateSettingsToDB24() error { func (m *Migrator) updateSettingsToDB24() error {
migrateLog.Info("Updating Settings") migrateLog.Info("- updating Settings")
legacySettings, err := m.settingsService.Settings() legacySettings, err := m.settingsService.Settings()
if err != nil { if err != nil {
@ -18,7 +18,7 @@ func (m *Migrator) updateSettingsToDB24() error {
} }
func (m *Migrator) updateStacksToDB24() error { func (m *Migrator) updateStacksToDB24() error {
migrateLog.Info("Updating stacks") migrateLog.Info("- updating stacks")
stacks, err := m.stackService.Stacks() stacks, err := m.stackService.Stacks()
if err != nil { if err != nil {
return err return err

@ -5,7 +5,7 @@ import (
) )
func (m *Migrator) updateSettingsToDB25() error { func (m *Migrator) updateSettingsToDB25() error {
migrateLog.Info("Updating settings") migrateLog.Info("- updating settings")
legacySettings, err := m.settingsService.Settings() legacySettings, err := m.settingsService.Settings()
if err != nil { if err != nil {

@ -5,7 +5,7 @@ import (
) )
func (m *Migrator) updateEndpointSettingsToDB25() error { func (m *Migrator) updateEndpointSettingsToDB25() error {
migrateLog.Info("Updating endpoint settings") migrateLog.Info("- updating endpoint settings")
settings, err := m.settingsService.Settings() settings, err := m.settingsService.Settings()
if err != nil { if err != nil {
return err return err

@ -7,7 +7,7 @@ import (
) )
func (m *Migrator) updateStackResourceControlToDB27() error { func (m *Migrator) updateStackResourceControlToDB27() error {
migrateLog.Info("Updating stack resource controls") migrateLog.Info("- updating stack resource controls")
resourceControls, err := m.resourceControlService.ResourceControls() resourceControls, err := m.resourceControlService.ResourceControls()
if err != nil { if err != nil {
return err return err

@ -1,7 +1,7 @@
package migrator package migrator
func (m *Migrator) migrateDBVersionToDB30() error { func (m *Migrator) migrateDBVersionToDB30() error {
migrateLog.Info("Updating legacy settings") migrateLog.Info("- updating legacy settings")
if err := m.MigrateSettingsToDB30(); err != nil { if err := m.MigrateSettingsToDB30(); err != nil {
return err return err
} }

@ -2,38 +2,34 @@ package migrator
import ( import (
"fmt" "fmt"
"github.com/portainer/portainer/api/dataservices/errors"
"log" "log"
"github.com/portainer/portainer/api/dataservices/errors"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/endpointutils" "github.com/portainer/portainer/api/internal/endpointutils"
snapshotutils "github.com/portainer/portainer/api/internal/snapshot" snapshotutils "github.com/portainer/portainer/api/internal/snapshot"
) )
func (m *Migrator) migrateDBVersionToDB32() error { func (m *Migrator) migrateDBVersionToDB32() error {
migrateLog.Info("Updating registries")
err := m.updateRegistriesToDB32() err := m.updateRegistriesToDB32()
if err != nil { if err != nil {
return err return err
} }
migrateLog.Info("Updating dockerhub")
err = m.updateDockerhubToDB32() err = m.updateDockerhubToDB32()
if err != nil { if err != nil {
return err return err
} }
migrateLog.Info("Updating resource controls")
if err := m.updateVolumeResourceControlToDB32(); err != nil { if err := m.updateVolumeResourceControlToDB32(); err != nil {
return err return err
} }
migrateLog.Info("Updating kubeconfig expiry")
if err := m.kubeconfigExpiryToDB32(); err != nil { if err := m.kubeconfigExpiryToDB32(); err != nil {
return err return err
} }
migrateLog.Info("Setting default helm repository url")
if err := m.helmRepositoryURLToDB32(); err != nil { if err := m.helmRepositoryURLToDB32(); err != nil {
return err return err
} }
@ -42,6 +38,7 @@ func (m *Migrator) migrateDBVersionToDB32() error {
} }
func (m *Migrator) updateRegistriesToDB32() error { func (m *Migrator) updateRegistriesToDB32() error {
migrateLog.Info("- updating registries")
registries, err := m.registryService.Registries() registries, err := m.registryService.Registries()
if err != nil { if err != nil {
return err return err
@ -84,6 +81,7 @@ func (m *Migrator) updateRegistriesToDB32() error {
} }
func (m *Migrator) updateDockerhubToDB32() error { func (m *Migrator) updateDockerhubToDB32() error {
migrateLog.Info("- updating dockerhub")
dockerhub, err := m.dockerhubService.DockerHub() dockerhub, err := m.dockerhubService.DockerHub()
if err == errors.ErrObjectNotFound { if err == errors.ErrObjectNotFound {
return nil return nil
@ -172,6 +170,7 @@ func (m *Migrator) updateDockerhubToDB32() error {
} }
func (m *Migrator) updateVolumeResourceControlToDB32() error { func (m *Migrator) updateVolumeResourceControlToDB32() error {
migrateLog.Info("- updating resource controls")
endpoints, err := m.endpointService.Endpoints() endpoints, err := m.endpointService.Endpoints()
if err != nil { if err != nil {
return fmt.Errorf("failed fetching environments: %w", err) return fmt.Errorf("failed fetching environments: %w", err)
@ -264,6 +263,7 @@ func findResourcesToUpdateForDB32(dockerID string, volumesData map[string]interf
} }
func (m *Migrator) kubeconfigExpiryToDB32() error { func (m *Migrator) kubeconfigExpiryToDB32() error {
migrateLog.Info("- updating kubeconfig expiry")
settings, err := m.settingsService.Settings() settings, err := m.settingsService.Settings()
if err != nil { if err != nil {
return err return err
@ -273,6 +273,7 @@ func (m *Migrator) kubeconfigExpiryToDB32() error {
} }
func (m *Migrator) helmRepositoryURLToDB32() error { func (m *Migrator) helmRepositoryURLToDB32() error {
migrateLog.Info("- setting default helm repository URL")
settings, err := m.settingsService.Settings() settings, err := m.settingsService.Settings()
if err != nil { if err != nil {
return err return err

@ -1,8 +1,11 @@
package migrator package migrator
import portainer "github.com/portainer/portainer/api" import (
portainer "github.com/portainer/portainer/api"
)
func (m *Migrator) migrateDBVersionToDB33() error { func (m *Migrator) migrateDBVersionToDB33() error {
migrateLog.Info("- updating settings")
if err := m.migrateSettingsToDB33(); err != nil { if err := m.migrateSettingsToDB33(); err != nil {
return err return err
} }
@ -16,7 +19,7 @@ func (m *Migrator) migrateSettingsToDB33() error {
return err return err
} }
migrateLog.Info("Setting default kubectl shell image") migrateLog.Info("- setting default kubectl shell image")
settings.KubectlShellImage = portainer.DefaultKubectlShellImage settings.KubectlShellImage = portainer.DefaultKubectlShellImage
return m.settingsService.UpdateSettings(settings) return m.settingsService.UpdateSettings(settings)
} }

@ -1,9 +1,11 @@
package migrator package migrator
import "github.com/portainer/portainer/api/dataservices" import (
"github.com/portainer/portainer/api/dataservices"
)
func (m *Migrator) migrateDBVersionToDB34() error { func (m *Migrator) migrateDBVersionToDB34() error {
migrateLog.Info("Migrating stacks") migrateLog.Info("- updating stacks")
err := MigrateStackEntryPoint(m.stackService) err := MigrateStackEntryPoint(m.stackService)
if err != nil { if err != nil {
return err return err

@ -3,7 +3,7 @@ package migrator
func (m *Migrator) migrateDBVersionToDB35() error { func (m *Migrator) migrateDBVersionToDB35() error {
// These should have been migrated already, but due to an earlier bug and a bunch of duplicates, // These should have been migrated already, but due to an earlier bug and a bunch of duplicates,
// calling it again will now fix the issue as the function has been repaired. // calling it again will now fix the issue as the function has been repaired.
migrateLog.Info("Updating dockerhub registries") migrateLog.Info("- updating dockerhub registries")
err := m.updateDockerhubToDB32() err := m.updateDockerhubToDB32()
if err != nil { if err != nil {
return err return err

File diff suppressed because it is too large Load Diff

@ -0,0 +1,802 @@
{
"dockerhub": [
{
"Authentication": false,
"Username": ""
}
],
"endpoint_groups": [
{
"AuthorizedTeams": null,
"AuthorizedUsers": null,
"Description": "Unassigned endpoints",
"Id": 1,
"Labels": [],
"Name": "Unassigned",
"TagIds": [],
"Tags": null,
"TeamAccessPolicies": {},
"UserAccessPolicies": {}
}
],
"endpoint_relations": [
{
"EdgeStacks": {},
"EndpointID": 1
}
],
"endpoints": [
{
"AuthorizedTeams": null,
"AuthorizedUsers": null,
"AzureCredentials": {
"ApplicationID": "",
"AuthenticationKey": "",
"TenantID": ""
},
"ComposeSyntaxMaxVersion": "",
"EdgeCheckinInterval": 0,
"EdgeKey": "",
"GroupId": 1,
"Id": 1,
"IsEdgeDevice": false,
"Kubernetes": {
"Configuration": {
"IngressClasses": null,
"RestrictDefaultNamespace": false,
"StorageClasses": null,
"UseLoadBalancer": false,
"UseServerMetrics": false
},
"Snapshots": null
},
"LastCheckInDate": 0,
"Name": "local",
"PublicURL": "",
"QueryDate": 0,
"SecuritySettings": {
"allowBindMountsForRegularUsers": true,
"allowContainerCapabilitiesForRegularUsers": true,
"allowDeviceMappingForRegularUsers": true,
"allowHostNamespaceForRegularUsers": true,
"allowPrivilegedModeForRegularUsers": true,
"allowStackManagementForRegularUsers": true,
"allowSysctlSettingForRegularUsers": false,
"allowVolumeBrowserForRegularUsers": false,
"enableHostManagementFeatures": false
},
"Snapshots": [
{
"DockerSnapshotRaw": {
"Containers": null,
"Images": null,
"Info": null,
"Networks": null,
"Version": null,
"Volumes": null
},
"DockerVersion": "20.10.13",
"HealthyContainerCount": 0,
"ImageCount": 9,
"NodeCount": 0,
"RunningContainerCount": 5,
"ServiceCount": 0,
"StackCount": 2,
"StoppedContainerCount": 0,
"Swarm": false,
"Time": 1648610112,
"TotalCPU": 8,
"TotalMemory": 25098706944,
"UnhealthyContainerCount": 0,
"VolumeCount": 10
}
],
"Status": 1,
"TLSConfig": {
"TLS": false,
"TLSSkipVerify": false
},
"TagIds": [],
"Tags": null,
"TeamAccessPolicies": {},
"Type": 1,
"URL": "unix:///var/run/docker.sock",
"UserAccessPolicies": {},
"UserTrusted": false
}
],
"registries": [
{
"Authentication": true,
"AuthorizedTeams": null,
"AuthorizedUsers": null,
"BaseURL": "",
"Ecr": {
"Region": ""
},
"Gitlab": {
"InstanceURL": "",
"ProjectId": 0,
"ProjectPath": ""
},
"Id": 1,
"ManagementConfiguration": null,
"Name": "canister.io",
"Password": "MjWbx8A6YK7cw7",
"Quay": {
"OrganisationName": "",
"UseOrganisation": false
},
"RegistryAccesses": {
"1": {
"Namespaces": [],
"TeamAccessPolicies": {},
"UserAccessPolicies": {}
}
},
"TeamAccessPolicies": {},
"Type": 3,
"URL": "cloud.canister.io:5000",
"UserAccessPolicies": {},
"Username": "prabhatkhera"
}
],
"resource_control": [
{
"AdministratorsOnly": false,
"Id": 2,
"Public": true,
"ResourceId": "762gbwaj8r4gcsdy8ld1u4why",
"SubResourceIds": [],
"System": false,
"TeamAccesses": [],
"Type": 5,
"UserAccesses": []
},
{
"AdministratorsOnly": false,
"Id": 3,
"Public": true,
"ResourceId": "1_alpine",
"SubResourceIds": [],
"System": false,
"TeamAccesses": [],
"Type": 6,
"UserAccesses": []
},
{
"AdministratorsOnly": false,
"Id": 4,
"Public": true,
"ResourceId": "1_redis",
"SubResourceIds": [],
"System": false,
"TeamAccesses": [],
"Type": 6,
"UserAccesses": []
},
{
"AdministratorsOnly": false,
"Id": 5,
"Public": false,
"ResourceId": "1_nginx",
"SubResourceIds": [],
"System": false,
"TeamAccesses": [
{
"AccessLevel": 1,
"TeamId": 1
}
],
"Type": 6,
"UserAccesses": []
}
],
"roles": [
{
"Authorizations": {
"DockerAgentBrowseDelete": true,
"DockerAgentBrowseGet": true,
"DockerAgentBrowseList": true,
"DockerAgentBrowsePut": true,
"DockerAgentBrowseRename": true,
"DockerAgentHostInfo": true,
"DockerAgentList": true,
"DockerAgentPing": true,
"DockerAgentUndefined": true,
"DockerBuildCancel": true,
"DockerBuildPrune": true,
"DockerConfigCreate": true,
"DockerConfigDelete": true,
"DockerConfigInspect": true,
"DockerConfigList": true,
"DockerConfigUpdate": true,
"DockerContainerArchive": true,
"DockerContainerArchiveInfo": true,
"DockerContainerAttach": true,
"DockerContainerAttachWebsocket": true,
"DockerContainerChanges": true,
"DockerContainerCreate": true,
"DockerContainerDelete": true,
"DockerContainerExec": true,
"DockerContainerExport": true,
"DockerContainerInspect": true,
"DockerContainerKill": true,
"DockerContainerList": true,
"DockerContainerLogs": true,
"DockerContainerPause": true,
"DockerContainerPrune": true,
"DockerContainerPutContainerArchive": true,
"DockerContainerRename": true,
"DockerContainerResize": true,
"DockerContainerRestart": true,
"DockerContainerStart": true,
"DockerContainerStats": true,
"DockerContainerStop": true,
"DockerContainerTop": true,
"DockerContainerUnpause": true,
"DockerContainerUpdate": true,
"DockerContainerWait": true,
"DockerDistributionInspect": true,
"DockerEvents": true,
"DockerExecInspect": true,
"DockerExecResize": true,
"DockerExecStart": true,
"DockerImageBuild": true,
"DockerImageCommit": true,
"DockerImageCreate": true,
"DockerImageDelete": true,
"DockerImageGet": true,
"DockerImageGetAll": true,
"DockerImageHistory": true,
"DockerImageInspect": true,
"DockerImageList": true,
"DockerImageLoad": true,
"DockerImagePrune": true,
"DockerImagePush": true,
"DockerImageSearch": true,
"DockerImageTag": true,
"DockerInfo": true,
"DockerNetworkConnect": true,
"DockerNetworkCreate": true,
"DockerNetworkDelete": true,
"DockerNetworkDisconnect": true,
"DockerNetworkInspect": true,
"DockerNetworkList": true,
"DockerNetworkPrune": true,
"DockerNodeDelete": true,
"DockerNodeInspect": true,
"DockerNodeList": true,
"DockerNodeUpdate": true,
"DockerPing": true,
"DockerPluginCreate": true,
"DockerPluginDelete": true,
"DockerPluginDisable": true,
"DockerPluginEnable": true,
"DockerPluginInspect": true,
"DockerPluginList": true,
"DockerPluginPrivileges": true,
"DockerPluginPull": true,
"DockerPluginPush": true,
"DockerPluginSet": true,
"DockerPluginUpgrade": true,
"DockerSecretCreate": true,
"DockerSecretDelete": true,
"DockerSecretInspect": true,
"DockerSecretList": true,
"DockerSecretUpdate": true,
"DockerServiceCreate": true,
"DockerServiceDelete": true,
"DockerServiceInspect": true,
"DockerServiceList": true,
"DockerServiceLogs": true,
"DockerServiceUpdate": true,
"DockerSessionStart": true,
"DockerSwarmInit": true,
"DockerSwarmInspect": true,
"DockerSwarmJoin": true,
"DockerSwarmLeave": true,
"DockerSwarmUnlock": true,
"DockerSwarmUnlockKey": true,
"DockerSwarmUpdate": true,
"DockerSystem": true,
"DockerTaskInspect": true,
"DockerTaskList": true,
"DockerTaskLogs": true,
"DockerUndefined": true,
"DockerVersion": true,
"DockerVolumeCreate": true,
"DockerVolumeDelete": true,
"DockerVolumeInspect": true,
"DockerVolumeList": true,
"DockerVolumePrune": true,
"EndpointResourcesAccess": true,
"IntegrationStoridgeAdmin": true,
"PortainerResourceControlCreate": true,
"PortainerResourceControlUpdate": true,
"PortainerStackCreate": true,
"PortainerStackDelete": true,
"PortainerStackFile": true,
"PortainerStackInspect": true,
"PortainerStackList": true,
"PortainerStackMigrate": true,
"PortainerStackUpdate": true,
"PortainerWebhookCreate": true,
"PortainerWebhookDelete": true,
"PortainerWebhookList": true,
"PortainerWebsocketExec": true
},
"Description": "Full control of all resources in an endpoint",
"Id": 1,
"Name": "Endpoint administrator",
"Priority": 1
},
{
"Authorizations": {
"DockerAgentHostInfo": true,
"DockerAgentList": true,
"DockerAgentPing": true,
"DockerConfigInspect": true,
"DockerConfigList": true,
"DockerContainerArchiveInfo": true,
"DockerContainerChanges": true,
"DockerContainerInspect": true,
"DockerContainerList": true,
"DockerContainerLogs": true,
"DockerContainerStats": true,
"DockerContainerTop": true,
"DockerDistributionInspect": true,
"DockerEvents": true,
"DockerImageGet": true,
"DockerImageGetAll": true,
"DockerImageHistory": true,
"DockerImageInspect": true,
"DockerImageList": true,
"DockerImageSearch": true,
"DockerInfo": true,
"DockerNetworkInspect": true,
"DockerNetworkList": true,
"DockerNodeInspect": true,
"DockerNodeList": true,
"DockerPing": true,
"DockerPluginList": true,
"DockerSecretInspect": true,
"DockerSecretList": true,
"DockerServiceInspect": true,
"DockerServiceList": true,
"DockerServiceLogs": true,
"DockerSwarmInspect": true,
"DockerSystem": true,
"DockerTaskInspect": true,
"DockerTaskList": true,
"DockerTaskLogs": true,
"DockerVersion": true,
"DockerVolumeInspect": true,
"DockerVolumeList": true,
"EndpointResourcesAccess": true,
"PortainerStackFile": true,
"PortainerStackInspect": true,
"PortainerStackList": true,
"PortainerWebhookList": true
},
"Description": "Read-only access of all resources in an endpoint",
"Id": 2,
"Name": "Helpdesk",
"Priority": 2
},
{
"Authorizations": {
"DockerAgentHostInfo": true,
"DockerAgentList": true,
"DockerAgentPing": true,
"DockerAgentUndefined": true,
"DockerBuildCancel": true,
"DockerBuildPrune": true,
"DockerConfigCreate": true,
"DockerConfigDelete": true,
"DockerConfigInspect": true,
"DockerConfigList": true,
"DockerConfigUpdate": true,
"DockerContainerArchive": true,
"DockerContainerArchiveInfo": true,
"DockerContainerAttach": true,
"DockerContainerAttachWebsocket": true,
"DockerContainerChanges": true,
"DockerContainerCreate": true,
"DockerContainerDelete": true,
"DockerContainerExec": true,
"DockerContainerExport": true,
"DockerContainerInspect": true,
"DockerContainerKill": true,
"DockerContainerList": true,
"DockerContainerLogs": true,
"DockerContainerPause": true,
"DockerContainerPutContainerArchive": true,
"DockerContainerRename": true,
"DockerContainerResize": true,
"DockerContainerRestart": true,
"DockerContainerStart": true,
"DockerContainerStats": true,
"DockerContainerStop": true,
"DockerContainerTop": true,
"DockerContainerUnpause": true,
"DockerContainerUpdate": true,
"DockerContainerWait": true,
"DockerDistributionInspect": true,
"DockerEvents": true,
"DockerExecInspect": true,
"DockerExecResize": true,
"DockerExecStart": true,
"DockerImageBuild": true,
"DockerImageCommit": true,
"DockerImageCreate": true,
"DockerImageDelete": true,
"DockerImageGet": true,
"DockerImageGetAll": true,
"DockerImageHistory": true,
"DockerImageInspect": true,
"DockerImageList": true,
"DockerImageLoad": true,
"DockerImagePush": true,
"DockerImageSearch": true,
"DockerImageTag": true,
"DockerInfo": true,
"DockerNetworkConnect": true,
"DockerNetworkCreate": true,
"DockerNetworkDelete": true,
"DockerNetworkDisconnect": true,
"DockerNetworkInspect": true,
"DockerNetworkList": true,
"DockerNodeDelete": true,
"DockerNodeInspect": true,
"DockerNodeList": true,
"DockerNodeUpdate": true,
"DockerPing": true,
"DockerPluginCreate": true,
"DockerPluginDelete": true,
"DockerPluginDisable": true,
"DockerPluginEnable": true,
"DockerPluginInspect": true,
"DockerPluginList": true,
"DockerPluginPrivileges": true,
"DockerPluginPull": true,
"DockerPluginPush": true,
"DockerPluginSet": true,
"DockerPluginUpgrade": true,
"DockerSecretCreate": true,
"DockerSecretDelete": true,
"DockerSecretInspect": true,
"DockerSecretList": true,
"DockerSecretUpdate": true,
"DockerServiceCreate": true,
"DockerServiceDelete": true,
"DockerServiceInspect": true,
"DockerServiceList": true,
"DockerServiceLogs": true,
"DockerServiceUpdate": true,
"DockerSessionStart": true,
"DockerSwarmInit": true,
"DockerSwarmInspect": true,
"DockerSwarmJoin": true,
"DockerSwarmLeave": true,
"DockerSwarmUnlock": true,
"DockerSwarmUnlockKey": true,
"DockerSwarmUpdate": true,
"DockerSystem": true,
"DockerTaskInspect": true,
"DockerTaskList": true,
"DockerTaskLogs": true,
"DockerUndefined": true,
"DockerVersion": true,
"DockerVolumeCreate": true,
"DockerVolumeDelete": true,
"DockerVolumeInspect": true,
"DockerVolumeList": true,
"PortainerResourceControlUpdate": true,
"PortainerStackCreate": true,
"PortainerStackDelete": true,
"PortainerStackFile": true,
"PortainerStackInspect": true,
"PortainerStackList": true,
"PortainerStackMigrate": true,
"PortainerStackUpdate": true,
"PortainerWebhookCreate": true,
"PortainerWebhookList": true,
"PortainerWebsocketExec": true
},
"Description": "Full control of assigned resources in an endpoint",
"Id": 3,
"Name": "Standard user",
"Priority": 3
},
{
"Authorizations": {
"DockerAgentHostInfo": true,
"DockerAgentList": true,
"DockerAgentPing": true,
"DockerConfigInspect": true,
"DockerConfigList": true,
"DockerContainerArchiveInfo": true,
"DockerContainerChanges": true,
"DockerContainerInspect": true,
"DockerContainerList": true,
"DockerContainerLogs": true,
"DockerContainerStats": true,
"DockerContainerTop": true,
"DockerDistributionInspect": true,
"DockerEvents": true,
"DockerImageGet": true,
"DockerImageGetAll": true,
"DockerImageHistory": true,
"DockerImageInspect": true,
"DockerImageList": true,
"DockerImageSearch": true,
"DockerInfo": true,
"DockerNetworkInspect": true,
"DockerNetworkList": true,
"DockerNodeInspect": true,
"DockerNodeList": true,
"DockerPing": true,
"DockerPluginList": true,
"DockerSecretInspect": true,
"DockerSecretList": true,
"DockerServiceInspect": true,
"DockerServiceList": true,
"DockerServiceLogs": true,
"DockerSwarmInspect": true,
"DockerSystem": true,
"DockerTaskInspect": true,
"DockerTaskList": true,
"DockerTaskLogs": true,
"DockerVersion": true,
"DockerVolumeInspect": true,
"DockerVolumeList": true,
"PortainerStackFile": true,
"PortainerStackInspect": true,
"PortainerStackList": true,
"PortainerWebhookList": true
},
"Description": "Read-only access of assigned resources in an endpoint",
"Id": 4,
"Name": "Read-only user",
"Priority": 4
}
],
"schedules": [
{
"Created": 1648608136,
"CronExpression": "@every 5m",
"EdgeSchedule": null,
"EndpointSyncJob": null,
"Id": 1,
"JobType": 2,
"Name": "system_snapshot",
"Recurring": true,
"ScriptExecutionJob": null,
"SnapshotJob": {}
}
],
"settings": {
"AllowBindMountsForRegularUsers": true,
"AllowContainerCapabilitiesForRegularUsers": true,
"AllowDeviceMappingForRegularUsers": true,
"AllowHostNamespaceForRegularUsers": true,
"AllowPrivilegedModeForRegularUsers": true,
"AllowStackManagementForRegularUsers": true,
"AllowVolumeBrowserForRegularUsers": false,
"AuthenticationMethod": 1,
"BlackListedLabels": [],
"DisableTrustOnFirstConnect": false,
"DisplayDonationHeader": false,
"DisplayExternalContributors": false,
"EdgeAgentCheckinInterval": 5,
"EnableEdgeComputeFeatures": false,
"EnableHostManagementFeatures": false,
"EnableTelemetry": true,
"EnforceEdgeID": false,
"FeatureFlagSettings": null,
"HelmRepositoryURL": "https://charts.bitnami.com/bitnami",
"KubeconfigExpiry": "0",
"KubectlShellImage": "portainer/kubectl-shell",
"LDAPSettings": {
"AnonymousMode": true,
"AutoCreateUsers": true,
"GroupSearchSettings": [
{
"GroupAttribute": "",
"GroupBaseDN": "",
"GroupFilter": ""
}
],
"ReaderDN": "",
"SearchSettings": [
{
"BaseDN": "",
"Filter": "",
"UserNameAttribute": ""
}
],
"StartTLS": false,
"TLSConfig": {
"TLS": false,
"TLSSkipVerify": false
},
"URL": ""
},
"LogoURL": "",
"OAuthSettings": {
"AccessTokenURI": "",
"AuthorizationURI": "",
"ClientID": "",
"DefaultTeamID": 0,
"KubeSecretKey": null,
"LogoutURI": "",
"OAuthAutoCreateUsers": false,
"RedirectURI": "",
"ResourceURI": "",
"SSO": false,
"Scopes": "",
"UserIdentifier": ""
},
"SnapshotInterval": "5m",
"TemplatesURL": "https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json",
"UserSessionTimeout": "8h",
"fdoConfiguration": {
"enabled": false,
"ownerPassword": "",
"ownerURL": "",
"ownerUsername": ""
},
"openAMTConfiguration": {
"certFileContent": "",
"certFileName": "",
"certFilePassword": "",
"domainName": "",
"enabled": false,
"mpsPassword": "",
"mpsServer": "",
"mpsToken": "",
"mpsUser": ""
}
},
"ssl": {
"certPath": "",
"httpEnabled": true,
"keyPath": "",
"selfSigned": false
},
"stacks": [
{
"AdditionalFiles": null,
"AutoUpdate": null,
"CreatedBy": "",
"CreationDate": 0,
"EndpointId": 1,
"EntryPoint": "docker/alpine37-compose.yml",
"Env": [],
"FromAppTemplate": false,
"GitConfig": null,
"Id": 2,
"IsComposeFormat": false,
"Name": "alpine",
"Namespace": "",
"ProjectPath": "/home/prabhat/portainer/data/ce1.25/compose/2",
"ResourceControl": null,
"Status": 1,
"SwarmId": "s3fd604zdba7z13tbq2x6lyue",
"Type": 1,
"UpdateDate": 0,
"UpdatedBy": ""
},
{
"AdditionalFiles": null,
"AutoUpdate": null,
"CreatedBy": "",
"CreationDate": 0,
"EndpointId": 1,
"EntryPoint": "docker-compose.yml",
"Env": [],
"FromAppTemplate": false,
"GitConfig": null,
"Id": 5,
"IsComposeFormat": false,
"Name": "redis",
"Namespace": "",
"ProjectPath": "/home/prabhat/portainer/data/ce1.25/compose/5",
"ResourceControl": null,
"Status": 1,
"SwarmId": "",
"Type": 2,
"UpdateDate": 0,
"UpdatedBy": ""
},
{
"AdditionalFiles": null,
"AutoUpdate": null,
"CreatedBy": "",
"CreationDate": 0,
"EndpointId": 1,
"EntryPoint": "docker-compose.yml",
"Env": [],
"FromAppTemplate": false,
"GitConfig": null,
"Id": 6,
"IsComposeFormat": false,
"Name": "nginx",
"Namespace": "",
"ProjectPath": "/home/prabhat/portainer/data/ce1.25/compose/6",
"ResourceControl": null,
"Status": 1,
"SwarmId": "",
"Type": 2,
"UpdateDate": 0,
"UpdatedBy": ""
}
],
"teams": [
{
"Id": 1,
"Name": "hello"
}
],
"tunnel_server": {
"PrivateKeySeed": "IvX6ZPRuWtLS5zyg"
},
"users": [
{
"EndpointAuthorizations": null,
"Id": 1,
"Password": "$2a$10$siRDprr/5uUFAU8iom3Sr./WXQkN2dhSNjAC471pkJaALkghS762a",
"PortainerAuthorizations": {
"PortainerDockerHubInspect": true,
"PortainerEndpointExtensionAdd": true,
"PortainerEndpointExtensionRemove": true,
"PortainerEndpointGroupList": true,
"PortainerEndpointInspect": true,
"PortainerEndpointList": true,
"PortainerExtensionList": true,
"PortainerMOTD": true,
"PortainerRegistryInspect": true,
"PortainerRegistryList": true,
"PortainerTeamList": true,
"PortainerTemplateInspect": true,
"PortainerTemplateList": true,
"PortainerUserInspect": true,
"PortainerUserList": true,
"PortainerUserMemberships": true
},
"Role": 1,
"Username": "admin"
},
{
"EndpointAuthorizations": null,
"Id": 2,
"Password": "$2a$10$WpCAW8mSt6FRRp1GkynbFOGSZnHR6E5j9cETZ8HiMlw06hVlDW/Li",
"PortainerAuthorizations": {
"PortainerDockerHubInspect": true,
"PortainerEndpointExtensionAdd": true,
"PortainerEndpointExtensionRemove": true,
"PortainerEndpointGroupList": true,
"PortainerEndpointInspect": true,
"PortainerEndpointList": true,
"PortainerExtensionList": true,
"PortainerMOTD": true,
"PortainerRegistryInspect": true,
"PortainerRegistryList": true,
"PortainerTeamList": true,
"PortainerTemplateInspect": true,
"PortainerTemplateList": true,
"PortainerUserInspect": true,
"PortainerUserList": true,
"PortainerUserMemberships": true
},
"Role": 1,
"Username": "prabhat"
}
],
"version": {
"DB_UPDATING": "false",
"DB_VERSION": "35",
"INSTANCE_ID": "null"
}
}

@ -18,8 +18,8 @@ func (store *Store) GetConnection() portainer.Connection {
return store.connection return store.connection
} }
func MustNewTestStore(init bool) (bool, *Store, func()) { func MustNewTestStore(init, secure bool) (bool, *Store, func()) {
newStore, store, teardown, err := NewTestStore(init) newStore, store, teardown, err := NewTestStore(init, secure)
if err != nil { if err != nil {
if !errors.Is(err, errTempDir) { if !errors.Is(err, errTempDir) {
teardown() teardown()
@ -30,7 +30,7 @@ func MustNewTestStore(init bool) (bool, *Store, func()) {
return newStore, store, teardown return newStore, store, teardown
} }
func NewTestStore(init bool) (bool, *Store, func(), error) { func NewTestStore(init, secure bool) (bool, *Store, func(), error) {
// Creates unique temp directory in a concurrency friendly manner. // Creates unique temp directory in a concurrency friendly manner.
storePath, err := ioutil.TempDir("", "test-store") storePath, err := ioutil.TempDir("", "test-store")
if err != nil { if err != nil {
@ -42,7 +42,12 @@ func NewTestStore(init bool) (bool, *Store, func(), error) {
return false, nil, nil, err return false, nil, nil, err
} }
connection, err := database.NewDatabase("boltdb", storePath, []byte("apassphrasewhichneedstobe32bytes")) secretKey := []byte("apassphrasewhichneedstobe32bytes")
if !secure {
secretKey = nil
}
connection, err := database.NewDatabase("boltdb", storePath, secretKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -0,0 +1,15 @@
package validate
import (
"github.com/go-playground/validator/v10"
portainer "github.com/portainer/portainer/api"
)
var validate *validator.Validate
func ValidateLDAPSettings(ldp *portainer.LDAPSettings) error {
validate = validator.New()
registerValidationMethods(validate)
return validate.Struct(ldp)
}

@ -0,0 +1,61 @@
package validate
import (
"testing"
portainer "github.com/portainer/portainer/api"
)
func TestValidateLDAPSettings(t *testing.T) {
tests := []struct {
name string
ldap portainer.LDAPSettings
wantErr bool
}{
{
name: "Empty LDAP Settings",
ldap: portainer.LDAPSettings{},
wantErr: true,
},
{
name: "With URL",
ldap: portainer.LDAPSettings{
AnonymousMode: true,
URL: "192.168.0.1:323",
},
wantErr: false,
},
{
name: "Validate URL and URLs",
ldap: portainer.LDAPSettings{
AnonymousMode: true,
URL: "192.168.0.1:323",
},
wantErr: false,
},
{
name: "validate client ldap",
ldap: portainer.LDAPSettings{
AnonymousMode: false,
ReaderDN: "CN=LDAP API Service Account",
Password: "Qu**dfUUU**",
URL: "aukdc15.pgc.co:389",
TLSConfig: portainer.TLSConfiguration{
TLS: false,
TLSSkipVerify: false,
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateLDAPSettings(&tt.ldap)
if (err == nil) == tt.wantErr {
t.Errorf("No error expected but got %s", err)
}
})
}
}

@ -0,0 +1,17 @@
package validate
import (
"github.com/go-playground/validator/v10"
)
func registerValidationMethods(v *validator.Validate) {
v.RegisterValidation("validate_bool", ValidateBool)
}
/**
* Validation methods below are being used for custom validation
*/
func ValidateBool(fl validator.FieldLevel) bool {
_, ok := fl.Field().Interface().(bool)
return ok
}

@ -16,8 +16,10 @@ require (
github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814 github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814
github.com/go-git/go-git/v5 v5.3.0 github.com/go-git/go-git/v5 v5.3.0
github.com/go-ldap/ldap/v3 v3.1.8 github.com/go-ldap/ldap/v3 v3.1.8
github.com/go-playground/validator/v10 v10.10.1
github.com/gofrs/uuid v4.0.0+incompatible github.com/gofrs/uuid v4.0.0+incompatible
github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/go-cmp v0.5.6
github.com/gorilla/handlers v1.5.1 github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.7.3 github.com/gorilla/mux v1.7.3
github.com/gorilla/securecookie v1.1.1 github.com/gorilla/securecookie v1.1.1
@ -39,7 +41,7 @@ require (
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/viney-shih/go-lock v1.1.1 github.com/viney-shih/go-lock v1.1.1
go.etcd.io/bbolt v1.3.6 go.etcd.io/bbolt v1.3.6
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/alecthomas/kingpin.v2 v2.2.6
@ -71,9 +73,10 @@ require (
github.com/go-git/gcfg v1.5.0 // indirect github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.1.0 // indirect github.com/go-git/go-billy/v5 v5.1.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect github.com/go-logr/logr v1.2.2 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect github.com/googleapis/gnostic v0.5.5 // indirect
@ -84,6 +87,7 @@ require (
github.com/jpillora/requestlog v1.0.0 // indirect github.com/jpillora/requestlog v1.0.0 // indirect
github.com/jpillora/sizestr v1.0.0 // indirect github.com/jpillora/sizestr v1.0.0 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/moby/spdystream v0.2.0 // indirect github.com/moby/spdystream v0.2.0 // indirect
@ -101,9 +105,9 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect

@ -432,6 +432,14 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.10.1 h1:uA0+amWMiglNZKZ9FJRKUAe9U3RX91eVn1JYXMWt7ig=
github.com/go-playground/validator/v10 v10.10.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
@ -651,13 +659,16 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo= github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@ -786,6 +797,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -843,6 +855,9 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
@ -1019,8 +1034,8 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 h1:syTAU9FwmvzEoIYMqcPHOcVm4H3U5u90WsvuYgwpETU= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@ -1114,9 +1129,8 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -1234,21 +1248,20 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

@ -22,7 +22,7 @@ import (
func Test_helmDelete(t *testing.T) { func Test_helmDelete(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
err := store.Endpoint().Create(&portainer.Endpoint{ID: 1}) err := store.Endpoint().Create(&portainer.Endpoint{ID: 1})

@ -25,7 +25,7 @@ import (
func Test_helmInstall(t *testing.T) { func Test_helmInstall(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
err := store.Endpoint().Create(&portainer.Endpoint{ID: 1}) err := store.Endpoint().Create(&portainer.Endpoint{ID: 1})

@ -24,7 +24,7 @@ import (
func Test_helmList(t *testing.T) { func Test_helmList(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
err := store.Endpoint().Create(&portainer.Endpoint{ID: 1}) err := store.Endpoint().Create(&portainer.Endpoint{ID: 1})

@ -13,7 +13,7 @@ import (
) )
func TestHandler_webhookInvoke(t *testing.T) { func TestHandler_webhookInvoke(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
webhookID := newGuidString(t) webhookID := newGuidString(t)

@ -21,7 +21,7 @@ import (
func Test_userCreateAccessToken(t *testing.T) { func Test_userCreateAccessToken(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create admin and standard user(s) // create admin and standard user(s)

@ -17,7 +17,7 @@ import (
func Test_deleteUserRemovesAccessTokens(t *testing.T) { func Test_deleteUserRemovesAccessTokens(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create standard user // create standard user

@ -20,7 +20,7 @@ import (
func Test_userGetAccessTokens(t *testing.T) { func Test_userGetAccessTokens(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create admin and standard user(s) // create admin and standard user(s)

@ -18,7 +18,7 @@ import (
func Test_userRemoveAccessToken(t *testing.T) { func Test_userRemoveAccessToken(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create admin and standard user(s) // create admin and standard user(s)

@ -17,7 +17,7 @@ import (
func Test_updateUserRemovesAccessTokens(t *testing.T) { func Test_updateUserRemovesAccessTokens(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create standard user // create standard user

@ -36,7 +36,7 @@ func tokenLookupFail(r *http.Request) *portainer.TokenData {
func Test_mwAuthenticateFirst(t *testing.T) { func Test_mwAuthenticateFirst(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
jwtService, err := jwt.NewService("1h", store) jwtService, err := jwt.NewService("1h", store)
@ -259,7 +259,7 @@ func Test_extractAPIKeyQueryParam(t *testing.T) {
func Test_apiKeyLookup(t *testing.T) { func Test_apiKeyLookup(t *testing.T) {
is := assert.New(t) is := assert.New(t)
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
// create standard user // create standard user

@ -559,13 +559,13 @@ type (
// LDAPSettings represents the settings used to connect to a LDAP server // LDAPSettings represents the settings used to connect to a LDAP server
LDAPSettings struct { LDAPSettings struct {
// Enable this option if the server is configured for Anonymous access. When enabled, ReaderDN and Password will not be used // Enable this option if the server is configured for Anonymous access. When enabled, ReaderDN and Password will not be used
AnonymousMode bool `json:"AnonymousMode" example:"true"` AnonymousMode bool `json:"AnonymousMode" example:"true" validate:"validate_bool"`
// Account that will be used to search for users // Account that will be used to search for users
ReaderDN string `json:"ReaderDN" example:"cn=readonly-account,dc=ldap,dc=domain,dc=tld"` ReaderDN string `json:"ReaderDN" example:"cn=readonly-account,dc=ldap,dc=domain,dc=tld" validate:"required_if=AnonymousMode false"`
// Password of the account that will be used to search users // Password of the account that will be used to search users
Password string `json:"Password,omitempty" example:"readonly-password"` Password string `json:"Password,omitempty" example:"readonly-password" validate:"required_if=AnonymousMode false"`
// URL or IP address of the LDAP server // URL or IP address of the LDAP server
URL string `json:"URL" example:"myldap.domain.tld:389"` URL string `json:"URL" example:"myldap.domain.tld:389" validate:"hostname_port"`
TLSConfig TLSConfiguration `json:"TLSConfig"` TLSConfig TLSConfiguration `json:"TLSConfig"`
// Whether LDAP connection should use StartTLS // Whether LDAP connection should use StartTLS
StartTLS bool `json:"StartTLS" example:"true"` StartTLS bool `json:"StartTLS" example:"true"`

@ -41,7 +41,7 @@ func (s *noopDeployer) DeployKubernetesStack(stack *portainer.Stack, endpoint *p
} }
func Test_redeployWhenChanged_FailsWhenCannotFindStack(t *testing.T) { func Test_redeployWhenChanged_FailsWhenCannotFindStack(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
err := RedeployWhenChanged(1, nil, store, nil) err := RedeployWhenChanged(1, nil, store, nil)
@ -50,7 +50,7 @@ func Test_redeployWhenChanged_FailsWhenCannotFindStack(t *testing.T) {
} }
func Test_redeployWhenChanged_DoesNothingWhenNotAGitBasedStack(t *testing.T) { func Test_redeployWhenChanged_DoesNothingWhenNotAGitBasedStack(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
admin := &portainer.User{ID: 1, Username: "admin"} admin := &portainer.User{ID: 1, Username: "admin"}
@ -65,7 +65,7 @@ func Test_redeployWhenChanged_DoesNothingWhenNotAGitBasedStack(t *testing.T) {
} }
func Test_redeployWhenChanged_DoesNothingWhenNoGitChanges(t *testing.T) { func Test_redeployWhenChanged_DoesNothingWhenNoGitChanges(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
tmpDir, _ := ioutil.TempDir("", "stack") tmpDir, _ := ioutil.TempDir("", "stack")
@ -91,7 +91,7 @@ func Test_redeployWhenChanged_DoesNothingWhenNoGitChanges(t *testing.T) {
func Test_redeployWhenChanged_FailsWhenCannotClone(t *testing.T) { func Test_redeployWhenChanged_FailsWhenCannotClone(t *testing.T) {
cloneErr := errors.New("failed to clone") cloneErr := errors.New("failed to clone")
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
admin := &portainer.User{ID: 1, Username: "admin"} admin := &portainer.User{ID: 1, Username: "admin"}
@ -114,7 +114,7 @@ func Test_redeployWhenChanged_FailsWhenCannotClone(t *testing.T) {
} }
func Test_redeployWhenChanged(t *testing.T) { func Test_redeployWhenChanged(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
tmpDir, _ := ioutil.TempDir("", "stack") tmpDir, _ := ioutil.TempDir("", "stack")
@ -165,7 +165,7 @@ func Test_redeployWhenChanged(t *testing.T) {
} }
func Test_getUserRegistries(t *testing.T) { func Test_getUserRegistries(t *testing.T) {
_, store, teardown := datastore.MustNewTestStore(true) _, store, teardown := datastore.MustNewTestStore(true, true)
defer teardown() defer teardown()
endpointID := 123 endpointID := 123

Loading…
Cancel
Save