Skip to content

Commit

Permalink
feature: add multi_step check type + runtime type to validate runtime…
Browse files Browse the repository at this point in the history
… version before creating or updating a check [sc-17816] (#117)
  • Loading branch information
Antoine-C committed Oct 31, 2023
1 parent a75fba5 commit 9ddd61d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
27 changes: 27 additions & 0 deletions checkly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9ddd61d

Please sign in to comment.