Skip to content

Commit

Permalink
Implemented get all keys
Browse files Browse the repository at this point in the history
Signed-off-by: cmendible <[email protected]>
  • Loading branch information
cmendible committed Jul 30, 2022
1 parent 3b96384 commit 0ed25aa
Showing 1 changed file with 55 additions and 16 deletions.
71 changes: 55 additions & 16 deletions configuration/azure/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +160,71 @@ func parseMetadata(meta configuration.Metadata) (metadata, error) {
func (r *ConfigurationStore) Get(ctx context.Context, req *configuration.GetRequest) (*configuration.GetResponse, error) {
keys := req.Keys
items := make([]*configuration.Item, 0, len(keys))
for _, key := range keys {
resp, err := r.client.GetSetting(
ctx,
key,
&azappconfig.GetSettingOptions{
Label: to.Ptr("label"),
})
if err != nil {

if len(keys) == 0 {
var err error
if items, err = r.getAll(ctx); err != nil {
return nil, err
}

item := &configuration.Item{
Metadata: map[string]string{},
} else {
for _, key := range keys {
resp, err := r.client.GetSetting(
ctx,
key,
&azappconfig.GetSettingOptions{
Label: to.Ptr("label"),
})
if err != nil {
return nil, err
}

item := &configuration.Item{
Metadata: map[string]string{},
}
item.Key = key
item.Value = *resp.Value
item.Metadata["label"] = *resp.Label

items = append(items, item)
}
item.Key = key
item.Value = *resp.Value
item.Metadata["label"] = *resp.Label

items = append(items, item)
}

return &configuration.GetResponse{
Items: items,
}, nil
}

func (r *ConfigurationStore) getAll(ctx context.Context) ([]*configuration.Item, error) {
items := make([]*configuration.Item, 0)

revPgr := r.client.NewListRevisionsPager(
azappconfig.SettingSelector{
KeyFilter: to.Ptr("*"),
LabelFilter: to.Ptr("*"),
Fields: azappconfig.AllSettingFields(),
},
nil)

for revPgr.More() {
if revResp, err := revPgr.NextPage(ctx); err == nil {
for _, setting := range revResp.Settings {
item := &configuration.Item{
Metadata: map[string]string{},
}
item.Key = *setting.Key
item.Value = *setting.Value
item.Metadata["label"] = *setting.Label

items = append(items, item)
}
} else {
return nil, fmt.Errorf("failed to load all keys, error is %s", err)
}
}

return items, nil
}

func (r *ConfigurationStore) Subscribe(ctx context.Context, req *configuration.SubscribeRequest, handler configuration.UpdateHandler) (string, error) {
return "", fmt.Errorf("Subscribe is not implemented by this configuration store")
}
Expand Down

0 comments on commit 0ed25aa

Please sign in to comment.