diff --git a/configuration/azure/appconfig/appconfig.go b/configuration/azure/appconfig/appconfig.go index d6bc29f96a..a7c0146ecd 100644 --- a/configuration/azure/appconfig/appconfig.go +++ b/configuration/azure/appconfig/appconfig.go @@ -160,25 +160,33 @@ 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{ @@ -186,6 +194,37 @@ 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 + 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") }