plugin-barman-cloud/internal/cnpgi/operator/specs/secrets.go
Leonardo Cecchi 76383a30af
feat: grant permissions to read secrets (#25)
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
2024-10-03 16:58:56 +02:00

52 lines
1.3 KiB
Go

package specs
import (
machineryapi "github.com/cloudnative-pg/machinery/pkg/api"
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
)
func collectSecretNames(object *barmancloudv1.ObjectStore) []string {
if object == nil {
return nil
}
var references []*machineryapi.SecretKeySelector
if object.Spec.Configuration.AWS != nil {
references = append(
references,
object.Spec.Configuration.AWS.AccessKeyIDReference,
object.Spec.Configuration.AWS.SecretAccessKeyReference,
object.Spec.Configuration.AWS.RegionReference,
object.Spec.Configuration.AWS.SessionToken,
)
}
if object.Spec.Configuration.Azure != nil {
references = append(
references,
object.Spec.Configuration.Azure.ConnectionString,
object.Spec.Configuration.Azure.StorageAccount,
object.Spec.Configuration.Azure.StorageKey,
object.Spec.Configuration.Azure.StorageSasToken,
)
}
if object.Spec.Configuration.Google != nil {
references = append(
references,
object.Spec.Configuration.Google.ApplicationCredentials,
)
}
result := make([]string, 0, len(references))
for _, reference := range references {
if reference == nil {
continue
}
result = append(result, reference.Name)
}
// TODO: stringset belongs to machinery :(
return result
}