github.com/argoproj/argo-cd/v3@v3.2.1/util/github_app/repos.go (about)

     1  package github_app
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/argoproj/argo-cd/v3/applicationset/services/github_app_auth"
     8  	"github.com/argoproj/argo-cd/v3/util/db"
     9  )
    10  
    11  // NewAuthCredentials returns a GtiHub App credentials lookup by repo-creds url.
    12  func NewAuthCredentials(creds db.RepoCredsDB) github_app_auth.Credentials {
    13  	return &repoAsCredentials{RepoCredsDB: creds}
    14  }
    15  
    16  type repoAsCredentials struct {
    17  	db.RepoCredsDB
    18  }
    19  
    20  func (r *repoAsCredentials) GetAuthSecret(ctx context.Context, secretName string) (*github_app_auth.Authentication, error) {
    21  	repo, err := r.GetRepoCredsBySecretName(ctx, secretName)
    22  	if err != nil {
    23  		return nil, fmt.Errorf("error getting creds for %s: %w", secretName, err)
    24  	}
    25  	if repo == nil || repo.GithubAppPrivateKey == "" {
    26  		return nil, fmt.Errorf("no github app found for %s", secretName)
    27  	}
    28  	return &github_app_auth.Authentication{
    29  		Id:                repo.GithubAppId,
    30  		InstallationId:    repo.GithubAppInstallationId,
    31  		EnterpriseBaseURL: repo.GitHubAppEnterpriseBaseURL,
    32  		PrivateKey:        repo.GithubAppPrivateKey,
    33  	}, nil
    34  }
    35  
    36  var _ github_app_auth.Credentials = (*repoAsCredentials)(nil)