From 9ddd61d64615b980a02392316ecc9c9f39322040 Mon Sep 17 00:00:00 2001 From: Antoine Coutellier Date: Tue, 31 Oct 2023 10:52:22 +0100 Subject: [PATCH] feature: add multi_step check type + runtime type to validate runtime version before creating or updating a check [sc-17816] (#117) --- checkly.go | 27 +++++++++++++++++++++++++++ types.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/checkly.go b/checkly.go index ac3ebf5..9b4ff5b 100644 --- a/checkly.go +++ b/checkly.go @@ -190,6 +190,8 @@ func (c *client) CreateCheck( checkType = "checks/api" } else if check.Type == "HEARTBEAT" { checkType = "checks/heartbeat" + } else if check.Type == "MULTI_STEP" { + checkType = "checks/multistep" } status, res, err := c.apiCall( ctx, @@ -1339,6 +1341,31 @@ func alertChannelFromJSON(response string) (*AlertChannel, error) { return resultAc, nil } +// Get a specific runtime specs +func (c *client) GetRuntime( + ctx context.Context, + ID string, +) (*Runtime, error) { + status, res, err := c.apiCall( + ctx, + http.MethodGet, + fmt.Sprintf("runtimes/%s", ID), + nil, + ) + if err != nil { + return nil, err + } + if status != http.StatusOK { + return nil, fmt.Errorf("unexpected response status %d: %q", status, res) + } + result := Runtime{} + err = json.NewDecoder(strings.NewReader(res)).Decode(&result) + if err != nil { + return nil, fmt.Errorf("decoding error for data %s: %v", res, err) + } + return &result, nil +} + // dumpResponse writes the raw response data to the debug output, if set, or // standard error otherwise. func (c *client) dumpResponse(resp *http.Response) { diff --git a/types.go b/types.go index 027aa49..8616c92 100644 --- a/types.go +++ b/types.go @@ -350,6 +350,12 @@ type Client interface { // SetChecklySource sets the source of the check for analytics purposes. SetChecklySource(source string) + + // Get a specific runtime specs. + GetRuntime( + ctx context.Context, + ID string, + ) (*Runtime, error) } // client represents a Checkly client. If the Debug field is set to an io.Writer @@ -471,6 +477,34 @@ type Check struct { DoubleCheck bool `json:"doubleCheck"` } +// Check represents the parameters for an existing check. +type MultiStepCheck struct { + ID string `json:"id"` + Name string `json:"name"` + Type string `json:"checkType"` + Frequency int `json:"frequency"` + FrequencyOffset int `json:"frequencyOffset,omitempty"` + Activated bool `json:"activated"` + Muted bool `json:"muted"` + ShouldFail bool `json:"shouldFail"` + Locations []string `json:"locations,omitempty"` + Script string `json:"script,omitempty"` + EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"` + Tags []string `json:"tags,omitempty"` + AlertSettings AlertSettings `json:"alertSettings,omitempty"` + UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"` + GroupID int64 `json:"groupId,omitempty"` + GroupOrder int `json:"groupOrder,omitempty"` + AlertChannelSubscriptions []AlertChannelSubscription `json:"alertChannelSubscriptions,omitempty"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + + // Pointers + PrivateLocations *[]string `json:"privateLocations"` + RuntimeID *string `json:"runtimeId"` + RetryStrategy *RetryStrategy `json:"retryStrategy,omitempty"` +} + type HeartbeatCheck struct { ID string `json:"id"` Name string `json:"name"` @@ -858,6 +892,14 @@ type Location struct { Region string `json:"region"` } +type Runtime struct { + Name string `json:"name"` + MultiStepSupport bool `json:"multiStepSupport"` + Stage string `json:"stage"` + RuntimeEndOfLife string `json:"runtimeEndOfLife"` + Description string `json:"description"` +} + // SetConfig sets config of alert channel based on it's type func (a *AlertChannel) SetConfig(cfg interface{}) { switch v := cfg.(type) {