Skip to content

Commit

Permalink
Add Scheme to MapProvider interface
Browse files Browse the repository at this point in the history
This is another required step in order to support configuring map providers via the Builder.

Updates #4759

This is a breaking change, since adds a new func to an interface. It is hard to make this backwards compatible, and would like to move forward with this exception.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Mar 23, 2022
1 parent 89da10b commit fd03881
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type MapProvider interface {
// Should never be called concurrently with itself or with Shutdown.
Retrieve(ctx context.Context, location string, watcher WatcherFunc) (Retrieved, error)

// Scheme returns the location scheme used by Retrieve.
Scheme() string

// Shutdown signals that the configuration for which this Provider was used to
// retrieve values is no longer in use and the Provider should close and release
// any resources that it may have created.
Expand Down
4 changes: 4 additions & 0 deletions config/mapprovider/envmapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (emp *mapProvider) Retrieve(_ context.Context, location string, _ config.Wa
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (fmp *mapProvider) Scheme() string {
return schemeName
}

func (*mapProvider) Shutdown(context.Context) error {
return nil
}
4 changes: 4 additions & 0 deletions config/mapprovider/filemapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (fmp *mapProvider) Retrieve(_ context.Context, location string, _ config.Wa
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (fmp *mapProvider) Scheme() string {
return schemeName
}

func (*mapProvider) Shutdown(context.Context) error {
return nil
}
4 changes: 4 additions & 0 deletions config/mapprovider/yamlmapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *mapProvider) Retrieve(_ context.Context, location string, _ config.Watc
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (fmp *mapProvider) Scheme() string {
return schemeName
}

func (s *mapProvider) Shutdown(context.Context) error {
return nil
}
14 changes: 9 additions & 5 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func MustNewConfigProvider(
func MustNewDefaultConfigProvider(configLocations []string, properties []string) ConfigProvider {
return MustNewConfigProvider(
configLocations,
map[string]config.MapProvider{
"file": filemapprovider.New(),
"env": envmapprovider.New(),
"yaml": yamlmapprovider.New(),
},
makeConfigMapProviderMap(filemapprovider.New(), envmapprovider.New(), yamlmapprovider.New()),
[]config.MapConverterFunc{
configmapprovider.NewOverwritePropertiesConverter(properties),
configmapprovider.NewExpandConverter(),
Expand Down Expand Up @@ -222,3 +218,11 @@ func (cm *configProvider) mergeRetrieve(ctx context.Context) (*config.Retrieved,
},
}, nil
}

func makeConfigMapProviderMap(providers ...config.MapProvider) map[string]config.MapProvider {
ret := make(map[string]config.MapProvider, len(providers))
for _, provider := range providers {
ret[provider.Scheme()] = provider
}
return ret
}

0 comments on commit fd03881

Please sign in to comment.