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

Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls #371

Closed
wants to merge 6 commits into from

Conversation

dnelson27
Copy link
Contributor

@dnelson27 dnelson27 commented Apr 11, 2023

This adds a new ConfigSetter function WithHttpInterceptorAndHttpClientPtr that allows clients to pass in a callback method that will be called for each HTTP request.

My organization currently uses WithHttpClientPtr to achieve this, but it would be great if the SDK supported it by default!

One significant use case is allowing clients to easily keep track of their API calls with their own observability code.

Example usage

func main() {
	ctx, client, err := okta.NewClient(
		context.TODO(),
		okta.WithHttpInterceptorAndHttpClientPtr(
			func(r *http.Request) error {
				fmt.Println("Some observability code")
				return nil
			},
			http.DefaultClient,
			true,
		),
	)

	if err != nil {
		panic(err)
	}

	users, resp, err := client.User.ListUsers(ctx, nil)

	if err != nil {
		panic(err)
	}

	fmt.Println(users)
	fmt.Println(resp)
}

Summary

Fixes #

Type of PR

  • Bug Fix (non-breaking fixes to existing functionality)
  • New Feature (non-breaking changes that add new functionality)
  • Documentation update
  • Test Updates
  • Other (Please describe the type)

Test Information

  • My PR required test updates

Go Version: go1.18.4 linux/amd64
Os Version: Linux 5.10.16.3-microsoft-standard-WSL2
OpenAPI Spec Version:

Signoff

  • I have submitted a CLA for this PR
  • Each commit message explains what the commit does
  • I have updated documentation to explain what my PR does
  • My code is covered by tests if required
  • I ran make fmt on my code
  • I did not edit any automatically generated files

@dnelson27 dnelson27 changed the title Add HTTP interceptor and unittests Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls Apr 11, 2023
@dnelson27 dnelson27 changed the title Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls [WIP] Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls Apr 11, 2023
@dnelson27 dnelson27 marked this pull request as draft April 11, 2023 19:45
@monde
Copy link
Collaborator

monde commented Apr 12, 2023

Cool PR @dnelson27 , is it still WIP?

@dnelson27
Copy link
Contributor Author

Cool PR @dnelson27 , is it still WIP?

I just need to sign the CLA! Is that something I need to input somewhere or is checking the box my "Signature"?

I figure the code is sort of self-documenting, but I can add some docstrings if its unclear.

@monde
Copy link
Collaborator

monde commented Apr 12, 2023

I just need to sign the CLA! Is that something I need to input somewhere or is checking the box my "Signature"?

@dnelson27 just follow the directions here
https://developer.okta.com/cla/

@dnelson27
Copy link
Contributor Author

I just need to sign the CLA! Is that something I need to input somewhere or is checking the box my "Signature"?

@dnelson27 just follow the directions here https://developer.okta.com/cla/

Ah, I completely missed the section about the email on my first pass-over. Thanks!

@monde
Copy link
Collaborator

monde commented Apr 12, 2023

@dnelson27 if you could get that CLA in today that would be great, I'd like to release this PR and #372 / #369 as a single release.

@dnelson27 dnelson27 marked this pull request as ready for review April 12, 2023 21:40
@dnelson27
Copy link
Contributor Author

@dnelson27 if you could get that CLA in today that would be great, I'd like to release this PR and #372 / #369 as a single release.

CLA is submitted!

@dnelson27 dnelson27 changed the title [WIP] Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls Add a new ConfigSetter that accepts a callback function that will intercept HTTP calls Apr 12, 2023
duytiennguyen-okta added a commit that referenced this pull request Apr 13, 2023
@dnelson27 dnelson27 deleted the dnelson27/http-interceptor branch April 13, 2023 19:03
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.

2 participants