diff --git a/databases.go b/databases.go index 276fb4a6..bc38c25e 100644 --- a/databases.go +++ b/databases.go @@ -350,14 +350,6 @@ type DatabaseTopic struct { Config *TopicConfig `json:"config,omitempty"` } -// DatabaseLogsink represents a logsink -type DatabaseLogsink struct { - ID string `json:"sink_id"` - Name string `json:"sink_name,omitempty"` - Type string `json:"sink_type,omitempty"` - Config *DatabaseLogsinkConfig `json:"config,omitempty"` -} - // TopicPartition represents the state of a Kafka topic partition type TopicPartition struct { EarliestOffset uint64 `json:"earliest_offset,omitempty"` @@ -507,14 +499,22 @@ type DatabaseFirewallRule struct { CreatedAt time.Time `json:"created_at"` } -// DatabaseCreateLogsinkRequest is used to create logsink for a database cluster +// DatabaseLogsink represents a logsink. +type DatabaseLogsink struct { + ID string `json:"sink_id"` + Name string `json:"sink_name,required"` + Type string `json:"sink_type,required"` + Config *DatabaseLogsinkConfig `json:"config,required"` +} + +// DatabaseCreateLogsinkRequest is used to create logsink for a database cluster. type DatabaseCreateLogsinkRequest struct { Name string `json:"sink_name"` Type string `json:"sink_type"` Config *DatabaseLogsinkConfig `json:"config"` } -// DatabaseUpdateLogsinkRequest is used to update logsink for a database cluster +// DatabaseUpdateLogsinkRequest is used to update logsink for a database cluster. type DatabaseUpdateLogsinkRequest struct { Config *DatabaseLogsinkConfig `json:"config"` } @@ -828,6 +828,10 @@ type databaseTopicsRoot struct { Topics []DatabaseTopic `json:"topics"` } +type databaseLogsinkRoot struct { + Sink DatabaseLogsink `json:"sink"` +} + type databaseLogsinksRoot struct { Sinks []DatabaseLogsink `json:"sinks"` } @@ -1878,7 +1882,7 @@ func (svc *DatabasesServiceOp) DeleteIndex(ctx context.Context, databaseID, name return resp, nil } -// CreateLogsink creates a new logsink for a database +// CreateLogsink creates a new logsink for a database cluster. func (svc *DatabasesServiceOp) CreateLogsink(ctx context.Context, databaseID string, createLogsink *DatabaseCreateLogsinkRequest) (*DatabaseLogsink, *Response, error) { path := fmt.Sprintf(databaseLogsinksPath, databaseID) req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createLogsink) @@ -1886,15 +1890,16 @@ func (svc *DatabasesServiceOp) CreateLogsink(ctx context.Context, databaseID str return nil, nil, err } - root := new(DatabaseLogsink) + root := new(databaseLogsinkRoot) resp, err := svc.client.Do(ctx, req, root) if err != nil { return nil, resp, err } - return root, resp, nil + + return &root.Sink, resp, nil } -// GetLogsink gets a logsink for a database +// GetLogsink gets a logsink for a database cluster. func (svc *DatabasesServiceOp) GetLogsink(ctx context.Context, databaseID string, logsinkID string) (*DatabaseLogsink, *Response, error) { path := fmt.Sprintf(databaseLogsinkPath, databaseID, logsinkID) req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil) @@ -1910,7 +1915,7 @@ func (svc *DatabasesServiceOp) GetLogsink(ctx context.Context, databaseID string return root, resp, nil } -// ListTopics returns all topics for a given kafka cluster +// ListTopics returns all logsinks for a given database cluster. func (svc *DatabasesServiceOp) ListLogsinks(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseLogsink, *Response, error) { path := fmt.Sprintf(databaseLogsinksPath, databaseID) path, err := addOptions(path, opts) @@ -1929,7 +1934,7 @@ func (svc *DatabasesServiceOp) ListLogsinks(ctx context.Context, databaseID stri return root.Sinks, resp, nil } -// UpdateLogsink updates a logsink for a database cluster +// UpdateLogsink updates a logsink for a database cluster. func (svc *DatabasesServiceOp) UpdateLogsink(ctx context.Context, databaseID string, logsinkID string, updateLogsink *DatabaseUpdateLogsinkRequest) (*Response, error) { path := fmt.Sprintf(databaseLogsinkPath, databaseID, logsinkID) req, err := svc.client.NewRequest(ctx, http.MethodPut, path, updateLogsink) @@ -1944,7 +1949,7 @@ func (svc *DatabasesServiceOp) UpdateLogsink(ctx context.Context, databaseID str return resp, nil } -// DeleteLogsink deletes a logsink for a database cluster +// DeleteLogsink deletes a logsink for a database cluster. func (svc *DatabasesServiceOp) DeleteLogsink(ctx context.Context, databaseID, logsinkID string) (*Response, error) { path := fmt.Sprintf(databaseLogsinkPath, databaseID, logsinkID) req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil) diff --git a/databases_test.go b/databases_test.go index 96d16eab..c31243ba 100644 --- a/databases_test.go +++ b/databases_test.go @@ -3853,14 +3853,16 @@ func TestDatabases_CreateLogsink(t *testing.T) { } body := `{ - "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", - "sink_name": "logs-sink", - "sink_type": "opensearch", - "config": { - "url": "https://user:passwd@192.168.0.1:25060", - "index_prefix": "opensearch-logs" - } - }` + "sink":{ + "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", + "sink_name":"logs-sink", + "sink_type":"opensearch", + "config":{ + "url":"https://user:passwd@192.168.0.1:25060", + "index_prefix":"opensearch-logs" + } + } + }` path := fmt.Sprintf("/v2/databases/%s/logsink", dbID) @@ -3869,7 +3871,7 @@ func TestDatabases_CreateLogsink(t *testing.T) { fmt.Fprint(w, body) }) - log, _, err := client.Databases.CreateLogsink(ctx, dbID, &DatabaseCreateLogsinkRequest{ + logsink, _, err := client.Databases.CreateLogsink(ctx, dbID, &DatabaseCreateLogsinkRequest{ Name: "logs-sink", Type: "opensearch", Config: &DatabaseLogsinkConfig{ @@ -3879,8 +3881,7 @@ func TestDatabases_CreateLogsink(t *testing.T) { }) require.NoError(t, err) - - require.Equal(t, want, log) + require.Equal(t, want, logsink) } func TestDatabases_GetLogsink(t *testing.T) { @@ -3903,14 +3904,14 @@ func TestDatabases_GetLogsink(t *testing.T) { } body := `{ - "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", - "sink_name": "logs-sink", - "sink_type": "opensearch", - "config": { - "url": "https://user:passwd@192.168.0.1:25060", - "index_prefix": "opensearch-logs" - } - }` + "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", + "sink_name":"logs-sink", + "sink_type":"opensearch", + "config":{ + "url":"https://user:passwd@192.168.0.1:25060", + "index_prefix":"opensearch-logs" + } + }` path := fmt.Sprintf("/v2/databases/%s/logsink/%s", dbID, logsinkID) @@ -3919,9 +3920,9 @@ func TestDatabases_GetLogsink(t *testing.T) { fmt.Fprint(w, body) }) - got, _, err := client.Databases.GetLogsink(ctx, dbID, logsinkID) + logsink, _, err := client.Databases.GetLogsink(ctx, dbID, logsinkID) require.NoError(t, err) - require.Equal(t, want, got) + require.Equal(t, want, logsink) } func TestDatabases_UpdateLogsink(t *testing.T) { @@ -3934,14 +3935,16 @@ func TestDatabases_UpdateLogsink(t *testing.T) { ) body := `{ - "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", - "sink_name": "logs-sink", - "sink_type": "opensearch", - "config": { - "url": "https://user:passwd@192.168.0.1:25060", - "index_prefix": "opensearch-logs" - } - }` + "sink":{ + "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", + "sink_name":"logs-sink", + "sink_type":"opensearch", + "config":{ + "url":"https://user:passwd@192.168.0.1:25060", + "index_prefix":"opensearch-logs" + } + } + }` path := fmt.Sprintf("/v2/databases/%s/logsink/%s", dbID, logsinkID) @@ -3988,30 +3991,31 @@ func TestDatabases_ListLogsinks(t *testing.T) { URL: "https://user:passwd@192.168.0.1:25060", IndexPrefix: "opensearch-logs", }, - }} + }, + } body := `{ - "sinks": [ - { - "sink_id": "deadbeef-dead-4aa5-beef-deadbeef347d", - "sink_name": "logs-sink", - "sink_type": "opensearch", - "config": { - "url": "https://user:passwd@192.168.0.1:25060", - "index_prefix": "opensearch-logs" - } - }, - { - "sink_id": "d6e95157-5f58-48d0-9023-8cfb409d102a", - "sink_name": "logs-sink-2", - "sink_type": "opensearch", - "config": { - "url": "https://user:passwd@192.168.0.1:25060", - "index_prefix": "opensearch-logs" + "sinks":[ + { + "sink_id":"deadbeef-dead-4aa5-beef-deadbeef347d", + "sink_name":"logs-sink", + "sink_type":"opensearch", + "config":{ + "url":"https://user:passwd@192.168.0.1:25060", + "index_prefix":"opensearch-logs" + } + }, + { + "sink_id":"d6e95157-5f58-48d0-9023-8cfb409d102a", + "sink_name":"logs-sink-2", + "sink_type":"opensearch", + "config":{ + "url":"https://user:passwd@192.168.0.1:25060", + "index_prefix":"opensearch-logs" + } } - } ] - }` + }` path := fmt.Sprintf("/v2/databases/%s/logsink", dbID) @@ -4020,9 +4024,9 @@ func TestDatabases_ListLogsinks(t *testing.T) { fmt.Fprint(w, body) }) - got, _, err := client.Databases.ListLogsinks(ctx, dbID, &ListOptions{}) + logsinks, _, err := client.Databases.ListLogsinks(ctx, dbID, &ListOptions{}) require.NoError(t, err) - require.Equal(t, want, got) + require.Equal(t, want, logsinks) } func TestDatabases_DeleteLogsink(t *testing.T) {