Files
argo-cd/util/github_app/repos.go
github-actions[bot] 4d9835927d Bump major version to 3 (#21410)
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>
2025-01-10 16:14:00 -05:00

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)