fleet/server/service/service_appconfig.go
Victor Vrantchan def24499b5 store WebAddress config in datastore (#421)
moves web address config to datastore so that it can be configured by a user
in the Web UI.
rename OrgInfo struct to AppConfig.

For #363
For #378
2016-11-04 16:44:38 -04:00

46 lines
1.2 KiB
Go

package service
import (
"github.com/kolide/kolide-ose/server/kolide"
"golang.org/x/net/context"
)
func (svc service) NewAppConfig(ctx context.Context, p kolide.AppConfigPayload) (*kolide.AppConfig, error) {
newConfig, err := svc.ds.NewAppConfig(fromPayload(p, kolide.AppConfig{}))
if err != nil {
return nil, err
}
return newConfig, nil
}
func (svc service) AppConfig(ctx context.Context) (*kolide.AppConfig, error) {
return svc.ds.AppConfig()
}
func (svc service) ModifyAppConfig(ctx context.Context, p kolide.AppConfigPayload) (*kolide.AppConfig, error) {
config, err := svc.ds.AppConfig()
if err != nil {
return nil, err
}
updated := fromPayload(p, *config)
if err := svc.ds.SaveAppConfig(updated); err != nil {
return nil, err
}
return config, nil
}
func fromPayload(p kolide.AppConfigPayload, config kolide.AppConfig) *kolide.AppConfig {
if p.OrgInfo != nil && p.OrgInfo.OrgLogoURL != nil {
config.OrgLogoURL = *p.OrgInfo.OrgLogoURL
}
if p.OrgInfo != nil && p.OrgInfo.OrgName != nil {
config.OrgName = *p.OrgInfo.OrgName
}
if p.ServerSettings != nil && p.ServerSettings.KolideServerURL != nil {
config.KolideServerURL = *p.ServerSettings.KolideServerURL
}
return &config
}