-
Notifications
You must be signed in to change notification settings - Fork 7k
feat(applicationset): reuse repo-creds for an existing GitHub App #10092
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package github_app_auth | ||
|
|
||
| import "context" | ||
|
|
||
| // Authentication has the authentication information required to access the GitHub API and repositories. | ||
| type Authentication struct { | ||
| // Id specifies the ID of the GitHub app used to access the repo | ||
| Id int64 | ||
| // InstallationId specifies the installation ID of the GitHub App used to access the repo | ||
| InstallationId int64 | ||
| // EnterpriseBaseURL specifies the base URL of GitHub Enterprise installation. If empty will default to https://api.github.com | ||
| EnterpriseBaseURL string | ||
| // PrivateKey in PEM format. | ||
| PrivateKey string | ||
| } | ||
|
|
||
| type Credentials interface { | ||
| GetAuthSecret(ctx context.Context, secretName string) (*Authentication, error) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package github_app | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/bradleyfalzon/ghinstallation/v2" | ||
| "github.com/google/go-github/v35/github" | ||
|
|
||
| "github.com/argoproj/argo-cd/v2/applicationset/services/github_app_auth" | ||
| ) | ||
|
|
||
| // Client builds a github client for the given app authentication. | ||
| func Client(g github_app_auth.Authentication, url string) (*github.Client, error) { | ||
| rt, err := ghinstallation.New(http.DefaultTransport, g.Id, g.InstallationId, []byte(g.PrivateKey)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create github app install: %w", err) | ||
| } | ||
| if url == "" { | ||
| url = g.EnterpriseBaseURL | ||
| } | ||
| var client *github.Client | ||
| httpClient := http.Client{Transport: rt} | ||
| if url == "" { | ||
| client = github.NewClient(&httpClient) | ||
| } else { | ||
| client, err = github.NewEnterpriseClient(url, url, &httpClient) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create github enterprise client: %w", err) | ||
| } | ||
| } | ||
| return client, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package pull_request | ||
|
|
||
| import ( | ||
| "github.com/argoproj/argo-cd/v2/applicationset/services/github_app_auth" | ||
| "github.com/argoproj/argo-cd/v2/applicationset/services/internal/github_app" | ||
| ) | ||
|
|
||
| func NewGithubAppService(g github_app_auth.Authentication, url, owner, repo string, labels []string) (PullRequestService, error) { | ||
| client, err := github_app.Client(g, url) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &GithubService{ | ||
| client: client, | ||
| owner: owner, | ||
| repo: repo, | ||
| labels: labels, | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package scm_provider | ||
|
|
||
| import ( | ||
| "github.com/argoproj/argo-cd/v2/applicationset/services/github_app_auth" | ||
| "github.com/argoproj/argo-cd/v2/applicationset/services/internal/github_app" | ||
| ) | ||
|
|
||
| func NewGithubAppProviderFor(g github_app_auth.Authentication, organization string, url string, allBranches bool) (*GithubProvider, error) { | ||
| client, err := github_app.Client(g, url) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &GithubProvider{client: client, organization: organization, allBranches: allBranches}, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.