-
Notifications
You must be signed in to change notification settings - Fork 1
[BB-508] baton-github: use github app to sync #63
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
Conversation
pkg/config/config.go
Outdated
| func ValidateConfig(cfg *Github) error { | ||
| apiKey := cfg.GetString(accessTokenField.FieldName) | ||
| appKey := cfg.GetString(appIDField.FieldName) | ||
| if len(apiKey) == 0 && len(appKey) == 0 { | ||
| return fmt.Errorf("api-key or app-privatekey is missing") | ||
| } | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be defined using relationships.
| } | ||
| return gitHubApp{ | ||
| appJWTClient: client, | ||
| appInstallationClient: installationsClient, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if many organizations are using the same app, they should have different tokens and clients.
| appPrivateKey = field.StringField( | ||
| "app-privatekey", | ||
| field.WithDescription("The private key used to connect to the GitHub App"), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might want to have it use the file instead of taking it as a string
| if len(o.appClients) != 0 { | ||
| var ok bool | ||
| client, ok = o.appClients[oID] | ||
| if !ok { | ||
| return "", fmt.Errorf("organization: %d doesn't exist", oID) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if its okay to cache like this, we generally don't rely on state like this, I think there can be times when we resume a sync
Customer wants to get rid of the
service accountand usegithub appinstead.This PR adds the option to sync via the GitHub App.
Today, we use the personal access token to access resources that a user is granted to.
In github app, it's not the same story, since.
installation token is pinned to an organization, that means different organizations using the same app should have different installation tokens and one installation tokens from one org cannot access the other repository.
see here
Test.
The results are consistent with what we get when using a personal access token.
How to configure.
Install the GitHub App on your organizations.
Copy the private key and App ID.
Update the configuration with these two values.
Followup.
Intallation token expires in 1 hour, if the syn process takes more than 1 hour, we should refresh the token.