Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DXEX-2581] Add support for Actions log sessions endpoint #127

Merged
merged 4 commits into from
Nov 2, 2022
Merged
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
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"`
}
FadyMak marked this conversation as resolved.
Show resolved Hide resolved

// 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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to find the json schema for this in api2 and filters has minItems: 1, so we can remove the omit empty here as well and from the other fields as well the pointers.

cc: @FadyMak

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergiught filters is not a required field so we need to have omitempty here otherwise it would result in a 400 if we pass in an empty filters array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense, but what about URL and Expires? They seem to be required properties in the response so we can remove the pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergiught these properties only exist on the response, not the request so they should have omitempty otherwise the Management API will throw a 400.

}

// 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)
FadyMak marked this conversation as resolved.
Show resolved Hide resolved

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.

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