Skip to content

Commit

Permalink
Add ssl support for synthetics (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
btoueg authored and Slavek Kabrda committed Jul 31, 2019
1 parent c32a832 commit e08ae06
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
124 changes: 124 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
68 changes: 68 additions & 0 deletions integration/synthetics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
}
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit e08ae06

Please sign in to comment.