Skip to content

Commit

Permalink
fix: refactor to lower cyclomatic complexity for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
KasnocknDave committed Sep 19, 2024
1 parent 7ba5a76 commit ad25b51
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
59 changes: 34 additions & 25 deletions pkg/controller/repositories/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,12 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, err
}

passwordSecretResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.PasswordRef)
if err != nil {
return managed.ExternalObservation{}, err
}
sshPrivateKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.SSHPrivateKeyRef)
if err != nil {
return managed.ExternalObservation{}, err
}
tlsClientCertDataResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.TLSClientCertDataRef)
if err != nil {
return managed.ExternalObservation{}, err
}
tlsClientCertKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.TLSClientCertKeyRef)
if err != nil {
return managed.ExternalObservation{}, err
}
githubAppPrivateKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.GithubAppPrivateKeyRef)
resourceVersions, err := e.getSecretResource(ctx, cr)

if err != nil {
return managed.ExternalObservation{}, err
}

resourceVersions := secretResourceVersion{
Password: passwordSecretResourceVersion,
SSHPrivateKey: sshPrivateKeyResourceVersion,
TLSClientCertData: tlsClientCertDataResourceVersion,
TLSClientCertKey: tlsClientCertKeyResourceVersion,
GithubAppPrivateKey: githubAppPrivateKeyResourceVersion,
}

current := cr.Spec.ForProvider.DeepCopy()
lateInitializeRepository(&cr.Spec.ForProvider, observedRepository)

Expand Down Expand Up @@ -550,3 +527,35 @@ func (e *external) getPayload(ctx context.Context, ref *v1alpha1.SecretReference

return nil, nil
}

func (e *external) getSecretResource(ctx context.Context, cr *v1alpha1.Repository) (secretResourceVersion, error) {
passwordSecretResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.PasswordRef)
if err != nil {
return secretResourceVersion{}, err
}
sshPrivateKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.SSHPrivateKeyRef)
if err != nil {
return secretResourceVersion{}, err
}
tlsClientCertDataResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.TLSClientCertDataRef)
if err != nil {
return secretResourceVersion{}, err
}
tlsClientCertKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.TLSClientCertKeyRef)
if err != nil {
return secretResourceVersion{}, err
}
githubAppPrivateKeyResourceVersion, err := e.getSecretResourceVersion(ctx, cr.Spec.ForProvider.GithubAppPrivateKeyRef)
if err != nil {
return secretResourceVersion{}, err
}

return secretResourceVersion{
Password: passwordSecretResourceVersion,
SSHPrivateKey: sshPrivateKeyResourceVersion,
TLSClientCertData: tlsClientCertDataResourceVersion,
TLSClientCertKey: tlsClientCertKeyResourceVersion,
GithubAppPrivateKey: githubAppPrivateKeyResourceVersion,
}, nil

}
2 changes: 1 addition & 1 deletion pkg/controller/repositories/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
var (
errBoom = errors.New("boom")
// Unused until issue https://github.com/argoproj/argo-cd/issues/20005 in Argo CD project is resolved
//errNotFound = errors.New("code = NotFound desc = repo")
// errNotFound = errors.New("code = NotFound desc = repo")
errPermissionDenied = errors.New("code = PermissionDenied desc = permission denied")
testRepositoryExternalName = "testRepo"
testRepo = "https://gitlab.com/example-group/example-project.git"
Expand Down

0 comments on commit ad25b51

Please sign in to comment.