okta / okta-sdk-golang

A Golang SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
https://github.com/okta/okta-sdk-golang
Other
174 stars 143 forks source link

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

Closed dnelson27 closed 1 year ago

dnelson27 commented 1 year ago

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

Test Information

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

Signoff

monde commented 1 year ago

Cool PR @dnelson27 , is it still WIP?

dnelson27 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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!