chore(code): replace interface{} with any EE-6513 (#11986)

pull/10206/merge
andres-portainer 5 months ago committed by GitHub
parent 9c4935286f
commit f0d43f941f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -54,7 +54,7 @@ func setLoggingMode(mode string) {
}
}
func formatMessage(i interface{}) string {
func formatMessage(i any) string {
if i == nil {
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
// 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{})
}
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{})
}

@ -5,21 +5,21 @@ import (
)
type ReadTransaction interface {
GetObject(bucketName string, key []byte, object interface{}) error
GetAll(bucketName string, obj interface{}, append func(o interface{}) (interface{}, error)) error
GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, append func(o interface{}) (interface{}, error)) error
GetObject(bucketName string, key []byte, object any) error
GetAll(bucketName string, obj any, append func(o any) (any, error)) error
GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj any, append func(o any) (any, error)) error
}
type Transaction interface {
ReadTransaction
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
CreateObject(bucketName string, fn func(uint64) (int, interface{})) error
CreateObjectWithId(bucketName string, id int, obj interface{}) error
CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error
DeleteAllObjects(bucketName string, obj interface{}, matching func(o interface{}) (id int, ok bool)) error
CreateObject(bucketName string, fn func(uint64) (int, any)) error
CreateObjectWithId(bucketName string, id int, obj any) error
CreateObjectWithStringId(bucketName string, id []byte, obj any) error
DeleteAllObjects(bucketName string, obj any, matching func(o any) (id int, ok bool)) error
GetNextIdentifier(bucketName string) int
}
@ -45,8 +45,8 @@ type Connection interface {
NeedsEncryptionMigration() (bool, error)
SetEncrypted(encrypted bool)
BackupMetadata() (map[string]interface{}, error)
RestoreMetadata(s map[string]interface{}) error
BackupMetadata() (map[string]any, error)
RestoreMetadata(s map[string]any) error
UpdateObjectFunc(bucketName string, key []byte, object any, updateFn func()) error
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.
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 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.
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 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).
// 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 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
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 tx.CreateObject(bucketName, fn)
})
}
// 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 tx.CreateObjectWithId(bucketName, id, obj)
})
}
// 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 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 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 tx.GetAllWithKeyPrefix(bucketName, keyPrefix, obj, appendFn)
})
}
// BackupMetadata will return a copy of the boltdb sequence numbers for all buckets.
func (connection *DbConnection) BackupMetadata() (map[string]interface{}, error) {
buckets := map[string]interface{}{}
func (connection *DbConnection) BackupMetadata() (map[string]any, error) {
buckets := map[string]any{}
err := connection.View(func(tx *bolt.Tx) 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.
func (connection *DbConnection) RestoreMetadata(s map[string]interface{}) error {
func (connection *DbConnection) RestoreMetadata(s map[string]any) error {
var err error
for bucketName, v := range s {

@ -8,8 +8,8 @@ import (
bolt "go.etcd.io/bbolt"
)
func backupMetadata(connection *bolt.DB) (map[string]interface{}, error) {
buckets := map[string]interface{}{}
func backupMetadata(connection *bolt.DB) (map[string]any, error) {
buckets := map[string]any{}
err := connection.View(func(tx *bolt.Tx) 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()
backup := make(map[string]interface{})
backup := make(map[string]any)
if metadata {
meta, err := backupMetadata(connection)
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 = tx.ForEach(func(name []byte, bucket *bolt.Bucket) error {
bucketName := string(name)
var list []interface{}
var list []any
version := make(map[string]string)
cursor := bucket.Cursor()
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
}
var obj interface{}
var obj any
err := c.UnmarshalObject(v, &obj)
if err != nil {
log.Error().

@ -14,7 +14,7 @@ import (
var errEncryptedStringTooShort = errors.New("encrypted string too short")
// 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{}
// 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
func (connection *DbConnection) UnmarshalObject(data []byte, object interface{}) error {
func (connection *DbConnection) UnmarshalObject(data []byte, object any) error {
var err error
if connection.getEncryptionKey() != nil {
data, err = decrypt(data, connection.getEncryptionKey())

@ -25,7 +25,7 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
uuid := uuid.Must(uuid.NewV4())
tests := []struct {
object interface{}
object any
expected string
}{
{
@ -57,7 +57,7 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
expected: uuid.String(),
},
{
object: map[string]interface{}{"key": "value"},
object: map[string]any{"key": "value"},
expected: `{"key":"value"}`,
},
{
@ -73,11 +73,11 @@ func Test_MarshalObjectUnencrypted(t *testing.T) {
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"}]`,
},
{
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"}]`,
},
}

@ -20,7 +20,7 @@ func (tx *DbTransaction) SetServiceName(bucketName string) error {
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))
value := bucket.Get(key)
@ -31,7 +31,7 @@ func (tx *DbTransaction) GetObject(bucketName string, key []byte, object interfa
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)
if err != nil {
return err
@ -46,7 +46,7 @@ func (tx *DbTransaction) DeleteObject(bucketName string, key []byte) error {
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
bucket := tx.tx.Bucket([]byte(bucketName))
@ -85,7 +85,7 @@ func (tx *DbTransaction) GetNextIdentifier(bucketName string) int {
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))
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)
}
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))
data, err := tx.conn.MarshalObject(obj)
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)
}
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))
data, err := tx.conn.MarshalObject(obj)
if err != nil {
@ -119,7 +119,7 @@ func (tx *DbTransaction) CreateObjectWithStringId(bucketName string, id []byte,
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))
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()
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(
BucketName,
&portainer.APIKey{},
func(obj interface{}) (interface{}, error) {
func(obj any) (any, error) {
record, ok := obj.(*portainer.APIKey)
if !ok {
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(
BucketName,
&portainer.APIKey{},
func(obj interface{}) (interface{}, error) {
func(obj any) (any, error) {
key, ok := obj.(*portainer.APIKey)
if !ok {
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
record.ID = portainer.APIKeyID(id)
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 {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
group.ID = portainer.EdgeGroupID(id)
return int(group.ID), group
},

@ -24,7 +24,7 @@ func (service ServiceTx) EdgeStacks() ([]portainer.EdgeStack, error) {
err := service.tx.GetAll(
BucketName,
&portainer.EdgeStack{},
func(obj interface{}) (interface{}, error) {
func(obj any) (any, error) {
stack, ok := obj.(*portainer.EdgeStack)
if !ok {
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
endpointGroup.ID = portainer.EndpointGroupID(id)
return int(endpointGroup.ID), endpointGroup
},

@ -13,7 +13,7 @@ type ServiceTx struct {
func (service ServiceTx) Create(endpointGroup *portainer.EndpointGroup) error {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
endpointGroup.ID = portainer.EndpointGroupID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
record.ID = portainer.HelmUserRepositoryID(id)
return int(record.ID), record
},

@ -17,8 +17,8 @@ func IsErrObjectNotFound(e error) bool {
}
// AppendFn appends elements to the given collection slice
func AppendFn[T any](collection *[]T) func(obj interface{}) (interface{}, error) {
return func(obj interface{}) (interface{}, error) {
func AppendFn[T any](collection *[]T) func(obj any) (any, error) {
return func(obj any) (any, error) {
element, ok := obj.(*T)
if !ok {
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
func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj interface{}) (interface{}, error) {
return func(obj interface{}) (interface{}, error) {
func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj any) (any, error) {
return func(obj any) (any, error) {
element, ok := obj.(*T)
if !ok {
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
// success
func FirstFn[T any](element *T, predicate func(T) bool) func(obj interface{}) (interface{}, error) {
return func(obj interface{}) (interface{}, error) {
func FirstFn[T any](element *T, predicate func(T) bool) func(obj any) (any, error) {
return func(obj any) (any, error) {
e, ok := obj.(*T)
if !ok {
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 {
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.CreatedAt = time.Now().Unix()

@ -42,7 +42,7 @@ func (service *Service) Tx(tx portainer.Transaction) ServiceTx {
func (service *Service) Create(registry *portainer.Registry) error {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
registry.ID = portainer.RegistryID(id)
return int(registry.ID), registry
},

@ -13,7 +13,7 @@ type ServiceTx struct {
func (service ServiceTx) Create(registry *portainer.Registry) error {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
registry.ID = portainer.RegistryID(id)
return int(registry.ID), registry
},

@ -52,7 +52,7 @@ func (service *Service) ResourceControlByResourceIDAndType(resourceID string, re
err := service.Connection.GetAll(
BucketName,
&portainer.ResourceControl{},
func(obj interface{}) (interface{}, error) {
func(obj any) (any, error) {
rc, ok := obj.(*portainer.ResourceControl)
if !ok {
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
resourceControl.ID = portainer.ResourceControlID(id)
return int(resourceControl.ID), resourceControl
},

@ -23,7 +23,7 @@ func (service ServiceTx) ResourceControlByResourceIDAndType(resourceID string, r
err := service.Tx.GetAll(
BucketName,
&portainer.ResourceControl{},
func(obj interface{}) (interface{}, error) {
func(obj any) (any, error) {
rc, ok := obj.(*portainer.ResourceControl)
if !ok {
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 {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
resourceControl.ID = portainer.ResourceControlID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
role.ID = portainer.RoleID(id)
return int(role.ID), role
},

@ -13,7 +13,7 @@ type ServiceTx struct {
func (service ServiceTx) Create(role *portainer.Role) error {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
role.ID = portainer.RoleID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
tag.ID = portainer.TagID(id)
return int(tag.ID), tag
},

@ -15,7 +15,7 @@ type ServiceTx struct {
func (service ServiceTx) Create(tag *portainer.Tag) error {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
tag.ID = portainer.TagID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
team.ID = portainer.TeamID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
membership.ID = portainer.TeamMembershipID(id)
return int(membership.ID), membership
},
@ -84,7 +84,7 @@ func (service *Service) DeleteTeamMembershipByUserID(userID portainer.UserID) er
return service.Connection.DeleteAllObjects(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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 {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
membership.ID = portainer.TeamMembershipID(id)
return int(membership.ID), membership
},
@ -55,7 +55,7 @@ func (service ServiceTx) DeleteTeamMembershipByUserID(userID portainer.UserID) e
return service.Tx.DeleteAllObjects(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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(
BucketName,
&portainer.TeamMembership{},
func(obj interface{}) (id int, ok bool) {
func(obj any) (id int, ok bool) {
membership, ok := obj.(portainer.TeamMembership)
if !ok {
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 {
return service.Tx.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
user.ID = portainer.UserID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
user.ID = portainer.UserID(id)
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 {
return service.Connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
func(id uint64) (int, any) {
webhook.ID = portainer.WebhookID(id)
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.
// Errors are logged with the testing package.
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.
d := json.NewDecoder(r)
@ -337,9 +337,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
for k, v := range objects {
switch k {
case "version":
versions, ok := v.(map[string]interface{})
versions, ok := v.(map[string]any)
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
@ -404,9 +404,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
}
case "dockerhub":
obj, ok := v.([]interface{})
obj, ok := v.([]any)
if !ok {
t.Logf("failed to cast %s to []interface{}", k)
t.Logf("failed to cast %s to []any", k)
}
err := con.CreateObjectWithStringId(
k,
@ -418,9 +418,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
}
case "ssl":
obj, ok := v.(map[string]interface{})
obj, ok := v.(map[string]any)
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(
k,
@ -432,9 +432,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
}
case "settings":
obj, ok := v.(map[string]interface{})
obj, ok := v.(map[string]any)
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(
k,
@ -446,9 +446,9 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
}
case "tunnel_server":
obj, ok := v.(map[string]interface{})
obj, ok := v.(map[string]any)
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(
k,
@ -462,18 +462,18 @@ func importJSON(t *testing.T, r io.Reader, store *Store) error {
continue
default:
objlist, ok := v.([]interface{})
objlist, ok := v.([]any)
if !ok {
t.Logf("failed to cast %s to []interface{}", k)
t.Logf("failed to cast %s to []any", k)
}
for _, obj := range objlist {
value, ok := obj.(map[string]interface{})
value, ok := obj.(map[string]any)
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 {
var ok bool
var id interface{}
var id any
switch k {
case "endpoint_relations":
// 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
// 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
return dbConn.UpdateObject("settings", []byte("SETTINGS"), preSetObj)
}
func setup(store *Store) error {
dummySettingsObj := map[string]interface{}{
dummySettingsObj := map[string]any{
"LogoURL": dummyLogoURL,
}

@ -15,7 +15,7 @@ func migrationError(err error, context string) error {
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()
}

@ -385,7 +385,7 @@ type storeExport struct {
User []portainer.User `json:"users,omitempty"`
Version models.Version `json:"version,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) {

@ -227,10 +227,10 @@ func (manager *SwarmStackManager) updateDockerCLIConfiguration(configPath string
}
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-Signature"] = signature
headersObject["X-PortainerAgent-PublicKey"] = manager.signatureService.EncodedPublicKey()
@ -238,12 +238,12 @@ func (manager *SwarmStackManager) updateDockerCLIConfiguration(configPath string
return manager.fileService.WriteJSONToFile(configFilePath, config)
}
func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (map[string]interface{}, error) {
var config map[string]interface{}
func (manager *SwarmStackManager) retrieveConfigurationFromDisk(path string) (map[string]any, error) {
var config map[string]any
raw, err := manager.fileService.GetFileContent(path, "")
if err != nil {
return make(map[string]interface{}), nil
return make(map[string]any), nil
}
err = json.Unmarshal(raw, &config)

@ -599,7 +599,7 @@ func (service *Service) Rename(oldPath, newPath string) error {
}
// 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)
if err != nil {
return err

@ -12,7 +12,7 @@ import (
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)
payload := map[string]interface{}{
payload := map[string]any{
"enableSOL": features.SOL,
"enableIDER": features.IDER,
"enableKVM": features.KVM,

@ -107,7 +107,7 @@ func TestCreateWithInvalidPayload(t *testing.T) {
cases := []struct {
Name string
Payload interface{}
Payload any
ExpectedStatusCode int
Method string
}{

@ -47,12 +47,12 @@ func (transport *Transport) createAzureRequestContext(request *http.Request) (*a
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 {
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
return object
@ -88,18 +88,18 @@ func (transport *Transport) userCanDeleteContainerGroup(request *http.Request, c
return authorization.UserCanAccessResource(context.userID, context.userTeamIDs, resourceControl)
}
func (transport *Transport) decorateContainerGroups(containerGroups []interface{}, context *azureRequestContext) []interface{} {
decoratedContainerGroups := make([]interface{}, 0)
func (transport *Transport) decorateContainerGroups(containerGroups []any, context *azureRequestContext) []any {
decoratedContainerGroups := make([]any, 0)
for _, containerGroup := range containerGroups {
containerGroup = transport.decorateContainerGroup(containerGroup.(map[string]interface{}), context)
containerGroup = transport.decorateContainerGroup(containerGroup.(map[string]any), context)
decoratedContainerGroups = append(decoratedContainerGroups, containerGroup)
}
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)
if ok {
resourceControl := transport.findResourceControl(containerGroupId, context)
@ -113,13 +113,13 @@ func (transport *Transport) decorateContainerGroup(containerGroup map[string]int
return containerGroup
}
func (transport *Transport) filterContainerGroups(containerGroups []interface{}, context *azureRequestContext) []interface{} {
filteredContainerGroups := make([]interface{}, 0)
func (transport *Transport) filterContainerGroups(containerGroups []any, context *azureRequestContext) []any {
filteredContainerGroups := make([]any, 0)
for _, containerGroup := range containerGroups {
userCanAccessResource := false
containerGroup := containerGroup.(map[string]interface{})
portainerObject, ok := containerGroup["Portainer"].(map[string]interface{})
containerGroup := containerGroup.(map[string]any)
portainerObject, ok := containerGroup["Portainer"].(map[string]any)
if ok {
resourceControl, ok := portainerObject["ResourceControl"].(*portainer.ResourceControl)
if ok {
@ -135,7 +135,7 @@ func (transport *Transport) filterContainerGroups(containerGroups []interface{},
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)
if !ok {
log.Debug().Msg("missing ID in container group")

@ -28,7 +28,7 @@ func (transport *Transport) proxyContainerGroupsGetRequest(request *http.Request
return nil, err
}
value, ok := responseObject["value"].([]interface{})
value, ok := responseObject["value"].([]any)
if ok {
context, err := transport.createAzureRequestContext(request)
if err != nil {

@ -22,7 +22,7 @@ const (
)
type (
resourceLabelsObjectSelector func(map[string]interface{}) map[string]interface{}
resourceLabelsObjectSelector func(map[string]any) map[string]any
resourceOperationParameters struct {
resourceIdentifierAttribute string
resourceType portainer.ResourceControlType
@ -47,7 +47,7 @@ func getUniqueElements(items string) []string {
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 {
resourceControl := authorization.NewPublicResourceControl(resourceID, resourceType)
@ -155,7 +155,7 @@ func (transport *Transport) getInheritedResourceControlFromServiceOrStack(resour
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 {
log.Warn().
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
@ -194,7 +194,7 @@ func (transport *Transport) applyAccessControlOnResource(parameters *resourceOpe
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 {
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)
}
func (transport *Transport) decorateResourceList(parameters *resourceOperationParameters, resourceData []interface{}, resourceControls []portainer.ResourceControl) ([]interface{}, error) {
decoratedResourceData := make([]interface{}, 0)
func (transport *Transport) decorateResourceList(parameters *resourceOperationParameters, resourceData []any, resourceControls []portainer.ResourceControl) ([]any, error) {
decoratedResourceData := make([]any, 0)
for _, resource := range resourceData {
resourceObject := resource.(map[string]interface{})
resourceObject := resource.(map[string]any)
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
log.Warn().
@ -244,11 +244,11 @@ func (transport *Transport) decorateResourceList(parameters *resourceOperationPa
return decoratedResourceData, nil
}
func (transport *Transport) filterResourceList(parameters *resourceOperationParameters, resourceData []interface{}, context *restrictedDockerOperationContext) ([]interface{}, error) {
filteredResourceData := make([]interface{}, 0)
func (transport *Transport) filterResourceList(parameters *resourceOperationParameters, resourceData []any, context *restrictedDockerOperationContext) ([]any, error) {
filteredResourceData := make([]any, 0)
for _, resource := range resourceData {
resourceObject := resource.(map[string]interface{})
resourceObject := resource.(map[string]any)
if resourceObject[parameters.resourceIdentifierAttribute] == nil {
log.Warn().
Str("identifier_attribute", parameters.resourceIdentifierAttribute).
@ -292,7 +292,7 @@ func (transport *Transport) filterResourceList(parameters *resourceOperationPara
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)
if resourceControl != nil {
return resourceControl, nil
@ -350,12 +350,12 @@ func getStackResourceIDFromLabels(resourceLabelsObject map[string]string, endpoi
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 {
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
return object

@ -75,7 +75,7 @@ func (transport *Transport) configInspectOperation(response *http.Response, exec
// API schema references:
// https://docs.docker.com/engine/api/v1.37/#operation/ConfigList
// 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 {
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.
// Labels are available under the "Config.Labels" property.
// 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")
if containerConfigObject != nil {
containerLabelsObject := utils.GetJSONObject(containerConfigObject, "Labels")
@ -115,18 +115,18 @@ func selectorContainerLabelsFromContainerInspectOperation(responseObject map[str
// This selector is specific to the containerList Docker operation.
// Labels are available under the "Labels" property.
// 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")
return containerLabelsObject
}
// filterContainersWithLabels loops through a list of containers, and filters containers that do not contains
// any labels in the labels black list.
func filterContainersWithBlackListedLabels(containerData []interface{}, labelBlackList []portainer.Pair) ([]interface{}, error) {
filteredContainerData := make([]interface{}, 0)
func filterContainersWithBlackListedLabels(containerData []any, labelBlackList []portainer.Pair) ([]any, error) {
filteredContainerData := make([]any, 0)
for _, container := range containerData {
containerObject := container.(map[string]interface{})
containerObject := container.(map[string]any)
containerLabels := selectorContainerLabelsFromContainerListOperation(containerObject)
if containerLabels != nil {
@ -141,7 +141,7 @@ func filterContainersWithBlackListedLabels(containerData []interface{}, labelBla
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 {
labelName := key
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) {
type PartialContainer struct {
HostConfig struct {
Privileged bool `json:"Privileged"`
PidMode string `json:"PidMode"`
Devices []interface{} `json:"Devices"`
Sysctls map[string]interface{} `json:"Sysctls"`
CapAdd []string `json:"CapAdd"`
CapDrop []string `json:"CapDrop"`
Binds []string `json:"Binds"`
Privileged bool `json:"Privileged"`
PidMode string `json:"PidMode"`
Devices []any `json:"Devices"`
Sysctls map[string]any `json:"Sysctls"`
CapAdd []string `json:"CapAdd"`
CapDrop []string `json:"CapDrop"`
Binds []string `json:"Binds"`
} `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
// 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 {
return nil
}
@ -98,6 +98,6 @@ func findSystemNetworkResourceControl(networkObject map[string]interface{}) *por
// API schema references:
// https://docs.docker.com/engine/api/v1.28/#operation/NetworkInspect
// 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")
}

@ -15,10 +15,10 @@ func init() {
portainerContainerId, _ = os.Hostname()
}
func (transport *Transport) applyPortainerContainers(resources []interface{}) ([]interface{}, error) {
decoratedResourceData := make([]interface{}, 0)
func (transport *Transport) applyPortainerContainers(resources []any) ([]any, error) {
decoratedResourceData := make([]any, 0)
for _, resource := range resources {
responseObject, ok := resource.(map[string]interface{})
responseObject, ok := resource.(map[string]any)
if !ok {
decoratedResourceData = append(decoratedResourceData, resource)
continue
@ -30,7 +30,7 @@ func (transport *Transport) applyPortainerContainers(resources []interface{}) ([
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)
if !ok {
return resourceObject, nil

@ -77,7 +77,7 @@ func (transport *Transport) secretInspectOperation(response *http.Response, exec
// API schema references:
// https://docs.docker.com/engine/api/v1.37/#operation/SecretList
// 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")
if secretSpec != nil {
secretLabelsObject := utils.GetJSONObject(secretSpec, "Labels")

@ -80,7 +80,7 @@ func (transport *Transport) serviceInspectOperation(response *http.Response, exe
// API schema references:
// https://docs.docker.com/engine/api/v1.28/#operation/ServiceInspect
// 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")
if serviceSpecObject != nil {
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.
// Labels are available under the "Spec.ContainerSpec.Labels" property.
// 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")
if taskSpecObject != nil {
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
if responseObject["Volumes"] != nil {
volumeData := responseObject["Volumes"].([]interface{})
volumeData := responseObject["Volumes"].([]any)
if transport.snapshotService != nil {
// 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 {
volume := volumeObject.(map[string]interface{})
volume := volumeObject.(map[string]any)
if err := transport.decorateVolumeResponseWithResourceID(volume); err != nil {
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)
}
func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject map[string]interface{}) error {
func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject map[string]any) error {
if responseObject["Name"] == nil {
return errors.New("missing identifier in Docker resource detail response")
}
@ -125,7 +125,7 @@ func (transport *Transport) decorateVolumeResponseWithResourceID(responseObject
// API schema references:
// https://docs.docker.com/engine/api/v1.28/#operation/VolumeInspect
// 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")
}

@ -13,25 +13,25 @@ import (
// GetJSONObject will extract an object from a specific property of another JSON object.
// 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]
if object != nil {
return object.(map[string]interface{})
return object.(map[string]any)
}
return nil
}
// GetArrayObject will extract an array from a specific property of another JSON object.
// 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]
if object != nil {
return object.([]interface{})
return object.([]any)
}
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 {
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()
var data interface{}
var data any
err := unmarshal(contentType, reader, &data)
if err != nil {
return nil, err
@ -58,7 +58,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
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"
mediaType, _, err := mime.ParseMediaType(contentType)
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)
}
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"
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {

@ -12,13 +12,13 @@ import (
)
// 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)
if err != nil {
return nil, err
}
responseObject, ok := responseData.(map[string]interface{})
responseObject, ok := responseData.(map[string]any)
if !ok {
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
func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
func GetResponseAsJSONArray(response *http.Response) ([]any, error) {
responseData, err := getResponseBody(response)
if err != nil {
return nil, err
@ -36,9 +36,9 @@ func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
}
switch responseObject := responseData.(type) {
case []interface{}:
case []any:
return responseObject, nil
case map[string]interface{}:
case map[string]any:
if responseObject["message"] != nil {
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
// 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)
if err != nil {
return err
@ -96,7 +96,7 @@ func RewriteResponse(response *http.Response, newResponseData interface{}, statu
return nil
}
func getResponseBody(response *http.Response) (interface{}, error) {
func getResponseBody(response *http.Response) (any, error) {
isGzip := response.Header.Get("Content-Encoding") == "gzip"
if isGzip {
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) {
scope := parseScope(token)
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 {
msg := fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
return nil, msg

@ -66,7 +66,7 @@ func TestService_GenerateTokenForKubeconfig(t *testing.T) {
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
})
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)
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
})
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
}
postProcessYaml := func(yamlDoc interface{}) error {
postProcessYaml := func(yamlDoc any) error {
addResourceLabels(yamlDoc, appLabels)
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
// Optionally post-process each document with a function, which can modify the document in place.
// 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)
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
for {
m := make(map[string]interface{})
m := make(map[string]any)
err := yamlDecoder.Decode(&m)
// 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
func GetNamespace(manifestYaml []byte) (string, error) {
yamlDecoder := yaml.NewDecoder(bytes.NewReader(manifestYaml))
m := make(map[string]interface{})
m := make(map[string]any)
err := yamlDecoder.Decode(&m)
if err != nil {
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 {
var namespace interface{}
var namespace any
var ok bool
if strings.EqualFold(kind, "namespace") {
namespace, ok = m["metadata"].(map[string]interface{})["name"]
namespace, ok = m["metadata"].(map[string]any)["name"]
} else {
namespace, ok = m["metadata"].(map[string]interface{})["namespace"]
namespace, ok = m["metadata"].(map[string]any)["namespace"]
}
if ok {
@ -143,8 +143,8 @@ func GetNamespace(manifestYaml []byte) (string, error) {
return "", nil
}
func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
m, ok := yamlDoc.(map[string]interface{})
func addResourceLabels(yamlDoc any, appLabels map[string]string) {
m, ok := yamlDoc.(map[string]any)
if !ok {
return
}
@ -157,9 +157,9 @@ func addResourceLabels(yamlDoc interface{}, appLabels map[string]string) {
for _, v := range m {
switch v := v.(type) {
case map[string]interface{}:
case map[string]any:
addResourceLabels(v, appLabels)
case []interface{}:
case []any:
for _, item := range v {
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) {
metadata := make(map[string]interface{})
func addLabels(obj map[string]any, appLabels map[string]string) {
metadata := make(map[string]any)
if m, ok := obj["metadata"]; ok {
metadata = m.(map[string]interface{})
metadata = m.(map[string]any)
}
labels := make(map[string]string)
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)
}
}

@ -61,7 +61,7 @@ func (*Service) Authenticate(code string, configuration *portainer.OAuthSettings
}
// 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 {
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.
// This is necessary for OAuth providers like Azure
// that do not provide information about user groups on the user resource endpoint.
func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
tokenData := make(map[string]interface{})
func getIdToken(token *oauth2.Token) (map[string]any, error) {
tokenData := make(map[string]any)
idToken := token.Extra("id_token")
if idToken == nil {
@ -113,7 +113,7 @@ func getIdToken(token *oauth2.Token) (map[string]interface{}, error) {
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)
if err != nil {
return nil, err
@ -151,7 +151,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
return nil, err
}
datamap := make(map[string]interface{})
datamap := make(map[string]any)
for k, v := range values {
if len(v) == 0 {
datamap[k] = ""
@ -162,7 +162,7 @@ func getResource(token string, configuration *portainer.OAuthSettings) (map[stri
return datamap, nil
}
var datamap map[string]interface{}
var datamap map[string]any
if err = json.Unmarshal(body, &datamap); err != nil {
return nil, err
}

@ -7,7 +7,7 @@ import (
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)
if ok && username != "" {
return username, nil

@ -9,7 +9,7 @@ import (
func Test_getUsername(t *testing.T) {
t.Run("fails for non-matching user identifier", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"name": "john"}
datamap := map[string]any{"name": "john"}
_, err := getUsername(datamap, oauthSettings)
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) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": ""}
datamap := map[string]any{"username": ""}
_, err := getUsername(datamap, oauthSettings)
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) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 0}
datamap := map[string]any{"username": 0}
_, err := getUsername(datamap, oauthSettings)
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) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": -1}
datamap := map[string]any{"username": -1}
_, err := getUsername(datamap, oauthSettings)
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) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": "john"}
datamap := map[string]any{"username": "john"}
_, err := getUsername(datamap, oauthSettings)
if err != nil {
@ -60,7 +60,7 @@ func Test_getUsername(t *testing.T) {
// looks like a bug!?
t.Run("fails if username is matched and is positive int", func(t *testing.T) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 1}
datamap := map[string]any{"username": 1}
_, err := getUsername(datamap, oauthSettings)
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) {
oauthSettings := &portainer.OAuthSettings{UserIdentifier: "username"}
datamap := map[string]interface{}{"username": 1.1}
datamap := map[string]any{"username": 1.1}
_, err := getUsername(datamap, oauthSettings)
if err != nil {

@ -34,7 +34,7 @@ func Test_getOAuthToken(t *testing.T) {
func Test_getIdToken(t *testing.T) {
verifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.GeU8XCV4Y4p5Vm-i63Aj7UP5zpb_0Zxb7-DjM2_z-s8`
nonVerifiedToken := `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2NTM1NDA3MjksImV4cCI6MTY4NTA3NjcyOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiam9obi5kb2VAZXhhbXBsZS5jb20iLCJHaXZlbk5hbWUiOiJKb2huIiwiU3VybmFtZSI6IkRvZSIsIkdyb3VwcyI6WyJGaXJzdCIsIlNlY29uZCJdfQ.`
claims := map[string]interface{}{
claims := map[string]any{
"iss": "Online JWT Builder",
"iat": float64(1653540729),
"exp": float64(1685076729),
@ -42,13 +42,13 @@ func Test_getIdToken(t *testing.T) {
"sub": "john.doe@example.com",
"GivenName": "John",
"Surname": "Doe",
"Groups": []interface{}{"First", "Second"},
"Groups": []any{"First", "Second"},
}
tests := []struct {
testName string
idToken string
expectedResult map[string]interface{}
expectedResult map[string]any
expectedError error
}{
{
@ -66,7 +66,7 @@ func Test_getIdToken(t *testing.T) {
{
testName: "should return empty map if token does not exist",
idToken: "",
expectedResult: make(map[string]interface{}),
expectedResult: make(map[string]any),
expectedError: nil,
},
}
@ -75,7 +75,7 @@ func Test_getIdToken(t *testing.T) {
t.Run(tc.testName, func(t *testing.T) {
token := &oauth2.Token{}
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)

@ -45,7 +45,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
json.NewEncoder(w).Encode(map[string]any{
"token_type": "Bearer",
"expires_in": 86400,
"access_token": AccessToken,
@ -67,7 +67,7 @@ func OAuthRoutes(code string, config *portainer.OAuthSettings) http.Handler {
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
json.NewEncoder(w).Encode(map[string]any{
"username": "test-oauth-user",
"groups": "testing",
})

@ -1421,7 +1421,7 @@ type (
KeyPairFilesExist() (bool, error)
StoreKeyPair(private, public []byte, privatePEMHeader, publicPEMHeader string) error
LoadKeyPair() ([]byte, []byte, error)
WriteJSONToFile(path string, content interface{}) error
WriteJSONToFile(path string, content any) error
FileExists(path string) (bool, error)
StoreEdgeJobFileFromBytes(identifier string, data []byte) (string, error)
GetEdgeJobFolder(identifier string) string

@ -9,10 +9,10 @@ import (
)
type StackBuilderDirector struct {
builder interface{}
builder any
}
func NewStackBuilderDirector(b interface{}) *StackBuilderDirector {
func NewStackBuilderDirector(b any) *StackBuilderDirector {
return &StackBuilderDirector{
builder: b,
}

@ -28,7 +28,7 @@ type Release struct {
Chart Chart `json:"chart,omitempty"`
// Config is the set of extra Values added to 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 string `json:"manifest,omitempty"`
// Hooks are all of the hooks declared for this release.
@ -57,7 +57,7 @@ type Chart struct {
// Templates for this chart.
Templates []*File `json:"templates"`
// 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 []byte `json:"schema"`
// Files are miscellaneous files in a chart archive,
@ -152,7 +152,7 @@ type Dependency struct {
Enabled bool `json:"enabled,omitempty"`
// 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.
ImportValues []interface{} `json:"import-values,omitempty"`
ImportValues []any `json:"import-values,omitempty"`
// Alias usable alias to be used for the chart
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.
// 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)
if err != nil {
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.
// 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)
if err != nil {
return err

@ -13,13 +13,13 @@ import (
// JSON encodes data to rw in JSON format. Returns a pointer to a
// 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)
}
// JSONWithStatus encodes data to rw in JSON format with a specific status code.
// 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.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
// 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")
strData, ok := data.(string)

@ -16,7 +16,7 @@ func TestJSONWithStatus(t *testing.T) {
tests := []struct {
name string
data interface{}
data any
status int
}{
{
@ -57,7 +57,7 @@ func TestJSON(t *testing.T) {
tests := []struct {
name string
data interface{}
data any
status int
}{
{
@ -88,7 +88,7 @@ func TestJSON(t *testing.T) {
func TestYAML(t *testing.T) {
tests := []struct {
name string
data interface{}
data any
expected string
invalid bool
}{
@ -105,7 +105,7 @@ func TestYAML(t *testing.T) {
},
{
name: "doesn't support an Object",
data: map[string]interface{}{
data: map[string]any{
"key": "value",
},
expected: "",

Loading…
Cancel
Save