-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(applicationset): reuse repo-creds for an existing GitHub App (#1…
…0092) Closes #10079 Signed-off-by: Noah Perks Sloan <[email protected]> Signed-off-by: Noah Perks Sloan <[email protected]>
- Loading branch information
Showing
21 changed files
with
337 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.