Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions configuration/azure/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,7 @@ func (r *ConfigurationStore) Get(ctx context.Context, req *configuration.GetRequ
return &configuration.GetResponse{}, err
}

item := &configuration.Item{
Metadata: map[string]string{},
}
item.Value = *resp.Value
if resp.Label != nil {
item.Metadata["label"] = *resp.Label
}
item := settingToConfigurationItem(resp.Setting)

items[key] = item
}
Expand Down Expand Up @@ -187,16 +181,11 @@ func (r *ConfigurationStore) getAll(ctx context.Context, req *configuration.GetR

for allSettingsPgr.More() {
timeoutContext, cancel := context.WithTimeout(ctx, r.metadata.RequestTimeout)
defer cancel()
if revResp, err := allSettingsPgr.NextPage(timeoutContext); err == nil {
revResp, err := allSettingsPgr.NextPage(timeoutContext)
cancel()
if err == nil {
for _, setting := range revResp.Settings {
item := &configuration.Item{
Metadata: map[string]string{},
}
item.Value = *setting.Value
if setting.Label != nil {
item.Metadata["label"] = *setting.Label
}
item := settingToConfigurationItem(setting)

items[*setting.Key] = item
}
Expand All @@ -207,6 +196,23 @@ func (r *ConfigurationStore) getAll(ctx context.Context, req *configuration.GetR
return items, nil
}

func settingToConfigurationItem(setting azappconfig.Setting) *configuration.Item {
item := &configuration.Item{
Metadata: map[string]string{},
}
if setting.Value != nil {
item.Value = *setting.Value
}
if setting.Label != nil {
item.Metadata["label"] = *setting.Label
}
if setting.ContentType != nil {
item.Metadata["contentType"] = *setting.ContentType
}

return item
}

func (r *ConfigurationStore) getLabelFromMetadata(metadata map[string]string) *string {
type labelMetadata = struct {
Label string `mapstructure:"label"`
Expand Down
14 changes: 13 additions & 1 deletion configuration/azure/appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func (m *MockConfigurationStore) GetSetting(ctx context.Context, key string, opt
if key == "testKey" || key == "test_sentinel_key" {
settings := azappconfig.Setting{}

settings.Key = ptr.Of("testKey")
settings.Key = ptr.Of(key)
settings.Value = ptr.Of("testValue")
settings.Label = ptr.Of("testLabel")
settings.ContentType = ptr.Of("application/json")

resp := azappconfig.GetSettingResponse{}
resp.Setting = settings
Expand All @@ -58,10 +60,14 @@ func (m *MockConfigurationStore) NewListSettingsPager(selector azappconfig.Setti
setting1 := azappconfig.Setting{}
setting1.Key = ptr.Of("testKey-1")
setting1.Value = ptr.Of("testValue-1")
setting1.Label = ptr.Of("testLabel-1")
setting1.ContentType = ptr.Of("application/json")

setting2 := azappconfig.Setting{}
setting2.Key = ptr.Of("testKey-2")
setting2.Value = ptr.Of("testValue-2")
setting2.Label = ptr.Of("testLabel-2")
setting2.ContentType = ptr.Of("text/plain")
settings[0] = setting1
settings[1] = setting2

Expand Down Expand Up @@ -113,6 +119,8 @@ func Test_getConfigurationWithProvidedKeys(t *testing.T) {
res, err := s.Get(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, res.Items, 1)
assert.Equal(t, "application/json", res.Items["testKey"].Metadata["contentType"])
assert.Equal(t, "testLabel", res.Items["testKey"].Metadata["label"])
})
}

Expand Down Expand Up @@ -189,6 +197,10 @@ func Test_getConfigurationWithNoProvidedKeys(t *testing.T) {
res, err := s.Get(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, res.Items, 2)
assert.Equal(t, "application/json", res.Items["testKey-1"].Metadata["contentType"])
assert.Equal(t, "testLabel-1", res.Items["testKey-1"].Metadata["label"])
assert.Equal(t, "text/plain", res.Items["testKey-2"].Metadata["contentType"])
assert.Equal(t, "testLabel-2", res.Items["testKey-2"].Metadata["label"])
})
}

Expand Down
Loading