Skip to content

Commit bd5506c

Browse files
committed
feat(flagd): add support for azure blob
- fix for EnvVarKey function to prevent corrupting Azure related env vars keys
1 parent c5e1158 commit bd5506c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

api/core/v1beta1/common/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

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

67
corev1 "k8s.io/api/core/v1"
78
)
@@ -11,6 +12,7 @@ type SyncProviderType string
1112
const (
1213
SyncProviderKubernetes SyncProviderType = "kubernetes"
1314
SyncProviderFilepath SyncProviderType = "file"
15+
SyncProviderAzureBlob SyncProviderType = "azblob"
1416
SyncProviderGcs SyncProviderType = "gcs"
1517
SyncProviderHttp SyncProviderType = "http"
1618
SyncProviderGrpc SyncProviderType = "grpc"
@@ -54,6 +56,10 @@ func (s SyncProviderType) IsKubernetes() bool {
5456
return s == SyncProviderKubernetes
5557
}
5658

59+
func (s SyncProviderType) IsAzureBlob() bool {
60+
return s == SyncProviderAzureBlob
61+
}
62+
5763
func (s SyncProviderType) IsHttp() bool {
5864
return s == SyncProviderHttp
5965
}
@@ -85,6 +91,10 @@ func FalseVal() *bool {
8591
}
8692

8793
func EnvVarKey(prefix string, suffix string) string {
94+
// If prefix is blank (empty or whitespace), return just the suffix as the env var key
95+
if strings.TrimSpace(prefix) == "" {
96+
return suffix
97+
}
8898
return fmt.Sprintf("%s_%s", prefix, suffix)
8999
}
90100

api/core/v1beta1/common/common_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,35 @@ func Test_FeatureFlagSource_SyncProvider(t *testing.T) {
1313
h := SyncProviderHttp
1414
g := SyncProviderGrpc
1515
gcs := SyncProviderGcs
16+
azureBlob := SyncProviderAzureBlob
1617

1718
require.True(t, k.IsKubernetes())
1819
require.True(t, f.IsFilepath())
1920
require.True(t, h.IsHttp())
2021
require.True(t, g.IsGrpc())
2122
require.True(t, gcs.IsGcs())
23+
require.True(t, azureBlob.IsAzureBlob())
2224

2325
require.False(t, f.IsKubernetes())
2426
require.False(t, h.IsFilepath())
2527
require.False(t, k.IsGrpc())
2628
require.False(t, g.IsHttp())
2729
require.False(t, g.IsGcs())
30+
require.False(t, gcs.IsAzureBlob())
2831
}
2932

3033
func Test_FLagSourceConfiguration_EnvVarKey(t *testing.T) {
3134
require.Equal(t, "pre_suf", EnvVarKey("pre", "suf"))
3235
}
3336

37+
func Test_FLagSourceConfiguration_EnvVarKey_EmptyPre(t *testing.T) {
38+
require.Equal(t, "suf", EnvVarKey(" ", "suf"))
39+
}
40+
41+
func Test_FLagSourceConfiguration_EnvVarKey_NoPre(t *testing.T) {
42+
require.Equal(t, "suf", EnvVarKey("", "suf"))
43+
}
44+
3445
func Test_FLagSourceConfiguration_FeatureFlagConfigurationId(t *testing.T) {
3546
require.Equal(t, "pre_suf", FeatureFlagConfigurationId("pre", "suf"))
3647
}

internal/common/flagdinjector/flagdinjector.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ func (fi *FlagdContainerInjector) newSourceConfig(ctx context.Context, source ap
236236
sourceCfg = fi.toGrpcProviderConfig(source)
237237
case source.Provider.IsFlagdProxy():
238238
sourceCfg, err = fi.toFlagdProxyConfig(ctx, objectMeta, source)
239+
case source.Provider.IsAzureBlob():
240+
sourceCfg = fi.toAzureBlobConfig(source)
239241
default:
240242
err = fmt.Errorf("could not add provider %s: %w", source.Provider, common.ErrUnrecognizedSyncProvider)
241243
}
@@ -327,6 +329,14 @@ func (fi *FlagdContainerInjector) toGrpcProviderConfig(source api.Source) types.
327329
}
328330
}
329331

332+
func (fi *FlagdContainerInjector) toAzureBlobConfig(source api.Source) types.SourceConfig {
333+
return types.SourceConfig{
334+
URI: source.Source,
335+
Provider: string(apicommon.SyncProviderAzureBlob),
336+
Interval: source.Interval,
337+
}
338+
}
339+
330340
func (fi *FlagdContainerInjector) toFlagdProxyConfig(ctx context.Context, objectMeta *metav1.ObjectMeta, source api.Source) (types.SourceConfig, error) {
331341
// does the proxy exist
332342
exists, ready, err := fi.isFlagdProxyReady(ctx)

0 commit comments

Comments
 (0)