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

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

merged 4 commits into from
Nov 2, 2022

Conversation

FadyMak
Copy link
Contributor

@FadyMak FadyMak commented Oct 21, 2022

🔧 Changes

Adds support for creating a log session via the Management API for tailing Actions Logs.

🔬 Testing

Tested against a space with the following steps:

Step 1: Generate Log Session

package main

import (
	"fmt"
	"log"

	_ "github.com/auth0/go-auth0"
	"github.com/auth0/go-auth0/management"
)

func main() {
	m, err := management.New(
		"AUTH0_DOMAIN",
		management.WithClientCredentials(
			"AUTH0_CLIENT_ID",
			"AUTH0_CLIENT_SECRET",
		),
	)

	if err != nil {
		log.Fatalf("failed to create client %v\n", err)
		return
	}

	key := "action_id"
	val := "ACTION_ID"
	resp := &management.ActionLogSession{
		Filters: []management.ActionLogSessionFilter{
			{
				Key: &key,
				Val: &val,
			},
		},
	}

	err = m.Action.LogSession(resp)
	if err != nil {
		log.Fatalf("failed to create log session %v\n", err)
		return
	}

	fmt.Printf("created log session URL: \n\nURL: %s\n", *resp.Url)
}

Step 2: Subscribe to Stream

const onMessage = (event) => {
  console.log(event.data);
};

eventSource = new EventSource(
  "LOG_SESSION_URL"
);

eventSource.onopen = () => {
  console.log("stream opened");
};

eventSource.onmessage = onMessage;

Step 3: Execute an Action

Execute an Action from the Dashboard or via the Authentication API and observe the event data for the specific Action being filtered.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@FadyMak FadyMak requested a review from a team as a code owner October 21, 2022 18:41
@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2022

Codecov Report

Base: 95.38% // Head: 95.39% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (ccc7948) compared to base (c21c84e).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   95.38%   95.39%   +0.01%     
==========================================
  Files          37       37              
  Lines        6068     6085      +17     
==========================================
+ Hits         5788     5805      +17     
  Misses        226      226              
  Partials       54       54              
Impacted Files Coverage Δ
management/actions.go 100.00% <100.00%> (ø)
management/management.gen.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@sergiught sergiught left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution folks! Just left a comment about the endpoint behavior to assess if we can remove the pointers from those fields, otherwise everything looks good 👍🏻

management/actions.go Show resolved Hide resolved
management/actions_test.go Show resolved Hide resolved
@FadyMak
Copy link
Contributor Author

FadyMak commented Oct 28, 2022

Thanks for the feedback @sergiught I've applied the suggestions and push the commit.

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.

@FadyMak FadyMak requested a review from sergiught November 1, 2022 17:10
@sergiught sergiught merged commit fe3727a into auth0:main Nov 2, 2022
@FadyMak FadyMak deleted the dxex-2581 branch November 3, 2022 13:27
johneke-auth0 added a commit to johneke-auth0/go-auth0 that referenced this pull request Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants