-
Notifications
You must be signed in to change notification settings - Fork 60
Expose the token of the installation client #78
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
base: develop
Are you sure you want to change the base?
Expose the token of the installation client #78
Conversation
This installation token retrievable from TokenSource can be used to clone repositories.
Thanks for your interest in palantir/go-githubapp, @hermanbanken! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
46629a4
to
1d67412
Compare
@hermanbanken I'm not sure this is required. You can already get an installation token: func getToken() string {
owner := "repo-owner"
appClient, _ := h.NewAppClient()
installation, _ := getInstallationClient(ctx, appClient, owner)
var repoIDs []int64
token, _, err := appClient.Apps.CreateInstallationToken(ctx, installation.ID, &github.InstallationTokenOptions{
RepositoryIDs: repoIDs,
})
return token
}
func getInstallationClient(ctx context.Context, appClient *github.Client, owner string) (githubapp.Installation, error) {
installations := githubapp.NewInstallationsService(appClient)
installation, err := installations.GetByOwner(ctx, owner)
if err != nil {
return installation, errors.Wrapf(err, "unable to get installation for '%s'", owner)
}
return installation, nil
} Where This is the method we use internally to get the token to check out repositories. |
Actually, on closer inspection I see what you're trying to do here. It would make things more simple |
I’m trying to prevent another token being created. No need to do that roundtrip twice right? |
The fact that github.Client exposes “Do” is a hint to me that they intent on giving some freedom in what you do using this token. In theory one hacky alternative would be to spin up a localhost server and capture the token from that by using client.Do. But that is so hacky I’m proposing this constructive solution. People can just ignore the second returned value (TokenSource) if they don’t need it. |
Thanks for proposing this. After some thought, I have two points I'd like to discuss before moving forward with an implementation. First, a user of While the code James suggested makes an additional request, it gives the user control over the the expiration time. In the specific Second, while easy to fix as far as API breaking changes go, the proposal is still a breaking change to a core API of this library that will require fixes in almost all consumers. I'd like to think about ways we can achieve this with fewer or no breaks in the API. Adding a If we do want to minimize extra requests, the problem with a new method is that Does my concern about token expiration seem valid to you? Do you have other ideas for how to implement this without breaking the API? |
@bluekeyes those concern seem very reasonable and would still allow us to use the token. Large/longrunning clones would indeed fail in my proposal. For me that wasn’t a problem, but it makes sense to add this correctly. I probably won’t have the time to work on this next week, but feel free to update the branch/create a new one. Otherwise I might work on it later than next week. |
The go-githubapp strives to enable easy setup of GitHub Apps. For several GitHub Apps there is a use case to checkout the git repository, next to the existing business of acting upon the GitHub API. Especially for more complex use cases, having access to the working tree and other repository state than the Pull Request diff is crucial.
This PR is a draft, as I am still working on the example. However, to speed up the discussion on whether this should be included I'm already creating the PR now.
The use case I'm specifically looking at is using the Access Token of the installation that is already retrieved & cached to clone the target repository. This is easily done using go-git, but is harder to do using the existing go-githubapp. This PR makes it much much simpler, and the example is intended to demonstrate how to do it exactly.