Skip to content

Commit

Permalink
plugins/ism: Fix error notification types
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Hahn <[email protected]>
  • Loading branch information
Jakob3xD committed Sep 10, 2024
1 parent 096d633 commit c1f0b75
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Fix ISM Transition to omitempty Conditions field ([#609](https://github.com/opensearch-project/opensearch-go/pull/609))
- Fix ISM Allocation field types ([#609](https://github.com/opensearch-project/opensearch-go/pull/609))
- Fix ISM Error Notification types ([#612](https://github.com/opensearch-project/opensearch-go/pull/612))

### Security

Expand Down
9 changes: 7 additions & 2 deletions plugins/ism/api_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ type PolicyBody struct {

// PolicyErrorNotification is a sub type of PolicyBody containing information about error notification
type PolicyErrorNotification struct {
Channel string `json:"channel,omitempty"`
Destination NotificationDestination `json:"destination,omitempty"`
Channel *NotificationChannel `json:"channel,omitempty"`
Destination *NotificationDestination `json:"destination,omitempty"`
MessageTemplate NotificationMessageTemplate `json:"message_template"`
}

// NotificationChannel is a sub type of PolicyErrorNotification containg the channel id
type NotificationChannel struct {
ID string `json:"id"`
}

// NotificationDestination is a sub type of PolicyErrorNotification containing information about notification destinations
type NotificationDestination struct {
Chime *NotificationDestinationURL `json:"chime,omitempty"`
Expand Down
47 changes: 45 additions & 2 deletions plugins/ism/api_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestPoliciesClient(t *testing.T) {
failingClient, err := osismtest.CreateFailingClient()
require.Nil(t, err)

t.Cleanup(func() { client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: "test2"}) })

var putResp ism.PoliciesPutResp

type policiesTests struct {
Expand All @@ -52,7 +54,7 @@ func TestPoliciesClient(t *testing.T) {
Policy: ism.PolicyBody{
Description: "test",
ErrorNotification: &ism.PolicyErrorNotification{
Destination: ism.NotificationDestination{
Destination: &ism.NotificationDestination{
CustomWebhook: &ism.NotificationDestinationCustomWebhook{
Host: "exmaple.com",
Scheme: "https",
Expand Down Expand Up @@ -113,7 +115,7 @@ func TestPoliciesClient(t *testing.T) {
},
Template: []ism.Template{
ism.Template{
IndexPatterns: []string{"*test*"},
IndexPatterns: []string{"test"},
Priority: 20,
},
},
Expand All @@ -124,6 +126,47 @@ func TestPoliciesClient(t *testing.T) {
return putResp, err
},
},
{
Name: "Create with Channel",
Results: func() (osismtest.Response, error) {
return client.Policies.Put(
nil,
ism.PoliciesPutReq{
Policy: "test2",
Body: ism.PoliciesPutBody{
Policy: ism.PolicyBody{
Description: "test",
ErrorNotification: &ism.PolicyErrorNotification{
Channel: &ism.NotificationChannel{
ID: "test",
},
MessageTemplate: ism.NotificationMessageTemplate{
Source: "The index {{ctx.index}} failed during policy execution.",
},
},
DefaultState: "delete",
States: []ism.PolicyState{
ism.PolicyState{
Name: "delete",
Actions: []ism.PolicyStateAction{
ism.PolicyStateAction{
Delete: &ism.PolicyStateDelete{},
},
},
},
},
Template: []ism.Template{
ism.Template{
IndexPatterns: []string{"test2"},
Priority: 21,
},
},
},
},
},
)
},
},
{
Name: "Update",
Results: func() (osismtest.Response, error) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/ism/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestClient(t *testing.T) {
Policy: ism.PolicyBody{
Description: "test",
ErrorNotification: &ism.PolicyErrorNotification{
Destination: ism.NotificationDestination{
Destination: &ism.NotificationDestination{
CustomWebhook: &ism.NotificationDestinationCustomWebhook{
Host: "exmaple.com",
Scheme: "https",
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestClient(t *testing.T) {
Template: []ism.Template{
ism.Template{
IndexPatterns: []string{"test"},
Priority: 20,
Priority: 22,
},
},
},
Expand Down

0 comments on commit c1f0b75

Please sign in to comment.