From 48c3f5b113a8cbbd8ca3ccccb2876ce05d77bab2 Mon Sep 17 00:00:00 2001 From: Fady Abdelmalik Date: Fri, 21 Oct 2022 14:30:10 -0400 Subject: [PATCH 1/4] [DXEX-2581] Add support for Actions log sessions endpoint --- management/actions.go | 23 +++++++++++++++++++ management/actions_test.go | 17 ++++++++++++++ .../TestActionManager_LogSession.yaml | 22 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 management/testdata/recordings/TestActionManager_LogSession.yaml diff --git a/management/actions.go b/management/actions.go index bdde8100..62ef7738 100644 --- a/management/actions.go +++ b/management/actions.go @@ -200,6 +200,21 @@ type ActionExecution struct { UpdatedAt *time.Time `json:"updated_at"` } +// ActionLogSessionFilter defines a filter for +type ActionLogSessionFilter struct { + Key *string `json:"key,omitempty"` + Val *string `json:"val,omitempty"` +} + +// ActionLogSession contains a presigned URL that can be used for tailing realtime +// logs from Actions +type ActionLogSession struct { + Url *string `json:"url,omitempty"` + Expires *time.Time `json:"expires,omitempty"` + + Filters []ActionLogSessionFilter `json:"filters,omitempty"` +} + // ActionManager manages Auth0 Action resources. type ActionManager struct { *Management @@ -331,3 +346,11 @@ func (m *ActionManager) Execution(executionID string, opts ...RequestOption) (v err = m.Request("GET", m.URI("actions", "executions", executionID), &v, opts...) return } + +// Create a log session for tailing Actions logs. +// +// See: https://auth0.com/docs/api/management/v2/#!/Actions/post_actions_log_sessions +func (m *ActionManager) LogSession(l *ActionLogSession, opts ...RequestOption) (err error) { + err = m.Request("POST", m.URI("actions", "log-sessions"), &l, opts...) + return +} diff --git a/management/actions_test.go b/management/actions_test.go index 0f486b10..2b638276 100644 --- a/management/actions_test.go +++ b/management/actions_test.go @@ -238,6 +238,23 @@ func TestActionManager_Execution(t *testing.T) { assert.Equal(t, http.StatusNotFound, err.(Error).Status()) } +func TestActionManager_LogSession(t *testing.T) { + setupHTTPRecordings(t) + + expectedLogSession := &ActionLogSession{ + Filters: []ActionLogSessionFilter{{ + Key: auth0.String("action_id"), + Val: auth0.String("act_123"), + }}, + } + + err := m.Action.LogSession(expectedLogSession) + + assert.NoError(t, err) + assert.Equal(t, *expectedLogSession.Url, "https://go-auth0-dev.eu.auth0.com/actions/log-sessions/tail?token=tkn_123") + assert.NotEmpty(t, expectedLogSession.Expires) +} + func cleanupAction(t *testing.T, actionID string) { t.Helper() diff --git a/management/testdata/recordings/TestActionManager_LogSession.yaml b/management/testdata/recordings/TestActionManager_LogSession.yaml new file mode 100644 index 00000000..a6fe64fd --- /dev/null +++ b/management/testdata/recordings/TestActionManager_LogSession.yaml @@ -0,0 +1,22 @@ +--- +version: 1 +interactions: +- request: + body: | + {} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0-SDK/latest + url: https://go-auth0-dev.eu.auth0.com/api/v2/actions/log-sessions + method: POST + response: + body: '{"url":"https://go-auth0-dev.eu.auth0.com/actions/log-sessions/tail?token=tkn_123","expires":"2022-10-21T16:48:15.576883302Z"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 1ms From 5651234993ad554b6187fda395001ca44a50f556 Mon Sep 17 00:00:00 2001 From: Fady Abdelmalik Date: Fri, 21 Oct 2022 14:47:56 -0400 Subject: [PATCH 2/4] chore: run go generate --- management/management.gen.go | 42 +++++++++++++++++++++++ management/management.gen_test.go | 56 +++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/management/management.gen.go b/management/management.gen.go index f8897bef..0ae897bf 100644 --- a/management/management.gen.go +++ b/management/management.gen.go @@ -295,6 +295,48 @@ func (a *ActionList) String() string { return Stringify(a) } +// GetExpires returns the Expires field if it's non-nil, zero value otherwise. +func (a *ActionLogSession) GetExpires() time.Time { + if a == nil || a.Expires == nil { + return time.Time{} + } + return *a.Expires +} + +// GetUrl returns the Url field if it's non-nil, zero value otherwise. +func (a *ActionLogSession) GetUrl() string { + if a == nil || a.Url == nil { + return "" + } + return *a.Url +} + +// String returns a string representation of ActionLogSession. +func (a *ActionLogSession) String() string { + return Stringify(a) +} + +// GetKey returns the Key field if it's non-nil, zero value otherwise. +func (a *ActionLogSessionFilter) GetKey() string { + if a == nil || a.Key == nil { + return "" + } + return *a.Key +} + +// GetVal returns the Val field if it's non-nil, zero value otherwise. +func (a *ActionLogSessionFilter) GetVal() string { + if a == nil || a.Val == nil { + return "" + } + return *a.Val +} + +// String returns a string representation of ActionLogSessionFilter. +func (a *ActionLogSessionFilter) String() string { + return Stringify(a) +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (a *ActionSecret) GetName() string { if a == nil || a.Name == nil { diff --git a/management/management.gen_test.go b/management/management.gen_test.go index 340b5433..06e3845f 100644 --- a/management/management.gen_test.go +++ b/management/management.gen_test.go @@ -374,6 +374,62 @@ func TestActionList_String(t *testing.T) { } } +func TestActionLogSession_GetExpires(tt *testing.T) { + var zeroValue time.Time + a := &ActionLogSession{Expires: &zeroValue} + a.GetExpires() + a = &ActionLogSession{} + a.GetExpires() + a = nil + a.GetExpires() +} + +func TestActionLogSession_GetUrl(tt *testing.T) { + var zeroValue string + a := &ActionLogSession{Url: &zeroValue} + a.GetUrl() + a = &ActionLogSession{} + a.GetUrl() + a = nil + a.GetUrl() +} + +func TestActionLogSession_String(t *testing.T) { + var rawJSON json.RawMessage + v := &ActionLogSession{} + if err := json.Unmarshal([]byte(v.String()), &rawJSON); err != nil { + t.Errorf("failed to produce a valid json") + } +} + +func TestActionLogSessionFilter_GetKey(tt *testing.T) { + var zeroValue string + a := &ActionLogSessionFilter{Key: &zeroValue} + a.GetKey() + a = &ActionLogSessionFilter{} + a.GetKey() + a = nil + a.GetKey() +} + +func TestActionLogSessionFilter_GetVal(tt *testing.T) { + var zeroValue string + a := &ActionLogSessionFilter{Val: &zeroValue} + a.GetVal() + a = &ActionLogSessionFilter{} + a.GetVal() + a = nil + a.GetVal() +} + +func TestActionLogSessionFilter_String(t *testing.T) { + var rawJSON json.RawMessage + v := &ActionLogSessionFilter{} + if err := json.Unmarshal([]byte(v.String()), &rawJSON); err != nil { + t.Errorf("failed to produce a valid json") + } +} + func TestActionSecret_GetName(tt *testing.T) { var zeroValue string a := &ActionSecret{Name: &zeroValue} From b5e4d7481b7baa1a7ead6c20e048500ba976b603 Mon Sep 17 00:00:00 2001 From: Fady Abdelmalik Date: Fri, 21 Oct 2022 14:58:28 -0400 Subject: [PATCH 3/4] chore: linting --- management/actions.go | 8 ++++---- management/actions_test.go | 2 +- management/management.gen.go | 8 ++++---- management/management.gen_test.go | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/management/actions.go b/management/actions.go index 62ef7738..6ca7bc29 100644 --- a/management/actions.go +++ b/management/actions.go @@ -200,16 +200,16 @@ type ActionExecution struct { UpdatedAt *time.Time `json:"updated_at"` } -// ActionLogSessionFilter defines a filter for +// ActionLogSessionFilter defines a filter for the log session. type ActionLogSessionFilter struct { Key *string `json:"key,omitempty"` Val *string `json:"val,omitempty"` } // ActionLogSession contains a presigned URL that can be used for tailing realtime -// logs from Actions +// logs from Actions. type ActionLogSession struct { - Url *string `json:"url,omitempty"` + URL *string `json:"url,omitempty"` Expires *time.Time `json:"expires,omitempty"` Filters []ActionLogSessionFilter `json:"filters,omitempty"` @@ -347,7 +347,7 @@ func (m *ActionManager) Execution(executionID string, opts ...RequestOption) (v return } -// Create a log session for tailing Actions logs. +// LogSession creates a log session for tailing Actions logs. // // See: https://auth0.com/docs/api/management/v2/#!/Actions/post_actions_log_sessions func (m *ActionManager) LogSession(l *ActionLogSession, opts ...RequestOption) (err error) { diff --git a/management/actions_test.go b/management/actions_test.go index 2b638276..8454c77d 100644 --- a/management/actions_test.go +++ b/management/actions_test.go @@ -251,7 +251,7 @@ func TestActionManager_LogSession(t *testing.T) { err := m.Action.LogSession(expectedLogSession) assert.NoError(t, err) - assert.Equal(t, *expectedLogSession.Url, "https://go-auth0-dev.eu.auth0.com/actions/log-sessions/tail?token=tkn_123") + assert.Equal(t, *expectedLogSession.URL, "https://go-auth0-dev.eu.auth0.com/actions/log-sessions/tail?token=tkn_123") assert.NotEmpty(t, expectedLogSession.Expires) } diff --git a/management/management.gen.go b/management/management.gen.go index 0ae897bf..0c5f161a 100644 --- a/management/management.gen.go +++ b/management/management.gen.go @@ -303,12 +303,12 @@ func (a *ActionLogSession) GetExpires() time.Time { return *a.Expires } -// GetUrl returns the Url field if it's non-nil, zero value otherwise. -func (a *ActionLogSession) GetUrl() string { - if a == nil || a.Url == nil { +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (a *ActionLogSession) GetURL() string { + if a == nil || a.URL == nil { return "" } - return *a.Url + return *a.URL } // String returns a string representation of ActionLogSession. diff --git a/management/management.gen_test.go b/management/management.gen_test.go index 06e3845f..7abafb6d 100644 --- a/management/management.gen_test.go +++ b/management/management.gen_test.go @@ -384,14 +384,14 @@ func TestActionLogSession_GetExpires(tt *testing.T) { a.GetExpires() } -func TestActionLogSession_GetUrl(tt *testing.T) { +func TestActionLogSession_GetURL(tt *testing.T) { var zeroValue string - a := &ActionLogSession{Url: &zeroValue} - a.GetUrl() + a := &ActionLogSession{URL: &zeroValue} + a.GetURL() a = &ActionLogSession{} - a.GetUrl() + a.GetURL() a = nil - a.GetUrl() + a.GetURL() } func TestActionLogSession_String(t *testing.T) { From ccc79484b57d2f13e6158a6b4c93d64e031edffa Mon Sep 17 00:00:00 2001 From: Fady Abdelmalik Date: Fri, 28 Oct 2022 11:45:34 -0400 Subject: [PATCH 4/4] remove omitempty and convert filter props to string --- management/actions.go | 4 ++-- management/actions_test.go | 4 ++-- management/management.gen.go | 16 ---------------- management/management.gen_test.go | 20 -------------------- 4 files changed, 4 insertions(+), 40 deletions(-) diff --git a/management/actions.go b/management/actions.go index 6ca7bc29..d0970e6c 100644 --- a/management/actions.go +++ b/management/actions.go @@ -202,8 +202,8 @@ type ActionExecution struct { // ActionLogSessionFilter defines a filter for the log session. type ActionLogSessionFilter struct { - Key *string `json:"key,omitempty"` - Val *string `json:"val,omitempty"` + Key string `json:"key"` + Val string `json:"val"` } // ActionLogSession contains a presigned URL that can be used for tailing realtime diff --git a/management/actions_test.go b/management/actions_test.go index 8454c77d..366608ba 100644 --- a/management/actions_test.go +++ b/management/actions_test.go @@ -243,8 +243,8 @@ func TestActionManager_LogSession(t *testing.T) { expectedLogSession := &ActionLogSession{ Filters: []ActionLogSessionFilter{{ - Key: auth0.String("action_id"), - Val: auth0.String("act_123"), + Key: "action_id", + Val: "act_123", }}, } diff --git a/management/management.gen.go b/management/management.gen.go index 0c5f161a..6aab3fee 100644 --- a/management/management.gen.go +++ b/management/management.gen.go @@ -316,22 +316,6 @@ func (a *ActionLogSession) String() string { return Stringify(a) } -// GetKey returns the Key field if it's non-nil, zero value otherwise. -func (a *ActionLogSessionFilter) GetKey() string { - if a == nil || a.Key == nil { - return "" - } - return *a.Key -} - -// GetVal returns the Val field if it's non-nil, zero value otherwise. -func (a *ActionLogSessionFilter) GetVal() string { - if a == nil || a.Val == nil { - return "" - } - return *a.Val -} - // String returns a string representation of ActionLogSessionFilter. func (a *ActionLogSessionFilter) String() string { return Stringify(a) diff --git a/management/management.gen_test.go b/management/management.gen_test.go index 7abafb6d..ac829830 100644 --- a/management/management.gen_test.go +++ b/management/management.gen_test.go @@ -402,26 +402,6 @@ func TestActionLogSession_String(t *testing.T) { } } -func TestActionLogSessionFilter_GetKey(tt *testing.T) { - var zeroValue string - a := &ActionLogSessionFilter{Key: &zeroValue} - a.GetKey() - a = &ActionLogSessionFilter{} - a.GetKey() - a = nil - a.GetKey() -} - -func TestActionLogSessionFilter_GetVal(tt *testing.T) { - var zeroValue string - a := &ActionLogSessionFilter{Val: &zeroValue} - a.GetVal() - a = &ActionLogSessionFilter{} - a.GetVal() - a = nil - a.GetVal() -} - func TestActionLogSessionFilter_String(t *testing.T) { var rawJSON json.RawMessage v := &ActionLogSessionFilter{}