2016-11-09 17:19:07 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2017-02-01 17:20:50 +00:00
|
|
|
"github.com/kolide/kolide/server/kolide"
|
2016-11-09 17:19:07 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
serverURLString = *payload.ServerSettings.KolideServerURL
|
|
|
|
}
|
|
|
|
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" {
|
|
|
|
return fmt.Errorf("url scheme must be https")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|