Skip to content

Commit 76c4091

Browse files
committed
feat: fork to omit '--credentials' command for azure-blob-storage credentials
Signed-off-by: Tao Li <[email protected]>
1 parent 018944b commit 76c4091

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pkg/command/commandbuilder.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func appendCloudProviderOptions(
115115
break
116116
}
117117

118+
// if flag to use DefaultAzureCredential, we do not
119+
// append the --credentials command here
120+
if forkCheckUseDefaultAzureCredentials(ctx) {
121+
break
122+
}
123+
118124
if !capabilities.HasAzureManagedIdentity {
119125
err := fmt.Errorf(
120126
"barman >= 2.18 is required to use azureInheritFromAzureAD, current: %v",
@@ -143,3 +149,19 @@ func appendCloudProviderOptions(
143149

144150
return options, nil
145151
}
152+
153+
type contextKey string
154+
155+
const useDefaultAzureCredentials contextKey = "useDefaultAzureCredentials"
156+
157+
func forkCheckUseDefaultAzureCredentials(ctx context.Context) bool {
158+
v := ctx.Value(useDefaultAzureCredentials)
159+
if v == nil {
160+
return false
161+
}
162+
result, ok := v.(bool)
163+
if !ok {
164+
return false
165+
}
166+
return result
167+
}

pkg/command/commandbuilder_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package command
1818

1919
import (
20+
"context"
2021
"strings"
2122

2223
barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
@@ -57,3 +58,25 @@ var _ = Describe("barmanCloudWalRestoreOptions", func() {
5758
))
5859
})
5960
})
61+
62+
var _ = Describe("forkCheckUseDefaultAzureCredentials", func() {
63+
It("forkCheckUseDefaultAzureCredentials should be false by default", func(ctx SpecContext) {
64+
Expect(forkCheckUseDefaultAzureCredentials(ctx)).To(BeFalse())
65+
})
66+
67+
It("forkCheckUseDefaultAzureCredentials should be false if ctx contains invalid value", func(ctx SpecContext) {
68+
newCtx := context.WithValue(ctx, useDefaultAzureCredentials, "invalidValue")
69+
Expect(forkCheckUseDefaultAzureCredentials(newCtx)).To(BeFalse())
70+
})
71+
72+
It("forkCheckUseDefaultAzureCredentials should be false if ctx contains false value", func(ctx SpecContext) {
73+
newCtx := context.WithValue(ctx, useDefaultAzureCredentials, false)
74+
Expect(forkCheckUseDefaultAzureCredentials(newCtx)).To(BeFalse())
75+
})
76+
77+
It("forkCheckUseDefaultAzureCredentials should be true only if ctx contains true value", func(ctx SpecContext) {
78+
newCtx := context.WithValue(ctx, useDefaultAzureCredentials, true)
79+
Expect(forkCheckUseDefaultAzureCredentials(newCtx)).To(BeTrue())
80+
})
81+
82+
})

0 commit comments

Comments
 (0)