2016-11-09 17:19:07 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2018-05-04 16:53:21 +00:00
|
|
|
"errors"
|
2016-11-09 17:19:07 +00:00
|
|
|
"net/url"
|
|
|
|
|
2020-11-11 17:59:12 +00:00
|
|
|
"github.com/fleetdm/fleet/server/kolide"
|
2016-11-09 17:19:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (mw validationMiddleware) NewAppConfig(ctx context.Context, payload kolide.AppConfigPayload) (*kolide.AppConfig, error) {
|
|
|
|
invalid := &invalidArgumentError{}
|
|
|
|
var serverURLString string
|
|
|
|
if payload.ServerSettings == nil {
|
|
|
|
invalid.Append("kolide_server_url", "missing required argument")
|
|
|
|
} else {
|
2017-03-22 19:40:01 +00:00
|
|
|
serverURLString = cleanupURL(*payload.ServerSettings.KolideServerURL)
|
2016-11-09 17:19:07 +00:00
|
|
|
}
|
|
|
|
if err := validateKolideServerURL(serverURLString); err != nil {
|
|
|
|
invalid.Append("kolide_server_url", err.Error())
|
|
|
|
}
|
|
|
|
if invalid.HasErrors() {
|
|
|
|
return nil, invalid
|
|
|
|
}
|
|
|
|
return mw.Service.NewAppConfig(ctx, payload)
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateKolideServerURL(urlString string) error {
|
|
|
|
serverURL, err := url.Parse(urlString)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if serverURL.Scheme != "https" {
|
2018-05-04 16:53:21 +00:00
|
|
|
return errors.New("url scheme must be https")
|
2016-11-09 17:19:07 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|