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

Reconcile ClientCreator and TransportManager #33

Open
jlewi opened this issue May 19, 2023 · 4 comments
Open

Reconcile ClientCreator and TransportManager #33

jlewi opened this issue May 19, 2023 · 4 comments

Comments

@jlewi
Copy link
Owner

jlewi commented May 19, 2023

The code base has started using two different mechanisms for handling auth credentials.
Palantir's Client Creator

Transport Manager

ClientCreator caches clients for different repositories
TransportManager caches different http transports from which clients can then be created.

You can extract the transport from the client's returned by ClientCreator e.g.

client.Client().Transport

https://github.com/google/go-github/blob/dff9dcc41c9c60c776df318d0938c1ad3dc2d2e4/github/github.go#L218

TransportManager is using
https://github.com/bradleyfalzon/ghinstallation to handle authenticating as a GitHubApp.

How does ClientCreator handle this?
Looks like its using ghinstallation as well
https://github.com/palantir/go-githubapp/blob/6c26ee49f52ddf0a2485d1c5f666b3dfda9ec8c1/githubapp/client_creator.go#L355

@jlewi
Copy link
Owner Author

jlewi commented May 19, 2023

So I think we could consolidate on ClientCreator and pass github.client arounds as needed. On the other hand github.client is a github V3 (REST client) and some of our code is using GitHub V4 (GraphQL). Seems a bit weird to obtain a V4 client from a V3 client.

@jlewi
Copy link
Owner Author

jlewi commented Oct 29, 2023

It looks like Palantir's clientcreator adds some functionality for setting up middleware.

@jlewi
Copy link
Owner Author

jlewi commented Oct 29, 2023

Here's an example of creating Palantir's ClientCreator

config, err := app.BuildConfig(githubAppID, webhookSecret, privateKeySecret)

It uses a Config object to pass in the secret and other app configuration

config := &githubapp.Config{

@jlewi
Copy link
Owner Author

jlewi commented Oct 29, 2023

Palantir's ClientCreator takes an InstallationID to create a client.

We have the helper function

func GetInstallID(appID int64, privateKey []byte, owner string, repo string) (int64, error) {

TransportManager.Get

func (m *TransportManager) Get(org string, repo string) (*ghinstallation.Transport, error) {

Provides a convenient wrapper to get the InstallD for a given repository and then return the client for it.

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

No branches or pull requests

1 participant