mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
417ef2c9b6
- Move team-related service methods to `ee/server/service`. - Instantiate different service on startup based on license key. - Refactor service errors into separate package. - Add support for running E2E tests in both Core and Basic tiers.
38 lines
937 B
Go
38 lines
937 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/url"
|
|
|
|
"github.com/fleetdm/fleet/server/kolide"
|
|
)
|
|
|
|
func (mw validationMiddleware) NewAppConfig(ctx context.Context, payload kolide.AppConfigPayload) (*kolide.AppConfig, error) {
|
|
invalid := &kolide.InvalidArgumentError{}
|
|
var serverURLString string
|
|
if payload.ServerSettings == nil {
|
|
invalid.Append("kolide_server_url", "missing required argument")
|
|
} else {
|
|
serverURLString = cleanupURL(*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 errors.New("url scheme must be https")
|
|
}
|
|
return nil
|
|
}
|