Skip to content
Open
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,36 @@ type DatabaseUpdateLogsinkRequest struct {
Config *DatabaseLogsinkConfig `json:"config"`
}

// MarshalJSON implements custom JSON marshaling for DatabaseUpdateLogsinkRequest
// to ensure the TLS field is always included for rsyslog configurations, which
// require it even when false. Elasticsearch and OpenSearch configurations
// (identified by the absence of rsyslog fields) keep omitting it.
func (r DatabaseUpdateLogsinkRequest) MarshalJSON() ([]byte, error) {
if r.Config != nil && (r.Config.Server != "" || r.Config.Port != 0 || r.Config.Format != "") {
type rsyslogConfig struct {
URL string `json:"url,omitempty"`
IndexPrefix string `json:"index_prefix,omitempty"`
IndexDaysMax int `json:"index_days_max,omitempty"`
Timeout float32 `json:"timeout,omitempty"`
Server string `json:"server,omitempty"`
Port int `json:"port,omitempty"`
TLS bool `json:"tls"` // Always include for rsyslog
Format string `json:"format,omitempty"`
Logline string `json:"logline,omitempty"`
SD string `json:"sd,omitempty"`
CA string `json:"ca,omitempty"`
Key string `json:"key,omitempty"`
Cert string `json:"cert,omitempty"`
}
return json.Marshal(struct {
Config *rsyslogConfig `json:"config"`
}{Config: (*rsyslogConfig)(r.Config)})
}

type alias DatabaseUpdateLogsinkRequest
return json.Marshal(alias(r))
}

// DatabaseLogsinkConfig represents one of the configurable options (rsyslog_logsink, elasticsearch_logsink, or opensearch_logsink) for a logsink.
type DatabaseLogsinkConfig struct {
URL string `json:"url,omitempty"`
Expand Down
61 changes: 61 additions & 0 deletions databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5199,3 +5199,64 @@ func TestDatabases_GetStorageAutoscale(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, want, got)
}

func TestDatabases_UpdateLogsink_RsyslogKeepsTLSFalse(t *testing.T) {
setup()
defer teardown()

var (
dbID = "deadbeef-dead-4aa5-beef-deadbeef347d"
logsinkID = "50484ec3-19d6-4cd3-b56f-3b0381c289a6"
)

path := fmt.Sprintf("/v2/databases/%s/logsink/%s", dbID, logsinkID)

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)

var got map[string]map[string]interface{}
require.NoError(t, json.NewDecoder(r.Body).Decode(&got))
require.Contains(t, got["config"], "tls")
require.Equal(t, false, got["config"]["tls"])
})

_, err := client.Databases.UpdateLogsink(ctx, dbID, logsinkID, &DatabaseUpdateLogsinkRequest{
Config: &DatabaseLogsinkConfig{
Server: "192.168.0.1",
Port: 514,
TLS: false,
Format: "rfc3164",
},
})

require.NoError(t, err)
}

func TestDatabases_UpdateLogsink_OpensearchOmitsTLS(t *testing.T) {
setup()
defer teardown()

var (
dbID = "deadbeef-dead-4aa5-beef-deadbeef347d"
logsinkID = "50484ec3-19d6-4cd3-b56f-3b0381c289a6"
)

path := fmt.Sprintf("/v2/databases/%s/logsink/%s", dbID, logsinkID)

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)

var got map[string]map[string]interface{}
require.NoError(t, json.NewDecoder(r.Body).Decode(&got))
require.NotContains(t, got["config"], "tls")
})

_, err := client.Databases.UpdateLogsink(ctx, dbID, logsinkID, &DatabaseUpdateLogsinkRequest{
Config: &DatabaseLogsinkConfig{
URL: "https://user:passwd@192.168.0.1:25060",
IndexPrefix: "opensearch-logs",
},
})

require.NoError(t, err)
}