Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new endpoints that manipulate individual PD service objects #247

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for new endpoints that manipulate individual PD service o…
…bjects
  • Loading branch information
Slavek Kabrda committed Jun 14, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 76a80505e29e5b01cdac11e936330495d82d48d8
43 changes: 43 additions & 0 deletions integration/integrations_test.go
Original file line number Diff line number Diff line change
@@ -86,6 +86,49 @@ func TestIntegrationPDGet(t *testing.T) {
assert.Equal(t, expectedServiceNames, actualServiceNames)
}

func TestIntegrationPDService(t *testing.T) {
// test manipulation of individual service objects in the PD integration
// when the integration is not active, manipulating service objects
// should return 404
so := datadog.ServicePDRequest{
ServiceName: datadog.String("testPDServiceNameIndividual"),
ServiceKey: datadog.String("testPDServiceKeyIndividual"),
}

err := client.CreateIntegrationPDService(&so)
if err == nil {
t.Fatalf("Creating PD integration service object succeeded without active PD integration")
}

_ = createTestIntegrationPD(t)
defer cleanUpIntegrationPD(t)

err = client.CreateIntegrationPDService(&so)
if err != nil {
t.Fatalf("Creating PD integration service object failed when it shouldn't: %s", err)
}

var soRead *datadog.ServicePDRequest
soRead, err = client.GetIntegrationPDService(*so.ServiceName)
if err != nil {
t.Fatalf("Reading PD integration service object failed when it shouldn't: %s", err)
}
// ServiceKey is never returned by API, so we can't test it
assert.Equal(t, *so.ServiceName, *soRead.ServiceName)

so.SetServiceKey("other")
err = client.UpdateIntegrationPDService(&so)
if err != nil {
t.Fatalf("Updating PD integration service object failed when it shouldn't: %s", err)
}
// we can't really test anything here, since only the ServiceKey was changed

err = client.DeleteIntegrationPDService(*so.ServiceName)
if err != nil {
t.Fatalf("Deleting PD integration service object failed when it shouldn't: %s", err)
}
}

func getTestIntegrationPD() *datadog.IntegrationPDRequest {
return &datadog.IntegrationPDRequest{
Services: []datadog.ServicePDRequest{
35 changes: 35 additions & 0 deletions integrations.go
Original file line number Diff line number Diff line change
@@ -68,6 +68,41 @@ func (client *Client) DeleteIntegrationPD() error {
return client.doJsonRequest("DELETE", "/v1/integration/pagerduty", nil, nil)
}

// CreateIntegrationPDService creates a single service object in the PagerDuty integration
// Note that creating a service object requires the integration to be activated
func (client *Client) CreateIntegrationPDService(serviceObject *ServicePDRequest) error {
return client.doJsonRequest("POST", "/v1/integration/pagerduty/configuration/services", serviceObject, nil)
}

// UpdateIntegrationPDService updates a single service object in the PagerDuty integration
func (client *Client) UpdateIntegrationPDService(serviceObject *ServicePDRequest) error {
// we can only post the ServiceKey, not ServiceName
toPost := struct {
ServiceKey *string `json:"service_key,omitempty"`
}{
serviceObject.ServiceKey,
}
uri := "/v1/integration/pagerduty/configuration/services/" + *serviceObject.ServiceName
return client.doJsonRequest("PUT", uri, toPost, nil)
}

// GetIntegrationPDService gets a single service object in the PagerDuty integration
// NOTE: the service key is never returned by the API, so it won't be set
func (client *Client) GetIntegrationPDService(serviceName string) (*ServicePDRequest, error) {
uri := "/v1/integration/pagerduty/configuration/services/" + serviceName
var out ServicePDRequest
if err := client.doJsonRequest("GET", uri, nil, &out); err != nil {
return nil, err
}
return &out, nil
}

// DeleteIntegrationPDService deletes a single service object in the PagerDuty integration
func (client *Client) DeleteIntegrationPDService(serviceName string) error {
uri := "/v1/integration/pagerduty/configuration/services/" + serviceName
return client.doJsonRequest("DELETE", uri, nil, nil)
}

/*
Slack Integration
*/