Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow private base without key ref or with extra comment #4

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WORKDIR /app


RUN go test -v -cover ./... \
&& go build -o /argocd-voodoobox-plugin .
&& go build -ldflags='-s -w' -o /argocd-voodoobox-plugin .

# final stage
# argocd requires that sidecar container is running as user 999
Expand Down
7 changes: 4 additions & 3 deletions git-ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
)

var (
reKeyName = regexp.MustCompile(`#\s*?argocd-voodoobox-plugin:\s*?(?P<keyName>\w+)`)
reKeyName = regexp.MustCompile(`#.*?argocd-voodoobox-plugin:\s*?(?P<keyName>\w+)`)
reRepoAddressWithSSH = regexp.MustCompile(`(?P<beginning>^\s*-\s*ssh:\/\/)(?P<domain>\w.+?)(?P<repoDetails>\/.*$)`)
)

Expand Down Expand Up @@ -167,8 +167,9 @@ func updateRepoBaseAddresses(in io.Reader) (map[string]string, []byte, error) {
case keyName != "" && !reRepoAddressWithSSH.MatchString(l):
return nil, nil, fmt.Errorf("found key reference in comment but next remote base url doesn't contain ssh://")

case keyName == "" && reRepoAddressWithSSH.MatchString(l):
return nil, nil, fmt.Errorf("found remote base url with ssh protocol without referenced key comment above")
// referencing key is not mandatory since only 1 key can be used for all private base
// case keyName == "" && reRepoAddressWithSSH.MatchString(l):
// return nil, nil, fmt.Errorf("found remote base url with ssh protocol without referenced key comment above")

case keyName != "" && reRepoAddressWithSSH.MatchString(l):
// If Key if found replace domain
Expand Down
47 changes: 44 additions & 3 deletions git-ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ resources:
"keyD": "github.com",
},
},

{
name: "extra comments before key ref",
args: args{
in: []byte(`apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- app/

- github.com/org/open1//manifests/lab-foo?ref=master
# some-extra comment : key_b argocd-voodoobox-plugin: sshKeyB
- ssh://gitlab.io/org/repo2//manifests/lab-bar?ref=main
# argocd-voodoobox-plugin: key_c
- ssh://bitbucket.org/org/repo3//manifests/lab-zoo?ref=dev
`)},
wantOut: []byte(`apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- app/

- github.com/org/open1//manifests/lab-foo?ref=master
# some-extra comment : key_b argocd-voodoobox-plugin: sshKeyB
- ssh://sshKeyB_gitlab_io/org/repo2//manifests/lab-bar?ref=main
# argocd-voodoobox-plugin: key_c
- ssh://key_c_bitbucket_org/org/repo3//manifests/lab-zoo?ref=dev
`),
wantKeyMap: map[string]string{
"sshKeyB": "gitlab.io",
"key_c": "bitbucket.org",
},
wantErr: false,
},

{
name: "missing key ref",
args: args{
Expand All @@ -118,10 +151,18 @@ resources:
- github.com/org/open1//manifests/lab-foo?ref=master
- ssh://github.com/org/repo3//manifests/lab-zoo?ref=dev
`)},
wantOut: nil,
wantKeyMap: nil,
wantErr: true,
wantOut: []byte(`apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- app/

- github.com/org/open1//manifests/lab-foo?ref=master
- ssh://github.com/org/repo3//manifests/lab-zoo?ref=dev
`),
wantKeyMap: map[string]string{},
wantErr: false,
},

{
name: "missing ssh protocol",
args: args{
Expand Down