diff --git a/.gitignore b/.gitignore index 14e2032..185c7cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -cli -appclacks \ No newline at end of file +/cli +/appclacks \ No newline at end of file diff --git a/vendor/github.com/appclacks/go-types/README.md b/vendor/github.com/appclacks/go-types/README.md new file mode 100644 index 0000000..021b723 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/README.md @@ -0,0 +1,3 @@ +# Appclacks API Go types + +This is a collection of Golang types representing the [Appclacks](https://appclacks.com/) API requests and responses. diff --git a/vendor/github.com/appclacks/go-types/healthcheck.go b/vendor/github.com/appclacks/go-types/healthcheck.go new file mode 100644 index 0000000..49ea003 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/healthcheck.go @@ -0,0 +1,137 @@ +package types + +import ( + "encoding/json" + "fmt" + "time" +) + +type Healthcheck struct { + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + Type string `json:"type"` + Labels map[string]string `json:"labels,omitempty"` + Timeout string `json:"timeout" validate:"required"` + Interval string `json:"interval" validate:"required"` + CreatedAt time.Time `json:"created-at"` + Enabled bool `json:"enabled"` + Definition any `json:",inline"` +} + +type internalHealthcheck struct { + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + Type string `json:"type"` + Labels map[string]string `json:"labels,omitempty"` + Enabled bool `json:"enabled"` + Interval string `json:"interval" validate:"required"` + Timeout string `json:"timeout" validate:"required"` + CreatedAt time.Time `json:"created-at"` +} + +func (h *Healthcheck) MarshalJSON() ([]byte, error) { + result := make(map[string]any) + internal := internalHealthcheck{ + ID: h.ID, + Name: h.Name, + Enabled: h.Enabled, + Description: h.Description, + Type: h.Type, + Timeout: h.Timeout, + Labels: h.Labels, + Interval: h.Interval, + CreatedAt: h.CreatedAt, + } + internalStr, err := json.Marshal(internal) + if err != nil { + return nil, err + } + defStr, err := json.Marshal(h.Definition) + if err != nil { + return nil, err + } + + err = json.Unmarshal(internalStr, &result) + if err != nil { + return nil, err + } + + err = json.Unmarshal(defStr, &result) + if err != nil { + return nil, err + } + return json.Marshal(result) +} + +func (h *Healthcheck) UnmarshalJSON(data []byte) error { + + var internal internalHealthcheck + if err := json.Unmarshal(data, &internal); err != nil { + return err + } + + if internal.Type == "dns" { + var definition HealthcheckDNSDefinition + if err := json.Unmarshal(data, &definition); err != nil { + return err + } + h.Definition = definition + } else if internal.Type == "tcp" { + var definition HealthcheckTCPDefinition + if err := json.Unmarshal(data, &definition); err != nil { + return err + } + h.Definition = definition + } else if internal.Type == "http" { + var definition HealthcheckHTTPDefinition + if err := json.Unmarshal(data, &definition); err != nil { + return err + } + h.Definition = definition + } else if internal.Type == "tls" { + var definition HealthcheckTLSDefinition + if err := json.Unmarshal(data, &definition); err != nil { + return err + } + h.Definition = definition + } else { + return fmt.Errorf("Unknown healthcheck type %s", h.Type) + } + h.ID = internal.ID + h.Name = internal.Name + h.Timeout = internal.Timeout + h.Description = internal.Description + h.Type = internal.Type + h.Enabled = internal.Enabled + h.Labels = internal.Labels + h.Interval = internal.Interval + h.CreatedAt = internal.CreatedAt + + return nil +} + +type DeleteHealthcheckInput struct { + ID string `param:"id" description:"Healthcheck ID" validate:"required,uuid"` +} + +type GetHealthcheckInput struct { + ID string `param:"id" description:"Healthcheck ID" validate:"required,uuid"` +} + +type ListHealthchecksOutput struct { + Result []Healthcheck `json:"result"` +} + +type CabourotteDiscoveryInput struct { + // foo=bar,a=b + Labels string `query:"labels,omitempty"` +} + +type CabourotteDiscoveryOutput struct { + DNSChecks []Healthcheck `json:"dns-checks,omitempty"` + TCPChecks []Healthcheck `json:"tcp-checks,omitempty"` + HTTPChecks []Healthcheck `json:"http-checks,omitempty"` + TLSChecks []Healthcheck `json:"tls-checks,omitempty"` +} diff --git a/vendor/github.com/appclacks/go-types/healthcheck_dns.go b/vendor/github.com/appclacks/go-types/healthcheck_dns.go new file mode 100644 index 0000000..c5ad2ee --- /dev/null +++ b/vendor/github.com/appclacks/go-types/healthcheck_dns.go @@ -0,0 +1,27 @@ +package types + +type HealthcheckDNSDefinition struct { + Domain string `json:"domain,omitempty" description:"Domain to check" validate:"required,max=255,min=1"` + ExpectedIPs []string `json:"expected-ips,omitempty" description:"Domain to check" validate:"max=10,dive,ip_addr"` +} + +type CreateDNSHealthcheckInput 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"` + HealthcheckDNSDefinition +} + +type UpdateDNSHealthcheckInput struct { + ID string `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"` + HealthcheckDNSDefinition +} diff --git a/vendor/github.com/appclacks/go-types/healthcheck_http.go b/vendor/github.com/appclacks/go-types/healthcheck_http.go new file mode 100644 index 0000000..89f8d93 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/healthcheck_http.go @@ -0,0 +1,38 @@ +package types + +type HealthcheckHTTPDefinition struct { + ValidStatus []uint `json:"valid-status" validate:"required,min=1,max=20,dive,max=1000"` + Target string `json:"target" validate:"required,max=255,min=1"` + Method string `json:"method" validate:"required,oneof=GET POST PUT DELETE HEAD"` + Port uint `json:"port" validate:"required,max=65535,min=1"` + Redirect bool `json:"redirect"` + Body string `json:"body,omitempty"` + BodyRegexp []string `json:"body-regexp,omitempty" validate:"max=3"` + Headers map[string]string `json:"headers,omitempty" validate:"max=5"` + Protocol string `json:"protocol" validate:"oneof=http https"` + Path string `json:"path,omitempty"` + Key string `json:"key,omitempty"` + Cert string `json:"cert,omitempty"` + Cacert string `json:"cacert,omitempty"` +} + +type CreateHTTPHealthcheckInput 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"` + HealthcheckHTTPDefinition +} + +type UpdateHTTPHealthcheckInput struct { + ID string `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"` + Enabled bool `json:"enabled" description:"Enable the healthcheck on the appclacks platform"` + Timeout string `json:"timeout" validate:"required"` + HealthcheckHTTPDefinition +} diff --git a/vendor/github.com/appclacks/go-types/healthcheck_tcp.go b/vendor/github.com/appclacks/go-types/healthcheck_tcp.go new file mode 100644 index 0000000..f832506 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/healthcheck_tcp.go @@ -0,0 +1,28 @@ +package types + +type HealthcheckTCPDefinition struct { + Target string `json:"target" validate:"required"` + Port uint `json:"port" validate:"required,max=65535,min=1"` + ShouldFail bool `json:"should-fail"` +} + +type CreateTCPHealthcheckInput 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"` + HealthcheckTCPDefinition +} + +type UpdateTCPHealthcheckInput struct { + ID string `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"` + HealthcheckTCPDefinition +} diff --git a/vendor/github.com/appclacks/go-types/healthcheck_tls.go b/vendor/github.com/appclacks/go-types/healthcheck_tls.go new file mode 100644 index 0000000..b79bfc3 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/healthcheck_tls.go @@ -0,0 +1,33 @@ +package types + +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 `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 +} diff --git a/vendor/github.com/appclacks/go-types/organization.go b/vendor/github.com/appclacks/go-types/organization.go new file mode 100644 index 0000000..f11b006 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/organization.go @@ -0,0 +1,50 @@ +package types + +import ( + "time" +) + +type CreateOrganizationOrg struct { + Name string `json:"name" description:"Organization name" validate:"required,max=255"` + Description string `json:"description" description:"Organization description" validate:"max=255"` +} + +type CreateOrganizationAccount struct { + FirstName string `json:"first-name" description:"User first name" validate:"required,max=255"` + LastName string `json:"last-name" description:"User last name" validate:"required,max=255"` + Password string `json:"password" description:"User password" validate:"required,min=10,max=255"` + Email string `json:"email" description:"User email" validate:"required,max=255"` +} + +type CreateOrganizationInput struct { + Organization CreateOrganizationOrg `json:"organization" validate:"required"` + Account CreateOrganizationAccount `json:"account" validate:"required"` +} + +type CreateOrganizationOutput struct { + Organization Organization `json:"organization"` + Account Account `json:"account"` +} + +type Organization struct { + ID string `json:"id"` + Name string `json:"name"` + Description *string `json:"description"` + CreatedAt time.Time `json:"created-at"` +} + +type Account struct { + ID string `json:"id"` + FirstName string `json:"first-name"` + LastName string `json:"last-name"` + Email string `json:"email"` + CreatedAt time.Time `json:"created-at"` +} + +type GetOrganizationInput struct { + ID string `param:"id" description:"Organization ID" validate:"required"` +} + +type GetOrganizationOutput struct { + Organization Organization `json:"organization"` +} diff --git a/vendor/github.com/appclacks/go-types/response.go b/vendor/github.com/appclacks/go-types/response.go new file mode 100644 index 0000000..ebcb0c4 --- /dev/null +++ b/vendor/github.com/appclacks/go-types/response.go @@ -0,0 +1,5 @@ +package types + +type Response struct { + Messages []string `json:"messages"` +} diff --git a/vendor/github.com/appclacks/go-types/result.go b/vendor/github.com/appclacks/go-types/result.go new file mode 100644 index 0000000..189173f --- /dev/null +++ b/vendor/github.com/appclacks/go-types/result.go @@ -0,0 +1,26 @@ +package types + +import ( + "time" +) + +type ListHealthchecksResultsInput struct { + StartDate time.Time `query:"start-date" validate:"required"` + EndDate time.Time `query:"end-date" validate:"required"` + HealthcheckID string `query:"healthcheck-id" validate:"omitempty,uuid"` + Page int `query:"page" validate:"omitempty,min=1"` +} + +type HealthcheckResult struct { + ID string `json:"id"` + Success bool `json:"success"` + Labels map[string]string `json:"labels,omitempty"` + CreatedAt time.Time `json:"created-at"` + Summary string `json:"summary"` + Message string `json:"message"` + HealthcheckID string `json:"healthcheck-id"` +} + +type ListHealthchecksResultsOutput struct { + Result []HealthcheckResult `json:"result"` +} diff --git a/vendor/github.com/appclacks/go-types/token.go b/vendor/github.com/appclacks/go-types/token.go new file mode 100644 index 0000000..231833d --- /dev/null +++ b/vendor/github.com/appclacks/go-types/token.go @@ -0,0 +1,38 @@ +package types + +import ( + "time" +) + +type Permissions struct { + Actions []string `json:"actions,omitempty"` +} + +type APIToken struct { + ID string `json:"id"` + Name string `json:"name"` + Token string `json:"token"` + Description string `json:"description"` + Permissions Permissions + CreatedAt time.Time `json:"created-at"` + TTL string `json:"ttl"` +} + +type CreateAPITokenInput struct { + Name string `json:"name" description:"Token name" validate:"required,max=255"` + Description string `json:"description" description:"Token description" validate:"max=255"` + TTL string `json:"ttl" description:"Token TTL in seconds" validate:"required"` + Permissions Permissions `json:"permissions"` +} + +type GetAPITokenInput struct { + ID string `param:"id" description:"Token ID" validate:"required"` +} + +type DeleteAPITokenInput struct { + ID string `param:"id" description:"Token ID" validate:"required"` +} + +type ListAPITokensOutput struct { + Result []APIToken `json:"result"` +}