Skip to content

Commit

Permalink
chore: fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
TeodorSAP committed Oct 18, 2024
1 parent 482a81f commit 0c850c1
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions internal/validators/secretref/secret_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type Validator struct {
}

var (
ErrSecretKeyNotFound = errors.New("one or more keys in a referenced Secret are missing")
ErrSecretRefNotFound = errors.New("one or more referenced Secrets are missing")
ErrSecretKeyNotFound = errors.New("one or more keys in a referenced Secret are missing")
ErrSecretRefNotFound = errors.New("one or more referenced Secrets are missing")
ErrSecretRefMissingFields = errors.New("secret reference is missing field/s")
)

Expand All @@ -44,7 +44,7 @@ func GetValue(ctx context.Context, client client.Reader, ref telemetryv1alpha1.S
if err := checkForMissingFields(ref); err != nil {
return nil, err
}

var secret corev1.Secret
if err := client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: ref.Namespace}, &secret); err != nil {
if apierrors.IsNotFound(err) {
Expand All @@ -66,19 +66,21 @@ func GetValue(ctx context.Context, client client.Reader, ref telemetryv1alpha1.S
func checkForMissingFields(ref telemetryv1alpha1.SecretKeyRef) error {
var missingAttributes []string

if ref.Name == "" {
missingAttributes = append(missingAttributes, "Name")
}
if ref.Namespace == "" {
missingAttributes = append(missingAttributes, "Namespace")
}
if ref.Key == "" {
missingAttributes = append(missingAttributes, "Key")
}

if len(missingAttributes) > 0 {
return fmt.Errorf("%w: %s", ErrSecretRefMissingFields, strings.Join(missingAttributes, ", "))
}
if ref.Name == "" {
missingAttributes = append(missingAttributes, "Name")
}

if ref.Namespace == "" {
missingAttributes = append(missingAttributes, "Namespace")
}

if ref.Key == "" {
missingAttributes = append(missingAttributes, "Key")
}

if len(missingAttributes) > 0 {
return fmt.Errorf("%w: %s", ErrSecretRefMissingFields, strings.Join(missingAttributes, ", "))
}

return nil
}

0 comments on commit 0c850c1

Please sign in to comment.