ValidateProjects checks if the project has more than one remote configured then a checkout remote is mandatory and if the checkout remote matches the renote configured
(projects []v1alpha2.Project)
| 45 | // ValidateProjects checks if the project has more than one remote configured then a checkout |
| 46 | // remote is mandatory and if the checkout remote matches the renote configured |
| 47 | func ValidateProjects(projects []v1alpha2.Project) (returnedErr error) { |
| 48 | |
| 49 | for _, project := range projects { |
| 50 | var gitSource v1alpha2.GitLikeProjectSource |
| 51 | if project.Git != nil { |
| 52 | gitSource = project.Git.GitLikeProjectSource |
| 53 | } else { |
| 54 | continue |
| 55 | } |
| 56 | switch len(gitSource.Remotes) { |
| 57 | case 0: |
| 58 | |
| 59 | newErr := resolveErrorMessageWithImportAttributes(&MissingProjectRemoteError{projectName: project.Name}, project.Attributes) |
| 60 | returnedErr = multierror.Append(returnedErr, newErr) |
| 61 | case 1: |
| 62 | if gitSource.CheckoutFrom != nil && gitSource.CheckoutFrom.Remote != "" { |
| 63 | if err := validateRemoteMap(gitSource.Remotes, gitSource.CheckoutFrom.Remote, "project", project.Name); err != nil { |
| 64 | newErr := resolveErrorMessageWithImportAttributes(err, project.Attributes) |
| 65 | returnedErr = multierror.Append(returnedErr, newErr) |
| 66 | } |
| 67 | } |
| 68 | default: // len(gitSource.Remotes) >= 2 |
| 69 | if gitSource.CheckoutFrom == nil || gitSource.CheckoutFrom.Remote == "" { |
| 70 | |
| 71 | newErr := resolveErrorMessageWithImportAttributes(&MissingProjectCheckoutFromRemoteError{projectName: project.Name}, project.Attributes) |
| 72 | returnedErr = multierror.Append(returnedErr, newErr) |
| 73 | continue |
| 74 | } |
| 75 | if err := validateRemoteMap(gitSource.Remotes, gitSource.CheckoutFrom.Remote, "project", project.Name); err != nil { |
| 76 | newErr := resolveErrorMessageWithImportAttributes(err, project.Attributes) |
| 77 | returnedErr = multierror.Append(returnedErr, newErr) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return returnedErr |
| 83 | } |
| 84 | |
| 85 | // validateRemoteMap checks if the checkout remote is present in the project remote map |
| 86 | func validateRemoteMap(remotes map[string]string, checkoutRemote, objectType, objectName string) error { |