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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
|
||||||
|
|
||||||
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: refactor.
|
// TODO: refactor.
|
||||||
@ -70,3 +73,8 @@ func MergeEnv(env []string, incomingEnv []string) []string {
|
|||||||
|
|
||||||
return result
|
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.Namespace,
|
||||||
&objectStore.Spec.Configuration,
|
&objectStore.Spec.Configuration,
|
||||||
os.Environ(),
|
os.Environ(),
|
||||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
BuildCertificateFilePath(objectStore.Name),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsForbidden(err) {
|
if apierrors.IsForbidden(err) {
|
||||||
@ -199,7 +199,7 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
|
|||||||
objectStore.Namespace,
|
objectStore.Namespace,
|
||||||
&objectStore.Spec.Configuration,
|
&objectStore.Spec.Configuration,
|
||||||
os.Environ(),
|
os.Environ(),
|
||||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
BuildCertificateFilePath(objectStore.Name),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("while getting recover credentials: %w", err)
|
return fmt.Errorf("while getting recover credentials: %w", err)
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -105,7 +104,7 @@ func (b BackupServiceImplementation) Backup(
|
|||||||
objectStore.Namespace,
|
objectStore.Namespace,
|
||||||
&objectStore.Spec.Configuration,
|
&objectStore.Spec.Configuration,
|
||||||
common.MergeEnv(osEnvironment, caBundleEnvironment),
|
common.MergeEnv(osEnvironment, caBundleEnvironment),
|
||||||
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
|
common.BuildCertificateFilePath(objectStore.Name),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
contextLogger.Error(err, "while setting backup cloud credentials")
|
contextLogger.Error(err, "while setting backup cloud credentials")
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import (
|
|||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
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/metadata"
|
||||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
|
||||||
)
|
)
|
||||||
@ -234,7 +235,7 @@ func (impl *JobHookImpl) checkBackupDestination(
|
|||||||
cluster.Namespace,
|
cluster.Namespace,
|
||||||
barmanConfiguration,
|
barmanConfiguration,
|
||||||
os.Environ(),
|
os.Environ(),
|
||||||
path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName),
|
common.BuildCertificateFilePath(objectStoreName),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't get credentials for cluster %v: %w", cluster.Name, err)
|
return fmt.Errorf("can't get credentials for cluster %v: %w", cluster.Name, err)
|
||||||
@ -353,7 +354,7 @@ func loadBackupObjectFromExternalCluster(
|
|||||||
cluster.Namespace,
|
cluster.Namespace,
|
||||||
recoveryObjectStore,
|
recoveryObjectStore,
|
||||||
os.Environ(),
|
os.Environ(),
|
||||||
path.Join(metadata.BarmanCertificatesPath, recoveryObjectStoreName, metadata.BarmanCertificatesFileName))
|
common.BuildCertificateFilePath(recoveryObjectStoreName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user