mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 14:29:40 +02:00
* bootstrap encryption key * secret key message change in cli and secret key file content trimmed * Migrate encryption code to latest version * pull in newer code * tidying up * working data encryption layer * fix tests * remove stray comment * fix a few minor issues and improve the comments * split out databasefilename with param to two methods to be more obvious * DB encryption integration (#6374) * json methods moved under DBConnection * store encryption fixed * cleaned * review comments addressed * newstore value fixed * backup test updated * logrus format config updated * Fix for newStore Co-authored-by: Matt Hook <hookenz@gmail.com> * Minor improvements * Improve the export code. Add missing webhook for import * rename HelmUserRepositorys to HelmUserRepositories * fix logging messages * when starting portainer with a key (first use) http is disabled by default. But when starting fresh without a key, http is enabled? * Fix bug for default settings on new installs Co-authored-by: Prabhat Khera <prabhat.khera@portainer.io> Co-authored-by: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package boltdb
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/boltdb/bolt"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// inspired by github.com/konoui/boltdb-exporter (which has no license)
|
|
// but very much simplified, based on how we use boltdb
|
|
func (c *DbConnection) exportJson(databasePath string) ([]byte, error) {
|
|
logrus.WithField("databasePath", databasePath).Infof("exportJson")
|
|
|
|
connection, err := bolt.Open(databasePath, 0600, &bolt.Options{Timeout: 1 * time.Second, ReadOnly: true})
|
|
if err != nil {
|
|
return []byte("{}"), err
|
|
}
|
|
defer connection.Close()
|
|
|
|
backup := make(map[string]interface{})
|
|
|
|
err = connection.View(func(tx *bolt.Tx) error {
|
|
err = tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
|
|
bucketName := string(name)
|
|
var list []interface{}
|
|
version := make(map[string]string)
|
|
cursor := bucket.Cursor()
|
|
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
|
|
if v == nil {
|
|
continue
|
|
}
|
|
var obj interface{}
|
|
err := c.UnmarshalObject(v, &obj)
|
|
if err != nil {
|
|
logrus.WithError(err).Errorf("Failed to unmarshal (bucket %s): %v", bucketName, string(v))
|
|
obj = v
|
|
}
|
|
if bucketName == "version" {
|
|
version[string(k)] = string(v)
|
|
} else {
|
|
list = append(list, obj)
|
|
}
|
|
}
|
|
if bucketName == "version" {
|
|
backup[bucketName] = version
|
|
}
|
|
if len(list) > 0 {
|
|
if bucketName == "ssl" ||
|
|
bucketName == "settings" ||
|
|
bucketName == "tunnel_server" {
|
|
backup[bucketName] = list[0]
|
|
return nil
|
|
}
|
|
backup[bucketName] = list
|
|
}
|
|
|
|
return nil
|
|
})
|
|
return err
|
|
})
|
|
if err != nil {
|
|
return []byte("{}"), err
|
|
}
|
|
|
|
return json.MarshalIndent(backup, "", " ")
|
|
}
|