Skip to content

Commit

Permalink
[DXEX-2581] Add support for Actions log sessions endpoint (auth0#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
FadyMak authored Nov 2, 2022
1 parent 06b011d commit fe3727a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
23 changes: 23 additions & 0 deletions management/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ type ActionExecution struct {
UpdatedAt *time.Time `json:"updated_at"`
}

// ActionLogSessionFilter defines a filter for the log session.
type ActionLogSessionFilter struct {
Key string `json:"key"`
Val string `json:"val"`
}

// 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
Expand Down Expand Up @@ -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
}

// 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) {
err = m.Request("POST", m.URI("actions", "log-sessions"), &l, opts...)
return
}
17 changes: 17 additions & 0 deletions management/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "action_id",
Val: "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()

Expand Down
26 changes: 26 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions management/testdata/recordings/TestActionManager_LogSession.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fe3727a

Please sign in to comment.