plugin-barman-cloud/internal/cnpgi/common/backup.go
Armando Ruocco 6067121c67 chore: lint
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
2024-11-06 10:51:16 +01:00

22 lines
619 B
Go

package common
import (
"encoding/json"
"fmt"
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
)
// GetCredentialsFromBackup extracts the Barman credentials from the backup
func GetCredentialsFromBackup(backup *cnpgv1.Backup) (barmanapi.BarmanCredentials, error) {
rawCred := backup.Status.PluginMetadata["credentials"]
var creds barmanapi.BarmanCredentials
if err := json.Unmarshal([]byte(rawCred), &creds); err != nil {
return barmanapi.BarmanCredentials{}, fmt.Errorf("while unmarshaling credentials: %w", err)
}
return creds, nil
}