mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
018e10ea66
``` $ fleetctl config set address https://localhost:8080 [+] Set the "address" config key to "https://localhost:8080" in the "default" context $ fleetctl config set ignore_tls true [+] Set the "ignore_tls" config key to "true" in the "default" context $ fleetctl setup --email mike@arpaia.co --password "abc123" [+] Fleet setup successful and context configured! $ cat ~/.fleet/config contexts: default: address: https://localhost:8080 email: mike@arpaia.co ignore_tls: true token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6IlUvdm05Vk9wSG0xUlA4SUtjQnBhb2ovWlo1TXppSEVXcFRCNFNPb2tHQnNLUFpDQXFieVpWWnpJb0UvczQzcWkyd1pHZXJOa29SNFVIQ2hNZUc0K09RPT0ifQ.rHawSN8JvD4jjWAPTYX2Ep9ZpMt3u4mSIQcu920C-_s $ fleetctl logout [+] Fleet logout successful and local token cleared! $ cat ~/.fleet/config contexts: default: address: https://localhost:8080 email: mike@arpaia.co ignore_tls: true token: "" ```
38 lines
929 B
Go
38 lines
929 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/url"
|
|
|
|
"github.com/kolide/fleet/server/kolide"
|
|
)
|
|
|
|
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 = 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
|
|
}
|