mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: crenshaw-dev <350466+crenshaw-dev@users.noreply.github.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package github_app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/argoproj/argo-cd/v3/applicationset/services/github_app_auth"
|
|
"github.com/argoproj/argo-cd/v3/util/db"
|
|
)
|
|
|
|
// NewAuthCredentials returns a GtiHub App credentials lookup by repo-creds url.
|
|
func NewAuthCredentials(creds db.RepoCredsDB) github_app_auth.Credentials {
|
|
return &repoAsCredentials{RepoCredsDB: creds}
|
|
}
|
|
|
|
type repoAsCredentials struct {
|
|
db.RepoCredsDB
|
|
}
|
|
|
|
func (r *repoAsCredentials) GetAuthSecret(ctx context.Context, secretName string) (*github_app_auth.Authentication, error) {
|
|
repo, err := r.GetRepoCredsBySecretName(ctx, secretName)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error getting creds for %s: %w", secretName, err)
|
|
}
|
|
if repo == nil || repo.GithubAppPrivateKey == "" {
|
|
return nil, fmt.Errorf("no github app found for %s", secretName)
|
|
}
|
|
return &github_app_auth.Authentication{
|
|
Id: repo.GithubAppId,
|
|
InstallationId: repo.GithubAppInstallationId,
|
|
EnterpriseBaseURL: repo.GitHubAppEnterpriseBaseURL,
|
|
PrivateKey: repo.GithubAppPrivateKey,
|
|
}, nil
|
|
}
|
|
|
|
var _ github_app_auth.Credentials = (*repoAsCredentials)(nil)
|