Skip to content

Commit 451a222

Browse files
committed
chore: encapsulate certificate string building logic
Signed-off-by: Armando Ruocco <[email protected]>
1 parent 7761e2f commit 451a222

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

internal/cnpgi/common/common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package common
22

33
import (
44
"fmt"
5+
"path"
56
"strings"
67

78
barmanapi "github.com/cloudnative-pg/barman-cloud/pkg/api"
9+
10+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
811
)
912

1013
// TODO: refactor.
@@ -70,3 +73,8 @@ func MergeEnv(env []string, incomingEnv []string) []string {
7073

7174
return result
7275
}
76+
77+
// BuildCertificateFilePath builds the path to the barman objectStore certificate
78+
func BuildCertificateFilePath(objectStoreName string) string {
79+
return path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName)
80+
}

internal/cnpgi/common/wal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (w WALServiceImplementation) Archive(
8383
objectStore.Namespace,
8484
&objectStore.Spec.Configuration,
8585
os.Environ(),
86-
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
86+
BuildCertificateFilePath(objectStore.Name),
8787
)
8888
if err != nil {
8989
if apierrors.IsForbidden(err) {
@@ -199,7 +199,7 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
199199
objectStore.Namespace,
200200
&objectStore.Spec.Configuration,
201201
os.Environ(),
202-
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
202+
BuildCertificateFilePath(objectStore.Name),
203203
)
204204
if err != nil {
205205
return fmt.Errorf("while getting recover credentials: %w", err)

internal/cnpgi/instance/backup.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"path"
87
"strconv"
98
"time"
109

@@ -105,7 +104,7 @@ func (b BackupServiceImplementation) Backup(
105104
objectStore.Namespace,
106105
&objectStore.Spec.Configuration,
107106
common.MergeEnv(osEnvironment, caBundleEnvironment),
108-
path.Join(metadata.BarmanCertificatesPath, objectStore.Name, metadata.BarmanCertificatesFileName),
107+
common.BuildCertificateFilePath(objectStore.Name),
109108
)
110109
if err != nil {
111110
contextLogger.Error(err, "while setting backup cloud credentials")

internal/cnpgi/restore/restore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727

2828
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
29+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
2930
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
3031
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
3132
)
@@ -234,7 +235,7 @@ func (impl *JobHookImpl) checkBackupDestination(
234235
cluster.Namespace,
235236
barmanConfiguration,
236237
os.Environ(),
237-
path.Join(metadata.BarmanCertificatesPath, objectStoreName, metadata.BarmanCertificatesFileName),
238+
common.BuildCertificateFilePath(objectStoreName),
238239
)
239240
if err != nil {
240241
return fmt.Errorf("can't get credentials for cluster %v: %w", cluster.Name, err)
@@ -353,7 +354,7 @@ func loadBackupObjectFromExternalCluster(
353354
cluster.Namespace,
354355
recoveryObjectStore,
355356
os.Environ(),
356-
path.Join(metadata.BarmanCertificatesPath, recoveryObjectStoreName, metadata.BarmanCertificatesFileName))
357+
common.BuildCertificateFilePath(recoveryObjectStoreName))
357358
if err != nil {
358359
return nil, nil, err
359360
}

0 commit comments

Comments
 (0)