Implemented get all keys
@@ -159,16 +159,25 @@ 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))
+ var items []*configuration.Item
+
+ if len(keys) == 0 {
+ var err error
+ if items, err = r.getAll(ctx); err != nil {
+ return &configuration.GetResponse{}, err
+ }
+ } else {
+ items = make([]*configuration.Item, 0, len(keys))
+ i := 0
for _, key := range keys {
resp, err := r.client.GetSetting(
ctx,
key,
&azappconfig.GetSettingOptions{
- Label: to.Ptr("label"),
+ Label: to.Ptr("*"),
})
if err != nil {
- return nil, err
+ return &configuration.GetResponse{}, err
}
item := &configuration.Item{
@@ -176,9 +185,14 @@ func (r *ConfigurationStore) Get(ctx context.Context, req *configuration.GetRequ
}
item.Key = key
item.Value = *resp.Value
+ if resp.Label != nil {
item.Metadata["label"] = *resp.Label
+ }
- items = append(items, item)
+ items[i] = item
+ i++
+ }
+ items = items[:i]
}
return &configuration.GetResponse{
@@ -186,6 +200,39 @@ func (r *ConfigurationStore) Get(ctx context.Context, req *configuration.GetRequ
}, 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
+ if setting.Label != nil {
+ 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")
}
