-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck_tls.go
69 lines (63 loc) · 2.96 KB
/
healthcheck_tls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package client
import (
"context"
"fmt"
"net/http"
)
type HealthcheckTLSDefinition struct {
Target string `json:"target" validate:"required"`
Port uint `json:"port" validate:"required,max=65535,min=1"`
Key string `json:"key,omitempty"`
Cert string `json:"cert,omitempty"`
Cacert string `json:"cacert,omitempty"`
ServerName string `json:"server-name,omitempty"`
Insecure bool `json:"insecure"`
ExpirationDelay string `json:"expiration-delay"`
}
type CreateTLSHealthcheckInput struct {
Name string `json:"name" description:"Healthcheck name" validate:"required,max=255,min=1"`
Description string `json:"description" description:"Healthcheck description" validate:"max=255"`
Labels map[string]string `json:"labels" description:"Healthcheck labels" validate:"dive,keys,max=255,min=1,endkeys,max=255,min=1"`
Interval string `json:"interval" description:"Healthcheck interval" validate:"required"`
Enabled bool `json:"bool" description:"Enable the healthcheck on the appclacks platform"`
Timeout string `json:"timeout" validate:"required"`
HealthcheckTLSDefinition
}
type UpdateTLSHealthcheckInput struct {
ID string `json:"-" param:"id" description:"Healthcheck ID" validate:"required,uuid"`
Name string `json:"name" description:"Healthcheck name" validate:"required,max=255,min=1"`
Description string `json:"description" description:"Healthcheck description" validate:"max=255"`
Labels map[string]string `json:"labels" description:"Healthcheck labels" validate:"dive,keys,max=255,min=1,endkeys,max=255,min=1"`
Interval string `json:"interval" description:"Healthcheck interval" validate:"required"`
Timeout string `json:"timeout" validate:"required"`
Enabled bool `json:"enabled" description:"Enable the healthcheck on the appclacks platform"`
HealthcheckTLSDefinition
}
func (c *Client) CreateTLSHealthcheck(ctx context.Context, input CreateTLSHealthcheckInput) (Healthcheck, error) {
var result Healthcheck
_, err := c.sendRequest(ctx, "/api/v1/healthcheck/tls", http.MethodPost, input, &result, nil)
if err != nil {
return Healthcheck{}, err
}
return result, nil
}
func (c *Client) UpdateTLSHealthcheck(ctx context.Context, input UpdateTLSHealthcheckInput) (Healthcheck, error) {
var result Healthcheck
internalInput := internalUpdateHealthcheckInput{
Name: input.Name,
Description: input.Description,
Labels: input.Labels,
Interval: input.Interval,
Enabled: input.Enabled,
Timeout: input.Timeout,
}
payload, err := jsonMerge(internalInput, input.HealthcheckTLSDefinition)
if err != nil {
return result, err
}
_, err = c.sendRequest(ctx, fmt.Sprintf("/api/v1/healthcheck/tls/%s", input.ID), http.MethodPut, payload, &result, nil)
if err != nil {
return Healthcheck{}, err
}
return result, nil
}