Provisioning: count for Connection reference in Validation and Tester

This commit is contained in:
Daniele Ferru
2026-01-14 23:35:30 +01:00
parent 91ab753368
commit 39a5836ff0
23 changed files with 2423 additions and 522 deletions
@@ -101,7 +101,8 @@ func (r *gitRepository) Validate() (list field.ErrorList) {
}
// Readonly repositories may not need a token (if public)
if len(r.config.Spec.Workflows) > 0 {
// Also, in case a connection is provided, the token will be created by the controller.
if len(r.config.Spec.Workflows) > 0 && r.config.Spec.Connection == nil {
if cfg.Token == "" && r.config.Secure.Token.IsZero() {
list = append(list, field.Required(field.NewPath("secure", "token"), "a git access token is required"))
}
@@ -169,6 +169,22 @@ func TestGitRepository_Validate(t *testing.T) {
},
want: nil,
},
{
name: "missing token for R/W repository with connection",
config: &provisioning.Repository{
Spec: provisioning.RepositorySpec{
Type: "test_type",
Workflows: []provisioning.Workflow{provisioning.WriteWorkflow},
Connection: &provisioning.ConnectionInfo{Name: "my-connection"},
},
},
gitConfig: RepositoryConfig{
URL: "https://git.example.com/repo.git",
Branch: "main",
Token: "", // Empty token - should be OK because connection is provided
},
want: nil,
},
{
name: "unsafe path",
config: &provisioning.Repository{