From e08ae06cbcc38fedca675d901a95b7a44e7f22a8 Mon Sep 17 00:00:00 2001 From: Benjamin Toueg Date: Wed, 31 Jul 2019 13:13:47 +0200 Subject: [PATCH] Add ssl support for synthetics (#254) --- datadog-accessors.go | 124 +++++++++++++++++++++++++++++++++ integration/synthetics_test.go | 68 ++++++++++++++++++ synthetics.go | 4 ++ 3 files changed, 196 insertions(+) diff --git a/datadog-accessors.go b/datadog-accessors.go index 0f49b75..22e8f4d 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -15855,6 +15855,37 @@ func (s *SyntheticsLocation) SetRegion(v string) { s.Region = &v } +// GetAcceptSelfSigned returns the AcceptSelfSigned field if non-nil, zero value otherwise. +func (s *SyntheticsOptions) GetAcceptSelfSigned() bool { + if s == nil || s.AcceptSelfSigned == nil { + return false + } + return *s.AcceptSelfSigned +} + +// GetAcceptSelfSignedOk returns a tuple with the AcceptSelfSigned field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *SyntheticsOptions) GetAcceptSelfSignedOk() (bool, bool) { + if s == nil || s.AcceptSelfSigned == nil { + return false, false + } + return *s.AcceptSelfSigned, true +} + +// HasAcceptSelfSigned returns a boolean if a field has been set. +func (s *SyntheticsOptions) HasAcceptSelfSigned() bool { + if s != nil && s.AcceptSelfSigned != nil { + return true + } + + return false +} + +// SetAcceptSelfSigned allocates a new s.AcceptSelfSigned and returns the pointer to it. +func (s *SyntheticsOptions) SetAcceptSelfSigned(v bool) { + s.AcceptSelfSigned = &v +} + // GetFollowRedirects returns the FollowRedirects field if non-nil, zero value otherwise. func (s *SyntheticsOptions) GetFollowRedirects() bool { if s == nil || s.FollowRedirects == nil { @@ -16010,6 +16041,37 @@ func (s *SyntheticsRequest) SetBody(v string) { s.Body = &v } +// GetHost returns the Host field if non-nil, zero value otherwise. +func (s *SyntheticsRequest) GetHost() string { + if s == nil || s.Host == nil { + return "" + } + return *s.Host +} + +// GetHostOk returns a tuple with the Host field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *SyntheticsRequest) GetHostOk() (string, bool) { + if s == nil || s.Host == nil { + return "", false + } + return *s.Host, true +} + +// HasHost returns a boolean if a field has been set. +func (s *SyntheticsRequest) HasHost() bool { + if s != nil && s.Host != nil { + return true + } + + return false +} + +// SetHost allocates a new s.Host and returns the pointer to it. +func (s *SyntheticsRequest) SetHost(v string) { + s.Host = &v +} + // GetMethod returns the Method field if non-nil, zero value otherwise. func (s *SyntheticsRequest) GetMethod() string { if s == nil || s.Method == nil { @@ -16041,6 +16103,37 @@ func (s *SyntheticsRequest) SetMethod(v string) { s.Method = &v } +// GetPort returns the Port field if non-nil, zero value otherwise. +func (s *SyntheticsRequest) GetPort() int { + if s == nil || s.Port == nil { + return 0 + } + return *s.Port +} + +// GetPortOk returns a tuple with the Port field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *SyntheticsRequest) GetPortOk() (int, bool) { + if s == nil || s.Port == nil { + return 0, false + } + return *s.Port, true +} + +// HasPort returns a boolean if a field has been set. +func (s *SyntheticsRequest) HasPort() bool { + if s != nil && s.Port != nil { + return true + } + + return false +} + +// SetPort allocates a new s.Port and returns the pointer to it. +func (s *SyntheticsRequest) SetPort(v int) { + s.Port = &v +} + // GetTimeout returns the Timeout field if non-nil, zero value otherwise. func (s *SyntheticsRequest) GetTimeout() int { if s == nil || s.Timeout == nil { @@ -16506,6 +16599,37 @@ func (s *SyntheticsTest) SetStatus(v string) { s.Status = &v } +// GetSubtype returns the Subtype field if non-nil, zero value otherwise. +func (s *SyntheticsTest) GetSubtype() string { + if s == nil || s.Subtype == nil { + return "" + } + return *s.Subtype +} + +// GetSubtypeOk returns a tuple with the Subtype field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *SyntheticsTest) GetSubtypeOk() (string, bool) { + if s == nil || s.Subtype == nil { + return "", false + } + return *s.Subtype, true +} + +// HasSubtype returns a boolean if a field has been set. +func (s *SyntheticsTest) HasSubtype() bool { + if s != nil && s.Subtype != nil { + return true + } + + return false +} + +// SetSubtype allocates a new s.Subtype and returns the pointer to it. +func (s *SyntheticsTest) SetSubtype(v string) { + s.Subtype = &v +} + // GetType returns the Type field if non-nil, zero value otherwise. func (s *SyntheticsTest) GetType() string { if s == nil || s.Type == nil { diff --git a/integration/synthetics_test.go b/integration/synthetics_test.go index 6090271..c9eb190 100644 --- a/integration/synthetics_test.go +++ b/integration/synthetics_test.go @@ -33,6 +33,32 @@ func TestSyntheticsCreateAndDelete(t *testing.T) { assert.Equal(t, expected, actual) } +func TestSyntheticsCreateAndDeleteSSL(t *testing.T) { + expected := getTestSyntheticsSSL() + // create the monitor and compare it + actual := createTestSyntheticsSSL(t) + defer cleanUpSynthetics(t, actual.GetPublicId()) + + // Set ID of our original struct to zero so we can easily compare the results + expected.SetPublicId(actual.GetPublicId()) + // Set Creator to the original struct as we can't predict details of the creator + expected.SetCreatedAt(actual.GetCreatedAt()) + expected.SetModifiedAt(actual.GetModifiedAt()) + expected.SetMonitorId(actual.GetMonitorId()) + + assert.Equal(t, expected, actual) + + actual, err := client.GetSyntheticsTest(*actual.PublicId) + if err != nil { + t.Fatalf("Retrieving a synthetics failed when it shouldn't: (%s)", err) + } + expected.SetStatus(actual.GetStatus()) + expected.SetCreatedBy(actual.GetCreatedBy()) + expected.SetModifiedBy(actual.GetModifiedBy()) + expected.SetMonitorId(actual.GetMonitorId()) + assert.Equal(t, expected, actual) +} + func TestSyntheticsUpdate(t *testing.T) { syntheticsTest := createTestSynthetics(t) @@ -192,6 +218,7 @@ func getTestSynthetics() *datadog.SyntheticsTest { Locations: []string{"aws:eu-central-1"}, Status: datadog.String("live"), Type: datadog.String("api"), + Subtype: datadog.String("http"), Tags: []string{"tag1:value1", "tag2:value2"}, } } @@ -206,6 +233,47 @@ func createTestSynthetics(t *testing.T) *datadog.SyntheticsTest { return synthetics } +func getTestSyntheticsSSL() *datadog.SyntheticsTest { + c := &datadog.SyntheticsConfig{ + Request: &datadog.SyntheticsRequest{ + Host: datadog.String("example.org"), + Port: datadog.Int(443), + }, + Assertions: []datadog.SyntheticsAssertion{{ + Type: datadog.String("certificate"), + Property: datadog.String("sslExpirationDate"), + Operator: datadog.String("isInMoreThan"), + Target: float64(30), + }}, + } + o := &datadog.SyntheticsOptions{ + TickEvery: datadog.Int(60), + AcceptSelfSigned: datadog.Bool(true), + } + + return &datadog.SyntheticsTest{ + Message: datadog.String("Test message"), + Name: datadog.String("Test synthetics"), + Config: c, + Options: o, + Locations: []string{"aws:eu-central-1"}, + Status: datadog.String("live"), + Type: datadog.String("api"), + Subtype: datadog.String("ssl"), + Tags: []string{"tag1:value1", "tag2:value2"}, + } +} + +func createTestSyntheticsSSL(t *testing.T) *datadog.SyntheticsTest { + synthetics := getTestSyntheticsSSL() + synthetics, err := client.CreateSyntheticsTest(synthetics) + if err != nil { + t.Fatalf("Creating a synthetics failed when it shouldn't: %s", err) + } + + return synthetics +} + func cleanUpSynthetics(t *testing.T, publicId string) { if err := client.DeleteSyntheticsTests([]string{publicId}); err != nil { t.Fatalf("Deleting a synthetics failed when it shouldn't. Manual cleanup needed. (%s)", err) diff --git a/synthetics.go b/synthetics.go index afe1466..091cce8 100644 --- a/synthetics.go +++ b/synthetics.go @@ -11,6 +11,7 @@ type SyntheticsTest struct { MonitorId *int `json:"monitor_id,omitempty"` Name *string `json:"name,omitempty"` Type *string `json:"type,omitempty"` + Subtype *string `json:"subtype,omitempty"` Tags []string `json:"tags"` CreatedAt *string `json:"created_at,omitempty"` ModifiedAt *string `json:"modified_at,omitempty"` @@ -37,6 +38,8 @@ type SyntheticsRequest struct { Timeout *int `json:"timeout,omitempty"` Headers map[string]string `json:"headers,omitempty"` Body *string `json:"body,omitempty"` + Host *string `json:"host,omitempty"` + Port *int `json:"port,omitempty"` } type SyntheticsAssertion struct { @@ -54,6 +57,7 @@ type SyntheticsOptions struct { MinFailureDuration *int `json:"min_failure_duration,omitempty"` MinLocationFailed *int `json:"min_location_failed,omitempty"` DeviceIds []string `json:"device_ids,omitempty"` + AcceptSelfSigned *bool `json:"accept_self_signed,omitempty"` } type SyntheticsUser struct {