Extract providers configuration from server.go
This commit is contained in:
parent
ef4aa202d0
commit
395b1702de
5 changed files with 121 additions and 89 deletions
|
@ -15,9 +15,8 @@ import (
|
|||
|
||||
// Provider is a provider.Provider implementation that provides a Rest API
|
||||
type Provider struct {
|
||||
configurationChan chan<- types.ConfigMessage
|
||||
EntryPoint string `description:"EntryPoint" export:"true"`
|
||||
CurrentConfigurations *safe.Safe
|
||||
configurationChan chan<- types.ConfigMessage
|
||||
EntryPoint string `description:"EntryPoint" export:"true"`
|
||||
}
|
||||
|
||||
var templatesRenderer = render.New(render.Options{Directory: "nowhere"})
|
||||
|
@ -45,7 +44,10 @@ func (p *Provider) AddRoutes(systemRouter *mux.Router) {
|
|||
if err == nil {
|
||||
// TODO: Deprecated configuration - Change to `rest` in the future
|
||||
p.configurationChan <- types.ConfigMessage{ProviderName: "web", Configuration: configuration}
|
||||
p.getConfigHandler(response, request)
|
||||
err := templatesRenderer.JSON(response, http.StatusOK, configuration)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("Error parsing configuration %+v", err)
|
||||
http.Error(response, fmt.Sprintf("%+v", err), http.StatusBadRequest)
|
||||
|
@ -59,11 +61,3 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
|||
p.configurationChan = configurationChan
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) getConfigHandler(response http.ResponseWriter, request *http.Request) {
|
||||
currentConfigurations := p.CurrentConfigurations.Get().(types.Configurations)
|
||||
err := templatesRenderer.JSON(response, http.StatusOK, currentConfigurations)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue