mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
chore: encapsulate certificate string building logic
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
7761e2fd7e
commit
451a222b8a
@ -2,9 +2,12 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
||||
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||
)
|
||||
|
||||
// TODO: refactor.
|
||||
@ -70,3 +73,8 @@ func MergeEnv(env []string, incomingEnv []string) []string {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// BuildCertificateFilePath builds the path to the barman objectStore certificate
|
||||
func BuildCertificateFilePath(objectStoreName string) string {
|
||||
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ func (w WALServiceImplementation) Archive(
|
||||
objectStore.Namespace,
|
||||
&objectStore.Spec.Configuration,
|
||||
os.Environ(),
|
||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
||||
BuildCertificateFilePath(objectStore.Name),
|
||||
)
|
||||
if err != nil {
|
||||
if apierrors.IsForbidden(err) {
|
||||
@ -199,7 +199,7 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
|
||||
objectStore.Namespace,
|
||||
&objectStore.Spec.Configuration,
|
||||
os.Environ(),
|
||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
||||
BuildCertificateFilePath(objectStore.Name),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("while getting recover credentials: %w", err)
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -105,7 +104,7 @@ func (b BackupServiceImplementation) Backup(
|
||||
objectStore.Namespace,
|
||||
&objectStore.Spec.Configuration,
|
||||
common.MergeEnv(osEnvironment, caBundleEnvironment),
|
||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
||||
common.BuildCertificateFilePath(objectStore.Name),
|
||||
)
|
||||
if err != nil {
|
||||
contextLogger.Error(err, "while setting backup cloud credentials")
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
||||
)
|
||||
@ -234,7 +235,7 @@ func (impl *JobHookImpl) checkBackupDestination(
|
||||
cluster.Namespace,
|
||||
barmanConfiguration,
|
||||
os.Environ(),
|
||||
path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName),
|
||||
common.BuildCertificateFilePath(objectStoreName),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't get credentials for cluster %v: %w", cluster.Name, err)
|
||||
@ -353,7 +354,7 @@ func loadBackupObjectFromExternalCluster(
|
||||
cluster.Namespace,
|
||||
recoveryObjectStore,
|
||||
os.Environ(),
|
||||
path.Join(metadata.BarmanCertificatesPath, recoveryObjectStoreName, metadata.BarmanCertificatesFileName))
|
||||
common.BuildCertificateFilePath(recoveryObjectStoreName))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user