2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-22 00:45:57 +00:00
|
|
|
|
|
|
|
import (
|
2016-12-20 21:54:30 +00:00
|
|
|
"fmt"
|
|
|
|
|
2016-09-22 00:45:57 +00:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
2016-12-20 21:54:30 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/contexts/viewer"
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
2016-09-22 00:45:57 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-12-20 21:54:30 +00:00
|
|
|
type appConfigResponse struct {
|
|
|
|
OrgInfo *kolide.OrgInfo `json:"org_info,omitemtpy"`
|
|
|
|
ServerSettings *kolide.ServerSettings `json:"server_settings,omitempty"`
|
|
|
|
SMTPSettings *kolide.SMTPSettings `json:"smtp_settings,omitempty"`
|
|
|
|
Err error `json:"error,omitempty"`
|
2016-09-22 00:45:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:54:30 +00:00
|
|
|
func (r appConfigResponse) error() error { return r.Err }
|
2016-09-22 00:45:57 +00:00
|
|
|
|
|
|
|
func makeGetAppConfigEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
2016-12-20 21:54:30 +00:00
|
|
|
vc, ok := viewer.FromContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("could not fetch user")
|
|
|
|
}
|
2016-11-04 20:44:38 +00:00
|
|
|
config, err := svc.AppConfig(ctx)
|
2016-09-22 00:45:57 +00:00
|
|
|
if err != nil {
|
2016-12-20 21:54:30 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var smtpSettings *kolide.SMTPSettings
|
|
|
|
// only admin can see smtp settings
|
|
|
|
if vc.IsAdmin() {
|
|
|
|
smtpSettings = smtpSettingsFromAppConfig(config)
|
|
|
|
}
|
|
|
|
response := appConfigResponse{
|
|
|
|
OrgInfo: &kolide.OrgInfo{
|
|
|
|
OrgName: &config.OrgName,
|
|
|
|
OrgLogoURL: &config.OrgLogoURL,
|
|
|
|
},
|
|
|
|
ServerSettings: &kolide.ServerSettings{
|
|
|
|
KolideServerURL: &config.KolideServerURL,
|
|
|
|
},
|
|
|
|
SMTPSettings: smtpSettings,
|
2016-09-22 00:45:57 +00:00
|
|
|
}
|
2016-11-04 20:44:38 +00:00
|
|
|
return response, nil
|
2016-09-22 00:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeModifyAppConfigRequest(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
2016-12-20 21:54:30 +00:00
|
|
|
req := request.(kolide.AppConfigPayload)
|
|
|
|
config, err := svc.ModifyAppConfig(ctx, req)
|
2016-09-22 00:45:57 +00:00
|
|
|
if err != nil {
|
2016-12-20 21:54:30 +00:00
|
|
|
return appConfigResponse{Err: err}, nil
|
2016-11-04 20:44:38 +00:00
|
|
|
}
|
2016-12-20 21:54:30 +00:00
|
|
|
response := appConfigResponse{
|
|
|
|
OrgInfo: &kolide.OrgInfo{
|
|
|
|
OrgName: &config.OrgName,
|
|
|
|
OrgLogoURL: &config.OrgLogoURL,
|
|
|
|
},
|
|
|
|
ServerSettings: &kolide.ServerSettings{
|
|
|
|
KolideServerURL: &config.KolideServerURL,
|
|
|
|
},
|
2017-01-11 02:00:46 +00:00
|
|
|
SMTPSettings: smtpSettingsFromAppConfig(config),
|
2016-09-22 00:45:57 +00:00
|
|
|
}
|
2016-12-20 21:54:30 +00:00
|
|
|
return response, nil
|
2016-09-22 00:45:57 +00:00
|
|
|
}
|
|
|
|
}
|