mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
chore(code): replace interface{} with any EE-6513 (#11986)
This commit is contained in:
parent
9c4935286f
commit
f0d43f941f
66 changed files with 231 additions and 231 deletions
|
@ -54,7 +54,7 @@ func setLoggingMode(mode string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMessage(i interface{}) string {
|
func formatMessage(i any) string {
|
||||||
if i == nil {
|
if i == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,11 @@ func (kcl *KubeClient) GetConfigMapsAndSecrets(namespace string) ([]models.K8sCo
|
||||||
// use closures to capture the current kube client and namespace by declaring wrapper functions
|
// use closures to capture the current kube client and namespace by declaring wrapper functions
|
||||||
// that match the interface signature for concurrent.Func
|
// that match the interface signature for concurrent.Func
|
||||||
|
|
||||||
listConfigMaps := func(ctx context.Context) (interface{}, error) {
|
listConfigMaps := func(ctx context.Context) (any, error) {
|
||||||
return kcl.cli.CoreV1().ConfigMaps(namespace).List(context.Background(), meta.ListOptions{})
|
return kcl.cli.CoreV1().ConfigMaps(namespace).List(context.Background(), meta.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
listSecrets := func(ctx context.Context) (interface{}, error) {
|
listSecrets := func(ctx context.Context) (any, error) {
|
||||||
return kcl.cli.CoreV1().Secrets(namespace).List(context.Background(), meta.ListOptions{})
|
return kcl.cli.CoreV1().Secrets(namespace).List(context.Background(), meta.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReadTransaction interface {
|
type ReadTransaction interface {
|
||||||
GetObject(bucketName string, key []byte, object interface{}) error
|
GetObject(bucketName string, key []byte, object any) error
|
||||||
GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
GetAll(bucketName string, obj any, append func(o any) (any, error)) error
|
||||||
GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, append func(o interface{}) (interface{}, error)) error
|
GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj any, append func(o any) (any, error)) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transaction interface {
|
type Transaction interface {
|
||||||
ReadTransaction
|
ReadTransaction
|
||||||
|
|
||||||
SetServiceName(bucketName string) error
|
SetServiceName(bucketName string) error
|
||||||
UpdateObject(bucketName string, key []byte, object interface{}) error
|
UpdateObject(bucketName string, key []byte, object any) error
|
||||||
DeleteObject(bucketName string, key []byte) error
|
DeleteObject(bucketName string, key []byte) error
|
||||||
CreateObject(bucketName string, fn func(uint64) (int, interface{})) error
|
CreateObject(bucketName string, fn func(uint64) (int, any)) error
|
||||||
CreateObjectWithId(bucketName string, id int, obj interface{}) error
|
CreateObjectWithId(bucketName string, id int, obj any) error
|
||||||
CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error
|
CreateObjectWithStringId(bucketName string, id []byte, obj any) error
|
||||||
DeleteAllObjects(bucketName string, obj interface{}, matching func(o interface{}) (id int, ok bool)) error
|
DeleteAllObjects(bucketName string, obj any, matching func(o any) (id int, ok bool)) error
|
||||||
GetNextIdentifier(bucketName string) int
|
GetNextIdentifier(bucketName string) int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ type Connection interface {
|
||||||
NeedsEncryptionMigration() (bool, error)
|
NeedsEncryptionMigration() (bool, error)
|
||||||
SetEncrypted(encrypted bool)
|
SetEncrypted(encrypted bool)
|
||||||
|
|
||||||
BackupMetadata() (map[string]interface{}, error)
|
BackupMetadata() (map[string]any, error)
|
||||||
RestoreMetadata(s map[string]interface{}) error
|
RestoreMetadata(s map[string]any) error
|
||||||
|
|
||||||
UpdateObjectFunc(bucketName string, key []byte, object any, updateFn func()) error
|
UpdateObjectFunc(bucketName string, key []byte, object any, updateFn func()) error
|
||||||
ConvertToKey(v int) []byte
|
ConvertToKey(v int) []byte
|
||||||
|
|
|
@ -229,7 +229,7 @@ func (connection *DbConnection) SetServiceName(bucketName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetObject is a generic function used to retrieve an unmarshalled object from a database.
|
// GetObject is a generic function used to retrieve an unmarshalled object from a database.
|
||||||
func (connection *DbConnection) GetObject(bucketName string, key []byte, object interface{}) error {
|
func (connection *DbConnection) GetObject(bucketName string, key []byte, object any) error {
|
||||||
return connection.ViewTx(func(tx portainer.Transaction) error {
|
return connection.ViewTx(func(tx portainer.Transaction) error {
|
||||||
return tx.GetObject(bucketName, key, object)
|
return tx.GetObject(bucketName, key, object)
|
||||||
})
|
})
|
||||||
|
@ -244,7 +244,7 @@ func (connection *DbConnection) getEncryptionKey() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateObject is a generic function used to update an object inside a database.
|
// UpdateObject is a generic function used to update an object inside a database.
|
||||||
func (connection *DbConnection) UpdateObject(bucketName string, key []byte, object interface{}) error {
|
func (connection *DbConnection) UpdateObject(bucketName string, key []byte, object any) error {
|
||||||
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
||||||
return tx.UpdateObject(bucketName, key, object)
|
return tx.UpdateObject(bucketName, key, object)
|
||||||
})
|
})
|
||||||
|
@ -285,7 +285,7 @@ func (connection *DbConnection) DeleteObject(bucketName string, key []byte) erro
|
||||||
|
|
||||||
// DeleteAllObjects delete all objects where matching() returns (id, ok).
|
// DeleteAllObjects delete all objects where matching() returns (id, ok).
|
||||||
// TODO: think about how to return the error inside (maybe change ok to type err, and use "notfound"?
|
// TODO: think about how to return the error inside (maybe change ok to type err, and use "notfound"?
|
||||||
func (connection *DbConnection) DeleteAllObjects(bucketName string, obj interface{}, matching func(o interface{}) (id int, ok bool)) error {
|
func (connection *DbConnection) DeleteAllObjects(bucketName string, obj any, matching func(o any) (id int, ok bool)) error {
|
||||||
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
||||||
return tx.DeleteAllObjects(bucketName, obj, matching)
|
return tx.DeleteAllObjects(bucketName, obj, matching)
|
||||||
})
|
})
|
||||||
|
@ -304,41 +304,41 @@ func (connection *DbConnection) GetNextIdentifier(bucketName string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateObject creates a new object in the bucket, using the next bucket sequence id
|
// CreateObject creates a new object in the bucket, using the next bucket sequence id
|
||||||
func (connection *DbConnection) CreateObject(bucketName string, fn func(uint64) (int, interface{})) error {
|
func (connection *DbConnection) CreateObject(bucketName string, fn func(uint64) (int, any)) error {
|
||||||
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
||||||
return tx.CreateObject(bucketName, fn)
|
return tx.CreateObject(bucketName, fn)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateObjectWithId creates a new object in the bucket, using the specified id
|
// CreateObjectWithId creates a new object in the bucket, using the specified id
|
||||||
func (connection *DbConnection) CreateObjectWithId(bucketName string, id int, obj interface{}) error {
|
func (connection *DbConnection) CreateObjectWithId(bucketName string, id int, obj any) error {
|
||||||
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
||||||
return tx.CreateObjectWithId(bucketName, id, obj)
|
return tx.CreateObjectWithId(bucketName, id, obj)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateObjectWithStringId creates a new object in the bucket, using the specified id
|
// CreateObjectWithStringId creates a new object in the bucket, using the specified id
|
||||||
func (connection *DbConnection) CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error {
|
func (connection *DbConnection) CreateObjectWithStringId(bucketName string, id []byte, obj any) error {
|
||||||
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
return connection.UpdateTx(func(tx portainer.Transaction) error {
|
||||||
return tx.CreateObjectWithStringId(bucketName, id, obj)
|
return tx.CreateObjectWithStringId(bucketName, id, obj)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (connection *DbConnection) GetAll(bucketName string, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error {
|
func (connection *DbConnection) GetAll(bucketName string, obj any, appendFn func(o any) (any, error)) error {
|
||||||
return connection.ViewTx(func(tx portainer.Transaction) error {
|
return connection.ViewTx(func(tx portainer.Transaction) error {
|
||||||
return tx.GetAll(bucketName, obj, appendFn)
|
return tx.GetAll(bucketName, obj, appendFn)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (connection *DbConnection) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error {
|
func (connection *DbConnection) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj any, appendFn func(o any) (any, error)) error {
|
||||||
return connection.ViewTx(func(tx portainer.Transaction) error {
|
return connection.ViewTx(func(tx portainer.Transaction) error {
|
||||||
return tx.GetAllWithKeyPrefix(bucketName, keyPrefix, obj, appendFn)
|
return tx.GetAllWithKeyPrefix(bucketName, keyPrefix, obj, appendFn)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackupMetadata will return a copy of the boltdb sequence numbers for all buckets.
|
// BackupMetadata will return a copy of the boltdb sequence numbers for all buckets.
|
||||||
func (connection *DbConnection) BackupMetadata() (map[string]interface{}, error) {
|
func (connection *DbConnection) BackupMetadata() (map[string]any, error) {
|
||||||
buckets := map[string]interface{}{}
|
buckets := map[string]any{}
|
||||||
|
|
||||||
err := connection.View(func(tx *bolt.Tx) error {
|
err := connection.View(func(tx *bolt.Tx) error {
|
||||||
return tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
|
return tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
|
||||||
|
@ -354,7 +354,7 @@ func (connection *DbConnection) BackupMetadata() (map[string]interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreMetadata will restore the boltdb sequence numbers for all buckets.
|
// RestoreMetadata will restore the boltdb sequence numbers for all buckets.
|
||||||
func (connection *DbConnection) RestoreMetadata(s map[string]interface{}) error {
|
func (connection *DbConnection) RestoreMetadata(s map[string]any) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for bucketName, v := range s {
|
for bucketName, v := range s {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
bolt "go.etcd.io/bbolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func backupMetadata(connection *bolt.DB) (map[string]interface{}, error) {
|
func backupMetadata(connection *bolt.DB) (map[string]any, error) {
|
||||||
buckets := map[string]interface{}{}
|
buckets := map[string]any{}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -39,7 +39,7 @@ func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, e
|
||||||
}
|
}
|
||||||
defer connection.Close()
|
defer connection.Close()
|
||||||
|
|
||||||
backup := make(map[string]interface{})
|
backup := make(map[string]any)
|
||||||
if metadata {
|
if metadata {
|
||||||
meta, err := backupMetadata(connection)
|
meta, err := backupMetadata(connection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -52,7 +52,7 @@ func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, e
|
||||||
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 {
|
||||||
bucketName := string(name)
|
bucketName := string(name)
|
||||||
var list []interface{}
|
var list []any
|
||||||
version := make(map[string]string)
|
version := make(map[string]string)
|
||||||
cursor := bucket.Cursor()
|
cursor := bucket.Cursor()
|
||||||
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
|
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
|
||||||
|
@ -60,7 +60,7 @@ func (c *DbConnection) ExportJSON(databasePath string, metadata bool) ([]byte, e
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj interface{}
|
var obj any
|
||||||
err := c.UnmarshalObject(v, &obj)
|
err := c.UnmarshalObject(v, &obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
var errEncryptedStringTooShort = errors.New("encrypted string too short")
|
var errEncryptedStringTooShort = errors.New("encrypted string too short")
|
||||||
|
|
||||||
// MarshalObject encodes an object to binary format
|
// MarshalObject encodes an object to binary format
|
||||||
func (connection *DbConnection) MarshalObject(object interface{}) ([]byte, error) {
|
func (connection *DbConnection) MarshalObject(object any) ([]byte, error) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
// Special case for the VERSION bucket. Here we're not using json
|
// Special case for the VERSION bucket. Here we're not using json
|
||||||
|
@ -38,7 +38,7 @@ func (connection *DbConnection) MarshalObject(object interface{}) ([]byte, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalObject decodes an object from binary data
|
// UnmarshalObject decodes an object from binary data
|
||||||
func (connection *DbConnection) UnmarshalObject(data []byte, object interface{}) error {
|
func (connection *DbConnection) UnmarshalObject(data []byte, object any) error {
|
||||||
var err error
|
var err error
|
||||||
if connection.getEncryptionKey() != nil {
|
if connection.getEncryptionKey() != nil {
|
||||||
data, err = decrypt(data, connection.getEncryptionKey())
|
data, err = decrypt(data, connection.getEncryptionKey())
|
||||||
|
|
|
@ -25,7 +25,7 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
|
||||||
uuid := uuid.Must(uuid.NewV4())
|
uuid := uuid.Must(uuid.NewV4())
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
object interface{}
|
object any
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
|
||||||
expected: uuid.String(),
|
expected: uuid.String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
object: map[string]interface{}{"key": "value"},
|
object: map[string]any{"key": "value"},
|
||||||
expected: `{"key":"value"}`,
|
expected: `{"key":"value"}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -73,11 +73,11 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
|
||||||
expected: `["1","2","3"]`,
|
expected: `["1","2","3"]`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
object: []map[string]interface{}{{"key1": "value1"}, {"key2": "value2"}},
|
object: []map[string]any{{"key1": "value1"}, {"key2": "value2"}},
|
||||||
expected: `[{"key1":"value1"},{"key2":"value2"}]`,
|
expected: `[{"key1":"value1"},{"key2":"value2"}]`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
object: []interface{}{1, "2", false, map[string]interface{}{"key1": "value1"}},
|
object: []any{1, "2", false, map[string]any{"key1": "value1"}},
|
||||||
expected: `[1,"2",false,{"key1":"value1"}]`,
|
expected: `[1,"2",false,{"key1":"value1"}]`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (tx *DbTransaction) SetServiceName(bucketName string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) GetObject(bucketName string, key []byte, object interface{}) error {
|
func (tx *DbTransaction) GetObject(bucketName string, key []byte, object any) error {
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
|
|
||||||
value := bucket.Get(key)
|
value := bucket.Get(key)
|
||||||
|
@ -31,7 +31,7 @@ func (tx *DbTransaction) GetObject(bucketName string, key []byte, object interfa
|
||||||
return tx.conn.UnmarshalObject(value, object)
|
return tx.conn.UnmarshalObject(value, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) UpdateObject(bucketName string, key []byte, object interface{}) error {
|
func (tx *DbTransaction) UpdateObject(bucketName string, key []byte, object any) error {
|
||||||
data, err := tx.conn.MarshalObject(object)
|
data, err := tx.conn.MarshalObject(object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -46,7 +46,7 @@ func (tx *DbTransaction) DeleteObject(bucketName string, key []byte) error {
|
||||||
return bucket.Delete(key)
|
return bucket.Delete(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) DeleteAllObjects(bucketName string, obj interface{}, matchingFn func(o interface{}) (id int, ok bool)) error {
|
func (tx *DbTransaction) DeleteAllObjects(bucketName string, obj any, matchingFn func(o any) (id int, ok bool)) error {
|
||||||
var ids []int
|
var ids []int
|
||||||
|
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
|
@ -85,7 +85,7 @@ func (tx *DbTransaction) GetNextIdentifier(bucketName string) int {
|
||||||
return int(id)
|
return int(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) CreateObject(bucketName string, fn func(uint64) (int, interface{})) error {
|
func (tx *DbTransaction) CreateObject(bucketName string, fn func(uint64) (int, any)) error {
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
|
|
||||||
seqId, _ := bucket.NextSequence()
|
seqId, _ := bucket.NextSequence()
|
||||||
|
@ -99,7 +99,7 @@ func (tx *DbTransaction) CreateObject(bucketName string, fn func(uint64) (int, i
|
||||||
return bucket.Put(tx.conn.ConvertToKey(id), data)
|
return bucket.Put(tx.conn.ConvertToKey(id), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) CreateObjectWithId(bucketName string, id int, obj interface{}) error {
|
func (tx *DbTransaction) CreateObjectWithId(bucketName string, id int, obj any) error {
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
data, err := tx.conn.MarshalObject(obj)
|
data, err := tx.conn.MarshalObject(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +109,7 @@ func (tx *DbTransaction) CreateObjectWithId(bucketName string, id int, obj inter
|
||||||
return bucket.Put(tx.conn.ConvertToKey(id), data)
|
return bucket.Put(tx.conn.ConvertToKey(id), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error {
|
func (tx *DbTransaction) CreateObjectWithStringId(bucketName string, id []byte, obj any) error {
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
data, err := tx.conn.MarshalObject(obj)
|
data, err := tx.conn.MarshalObject(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -119,7 +119,7 @@ func (tx *DbTransaction) CreateObjectWithStringId(bucketName string, id []byte,
|
||||||
return bucket.Put(id, data)
|
return bucket.Put(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) GetAll(bucketName string, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error {
|
func (tx *DbTransaction) GetAll(bucketName string, obj any, appendFn func(o any) (any, error)) error {
|
||||||
bucket := tx.tx.Bucket([]byte(bucketName))
|
bucket := tx.tx.Bucket([]byte(bucketName))
|
||||||
|
|
||||||
return bucket.ForEach(func(k []byte, v []byte) error {
|
return bucket.ForEach(func(k []byte, v []byte) error {
|
||||||
|
@ -132,7 +132,7 @@ func (tx *DbTransaction) GetAll(bucketName string, obj interface{}, appendFn fun
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *DbTransaction) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error {
|
func (tx *DbTransaction) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj any, appendFn func(o any) (any, error)) error {
|
||||||
cursor := tx.tx.Bucket([]byte(bucketName)).Cursor()
|
cursor := tx.tx.Bucket([]byte(bucketName)).Cursor()
|
||||||
|
|
||||||
for k, v := cursor.Seek(keyPrefix); k != nil && bytes.HasPrefix(k, keyPrefix); k, v = cursor.Next() {
|
for k, v := cursor.Seek(keyPrefix); k != nil && bytes.HasPrefix(k, keyPrefix); k, v = cursor.Next() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (service *Service) GetAPIKeysByUserID(userID portainer.UserID) ([]portainer
|
||||||
err := service.Connection.GetAll(
|
err := service.Connection.GetAll(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.APIKey{},
|
&portainer.APIKey{},
|
||||||
func(obj interface{}) (interface{}, error) {
|
func(obj any) (any, error) {
|
||||||
record, ok := obj.(*portainer.APIKey)
|
record, ok := obj.(*portainer.APIKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to APIKey object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to APIKey object")
|
||||||
|
@ -66,7 +66,7 @@ func (service *Service) GetAPIKeyByDigest(digest string) (*portainer.APIKey, err
|
||||||
err := service.Connection.GetAll(
|
err := service.Connection.GetAll(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.APIKey{},
|
&portainer.APIKey{},
|
||||||
func(obj interface{}) (interface{}, error) {
|
func(obj any) (any, error) {
|
||||||
key, ok := obj.(*portainer.APIKey)
|
key, ok := obj.(*portainer.APIKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to APIKey object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to APIKey object")
|
||||||
|
@ -95,7 +95,7 @@ func (service *Service) GetAPIKeyByDigest(digest string) (*portainer.APIKey, err
|
||||||
func (service *Service) Create(record *portainer.APIKey) error {
|
func (service *Service) Create(record *portainer.APIKey) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
record.ID = portainer.APIKeyID(id)
|
record.ID = portainer.APIKeyID(id)
|
||||||
|
|
||||||
return int(record.ID), record
|
return int(record.ID), record
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (service ServiceTx) UpdateEdgeGroupFunc(ID portainer.EdgeGroupID, updateFun
|
||||||
func (service ServiceTx) Create(group *portainer.EdgeGroup) error {
|
func (service ServiceTx) Create(group *portainer.EdgeGroup) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
group.ID = portainer.EdgeGroupID(id)
|
group.ID = portainer.EdgeGroupID(id)
|
||||||
return int(group.ID), group
|
return int(group.ID), group
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ func (service ServiceTx) EdgeStacks() ([]portainer.EdgeStack, error) {
|
||||||
err := service.tx.GetAll(
|
err := service.tx.GetAll(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.EdgeStack{},
|
&portainer.EdgeStack{},
|
||||||
func(obj interface{}) (interface{}, error) {
|
func(obj any) (any, error) {
|
||||||
stack, ok := obj.(*portainer.EdgeStack)
|
stack, ok := obj.(*portainer.EdgeStack)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to EdgeStack object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to EdgeStack object")
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
||||||
func (service *Service) Create(endpointGroup *portainer.EndpointGroup) error {
|
func (service *Service) Create(endpointGroup *portainer.EndpointGroup) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
endpointGroup.ID = portainer.EndpointGroupID(id)
|
endpointGroup.ID = portainer.EndpointGroupID(id)
|
||||||
return int(endpointGroup.ID), endpointGroup
|
return int(endpointGroup.ID), endpointGroup
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ type ServiceTx struct {
|
||||||
func (service ServiceTx) Create(endpointGroup *portainer.EndpointGroup) error {
|
func (service ServiceTx) Create(endpointGroup *portainer.EndpointGroup) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
endpointGroup.ID = portainer.EndpointGroupID(id)
|
endpointGroup.ID = portainer.EndpointGroupID(id)
|
||||||
return int(endpointGroup.ID), endpointGroup
|
return int(endpointGroup.ID), endpointGroup
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (service *Service) HelmUserRepositoryByUserID(userID portainer.UserID) ([]p
|
||||||
func (service *Service) Create(record *portainer.HelmUserRepository) error {
|
func (service *Service) Create(record *portainer.HelmUserRepository) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
record.ID = portainer.HelmUserRepositoryID(id)
|
record.ID = portainer.HelmUserRepositoryID(id)
|
||||||
return int(record.ID), record
|
return int(record.ID), record
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,8 +17,8 @@ func IsErrObjectNotFound(e error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendFn appends elements to the given collection slice
|
// AppendFn appends elements to the given collection slice
|
||||||
func AppendFn[T any](collection *[]T) func(obj interface{}) (interface{}, error) {
|
func AppendFn[T any](collection *[]T) func(obj any) (any, error) {
|
||||||
return func(obj interface{}) (interface{}, error) {
|
return func(obj any) (any, error) {
|
||||||
element, ok := obj.(*T)
|
element, ok := obj.(*T)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
||||||
|
@ -32,8 +32,8 @@ func AppendFn[T any](collection *[]T) func(obj interface{}) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterFn appends elements to the given collection when the predicate is true
|
// FilterFn appends elements to the given collection when the predicate is true
|
||||||
func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj interface{}) (interface{}, error) {
|
func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj any) (any, error) {
|
||||||
return func(obj interface{}) (interface{}, error) {
|
return func(obj any) (any, error) {
|
||||||
element, ok := obj.(*T)
|
element, ok := obj.(*T)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
||||||
|
@ -50,8 +50,8 @@ func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj interface
|
||||||
|
|
||||||
// FirstFn sets the element to the first one that satisfies the predicate and stops the computation, returns ErrStop on
|
// FirstFn sets the element to the first one that satisfies the predicate and stops the computation, returns ErrStop on
|
||||||
// success
|
// success
|
||||||
func FirstFn[T any](element *T, predicate func(T) bool) func(obj interface{}) (interface{}, error) {
|
func FirstFn[T any](element *T, predicate func(T) bool) func(obj any) (any, error) {
|
||||||
return func(obj interface{}) (interface{}, error) {
|
return func(obj any) (any, error) {
|
||||||
e, ok := obj.(*T)
|
e, ok := obj.(*T)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("type assertion failed")
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ServiceTx) Create(config *portainer.PendingAction) error {
|
func (s ServiceTx) Create(config *portainer.PendingAction) error {
|
||||||
return s.Tx.CreateObject(BucketName, func(id uint64) (int, interface{}) {
|
return s.Tx.CreateObject(BucketName, func(id uint64) (int, any) {
|
||||||
config.ID = portainer.PendingActionID(id)
|
config.ID = portainer.PendingActionID(id)
|
||||||
config.CreatedAt = time.Now().Unix()
|
config.CreatedAt = time.Now().Unix()
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
||||||
func (service *Service) Create(registry *portainer.Registry) error {
|
func (service *Service) Create(registry *portainer.Registry) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
registry.ID = portainer.RegistryID(id)
|
registry.ID = portainer.RegistryID(id)
|
||||||
return int(registry.ID), registry
|
return int(registry.ID), registry
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ type ServiceTx struct {
|
||||||
func (service ServiceTx) Create(registry *portainer.Registry) error {
|
func (service ServiceTx) Create(registry *portainer.Registry) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
registry.ID = portainer.RegistryID(id)
|
registry.ID = portainer.RegistryID(id)
|
||||||
return int(registry.ID), registry
|
return int(registry.ID), registry
|
||||||
},
|
},
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (service *Service) ResourceControlByResourceIDAndType(resourceID string, re
|
||||||
err := service.Connection.GetAll(
|
err := service.Connection.GetAll(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.ResourceControl{},
|
&portainer.ResourceControl{},
|
||||||
func(obj interface{}) (interface{}, error) {
|
func(obj any) (any, error) {
|
||||||
rc, ok := obj.(*portainer.ResourceControl)
|
rc, ok := obj.(*portainer.ResourceControl)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to ResourceControl object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to ResourceControl object")
|
||||||
|
@ -84,7 +84,7 @@ func (service *Service) ResourceControlByResourceIDAndType(resourceID string, re
|
||||||
func (service *Service) Create(resourceControl *portainer.ResourceControl) error {
|
func (service *Service) Create(resourceControl *portainer.ResourceControl) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
resourceControl.ID = portainer.ResourceControlID(id)
|
resourceControl.ID = portainer.ResourceControlID(id)
|
||||||
return int(resourceControl.ID), resourceControl
|
return int(resourceControl.ID), resourceControl
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,7 @@ func (service ServiceTx) ResourceControlByResourceIDAndType(resourceID string, r
|
||||||
err := service.Tx.GetAll(
|
err := service.Tx.GetAll(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.ResourceControl{},
|
&portainer.ResourceControl{},
|
||||||
func(obj interface{}) (interface{}, error) {
|
func(obj any) (any, error) {
|
||||||
rc, ok := obj.(*portainer.ResourceControl)
|
rc, ok := obj.(*portainer.ResourceControl)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to ResourceControl object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to ResourceControl object")
|
||||||
|
@ -55,7 +55,7 @@ func (service ServiceTx) ResourceControlByResourceIDAndType(resourceID string, r
|
||||||
func (service ServiceTx) Create(resourceControl *portainer.ResourceControl) error {
|
func (service ServiceTx) Create(resourceControl *portainer.ResourceControl) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
resourceControl.ID = portainer.ResourceControlID(id)
|
resourceControl.ID = portainer.ResourceControlID(id)
|
||||||
return int(resourceControl.ID), resourceControl
|
return int(resourceControl.ID), resourceControl
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
||||||
func (service *Service) Create(role *portainer.Role) error {
|
func (service *Service) Create(role *portainer.Role) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
role.ID = portainer.RoleID(id)
|
role.ID = portainer.RoleID(id)
|
||||||
return int(role.ID), role
|
return int(role.ID), role
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ type ServiceTx struct {
|
||||||
func (service ServiceTx) Create(role *portainer.Role) error {
|
func (service ServiceTx) Create(role *portainer.Role) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
role.ID = portainer.RoleID(id)
|
role.ID = portainer.RoleID(id)
|
||||||
return int(role.ID), role
|
return int(role.ID), role
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
|
||||||
func (service *Service) Create(tag *portainer.Tag) error {
|
func (service *Service) Create(tag *portainer.Tag) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
tag.ID = portainer.TagID(id)
|
tag.ID = portainer.TagID(id)
|
||||||
return int(tag.ID), tag
|
return int(tag.ID), tag
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,7 +15,7 @@ type ServiceTx struct {
|
||||||
func (service ServiceTx) Create(tag *portainer.Tag) error {
|
func (service ServiceTx) Create(tag *portainer.Tag) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
tag.ID = portainer.TagID(id)
|
tag.ID = portainer.TagID(id)
|
||||||
return int(tag.ID), tag
|
return int(tag.ID), tag
|
||||||
},
|
},
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (service *Service) TeamByName(name string) (*portainer.Team, error) {
|
||||||
func (service *Service) Create(team *portainer.Team) error {
|
func (service *Service) Create(team *portainer.Team) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
team.ID = portainer.TeamID(id)
|
team.ID = portainer.TeamID(id)
|
||||||
return int(team.ID), team
|
return int(team.ID), team
|
||||||
},
|
},
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (service *Service) TeamMembershipsByTeamID(teamID portainer.TeamID) ([]port
|
||||||
func (service *Service) Create(membership *portainer.TeamMembership) error {
|
func (service *Service) Create(membership *portainer.TeamMembership) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
membership.ID = portainer.TeamMembershipID(id)
|
membership.ID = portainer.TeamMembershipID(id)
|
||||||
return int(membership.ID), membership
|
return int(membership.ID), membership
|
||||||
},
|
},
|
||||||
|
@ -84,7 +84,7 @@ func (service *Service) DeleteTeamMembershipByUserID(userID portainer.UserID) er
|
||||||
return service.Connection.DeleteAllObjects(
|
return service.Connection.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
@ -105,7 +105,7 @@ func (service *Service) DeleteTeamMembershipByTeamID(teamID portainer.TeamID) er
|
||||||
return service.Connection.DeleteAllObjects(
|
return service.Connection.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
@ -125,7 +125,7 @@ func (service *Service) DeleteTeamMembershipByTeamIDAndUserID(teamID portainer.T
|
||||||
return service.Connection.DeleteAllObjects(
|
return service.Connection.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (service ServiceTx) TeamMembershipsByTeamID(teamID portainer.TeamID) ([]por
|
||||||
func (service ServiceTx) Create(membership *portainer.TeamMembership) error {
|
func (service ServiceTx) Create(membership *portainer.TeamMembership) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
membership.ID = portainer.TeamMembershipID(id)
|
membership.ID = portainer.TeamMembershipID(id)
|
||||||
return int(membership.ID), membership
|
return int(membership.ID), membership
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@ func (service ServiceTx) DeleteTeamMembershipByUserID(userID portainer.UserID) e
|
||||||
return service.Tx.DeleteAllObjects(
|
return service.Tx.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
@ -76,7 +76,7 @@ func (service ServiceTx) DeleteTeamMembershipByTeamID(teamID portainer.TeamID) e
|
||||||
return service.Tx.DeleteAllObjects(
|
return service.Tx.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
@ -96,7 +96,7 @@ func (service ServiceTx) DeleteTeamMembershipByTeamIDAndUserID(teamID portainer.
|
||||||
return service.Tx.DeleteAllObjects(
|
return service.Tx.DeleteAllObjects(
|
||||||
BucketName,
|
BucketName,
|
||||||
&portainer.TeamMembership{},
|
&portainer.TeamMembership{},
|
||||||
func(obj interface{}) (id int, ok bool) {
|
func(obj any) (id int, ok bool) {
|
||||||
membership, ok := obj.(portainer.TeamMembership)
|
membership, ok := obj.(portainer.TeamMembership)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to TeamMembership object")
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (service ServiceTx) UsersByRole(role portainer.UserRole) ([]portainer.User,
|
||||||
func (service ServiceTx) Create(user *portainer.User) error {
|
func (service ServiceTx) Create(user *portainer.User) error {
|
||||||
return service.Tx.CreateObject(
|
return service.Tx.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
user.ID = portainer.UserID(id)
|
user.ID = portainer.UserID(id)
|
||||||
user.Username = strings.ToLower(user.Username)
|
user.Username = strings.ToLower(user.Username)
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (service *Service) UsersByRole(role portainer.UserRole) ([]portainer.User,
|
||||||
func (service *Service) Create(user *portainer.User) error {
|
func (service *Service) Create(user *portainer.User) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
user.ID = portainer.UserID(id)
|
user.ID = portainer.UserID(id)
|
||||||
user.Username = strings.ToLower(user.Username)
|
user.Username = strings.ToLower(user.Username)
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (service *Service) WebhookByToken(token string) (*portainer.Webhook, error)
|
||||||
func (service *Service) Create(webhook *portainer.Webhook) error {
|
func (service *Service) Create(webhook *portainer.Webhook) error {
|
||||||
return service.Connection.CreateObject(
|
return service.Connection.CreateObject(
|
||||||
BucketName,
|
BucketName,
|
||||||
func(id uint64) (int, interface{}) {
|
func(id uint64) (int, any) {
|
||||||
webhook.ID = portainer.WebhookID(id)
|
webhook.ID = portainer.WebhookID(id)
|
||||||
return int(webhook.ID), webhook
|
return int(webhook.ID), webhook
|
||||||
},
|
},
|
||||||
|
|
|
@ -321,7 +321,7 @@ func migrateDBTestHelper(t *testing.T, srcPath, wantPath string, overrideInstanc
|
||||||
// importJSON reads input JSON and commits it to a portainer datastore.Store.
|
// importJSON reads input JSON and commits it to a portainer datastore.Store.
|
||||||
// Errors are logged with the testing package.
|
// Errors are logged with the testing package.
|
||||||
func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
objects := make(map[string]interface{})
|
objects := make(map[string]any)
|
||||||
|
|
||||||
// Parse json into map of objects.
|
// Parse json into map of objects.
|
||||||
d := json.NewDecoder(r)
|
d := json.NewDecoder(r)
|
||||||
|
@ -337,9 +337,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
for k, v := range objects {
|
for k, v := range objects {
|
||||||
switch k {
|
switch k {
|
||||||
case "version":
|
case "version":
|
||||||
versions, ok := v.(map[string]interface{})
|
versions, ok := v.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed casting %s to map[string]interface{}", k)
|
t.Logf("failed casting %s to map[string]any", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New format db
|
// New format db
|
||||||
|
@ -404,9 +404,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "dockerhub":
|
case "dockerhub":
|
||||||
obj, ok := v.([]interface{})
|
obj, ok := v.([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to cast %s to []interface{}", k)
|
t.Logf("failed to cast %s to []any", k)
|
||||||
}
|
}
|
||||||
err := con.CreateObjectWithStringId(
|
err := con.CreateObjectWithStringId(
|
||||||
k,
|
k,
|
||||||
|
@ -418,9 +418,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "ssl":
|
case "ssl":
|
||||||
obj, ok := v.(map[string]interface{})
|
obj, ok := v.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to case %s to map[string]interface{}", k)
|
t.Logf("failed to case %s to map[string]any", k)
|
||||||
}
|
}
|
||||||
err := con.CreateObjectWithStringId(
|
err := con.CreateObjectWithStringId(
|
||||||
k,
|
k,
|
||||||
|
@ -432,9 +432,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "settings":
|
case "settings":
|
||||||
obj, ok := v.(map[string]interface{})
|
obj, ok := v.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to case %s to map[string]interface{}", k)
|
t.Logf("failed to case %s to map[string]any", k)
|
||||||
}
|
}
|
||||||
err := con.CreateObjectWithStringId(
|
err := con.CreateObjectWithStringId(
|
||||||
k,
|
k,
|
||||||
|
@ -446,9 +446,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "tunnel_server":
|
case "tunnel_server":
|
||||||
obj, ok := v.(map[string]interface{})
|
obj, ok := v.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to case %s to map[string]interface{}", k)
|
t.Logf("failed to case %s to map[string]any", k)
|
||||||
}
|
}
|
||||||
err := con.CreateObjectWithStringId(
|
err := con.CreateObjectWithStringId(
|
||||||
k,
|
k,
|
||||||
|
@ -462,18 +462,18 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
|
||||||
continue
|
continue
|
||||||
|
|
||||||
default:
|
default:
|
||||||
objlist, ok := v.([]interface{})
|
objlist, ok := v.([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to cast %s to []interface{}", k)
|
t.Logf("failed to cast %s to []any", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, obj := range objlist {
|
for _, obj := range objlist {
|
||||||
value, ok := obj.(map[string]interface{})
|
value, ok := obj.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Logf("failed to cast %v to map[string]interface{}", obj)
|
t.Logf("failed to cast %v to map[string]any", obj)
|
||||||
} else {
|
} else {
|
||||||
var ok bool
|
var ok bool
|
||||||
var id interface{}
|
var id any
|
||||||
switch k {
|
switch k {
|
||||||
case "endpoint_relations":
|
case "endpoint_relations":
|
||||||
// TODO: need to make into an int, then do that weird
|
// TODO: need to make into an int, then do that weird
|
||||||
|
|
|
@ -12,13 +12,13 @@ const dummyLogoURL = "example.com"
|
||||||
|
|
||||||
// initTestingDBConn creates a settings service with raw database DB connection
|
// initTestingDBConn creates a settings service with raw database DB connection
|
||||||
// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg
|
// for unit testing usage only since using NewStore will cause cycle import inside migrator pkg
|
||||||
func initTestingSettingsService(dbConn portainer.Connection, preSetObj map[string]interface{}) error {
|
func initTestingSettingsService(dbConn portainer.Connection, preSetObj map[string]any) error {
|
||||||
//insert a obj
|
//insert a obj
|
||||||
return dbConn.UpdateObject("settings", []byte("SETTINGS"), preSetObj)
|
return dbConn.UpdateObject("settings", []byte("SETTINGS"), preSetObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup(store *Store) error {
|
func setup(store *Store) error {
|
||||||
dummySettingsObj := map[string]interface{}{
|
dummySettingsObj := map[string]any{
|
||||||
"LogoURL": dummyLogoURL,
|
"LogoURL": dummyLogoURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ func migrationError(err error, context string) error {
|
||||||
return errors.Wrap(err, "failed in "+context)
|
return errors.Wrap(err, "failed in "+context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFunctionName(i interface{}) string {
|
func GetFunctionName(i any) string {
|
||||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ type storeExport struct {
|
||||||
User []portainer.User `json:"users,omitempty"`
|
User []portainer.User `json:"users,omitempty"`
|
||||||
Version models.Version `json:"version,omitempty"`
|
Version models.Version `json:"version,omitempty"`
|
||||||
Webhook []portainer.Webhook `json:"webhooks,omitempty"`
|
Webhook []portainer.Webhook `json:"webhooks,omitempty"`
|
||||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
Metadata map[string]any `json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *Store) Export(filename string) (err error) {
|
func (store *Store) Export(filename string) (err error) {
|
||||||
|
|
|
@ -227,10 +227,10 @@ func (manager *SwarmStackManager) updateDockerCLIConfiguration(configPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
if config["HttpHeaders"] == nil {
|
if config["HttpHeaders"] == nil {
|
||||||
config["HttpHeaders"] = make(map[string]interface{})
|
config["HttpHeaders"] = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
headersObject := config["HttpHeaders"].(map[string]interface{})
|
headersObject := config["HttpHeaders"].(map[string]any)
|
||||||
headersObject["X-PortainerAgent-ManagerOperation"] = "1"
|
headersObject["X-PortainerAgent-ManagerOperation"] = "1"
|
||||||
headersObject["X-PortainerAgent-Signature"] = signature
|
headersObject["X-PortainerAgent-Signature"] = signature
|
||||||
headersObject["X-PortainerAgent-PublicKey"] = manager.signatureService.EncodedPublicKey()
|
headersObject["X-PortainerAgent-PublicKey"] = manager.signatureService.EncodedPublicKey()
|
||||||
|
@ -238,12 +238,12 @@ func (manager *SwarmStackManager) updateDockerCLIConfiguration(configPath string
|
||||||
return manager.fileService.WriteJSONToFile(configFilePath, config)
|
return manager.fileService.WriteJSONToFile(configFilePath, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (map[string]interface{}, error) {
|
func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (map[string]any, error) {
|
||||||
var config map[string]interface{}
|
var config map[string]any
|
||||||
|
|
||||||
raw, err := manager.fileService.GetFileContent(path, "")
|
raw, err := manager.fileService.GetFileContent(path, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return make(map[string]interface{}), nil
|
return make(map[string]any), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(raw, &config)
|
err = json.Unmarshal(raw, &config)
|
||||||
|
|
|
@ -599,7 +599,7 @@ func (service *Service) Rename(oldPath, newPath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJSONToFile writes JSON to the specified file.
|
// WriteJSONToFile writes JSON to the specified file.
|
||||||
func (service *Service) WriteJSONToFile(path string, content interface{}) error {
|
func (service *Service) WriteJSONToFile(path string, content any) error {
|
||||||
jsonContent, err := json.Marshal(content)
|
jsonContent, err := json.Marshal(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func (service *Service) enableDeviceFeatures(configuration portainer.OpenAMTConfiguration, deviceGUID string, features portainer.OpenAMTDeviceEnabledFeatures) error {
|
func (service *Service) enableDeviceFeatures(configuration portainer.OpenAMTConfiguration, deviceGUID string, features portainer.OpenAMTDeviceEnabledFeatures) error {
|
||||||
url := fmt.Sprintf("https://%s/mps/api/v1/amt/features/%s", configuration.MPSServer, deviceGUID)
|
url := fmt.Sprintf("https://%s/mps/api/v1/amt/features/%s", configuration.MPSServer, deviceGUID)
|
||||||
|
|
||||||
payload := map[string]interface{}{
|
payload := map[string]any{
|
||||||
"enableSOL": features.SOL,
|
"enableSOL": features.SOL,
|
||||||
"enableIDER": features.IDER,
|
"enableIDER": features.IDER,
|
||||||
"enableKVM": features.KVM,
|
"enableKVM": features.KVM,
|
||||||
|
|
|
@ -107,7 +107,7 @@ func TestCreateWithInvalidPayload(t *testing.T) {
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Name string
|
Name string
|
||||||
Payload interface{}
|
Payload any
|
||||||
ExpectedStatusCode int
|
ExpectedStatusCode int
|
||||||
Method string
|
Method string
|
||||||
}{
|
}{
|
||||||
|
|
|
@ -47,12 +47,12 @@ func (transport *Transport) createAzureRequestContext(request *http.Request) (*a
|
||||||
return context, nil
|
return context, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decorateObject(object map[string]interface{}, resourceControl *portainer.ResourceControl) map[string]interface{} {
|
func decorateObject(object map[string]any, resourceControl *portainer.ResourceControl) map[string]any {
|
||||||
if object["Portainer"] == nil {
|
if object["Portainer"] == nil {
|
||||||
object["Portainer"] = make(map[string]interface{})
|
object["Portainer"] = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
portainerMetadata := object["Portainer"].(map[string]interface{})
|
portainerMetadata := object["Portainer"].(map[string]any)
|
||||||
portainerMetadata["ResourceControl"] = resourceControl
|
portainerMetadata["ResourceControl"] = resourceControl
|
||||||
|
|
||||||
return object
|
return object
|
||||||
|
@ -88,18 +88,18 @@ func (transport *Transport) userCanDeleteContainerGroup(request *http.Request, c
|
||||||
return authorization.UserCanAccessResource(context.userID, context.userTeamIDs, resourceControl)
|
return authorization.UserCanAccessResource(context.userID, context.userTeamIDs, resourceControl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) decorateContainerGroups(containerGroups []interface{}, context *azureRequestContext) []interface{} {
|
func (transport *Transport) decorateContainerGroups(containerGroups []any, context *azureRequestContext) []any {
|
||||||
decoratedContainerGroups := make([]interface{}, 0)
|
decoratedContainerGroups := make([]any, 0)
|
||||||
|
|
||||||
for _, containerGroup := range containerGroups {
|
for _, containerGroup := range containerGroups {
|
||||||
containerGroup = transport.decorateContainerGroup(containerGroup.(map[string]interface{}), context)
|
containerGroup = transport.decorateContainerGroup(containerGroup.(map[string]any), context)
|
||||||
decoratedContainerGroups = append(decoratedContainerGroups, containerGroup)
|
decoratedContainerGroups = append(decoratedContainerGroups, containerGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
return decoratedContainerGroups
|
return decoratedContainerGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) decorateContainerGroup(containerGroup map[string]interface{}, context *azureRequestContext) map[string]interface{} {
|
func (transport *Transport) decorateContainerGroup(containerGroup map[string]any, context *azureRequestContext) map[string]any {
|
||||||
containerGroupId, ok := containerGroup["id"].(string)
|
containerGroupId, ok := containerGroup["id"].(string)
|
||||||
if ok {
|
if ok {
|
||||||
resourceControl := transport.findResourceControl(containerGroupId, context)
|
resourceControl := transport.findResourceControl(containerGroupId, context)
|
||||||
|
@ -113,13 +113,13 @@ func (transport *Transport) decorateContainerGroup(containerGroup map[string]int
|
||||||
return containerGroup
|
return containerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) filterContainerGroups(containerGroups []interface{}, context *azureRequestContext) []interface{} {
|
func (transport *Transport) filterContainerGroups(containerGroups []any, context *azureRequestContext) []any {
|
||||||
filteredContainerGroups := make([]interface{}, 0)
|
filteredContainerGroups := make([]any, 0)
|
||||||
|
|
||||||
for _, containerGroup := range containerGroups {
|
for _, containerGroup := range containerGroups {
|
||||||
userCanAccessResource := false
|
userCanAccessResource := false
|
||||||
containerGroup := containerGroup.(map[string]interface{})
|
containerGroup := containerGroup.(map[string]any)
|
||||||
portainerObject, ok := containerGroup["Portainer"].(map[string]interface{})
|
portainerObject, ok := containerGroup["Portainer"].(map[string]any)
|
||||||
if ok {
|
if ok {
|
||||||
resourceControl, ok := portainerObject["ResourceControl"].(*portainer.ResourceControl)
|
resourceControl, ok := portainerObject["ResourceControl"].(*portainer.ResourceControl)
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -135,7 +135,7 @@ func (transport *Transport) filterContainerGroups(containerGroups []interface{},
|
||||||
return filteredContainerGroups
|
return filteredContainerGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) removeResourceControl(containerGroup map[string]interface{}, context *azureRequestContext) error {
|
func (transport *Transport) removeResourceControl(containerGroup map[string]any, context *azureRequestContext) error {
|
||||||
containerGroupID, ok := containerGroup["id"].(string)
|
containerGroupID, ok := containerGroup["id"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Debug().Msg("missing ID in container group")
|
log.Debug().Msg("missing ID in container group")
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (transport *Transport) proxyContainerGroupsGetRequest(request *http.Request
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
value, ok := responseObject["value"].([]interface{})
|
value, ok := responseObject["value"].([]any)
|
||||||
if ok {
|
if ok {
|
||||||
context, err := transport.createAzureRequestContext(request)
|
context, err := transport.createAzureRequestContext(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -22,7 +22,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
resourceLabelsObjectSelector func(map[string]interface{}) map[string]interface{}
|
resourceLabelsObjectSelector func(map[string]any) map[string]any
|
||||||
resourceOperationParameters struct {
|
resourceOperationParameters struct {
|
||||||
resourceIdentifierAttribute string
|
resourceIdentifierAttribute string
|
||||||
resourceType portainer.ResourceControlType
|
resourceType portainer.ResourceControlType
|
||||||
|
@ -47,7 +47,7 @@ func getUniqueElements(items string) []string {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject map[string]interface{}, resourceID string, resourceType portainer.ResourceControlType) (*portainer.ResourceControl, error) {
|
func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject map[string]any, resourceID string, resourceType portainer.ResourceControlType) (*portainer.ResourceControl, error) {
|
||||||
if labelsObject[resourceLabelForPortainerPublicResourceControl] != nil {
|
if labelsObject[resourceLabelForPortainerPublicResourceControl] != nil {
|
||||||
resourceControl := authorization.NewPublicResourceControl(resourceID, resourceType)
|
resourceControl := authorization.NewPublicResourceControl(resourceID, resourceType)
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func (transport *Transport) getInheritedResourceControlFromServiceOrStack(resour
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) applyAccessControlOnResource(parameters *resourceOperationParameters, responseObject map[string]interface{}, response *http.Response, executor *operationExecutor) error {
|
func (transport *Transport) applyAccessControlOnResource(parameters *resourceOperationParameters, responseObject map[string]any, response *http.Response, executor *operationExecutor) error {
|
||||||
if responseObject[parameters.resourceIdentifierAttribute] == nil {
|
if responseObject[parameters.resourceIdentifierAttribute] == nil {
|
||||||
log.Warn().
|
log.Warn().
|
||||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||||
|
@ -194,7 +194,7 @@ func (transport *Transport) applyAccessControlOnResource(parameters *resourceOpe
|
||||||
return utils.RewriteAccessDeniedResponse(response)
|
return utils.RewriteAccessDeniedResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) applyAccessControlOnResourceList(parameters *resourceOperationParameters, resourceData []interface{}, executor *operationExecutor) ([]interface{}, error) {
|
func (transport *Transport) applyAccessControlOnResourceList(parameters *resourceOperationParameters, resourceData []any, executor *operationExecutor) ([]any, error) {
|
||||||
if executor.operationContext.isAdmin {
|
if executor.operationContext.isAdmin {
|
||||||
return transport.decorateResourceList(parameters, resourceData, executor.operationContext.resourceControls)
|
return transport.decorateResourceList(parameters, resourceData, executor.operationContext.resourceControls)
|
||||||
}
|
}
|
||||||
|
@ -202,11 +202,11 @@ func (transport *Transport) applyAccessControlOnResourceList(parameters *resourc
|
||||||
return transport.filterResourceList(parameters, resourceData, executor.operationContext)
|
return transport.filterResourceList(parameters, resourceData, executor.operationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) decorateResourceList(parameters *resourceOperationParameters, resourceData []interface{}, resourceControls []portainer.ResourceControl) ([]interface{}, error) {
|
func (transport *Transport) decorateResourceList(parameters *resourceOperationParameters, resourceData []any, resourceControls []portainer.ResourceControl) ([]any, error) {
|
||||||
decoratedResourceData := make([]interface{}, 0)
|
decoratedResourceData := make([]any, 0)
|
||||||
|
|
||||||
for _, resource := range resourceData {
|
for _, resource := range resourceData {
|
||||||
resourceObject := resource.(map[string]interface{})
|
resourceObject := resource.(map[string]any)
|
||||||
|
|
||||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||||
log.Warn().
|
log.Warn().
|
||||||
|
@ -244,11 +244,11 @@ func (transport *Transport) decorateResourceList(parameters *resourceOperationPa
|
||||||
return decoratedResourceData, nil
|
return decoratedResourceData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) filterResourceList(parameters *resourceOperationParameters, resourceData []interface{}, context *restrictedDockerOperationContext) ([]interface{}, error) {
|
func (transport *Transport) filterResourceList(parameters *resourceOperationParameters, resourceData []any, context *restrictedDockerOperationContext) ([]any, error) {
|
||||||
filteredResourceData := make([]interface{}, 0)
|
filteredResourceData := make([]any, 0)
|
||||||
|
|
||||||
for _, resource := range resourceData {
|
for _, resource := range resourceData {
|
||||||
resourceObject := resource.(map[string]interface{})
|
resourceObject := resource.(map[string]any)
|
||||||
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
|
||||||
log.Warn().
|
log.Warn().
|
||||||
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
|
||||||
|
@ -292,7 +292,7 @@ func (transport *Transport) filterResourceList(parameters *resourceOperationPara
|
||||||
return filteredResourceData, nil
|
return filteredResourceData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) findResourceControl(resourceIdentifier string, resourceType portainer.ResourceControlType, resourceLabelsObject map[string]interface{}, resourceControls []portainer.ResourceControl) (*portainer.ResourceControl, error) {
|
func (transport *Transport) findResourceControl(resourceIdentifier string, resourceType portainer.ResourceControlType, resourceLabelsObject map[string]any, resourceControls []portainer.ResourceControl) (*portainer.ResourceControl, error) {
|
||||||
resourceControl := authorization.GetResourceControlByResourceIDAndType(resourceIdentifier, resourceType, resourceControls)
|
resourceControl := authorization.GetResourceControlByResourceIDAndType(resourceIdentifier, resourceType, resourceControls)
|
||||||
if resourceControl != nil {
|
if resourceControl != nil {
|
||||||
return resourceControl, nil
|
return resourceControl, nil
|
||||||
|
@ -350,12 +350,12 @@ func getStackResourceIDFromLabels(resourceLabelsObject map[string]string, endpoi
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func decorateObject(object map[string]interface{}, resourceControl *portainer.ResourceControl) map[string]interface{} {
|
func decorateObject(object map[string]any, resourceControl *portainer.ResourceControl) map[string]any {
|
||||||
if object["Portainer"] == nil {
|
if object["Portainer"] == nil {
|
||||||
object["Portainer"] = make(map[string]interface{})
|
object["Portainer"] = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
portainerMetadata := object["Portainer"].(map[string]interface{})
|
portainerMetadata := object["Portainer"].(map[string]any)
|
||||||
portainerMetadata["ResourceControl"] = resourceControl
|
portainerMetadata["ResourceControl"] = resourceControl
|
||||||
|
|
||||||
return object
|
return object
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (transport *Transport) configInspectOperation(response *http.Response, exec
|
||||||
// API schema references:
|
// API schema references:
|
||||||
// https://docs.docker.com/engine/api/v1.37/#operation/ConfigList
|
// https://docs.docker.com/engine/api/v1.37/#operation/ConfigList
|
||||||
// https://docs.docker.com/engine/api/v1.37/#operation/ConfigInspect
|
// https://docs.docker.com/engine/api/v1.37/#operation/ConfigInspect
|
||||||
func selectorConfigLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorConfigLabels(responseObject map[string]any) map[string]any {
|
||||||
if secretSpec := utils.GetJSONObject(responseObject, "Spec"); secretSpec != nil {
|
if secretSpec := utils.GetJSONObject(responseObject, "Spec"); secretSpec != nil {
|
||||||
return utils.GetJSONObject(secretSpec, "Labels")
|
return utils.GetJSONObject(secretSpec, "Labels")
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (transport *Transport) containerInspectOperation(response *http.Response, e
|
||||||
// This selector is specific to the containerInspect Docker operation.
|
// This selector is specific to the containerInspect Docker operation.
|
||||||
// Labels are available under the "Config.Labels" property.
|
// Labels are available under the "Config.Labels" property.
|
||||||
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/ContainerInspect
|
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/ContainerInspect
|
||||||
func selectorContainerLabelsFromContainerInspectOperation(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorContainerLabelsFromContainerInspectOperation(responseObject map[string]any) map[string]any {
|
||||||
containerConfigObject := utils.GetJSONObject(responseObject, "Config")
|
containerConfigObject := utils.GetJSONObject(responseObject, "Config")
|
||||||
if containerConfigObject != nil {
|
if containerConfigObject != nil {
|
||||||
containerLabelsObject := utils.GetJSONObject(containerConfigObject, "Labels")
|
containerLabelsObject := utils.GetJSONObject(containerConfigObject, "Labels")
|
||||||
|
@ -115,18 +115,18 @@ func selectorContainerLabelsFromContainerInspectOperation(responseObject map[str
|
||||||
// This selector is specific to the containerList Docker operation.
|
// This selector is specific to the containerList Docker operation.
|
||||||
// Labels are available under the "Labels" property.
|
// Labels are available under the "Labels" property.
|
||||||
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/ContainerList
|
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/ContainerList
|
||||||
func selectorContainerLabelsFromContainerListOperation(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorContainerLabelsFromContainerListOperation(responseObject map[string]any) map[string]any {
|
||||||
containerLabelsObject := utils.GetJSONObject(responseObject, "Labels")
|
containerLabelsObject := utils.GetJSONObject(responseObject, "Labels")
|
||||||
return containerLabelsObject
|
return containerLabelsObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterContainersWithLabels loops through a list of containers, and filters containers that do not contains
|
// filterContainersWithLabels loops through a list of containers, and filters containers that do not contains
|
||||||
// any labels in the labels black list.
|
// any labels in the labels black list.
|
||||||
func filterContainersWithBlackListedLabels(containerData []interface{}, labelBlackList []portainer.Pair) ([]interface{}, error) {
|
func filterContainersWithBlackListedLabels(containerData []any, labelBlackList []portainer.Pair) ([]any, error) {
|
||||||
filteredContainerData := make([]interface{}, 0)
|
filteredContainerData := make([]any, 0)
|
||||||
|
|
||||||
for _, container := range containerData {
|
for _, container := range containerData {
|
||||||
containerObject := container.(map[string]interface{})
|
containerObject := container.(map[string]any)
|
||||||
|
|
||||||
containerLabels := selectorContainerLabelsFromContainerListOperation(containerObject)
|
containerLabels := selectorContainerLabelsFromContainerListOperation(containerObject)
|
||||||
if containerLabels != nil {
|
if containerLabels != nil {
|
||||||
|
@ -141,7 +141,7 @@ func filterContainersWithBlackListedLabels(containerData []interface{}, labelBla
|
||||||
return filteredContainerData, nil
|
return filteredContainerData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func containerHasBlackListedLabel(containerLabels map[string]interface{}, labelBlackList []portainer.Pair) bool {
|
func containerHasBlackListedLabel(containerLabels map[string]any, labelBlackList []portainer.Pair) bool {
|
||||||
for key, value := range containerLabels {
|
for key, value := range containerLabels {
|
||||||
labelName := key
|
labelName := key
|
||||||
labelValue := value.(string)
|
labelValue := value.(string)
|
||||||
|
@ -159,13 +159,13 @@ func containerHasBlackListedLabel(containerLabels map[string]interface{}, labelB
|
||||||
func (transport *Transport) decorateContainerCreationOperation(request *http.Request, resourceIdentifierAttribute string, resourceType portainer.ResourceControlType) (*http.Response, error) {
|
func (transport *Transport) decorateContainerCreationOperation(request *http.Request, resourceIdentifierAttribute string, resourceType portainer.ResourceControlType) (*http.Response, error) {
|
||||||
type PartialContainer struct {
|
type PartialContainer struct {
|
||||||
HostConfig struct {
|
HostConfig struct {
|
||||||
Privileged bool `json:"Privileged"`
|
Privileged bool `json:"Privileged"`
|
||||||
PidMode string `json:"PidMode"`
|
PidMode string `json:"PidMode"`
|
||||||
Devices []interface{} `json:"Devices"`
|
Devices []any `json:"Devices"`
|
||||||
Sysctls map[string]interface{} `json:"Sysctls"`
|
Sysctls map[string]any `json:"Sysctls"`
|
||||||
CapAdd []string `json:"CapAdd"`
|
CapAdd []string `json:"CapAdd"`
|
||||||
CapDrop []string `json:"CapDrop"`
|
CapDrop []string `json:"CapDrop"`
|
||||||
Binds []string `json:"Binds"`
|
Binds []string `json:"Binds"`
|
||||||
} `json:"HostConfig"`
|
} `json:"HostConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (transport *Transport) networkInspectOperation(response *http.Response, exe
|
||||||
|
|
||||||
// findSystemNetworkResourceControl will check if the network object is a system network
|
// findSystemNetworkResourceControl will check if the network object is a system network
|
||||||
// and will return a system resource control if that's the case.
|
// and will return a system resource control if that's the case.
|
||||||
func findSystemNetworkResourceControl(networkObject map[string]interface{}) *portainer.ResourceControl {
|
func findSystemNetworkResourceControl(networkObject map[string]any) *portainer.ResourceControl {
|
||||||
if networkObject[networkObjectName] == nil {
|
if networkObject[networkObjectName] == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,6 @@ func findSystemNetworkResourceControl(networkObject map[string]interface{}) *por
|
||||||
// API schema references:
|
// API schema references:
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/NetworkInspect
|
// https://docs.docker.com/engine/api/v1.28/#operation/NetworkInspect
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/NetworkList
|
// https://docs.docker.com/engine/api/v1.28/#operation/NetworkList
|
||||||
func selectorNetworkLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorNetworkLabels(responseObject map[string]any) map[string]any {
|
||||||
return utils.GetJSONObject(responseObject, "Labels")
|
return utils.GetJSONObject(responseObject, "Labels")
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ func init() {
|
||||||
portainerContainerId, _ = os.Hostname()
|
portainerContainerId, _ = os.Hostname()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) applyPortainerContainers(resources []interface{}) ([]interface{}, error) {
|
func (transport *Transport) applyPortainerContainers(resources []any) ([]any, error) {
|
||||||
decoratedResourceData := make([]interface{}, 0)
|
decoratedResourceData := make([]any, 0)
|
||||||
for _, resource := range resources {
|
for _, resource := range resources {
|
||||||
responseObject, ok := resource.(map[string]interface{})
|
responseObject, ok := resource.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
decoratedResourceData = append(decoratedResourceData, resource)
|
decoratedResourceData = append(decoratedResourceData, resource)
|
||||||
continue
|
continue
|
||||||
|
@ -30,7 +30,7 @@ func (transport *Transport) applyPortainerContainers(resources []interface{}) ([
|
||||||
return decoratedResourceData, nil
|
return decoratedResourceData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) applyPortainerContainer(resourceObject map[string]interface{}) (map[string]interface{}, error) {
|
func (transport *Transport) applyPortainerContainer(resourceObject map[string]any) (map[string]any, error) {
|
||||||
resourceId, ok := resourceObject["Id"].(string)
|
resourceId, ok := resourceObject["Id"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return resourceObject, nil
|
return resourceObject, nil
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (transport *Transport) secretInspectOperation(response *http.Response, exec
|
||||||
// API schema references:
|
// API schema references:
|
||||||
// https://docs.docker.com/engine/api/v1.37/#operation/SecretList
|
// https://docs.docker.com/engine/api/v1.37/#operation/SecretList
|
||||||
// https://docs.docker.com/engine/api/v1.37/#operation/SecretInspect
|
// https://docs.docker.com/engine/api/v1.37/#operation/SecretInspect
|
||||||
func selectorSecretLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorSecretLabels(responseObject map[string]any) map[string]any {
|
||||||
secretSpec := utils.GetJSONObject(responseObject, "Spec")
|
secretSpec := utils.GetJSONObject(responseObject, "Spec")
|
||||||
if secretSpec != nil {
|
if secretSpec != nil {
|
||||||
secretLabelsObject := utils.GetJSONObject(secretSpec, "Labels")
|
secretLabelsObject := utils.GetJSONObject(secretSpec, "Labels")
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (transport *Transport) serviceInspectOperation(response *http.Response, exe
|
||||||
// API schema references:
|
// API schema references:
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/ServiceInspect
|
// https://docs.docker.com/engine/api/v1.28/#operation/ServiceInspect
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/ServiceList
|
// https://docs.docker.com/engine/api/v1.28/#operation/ServiceList
|
||||||
func selectorServiceLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorServiceLabels(responseObject map[string]any) map[string]any {
|
||||||
serviceSpecObject := utils.GetJSONObject(responseObject, "Spec")
|
serviceSpecObject := utils.GetJSONObject(responseObject, "Spec")
|
||||||
if serviceSpecObject != nil {
|
if serviceSpecObject != nil {
|
||||||
return utils.GetJSONObject(serviceSpecObject, "Labels")
|
return utils.GetJSONObject(serviceSpecObject, "Labels")
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (transport *Transport) taskListOperation(response *http.Response, executor
|
||||||
// selectorServiceLabels retrieve the labels object associated to the task object.
|
// selectorServiceLabels retrieve the labels object associated to the task object.
|
||||||
// Labels are available under the "Spec.ContainerSpec.Labels" property.
|
// Labels are available under the "Spec.ContainerSpec.Labels" property.
|
||||||
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/TaskList
|
// API schema reference: https://docs.docker.com/engine/api/v1.28/#operation/TaskList
|
||||||
func selectorTaskLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorTaskLabels(responseObject map[string]any) map[string]any {
|
||||||
taskSpecObject := utils.GetJSONObject(responseObject, "Spec")
|
taskSpecObject := utils.GetJSONObject(responseObject, "Spec")
|
||||||
if taskSpecObject != nil {
|
if taskSpecObject != nil {
|
||||||
containerSpecObject := utils.GetJSONObject(taskSpecObject, "ContainerSpec")
|
containerSpecObject := utils.GetJSONObject(taskSpecObject, "ContainerSpec")
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (transport *Transport) volumeListOperation(response *http.Response, executo
|
||||||
|
|
||||||
// The "Volumes" field contains the list of volumes as an array of JSON objects
|
// The "Volumes" field contains the list of volumes as an array of JSON objects
|
||||||
if responseObject["Volumes"] != nil {
|
if responseObject["Volumes"] != nil {
|
||||||
volumeData := responseObject["Volumes"].([]interface{})
|
volumeData := responseObject["Volumes"].([]any)
|
||||||
|
|
||||||
if transport.snapshotService != nil {
|
if transport.snapshotService != nil {
|
||||||
// Filling snapshot data can improve the performance of getVolumeResourceID
|
// Filling snapshot data can improve the performance of getVolumeResourceID
|
||||||
|
@ -57,7 +57,7 @@ func (transport *Transport) volumeListOperation(response *http.Response, executo
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, volumeObject := range volumeData {
|
for _, volumeObject := range volumeData {
|
||||||
volume := volumeObject.(map[string]interface{})
|
volume := volumeObject.(map[string]any)
|
||||||
|
|
||||||
if err := transport.decorateVolumeResponseWithResourceID(volume); err != nil {
|
if err := transport.decorateVolumeResponseWithResourceID(volume); err != nil {
|
||||||
return fmt.Errorf("failed decorating volume response: %w", err)
|
return fmt.Errorf("failed decorating volume response: %w", err)
|
||||||
|
@ -105,7 +105,7 @@ func (transport *Transport) volumeInspectOperation(response *http.Response, exec
|
||||||
return transport.applyAccessControlOnResource(resourceOperationParameters, responseObject, response, executor)
|
return transport.applyAccessControlOnResource(resourceOperationParameters, responseObject, response, executor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject map[string]interface{}) error {
|
func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject map[string]any) error {
|
||||||
if responseObject["Name"] == nil {
|
if responseObject["Name"] == nil {
|
||||||
return errors.New("missing identifier in Docker resource detail response")
|
return errors.New("missing identifier in Docker resource detail response")
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject
|
||||||
// API schema references:
|
// API schema references:
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/VolumeInspect
|
// https://docs.docker.com/engine/api/v1.28/#operation/VolumeInspect
|
||||||
// https://docs.docker.com/engine/api/v1.28/#operation/VolumeList
|
// https://docs.docker.com/engine/api/v1.28/#operation/VolumeList
|
||||||
func selectorVolumeLabels(responseObject map[string]interface{}) map[string]interface{} {
|
func selectorVolumeLabels(responseObject map[string]any) map[string]any {
|
||||||
return utils.GetJSONObject(responseObject, "Labels")
|
return utils.GetJSONObject(responseObject, "Labels")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,25 +13,25 @@ import (
|
||||||
|
|
||||||
// GetJSONObject will extract an object from a specific property of another JSON object.
|
// GetJSONObject will extract an object from a specific property of another JSON object.
|
||||||
// Returns nil if nothing is associated to the specified key.
|
// Returns nil if nothing is associated to the specified key.
|
||||||
func GetJSONObject(jsonObject map[string]interface{}, property string) map[string]interface{} {
|
func GetJSONObject(jsonObject map[string]any, property string) map[string]any {
|
||||||
object := jsonObject[property]
|
object := jsonObject[property]
|
||||||
if object != nil {
|
if object != nil {
|
||||||
return object.(map[string]interface{})
|
return object.(map[string]any)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArrayObject will extract an array from a specific property of another JSON object.
|
// GetArrayObject will extract an array from a specific property of another JSON object.
|
||||||
// Returns nil if nothing is associated to the specified key.
|
// Returns nil if nothing is associated to the specified key.
|
||||||
func GetArrayObject(jsonObject map[string]interface{}, property string) []interface{} {
|
func GetArrayObject(jsonObject map[string]any, property string) []any {
|
||||||
object := jsonObject[property]
|
object := jsonObject[property]
|
||||||
if object != nil {
|
if object != nil {
|
||||||
return object.([]interface{})
|
return object.([]any)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{}, error) {
|
func getBody(body io.ReadCloser, contentType string, isGzip bool) (any, error) {
|
||||||
if body == nil {
|
if body == nil {
|
||||||
return nil, errors.New("unable to parse response: empty response body")
|
return nil, errors.New("unable to parse response: empty response body")
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
|
||||||
|
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
var data interface{}
|
var data any
|
||||||
err := unmarshal(contentType, reader, &data)
|
err := unmarshal(contentType, reader, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -58,7 +58,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshal(contentType string, data interface{}) ([]byte, error) {
|
func marshal(contentType string, data any) ([]byte, error) {
|
||||||
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
||||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -75,7 +75,7 @@ func marshal(contentType string, data interface{}) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("content type is not supported for marshaling: %s", contentType)
|
return nil, fmt.Errorf("content type is not supported for marshaling: %s", contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshal(contentType string, body io.Reader, returnBody interface{}) error {
|
func unmarshal(contentType string, body io.Reader, returnBody any) error {
|
||||||
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
||||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,13 +12,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetResponseAsJSONObject returns the response content as a generic JSON object
|
// GetResponseAsJSONObject returns the response content as a generic JSON object
|
||||||
func GetResponseAsJSONObject(response *http.Response) (map[string]interface{}, error) {
|
func GetResponseAsJSONObject(response *http.Response) (map[string]any, error) {
|
||||||
responseData, err := getResponseBody(response)
|
responseData, err := getResponseBody(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
responseObject, ok := responseData.(map[string]interface{})
|
responseObject, ok := responseData.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func GetResponseAsJSONObject(response *http.Response) (map[string]interface{}, e
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResponseAsJSONArray returns the response content as an array of generic JSON object
|
// GetResponseAsJSONArray returns the response content as an array of generic JSON object
|
||||||
func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
func GetResponseAsJSONArray(response *http.Response) ([]any, error) {
|
||||||
responseData, err := getResponseBody(response)
|
responseData, err := getResponseBody(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -36,9 +36,9 @@ func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch responseObject := responseData.(type) {
|
switch responseObject := responseData.(type) {
|
||||||
case []interface{}:
|
case []any:
|
||||||
return responseObject, nil
|
return responseObject, nil
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
if responseObject["message"] != nil {
|
if responseObject["message"] != nil {
|
||||||
return nil, errors.New(responseObject["message"].(string))
|
return nil, errors.New(responseObject["message"].(string))
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func RewriteAccessDeniedResponse(response *http.Response) error {
|
||||||
|
|
||||||
// RewriteResponse will replace the existing response body and status code with the one specified
|
// RewriteResponse will replace the existing response body and status code with the one specified
|
||||||
// in parameters
|
// in parameters
|
||||||
func RewriteResponse(response *http.Response, newResponseData interface{}, statusCode int) error {
|
func RewriteResponse(response *http.Response, newResponseData any, statusCode int) error {
|
||||||
data, err := marshal(getContentType(response), newResponseData)
|
data, err := marshal(getContentType(response), newResponseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -96,7 +96,7 @@ func RewriteResponse(response *http.Response, newResponseData interface{}, statu
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResponseBody(response *http.Response) (interface{}, error) {
|
func getResponseBody(response *http.Response) (any, error) {
|
||||||
isGzip := response.Header.Get("Content-Encoding") == "gzip"
|
isGzip := response.Header.Get("Content-Encoding") == "gzip"
|
||||||
if isGzip {
|
if isGzip {
|
||||||
response.Header.Del("Content-Encoding")
|
response.Header.Del("Content-Encoding")
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (service *Service) GenerateToken(data *portainer.TokenData) (string, time.T
|
||||||
func (service *Service) ParseAndVerifyToken(token string) (*portainer.TokenData, error) {
|
func (service *Service) ParseAndVerifyToken(token string) (*portainer.TokenData, error) {
|
||||||
scope := parseScope(token)
|
scope := parseScope(token)
|
||||||
secret := service.secrets[scope]
|
secret := service.secrets[scope]
|
||||||
parsedToken, err := jwt.ParseWithClaims(token, &claims{}, func(token *jwt.Token) (interface{}, error) {
|
parsedToken, err := jwt.ParseWithClaims(token, &claims{}, func(token *jwt.Token) (any, error) {
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
msg := fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
msg := fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||||
return nil, msg
|
return nil, msg
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestService_GenerateTokenForKubeconfig(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedToken, err := jwt.ParseWithClaims(got, &claims{}, func(token *jwt.Token) (interface{}, error) {
|
parsedToken, err := jwt.ParseWithClaims(got, &claims{}, func(token *jwt.Token) (any, error) {
|
||||||
return service.secrets[kubeConfigScope], nil
|
return service.secrets[kubeConfigScope], nil
|
||||||
})
|
})
|
||||||
assert.NoError(t, err, "failed to parse generated token")
|
assert.NoError(t, err, "failed to parse generated token")
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestGenerateSignedToken(t *testing.T) {
|
||||||
generatedToken, err := svc.generateSignedToken(token, expiresAt, defaultScope)
|
generatedToken, err := svc.generateSignedToken(token, expiresAt, defaultScope)
|
||||||
assert.NoError(t, err, "failed to generate a signed token")
|
assert.NoError(t, err, "failed to generate a signed token")
|
||||||
|
|
||||||
parsedToken, err := jwt.ParseWithClaims(generatedToken, &claims{}, func(token *jwt.Token) (interface{}, error) {
|
parsedToken, err := jwt.ParseWithClaims(generatedToken, &claims{}, func(token *jwt.Token) (any, error) {
|
||||||
return svc.secrets[defaultScope], nil
|
return svc.secrets[defaultScope], nil
|
||||||
})
|
})
|
||||||
assert.NoError(t, err, "failed to parse generated token")
|
assert.NoError(t, err, "failed to parse generated token")
|
||||||
|
|
|
@ -55,7 +55,7 @@ func AddAppLabels(manifestYaml []byte, appLabels map[string]string) ([]byte, err
|
||||||
return manifestYaml, nil
|
return manifestYaml, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
postProcessYaml := func(yamlDoc interface{}) error {
|
postProcessYaml := func(yamlDoc any) error {
|
||||||
addResourceLabels(yamlDoc, appLabels)
|
addResourceLabels(yamlDoc, appLabels)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,12 @@ func AddAppLabels(manifestYaml []byte, appLabels map[string]string) ([]byte, err
|
||||||
// ExtractDocuments extracts all the documents from a yaml file
|
// ExtractDocuments extracts all the documents from a yaml file
|
||||||
// Optionally post-process each document with a function, which can modify the document in place.
|
// Optionally post-process each document with a function, which can modify the document in place.
|
||||||
// Pass in nil for postProcessYaml to skip post-processing.
|
// Pass in nil for postProcessYaml to skip post-processing.
|
||||||
func ExtractDocuments(manifestYaml []byte, postProcessYaml func(interface{}) error) ([][]byte, error) {
|
func ExtractDocuments(manifestYaml []byte, postProcessYaml func(any) error) ([][]byte, error) {
|
||||||
docs := make([][]byte, 0)
|
docs := make([][]byte, 0)
|
||||||
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
|
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]any)
|
||||||
err := yamlDecoder.Decode(&m)
|
err := yamlDecoder.Decode(&m)
|
||||||
|
|
||||||
// if decoded document is empty
|
// if decoded document is empty
|
||||||
|
@ -113,7 +113,7 @@ func ExtractDocuments(manifestYaml []byte, postProcessYaml func(interface{}) err
|
||||||
// It returns an empty string if namespace is not found in the resource
|
// It returns an empty string if namespace is not found in the resource
|
||||||
func GetNamespace(manifestYaml []byte) (string, error) {
|
func GetNamespace(manifestYaml []byte) (string, error) {
|
||||||
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
|
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]any)
|
||||||
err := yamlDecoder.Decode(&m)
|
err := yamlDecoder.Decode(&m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "failed to unmarshal yaml manifest when obtaining namespace")
|
return "", errors.Wrap(err, "failed to unmarshal yaml manifest when obtaining namespace")
|
||||||
|
@ -125,12 +125,12 @@ func GetNamespace(manifestYaml []byte) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := m["metadata"]; ok {
|
if _, ok := m["metadata"]; ok {
|
||||||
var namespace interface{}
|
var namespace any
|
||||||
var ok bool
|
var ok bool
|
||||||
if strings.EqualFold(kind, "namespace") {
|
if strings.EqualFold(kind, "namespace") {
|
||||||
namespace, ok = m["metadata"].(map[string]interface{})["name"]
|
namespace, ok = m["metadata"].(map[string]any)["name"]
|
||||||
} else {
|
} else {
|
||||||
namespace, ok = m["metadata"].(map[string]interface{})["namespace"]
|
namespace, ok = m["metadata"].(map[string]any)["namespace"]
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -143,8 +143,8 @@ func GetNamespace(manifestYaml []byte) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
|
func addResourceLabels(yamlDoc any, appLabels map[string]string) {
|
||||||
m, ok := yamlDoc.(map[string]interface{})
|
m, ok := yamlDoc.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -157,9 +157,9 @@ func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
|
||||||
|
|
||||||
for _, v := range m {
|
for _, v := range m {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
addResourceLabels(v, appLabels)
|
addResourceLabels(v, appLabels)
|
||||||
case []interface{}:
|
case []any:
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
addResourceLabels(item, appLabels)
|
addResourceLabels(item, appLabels)
|
||||||
}
|
}
|
||||||
|
@ -167,15 +167,15 @@ func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addLabels(obj map[string]interface{}, appLabels map[string]string) {
|
func addLabels(obj map[string]any, appLabels map[string]string) {
|
||||||
metadata := make(map[string]interface{})
|
metadata := make(map[string]any)
|
||||||
if m, ok := obj["metadata"]; ok {
|
if m, ok := obj["metadata"]; ok {
|
||||||
metadata = m.(map[string]interface{})
|
metadata = m.(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := make(map[string]string)
|
labels := make(map[string]string)
|
||||||
if l, ok := metadata["labels"]; ok {
|
if l, ok := metadata["labels"]; ok {
|
||||||
for k, v := range l.(map[string]interface{}) {
|
for k, v := range l.(map[string]any) {
|
||||||
labels[k] = fmt.Sprintf("%v", v)
|
labels[k] = fmt.Sprintf("%v", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (*Service) Authenticate(code string, configuration *portainer.OAuthSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeSecondIntoFirst merges the overlap map into the base overwriting any existing values.
|
// mergeSecondIntoFirst merges the overlap map into the base overwriting any existing values.
|
||||||
func mergeSecondIntoFirst(base map[string]interface{}, overlap map[string]interface{}) map[string]interface{} {
|
func mergeSecondIntoFirst(base map[string]any, overlap map[string]any) map[string]any {
|
||||||
for k, v := range overlap {
|
for k, v := range overlap {
|
||||||
base[k] = v
|
base[k] = v
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,8 @@ func getOAuthToken(code string, configuration *portainer.OAuthSettings) (*oauth2
|
||||||
// getIdToken retrieves parsed id_token from the OAuth token response.
|
// getIdToken retrieves parsed id_token from the OAuth token response.
|
||||||
// This is necessary for OAuth providers like Azure
|
// This is necessary for OAuth providers like Azure
|
||||||
// that do not provide information about user groups on the user resource endpoint.
|
// that do not provide information about user groups on the user resource endpoint.
|
||||||
func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
|
func getIdToken(token *oauth2.Token) (map[string]any, error) {
|
||||||
tokenData := make(map[string]interface{})
|
tokenData := make(map[string]any)
|
||||||
|
|
||||||
idToken := token.Extra("id_token")
|
idToken := token.Extra("id_token")
|
||||||
if idToken == nil {
|
if idToken == nil {
|
||||||
|
@ -113,7 +113,7 @@ func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
|
||||||
return tokenData, nil
|
return tokenData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResource(token string, configuration *portainer.OAuthSettings) (map[string]interface{}, error) {
|
func getResource(token string, configuration *portainer.OAuthSettings) (map[string]any, error) {
|
||||||
req, err := http.NewRequest("GET", configuration.ResourceURI, nil)
|
req, err := http.NewRequest("GET", configuration.ResourceURI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -151,7 +151,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
datamap := make(map[string]interface{})
|
datamap := make(map[string]any)
|
||||||
for k, v := range values {
|
for k, v := range values {
|
||||||
if len(v) == 0 {
|
if len(v) == 0 {
|
||||||
datamap[k] = ""
|
datamap[k] = ""
|
||||||
|
@ -162,7 +162,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
|
||||||
return datamap, nil
|
return datamap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var datamap map[string]interface{}
|
var datamap map[string]any
|
||||||
if err = json.Unmarshal(body, &datamap); err != nil {
|
if err = json.Unmarshal(body, &datamap); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUsername(datamap map[string]interface{}, configuration *portainer.OAuthSettings) (string, error) {
|
func getUsername(datamap map[string]any, configuration *portainer.OAuthSettings) (string, error) {
|
||||||
username, ok := datamap[configuration.UserIdentifier].(string)
|
username, ok := datamap[configuration.UserIdentifier].(string)
|
||||||
if ok && username != "" {
|
if ok && username != "" {
|
||||||
return username, nil
|
return username, nil
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
func Test_getUsername(t *testing.T) {
|
func Test_getUsername(t *testing.T) {
|
||||||
t.Run("fails for non-matching user identifier", func(t *testing.T) {
|
t.Run("fails for non-matching user identifier", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"name": "john"}
|
datamap := map[string]any{"name": "john"}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -19,7 +19,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
|
|
||||||
t.Run("fails if username is empty string", func(t *testing.T) {
|
t.Run("fails if username is empty string", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": ""}
|
datamap := map[string]any{"username": ""}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -29,7 +29,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
|
|
||||||
t.Run("fails if username is 0 int", func(t *testing.T) {
|
t.Run("fails if username is 0 int", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": 0}
|
datamap := map[string]any{"username": 0}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -39,7 +39,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
|
|
||||||
t.Run("fails if username is negative int", func(t *testing.T) {
|
t.Run("fails if username is negative int", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": -1}
|
datamap := map[string]any{"username": -1}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -49,7 +49,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
|
|
||||||
t.Run("succeeds if username is matched and is not empty", func(t *testing.T) {
|
t.Run("succeeds if username is matched and is not empty", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": "john"}
|
datamap := map[string]any{"username": "john"}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,7 +60,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
// looks like a bug!?
|
// looks like a bug!?
|
||||||
t.Run("fails if username is matched and is positive int", func(t *testing.T) {
|
t.Run("fails if username is matched and is positive int", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": 1}
|
datamap := map[string]any{"username": 1}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -70,7 +70,7 @@ func Test_getUsername(t *testing.T) {
|
||||||
|
|
||||||
t.Run("succeeds if username is matched and is non-zero (or negative) float", func(t *testing.T) {
|
t.Run("succeeds if username is matched and is non-zero (or negative) float", func(t *testing.T) {
|
||||||
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
|
||||||
datamap := map[string]interface{}{"username": 1.1}
|
datamap := map[string]any{"username": 1.1}
|
||||||
|
|
||||||
_, err := getUsername(datamap, oauthSettings)
|
_, err := getUsername(datamap, oauthSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Test_getOAuthToken(t *testing.T) {
|
||||||
func Test_getIdToken(t *testing.T) {
|
func Test_getIdToken(t *testing.T) {
|
||||||
verifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.GeU8XCV4Y4p5Vm-i63Aj7UP5zpb_0Zxb7-DjM2_z-s8`
|
verifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.GeU8XCV4Y4p5Vm-i63Aj7UP5zpb_0Zxb7-DjM2_z-s8`
|
||||||
nonVerifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.`
|
nonVerifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.`
|
||||||
claims := map[string]interface{}{
|
claims := map[string]any{
|
||||||
"iss": "Online JWT Builder",
|
"iss": "Online JWT Builder",
|
||||||
"iat": float64(1653540729),
|
"iat": float64(1653540729),
|
||||||
"exp": float64(1685076729),
|
"exp": float64(1685076729),
|
||||||
|
@ -42,13 +42,13 @@ func Test_getIdToken(t *testing.T) {
|
||||||
"sub": "john.doe@example.com",
|
"sub": "john.doe@example.com",
|
||||||
"GivenName": "John",
|
"GivenName": "John",
|
||||||
"Surname": "Doe",
|
"Surname": "Doe",
|
||||||
"Groups": []interface{}{"First", "Second"},
|
"Groups": []any{"First", "Second"},
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
testName string
|
testName string
|
||||||
idToken string
|
idToken string
|
||||||
expectedResult map[string]interface{}
|
expectedResult map[string]any
|
||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -66,7 +66,7 @@ func Test_getIdToken(t *testing.T) {
|
||||||
{
|
{
|
||||||
testName: "should return empty map if token does not exist",
|
testName: "should return empty map if token does not exist",
|
||||||
idToken: "",
|
idToken: "",
|
||||||
expectedResult: make(map[string]interface{}),
|
expectedResult: make(map[string]any),
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ func Test_getIdToken(t *testing.T) {
|
||||||
t.Run(tc.testName, func(t *testing.T) {
|
t.Run(tc.testName, func(t *testing.T) {
|
||||||
token := &oauth2.Token{}
|
token := &oauth2.Token{}
|
||||||
if tc.idToken != "" {
|
if tc.idToken != "" {
|
||||||
token = token.WithExtra(map[string]interface{}{"id_token": tc.idToken})
|
token = token.WithExtra(map[string]any{"id_token": tc.idToken})
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := getIdToken(token)
|
result, err := getIdToken(token)
|
||||||
|
|
|
@ -45,7 +45,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
"token_type": "Bearer",
|
"token_type": "Bearer",
|
||||||
"expires_in": 86400,
|
"expires_in": 86400,
|
||||||
"access_token": AccessToken,
|
"access_token": AccessToken,
|
||||||
|
@ -67,7 +67,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
"username": "test-oauth-user",
|
"username": "test-oauth-user",
|
||||||
"groups": "testing",
|
"groups": "testing",
|
||||||
})
|
})
|
||||||
|
|
|
@ -1421,7 +1421,7 @@ type (
|
||||||
KeyPairFilesExist() (bool, error)
|
KeyPairFilesExist() (bool, error)
|
||||||
StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error
|
StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error
|
||||||
LoadKeyPair() ([]byte, []byte, error)
|
LoadKeyPair() ([]byte, []byte, error)
|
||||||
WriteJSONToFile(path string, content interface{}) error
|
WriteJSONToFile(path string, content any) error
|
||||||
FileExists(path string) (bool, error)
|
FileExists(path string) (bool, error)
|
||||||
StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error)
|
StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error)
|
||||||
GetEdgeJobFolder(identifier string) string
|
GetEdgeJobFolder(identifier string) string
|
||||||
|
|
|
@ -9,10 +9,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type StackBuilderDirector struct {
|
type StackBuilderDirector struct {
|
||||||
builder interface{}
|
builder any
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStackBuilderDirector(b interface{}) *StackBuilderDirector {
|
func NewStackBuilderDirector(b any) *StackBuilderDirector {
|
||||||
return &StackBuilderDirector{
|
return &StackBuilderDirector{
|
||||||
builder: b,
|
builder: b,
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ type Release struct {
|
||||||
Chart Chart `json:"chart,omitempty"`
|
Chart Chart `json:"chart,omitempty"`
|
||||||
// Config is the set of extra Values added to the chart.
|
// Config is the set of extra Values added to the chart.
|
||||||
// These values override the default values inside of the chart.
|
// These values override the default values inside of the chart.
|
||||||
Config map[string]interface{} `json:"config,omitempty"`
|
Config map[string]any `json:"config,omitempty"`
|
||||||
// Manifest is the string representation of the rendered template.
|
// Manifest is the string representation of the rendered template.
|
||||||
Manifest string `json:"manifest,omitempty"`
|
Manifest string `json:"manifest,omitempty"`
|
||||||
// Hooks are all of the hooks declared for this release.
|
// Hooks are all of the hooks declared for this release.
|
||||||
|
@ -57,7 +57,7 @@ type Chart struct {
|
||||||
// Templates for this chart.
|
// Templates for this chart.
|
||||||
Templates []*File `json:"templates"`
|
Templates []*File `json:"templates"`
|
||||||
// Values are default config for this chart.
|
// Values are default config for this chart.
|
||||||
Values map[string]interface{} `json:"values"`
|
Values map[string]any `json:"values"`
|
||||||
// Schema is an optional JSON schema for imposing structure on Values
|
// Schema is an optional JSON schema for imposing structure on Values
|
||||||
Schema []byte `json:"schema"`
|
Schema []byte `json:"schema"`
|
||||||
// Files are miscellaneous files in a chart archive,
|
// Files are miscellaneous files in a chart archive,
|
||||||
|
@ -152,7 +152,7 @@ type Dependency struct {
|
||||||
Enabled bool `json:"enabled,omitempty"`
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
// ImportValues holds the mapping of source values to parent key to be imported. Each item can be a
|
// ImportValues holds the mapping of source values to parent key to be imported. Each item can be a
|
||||||
// string or pair of child/parent sublist items.
|
// string or pair of child/parent sublist items.
|
||||||
ImportValues []interface{} `json:"import-values,omitempty"`
|
ImportValues []any `json:"import-values,omitempty"`
|
||||||
// Alias usable alias to be used for the chart
|
// Alias usable alias to be used for the chart
|
||||||
Alias string `json:"alias,omitempty"`
|
Alias string `json:"alias,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func RetrieveMultiPartFormFile(request *http.Request, requestParameter string) (
|
||||||
|
|
||||||
// RetrieveMultiPartFormJSONValue decodes the value of some form data as a JSON object into the target parameter.
|
// RetrieveMultiPartFormJSONValue decodes the value of some form data as a JSON object into the target parameter.
|
||||||
// If optional is set to true, will not return an error when the form data value is not found.
|
// If optional is set to true, will not return an error when the form data value is not found.
|
||||||
func RetrieveMultiPartFormJSONValue(request *http.Request, name string, target interface{}, optional bool) error {
|
func RetrieveMultiPartFormJSONValue(request *http.Request, name string, target any, optional bool) error {
|
||||||
value, err := RetrieveMultiPartFormValue(request, name, optional)
|
value, err := RetrieveMultiPartFormValue(request, name, optional)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -149,7 +149,7 @@ func RetrieveBooleanQueryParameter(request *http.Request, name string, optional
|
||||||
|
|
||||||
// RetrieveJSONQueryParameter decodes the value of a query parameter as a JSON object into the target parameter.
|
// RetrieveJSONQueryParameter decodes the value of a query parameter as a JSON object into the target parameter.
|
||||||
// If optional is set to true, will not return an error when the query parameter is not found.
|
// If optional is set to true, will not return an error when the query parameter is not found.
|
||||||
func RetrieveJSONQueryParameter(request *http.Request, name string, target interface{}, optional bool) error {
|
func RetrieveJSONQueryParameter(request *http.Request, name string, target any, optional bool) error {
|
||||||
queryParameter, err := RetrieveQueryParameter(request, name, optional)
|
queryParameter, err := RetrieveQueryParameter(request, name, optional)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,13 +13,13 @@ import (
|
||||||
|
|
||||||
// JSON encodes data to rw in JSON format. Returns a pointer to a
|
// JSON encodes data to rw in JSON format. Returns a pointer to a
|
||||||
// HandlerError if encoding fails.
|
// HandlerError if encoding fails.
|
||||||
func JSON(rw http.ResponseWriter, data interface{}) *httperror.HandlerError {
|
func JSON(rw http.ResponseWriter, data any) *httperror.HandlerError {
|
||||||
return JSONWithStatus(rw, data, http.StatusOK)
|
return JSONWithStatus(rw, data, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONWithStatus encodes data to rw in JSON format with a specific status code.
|
// JSONWithStatus encodes data to rw in JSON format with a specific status code.
|
||||||
// Returns a pointer to a HandlerError if encoding fails.
|
// Returns a pointer to a HandlerError if encoding fails.
|
||||||
func JSONWithStatus(rw http.ResponseWriter, data interface{}, status int) *httperror.HandlerError {
|
func JSONWithStatus(rw http.ResponseWriter, data any, status int) *httperror.HandlerError {
|
||||||
rw.Header().Set("Content-Type", "application/json")
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
rw.WriteHeader(status)
|
rw.WriteHeader(status)
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func JSONWithStatus(rw http.ResponseWriter, data interface{}, status int) *httpe
|
||||||
|
|
||||||
// JSON encodes data to rw in YAML format. Returns a pointer to a
|
// JSON encodes data to rw in YAML format. Returns a pointer to a
|
||||||
// HandlerError if encoding fails.
|
// HandlerError if encoding fails.
|
||||||
func YAML(rw http.ResponseWriter, data interface{}) *httperror.HandlerError {
|
func YAML(rw http.ResponseWriter, data any) *httperror.HandlerError {
|
||||||
rw.Header().Set("Content-Type", "text/yaml")
|
rw.Header().Set("Content-Type", "text/yaml")
|
||||||
|
|
||||||
strData, ok := data.(string)
|
strData, ok := data.(string)
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestJSONWithStatus(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
data interface{}
|
data any
|
||||||
status int
|
status int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ func TestJSON(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
data interface{}
|
data any
|
||||||
status int
|
status int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ func TestJSON(t *testing.T) {
|
||||||
func TestYAML(t *testing.T) {
|
func TestYAML(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
data interface{}
|
data any
|
||||||
expected string
|
expected string
|
||||||
invalid bool
|
invalid bool
|
||||||
}{
|
}{
|
||||||
|
@ -105,7 +105,7 @@ func TestYAML(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "doesn't support an Object",
|
name: "doesn't support an Object",
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"key": "value",
|
"key": "value",
|
||||||
},
|
},
|
||||||
expected: "",
|
expected: "",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue