Files
zeekay 31c64ef661 test, applicationset: drop Argo branding, fix bugs it was hiding
Rename test names, comments, fixture data, and mock GitHub/webhook
responses that still said Argo/ArgoCD/argocd/argoproj in our own
voice, matching the hanzocd-* binary/configmap names and the
apps.hanzo.ai CRD/annotation domain already established elsewhere
in the fork. Also drop the dated argov1alpha1/argoprojiov1alpha1
import aliases for our own v1alpha1 API package.

Restore the CRD groups a prior blind rename had mangled on a
vendored third-party Argo Workflows example manifest back to the
real argoproj.io, and fix several places where an earlier
half-finished rename had gone silently wrong instead of just being
cosmetic: stale CD_BINARY_NAME values and a stale
--argocd-repo-server flag no longer recognized by the binary, cert
filenames and an ssh_known_hosts alias that didn't match what's
actually on disk, a namespace and a kustomize image substitution
that were silent no-ops, and a test assertion regex that could
never match its own fixture.

External lookup keys we don't control are left byte-exact:
quay.io/argoprojlabs images, the docker.io/argoproj CI builder
image, live argoproj/argo-workflows release URLs, the generated
ArgoprojV1alpha1() clientset method, and the Makefile-coupled
/tmp/argo-e2e and GOPATH mount conventions.
2026-09-05 01:07:59 -07:00

98 lines
3.9 KiB
Go

package services
import (
"context"
"fmt"
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
"github.com/hanzoai/cd/reposerver/apiclient"
"github.com/hanzoai/cd/util/db"
utilio "github.com/hanzoai/cd/util/io"
)
type repoService struct {
getRepository func(ctx context.Context, url, project string) (*v1alpha1.Repository, error)
submoduleEnabled bool
newFileGlobbingEnabled bool
getGitFilesFromRepoServer func(ctx context.Context, req *apiclient.GitFilesRequest) (*apiclient.GitFilesResponse, error)
getGitDirectoriesFromRepoServer func(ctx context.Context, req *apiclient.GitDirectoriesRequest) (*apiclient.GitDirectoriesResponse, error)
}
type Repos interface {
// GetFiles returns content of files (not directories) within the target repo
GetFiles(ctx context.Context, repoURL, revision, project, pattern string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) (map[string][]byte, error)
// GetDirectories returns a list of directories (not files) within the target repo
GetDirectories(ctx context.Context, repoURL, revision, project string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) ([]string, error)
}
func NewArgoCDService(db db.DB, submoduleEnabled bool, repoClientset apiclient.Clientset, newFileGlobbingEnabled bool) Repos {
return &repoService{
getRepository: db.GetRepository,
submoduleEnabled: submoduleEnabled,
newFileGlobbingEnabled: newFileGlobbingEnabled,
getGitFilesFromRepoServer: func(ctx context.Context, fileRequest *apiclient.GitFilesRequest) (*apiclient.GitFilesResponse, error) {
closer, client, err := repoClientset.NewRepoServerClient()
if err != nil {
return nil, fmt.Errorf("error initializing new repo server client: %w", err)
}
defer utilio.Close(closer)
return client.GetGitFiles(ctx, fileRequest)
},
getGitDirectoriesFromRepoServer: func(ctx context.Context, dirRequest *apiclient.GitDirectoriesRequest) (*apiclient.GitDirectoriesResponse, error) {
closer, client, err := repoClientset.NewRepoServerClient()
if err != nil {
return nil, fmt.Errorf("error initialising new repo server client: %w", err)
}
defer utilio.Close(closer)
return client.GetGitDirectories(ctx, dirRequest)
},
}
}
func (a *repoService) GetFiles(ctx context.Context, repoURL, revision, project, pattern string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) (map[string][]byte, error) {
repo, err := a.getRepository(ctx, repoURL, project)
if err != nil {
return nil, fmt.Errorf("error in GetRepository: %w", err)
}
fileRequest := &apiclient.GitFilesRequest{
Repo: repo,
SubmoduleEnabled: a.submoduleEnabled,
Revision: revision,
Path: pattern,
NewGitFileGlobbingEnabled: a.newFileGlobbingEnabled,
NoRevisionCache: noRevisionCache,
SourceIntegrity: sourceIntegrity,
VerifyCommit: sourceIntegrity != nil, // nolint:staticcheck
}
fileResponse, err := a.getGitFilesFromRepoServer(ctx, fileRequest)
if err != nil {
return nil, fmt.Errorf("error retrieving Git files: %w", err)
}
return fileResponse.GetMap(), nil
}
func (a *repoService) GetDirectories(ctx context.Context, repoURL, revision, project string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) ([]string, error) {
repo, err := a.getRepository(ctx, repoURL, project)
if err != nil {
return nil, fmt.Errorf("error in GetRepository: %w", err)
}
dirRequest := &apiclient.GitDirectoriesRequest{
Repo: repo,
SubmoduleEnabled: a.submoduleEnabled,
Revision: revision,
NoRevisionCache: noRevisionCache,
SourceIntegrity: sourceIntegrity,
VerifyCommit: sourceIntegrity != nil,
}
dirResponse, err := a.getGitDirectoriesFromRepoServer(ctx, dirRequest)
if err != nil {
return nil, fmt.Errorf("error retrieving Git Directories: %w", err)
}
return dirResponse.GetPaths(), nil
}