1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Move Git implementation validation to custom flag

Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
Hidde Beydals
2021-01-15 16:39:00 +01:00
parent a260403334
commit 9e1db06936
4 changed files with 110 additions and 9 deletions

View File

@@ -96,7 +96,7 @@ var (
sourceGitRSABits flags.RSAKeyBits = 2048
sourceGitECDSACurve = flags.ECDSACurve{Curve: elliptic.P384()}
sourceGitSecretRef string
sourceGitImplementation string
sourceGitImplementation flags.GitImplementation
)
func init() {
@@ -110,7 +110,7 @@ func init() {
createSourceGitCmd.Flags().Var(&sourceGitRSABits, "ssh-rsa-bits", sourceGitRSABits.Description())
createSourceGitCmd.Flags().Var(&sourceGitECDSACurve, "ssh-ecdsa-curve", sourceGitECDSACurve.Description())
createSourceGitCmd.Flags().StringVarP(&sourceGitSecretRef, "secret-ref", "", "", "the name of an existing secret containing SSH or basic credentials")
createSourceGitCmd.Flags().StringVar(&sourceGitImplementation, "git-implementation", "", "the git implementation to use, can be 'go-git' or 'libgit2'")
createSourceGitCmd.Flags().Var(&sourceGitImplementation, "git-implementation", sourceGitImplementation.Description())
createSourceCmd.AddCommand(createSourceGitCmd)
}
@@ -141,10 +141,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
return err
}
if !utils.ContainsItemString([]string{sourcev1.GoGitImplementation, sourcev1.LibGit2Implementation, ""}, sourceGitImplementation) {
return fmt.Errorf("Invalid git implementation %q", sourceGitImplementation)
}
gitRepository := sourcev1.GitRepository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -156,11 +152,14 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
Interval: metav1.Duration{
Duration: interval,
},
Reference: &sourcev1.GitRepositoryRef{},
GitImplementation: sourceGitImplementation,
Reference: &sourcev1.GitRepositoryRef{},
},
}
if sourceGitImplementation != "" {
gitRepository.Spec.GitImplementation = sourceGitImplementation.String()
}
if sourceGitSemver != "" {
gitRepository.Spec.Reference.SemVer = sourceGitSemver
} else if sourceGitTag != "" {