Skip to content

Commit

Permalink
pass more field on toplevel checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra committed Jan 25, 2023
1 parent 207b811 commit 6fc6708
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/superfly/flyctl/helpers"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/scanner"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -184,43 +185,28 @@ type ToplevelCheck struct {
}

func (chk *ToplevelCheck) toMachineCheck() (*api.MachineCheck, error) {
if chk.GracePeriod != nil {
return nil, fmt.Errorf("checks for machines do not yet support grace_period")
}
if chk.RestartLimit != nil {
return nil, fmt.Errorf("checks for machines do not yet support restart_limit")
}
if chk.HTTPProtocol != nil {
return nil, fmt.Errorf("checks for machines do not yet support protocol")
}
if len(chk.Headers) > 0 {
return nil, fmt.Errorf("checks for machines do not yet support headers")
}
if chk.Type == nil || !slices.Contains([]string{"http", "tcp"}, *chk.Type) {
return nil, fmt.Errorf("Missing or invalid check type, must be 'http' or 'tcp'")
}

res := &api.MachineCheck{
Type: chk.Type,
Port: chk.Port,
Interval: chk.Interval,
Timeout: chk.Timeout,
}
if chk.Type == nil {
return nil, fmt.Errorf("Missing type, it must be one of 'http' or 'tcp'")
} else {
switch *chk.Type {
case "tcp":
case "http":
if chk.HTTPMethod != nil {
res.HTTPMethod = api.Pointer(strings.ToUpper(*chk.HTTPMethod))
}
res.HTTPPath = chk.HTTPPath
res.HTTPProtocol = chk.HTTPProtocol
res.HTTPSkipTLSVerify = chk.TLSSkipVerify
res.HTTPHeaders = lo.MapToSlice(
chk.Headers, func(k string, v string) api.MachineHTTPHeader {
return api.MachineHTTPHeader{Name: k, Values: []string{v}}
})
default:
return nil, fmt.Errorf("error unknown check type: %s", *chk.Type)
}
Type: chk.Type,
Port: chk.Port,
Interval: chk.Interval,
Timeout: chk.Timeout,
HTTPPath: chk.HTTPPath,
HTTPProtocol: chk.HTTPProtocol,
HTTPSkipTLSVerify: chk.TLSSkipVerify,
HTTPHeaders: lo.MapToSlice(
chk.Headers, func(k string, v string) api.MachineHTTPHeader {
return api.MachineHTTPHeader{Name: k, Values: []string{v}}
}),
}
if chk.HTTPMethod != nil {
res.HTTPMethod = api.Pointer(strings.ToUpper(*chk.HTTPMethod))
}
return res, nil
}
Expand Down

0 comments on commit 6fc6708

Please sign in to comment.