func getRemoteRepoTarget()

in cmd/push.go [192:227]


func getRemoteRepoTarget(reference string, credsResolver obom.CredentialsResolver) (*remote.Repository, error) {
	// Parse the reference
	ref, err := registry.ParseReference(reference)
	if err != nil {
		return nil, fmt.Errorf("error parsing reference: %w", err)
	}

	// Construct the repository string without the tag/digest
	// This allows us to reuse this repository target for pushing the SBOM and attaching artifacts
	repoStr := fmt.Sprintf("%s/%s", ref.Registry, ref.Repository)

	// Connect to a remote repository
	repo, err := remote.NewRepository(repoStr)
	if err != nil {
		return nil, fmt.Errorf("error connecting to remote repository: %w", err)
	}

	// Check if registry has is localhost or starts with localhost:
	reg := repo.Reference.Registry
	if strings.HasPrefix(reg, "localhost:") {
		repo.PlainHTTP = true
	}

	// Prepare the auth client for the registry
	client := &auth.Client{
		Client: retry.DefaultClient,
		Cache:  auth.DefaultCache,
	}

	client.Credential = credsResolver

	client.SetUserAgent(APPLICATION_USERAGENT)
	repo.Client = client

	return repo, nil
}