From c030b97f462da3613f17e09c05fccafd0d9f9664 Mon Sep 17 00:00:00 2001 From: Jeff Ishar Date: Tue, 24 Jan 2023 19:19:30 +1100 Subject: [PATCH 1/3] feature: Add support for segment log stream --- management/log_stream.go | 10 ++++++++++ management/log_stream_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/management/log_stream.go b/management/log_stream.go index c12b31ed..a9066aa7 100644 --- a/management/log_stream.go +++ b/management/log_stream.go @@ -19,6 +19,8 @@ const ( LogStreamTypeSumo = "sumo" // LogStreamTypeMixpanel constant. LogStreamTypeMixpanel = "mixpanel" + // LogStreamTypeSegment constant. + LogStreamTypeSegment = "segment" ) // LogStream is used to export tenant log @@ -102,6 +104,8 @@ func (ls *LogStream) UnmarshalJSON(b []byte) error { v = &LogStreamSinkSumo{} case LogStreamTypeMixpanel: v = &LogStreamSinkMixpanel{} + case LogStreamTypeSegment: + v = &LogStreamSinkSegment{} default: v = make(map[string]interface{}) } @@ -161,6 +165,12 @@ type LogStreamSinkDatadog struct { APIKey *string `json:"datadogApiKey,omitempty"` } +// LogStreamSinkSegment is used to export logs to Segment. +type LogStreamSinkSegment struct { + // Segment Api Key + APIKey *string `json:"segmentApiKey,omitempty"` +} + // LogStreamSinkSplunk is used to export logs to Splunk. type LogStreamSinkSplunk struct { // Splunk Domain diff --git a/management/log_stream_test.go b/management/log_stream_test.go index 5f6bea5d..13b6f010 100644 --- a/management/log_stream_test.go +++ b/management/log_stream_test.go @@ -59,6 +59,16 @@ var logStreamTestCases = []logStreamTestCase{ }, }, }, + { + name: "Segment LogStream", + logStream: LogStream{ + Name: auth0.Stringf("Test-LogStream-%d", time.Now().Unix()), + Type: auth0.String(LogStreamTypeSegment), + Sink: &LogStreamSinkSegment{ + APIKey: auth0.String("121233123455"), + }, + }, + }, { name: "Splunk LogStream", logStream: LogStream{ From 9b89f693522d5d8bfe69ec0962a566dd5c3dbf32 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:56:32 +0100 Subject: [PATCH 2/3] Add tests for segment log stream --- management/log_stream.go | 6 +- management/log_stream_test.go | 2 +- ...ccessfully_create_a_Segment_LogStream.yaml | 44 ++++++++++ ...ccessfully_delete_a_Segment_LogStream.yaml | 85 ++++++++++++++++++ ...successfully_read_a_Segment_LogStream.yaml | 65 ++++++++++++++ ...ccessfully_update_a_Segment_LogStream.yaml | 86 +++++++++++++++++++ 6 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 management/testdata/recordings/TestLogStreamManager_Create/It_can_successfully_create_a_Segment_LogStream.yaml create mode 100644 management/testdata/recordings/TestLogStreamManager_Delete/It_can_successfully_delete_a_Segment_LogStream.yaml create mode 100644 management/testdata/recordings/TestLogStreamManager_Read/It_can_successfully_read_a_Segment_LogStream.yaml create mode 100644 management/testdata/recordings/TestLogStreamManager_Update/It_can_successfully_update_a_Segment_LogStream.yaml diff --git a/management/log_stream.go b/management/log_stream.go index a9066aa7..393b9755 100644 --- a/management/log_stream.go +++ b/management/log_stream.go @@ -36,7 +36,7 @@ type LogStream struct { Name *string `json:"name,omitempty"` // The type of the log-stream. Can be one of "http", "eventbridge", - // "eventgrid", "datadog" or "splunk". + // "eventgrid", "datadog", "splunk", "sumo", "mixpanel", "segment. Type *string `json:"type,omitempty"` // The status of the log-stream. Can be one of "active", "paused", or "suspended". @@ -167,8 +167,8 @@ type LogStreamSinkDatadog struct { // LogStreamSinkSegment is used to export logs to Segment. type LogStreamSinkSegment struct { - // Segment Api Key - APIKey *string `json:"segmentApiKey,omitempty"` + // Segment Write Key + WriteKey *string `json:"segmentWriteKey,omitempty"` } // LogStreamSinkSplunk is used to export logs to Splunk. diff --git a/management/log_stream_test.go b/management/log_stream_test.go index 13b6f010..a217cb3d 100644 --- a/management/log_stream_test.go +++ b/management/log_stream_test.go @@ -65,7 +65,7 @@ var logStreamTestCases = []logStreamTestCase{ Name: auth0.Stringf("Test-LogStream-%d", time.Now().Unix()), Type: auth0.String(LogStreamTypeSegment), Sink: &LogStreamSinkSegment{ - APIKey: auth0.String("121233123455"), + WriteKey: auth0.String("121233123455"), }, }, }, diff --git a/management/testdata/recordings/TestLogStreamManager_Create/It_can_successfully_create_a_Segment_LogStream.yaml b/management/testdata/recordings/TestLogStreamManager_Create/It_can_successfully_create_a_Segment_LogStream.yaml new file mode 100644 index 00000000..dcf66187 --- /dev/null +++ b/management/testdata/recordings/TestLogStreamManager_Create/It_can_successfully_create_a_Segment_LogStream.yaml @@ -0,0 +1,44 @@ +--- +version: 1 +interactions: + - request: + body: | + {"name":"Test-LogStream-1674586425","type":"segment","sink":{"segmentWriteKey":"121233123455"}} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams + method: POST + response: + body: '{"id":"lst_0000000000011465","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"}}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011465 + method: DELETE + response: + body: "" + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 1ms diff --git a/management/testdata/recordings/TestLogStreamManager_Delete/It_can_successfully_delete_a_Segment_LogStream.yaml b/management/testdata/recordings/TestLogStreamManager_Delete/It_can_successfully_delete_a_Segment_LogStream.yaml new file mode 100644 index 00000000..f133a35c --- /dev/null +++ b/management/testdata/recordings/TestLogStreamManager_Delete/It_can_successfully_delete_a_Segment_LogStream.yaml @@ -0,0 +1,85 @@ +--- +version: 1 +interactions: + - request: + body: | + {"name":"Test-LogStream-1674586425","type":"segment","sink":{"segmentWriteKey":"121233123455"}} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams + method: POST + response: + body: '{"id":"lst_0000000000011468","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"}}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011468 + method: DELETE + response: + body: "" + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 1ms + - request: + body: | + null + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011468 + method: GET + response: + body: '{"statusCode":404,"error":"Not Found","message":"The log stream does not exist."}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 404 Not Found + code: 404 + duration: 1ms + - request: + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011468 + method: DELETE + response: + body: "" + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 1ms diff --git a/management/testdata/recordings/TestLogStreamManager_Read/It_can_successfully_read_a_Segment_LogStream.yaml b/management/testdata/recordings/TestLogStreamManager_Read/It_can_successfully_read_a_Segment_LogStream.yaml new file mode 100644 index 00000000..6712691e --- /dev/null +++ b/management/testdata/recordings/TestLogStreamManager_Read/It_can_successfully_read_a_Segment_LogStream.yaml @@ -0,0 +1,65 @@ +--- +version: 1 +interactions: + - request: + body: | + {"name":"Test-LogStream-1674586425","type":"segment","sink":{"segmentWriteKey":"121233123455"}} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams + method: POST + response: + body: '{"id":"lst_0000000000011466","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"}}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: | + null + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011466 + method: GET + response: + body: '{"id":"lst_0000000000011466","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"}}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011466 + method: DELETE + response: + body: "" + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 1ms diff --git a/management/testdata/recordings/TestLogStreamManager_Update/It_can_successfully_update_a_Segment_LogStream.yaml b/management/testdata/recordings/TestLogStreamManager_Update/It_can_successfully_update_a_Segment_LogStream.yaml new file mode 100644 index 00000000..62141c45 --- /dev/null +++ b/management/testdata/recordings/TestLogStreamManager_Update/It_can_successfully_update_a_Segment_LogStream.yaml @@ -0,0 +1,86 @@ +--- +version: 1 +interactions: + - request: + body: | + {"name":"Test-LogStream-1674586425","type":"segment","sink":{"segmentWriteKey":"121233123455"}} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams + method: POST + response: + body: '{"id":"lst_0000000000011467","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"}}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: | + {"filters":[{"name":"auth.login.fail","type":"category"}]} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011467 + method: PATCH + response: + body: '{"id":"lst_0000000000011467","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"},"filters":[{"name":"auth.login.fail","type":"category"}]}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: | + null + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011467 + method: GET + response: + body: '{"id":"lst_0000000000011467","name":"Test-LogStream-1674586425","type":"segment","status":"active","sink":{"segmentWriteKey":"121233123455"},"filters":[{"name":"auth.login.fail","type":"category"}]}' + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 200 OK + code: 200 + duration: 1ms + - request: + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/log-streams/lst_0000000000011467 + method: DELETE + response: + body: "" + headers: + Access-Control-Expose-Headers: + - WWW-Authenticate,Server-Authorization + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 1ms From f715c787f30b686bb009096dc954526f282a92f1 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:58:19 +0100 Subject: [PATCH 3/3] Generate accessors for segment log stream --- management/management.gen.go | 13 +++++++++++++ management/management.gen_test.go | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/management/management.gen.go b/management/management.gen.go index 0ce4f7e2..57fa34ab 100644 --- a/management/management.gen.go +++ b/management/management.gen.go @@ -5388,6 +5388,19 @@ func (l *LogStreamSinkMixpanel) String() string { return Stringify(l) } +// GetWriteKey returns the WriteKey field if it's non-nil, zero value otherwise. +func (l *LogStreamSinkSegment) GetWriteKey() string { + if l == nil || l.WriteKey == nil { + return "" + } + return *l.WriteKey +} + +// String returns a string representation of LogStreamSinkSegment. +func (l *LogStreamSinkSegment) String() string { + return Stringify(l) +} + // GetDomain returns the Domain field if it's non-nil, zero value otherwise. func (l *LogStreamSinkSplunk) GetDomain() string { if l == nil || l.Domain == nil { diff --git a/management/management.gen_test.go b/management/management.gen_test.go index a51f3207..7fd38286 100644 --- a/management/management.gen_test.go +++ b/management/management.gen_test.go @@ -6838,6 +6838,24 @@ func TestLogStreamSinkMixpanel_String(t *testing.T) { } } +func TestLogStreamSinkSegment_GetWriteKey(tt *testing.T) { + var zeroValue string + l := &LogStreamSinkSegment{WriteKey: &zeroValue} + l.GetWriteKey() + l = &LogStreamSinkSegment{} + l.GetWriteKey() + l = nil + l.GetWriteKey() +} + +func TestLogStreamSinkSegment_String(t *testing.T) { + var rawJSON json.RawMessage + v := &LogStreamSinkSegment{} + if err := json.Unmarshal([]byte(v.String()), &rawJSON); err != nil { + t.Errorf("failed to produce a valid json") + } +} + func TestLogStreamSinkSplunk_GetDomain(tt *testing.T) { var zeroValue string l := &LogStreamSinkSplunk{Domain: &zeroValue}