Skip to content

Commit

Permalink
chore: address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-ibra committed Jul 8, 2024
1 parent 09e638b commit 3170449
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/ocivalidator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ type OciValidatorSpec struct {
OciRegistryRules []OciRegistryRule `json:"ociRegistryRules,omitempty" yaml:"ociRegistryRules,omitempty"`
}

// ResultCount returns the number of validation results expected for an OciValidatorSpec
func (s OciValidatorSpec) ResultCount() int {
return len(s.OciRegistryRules)
}

// OciRegistryRule defines the validation rule for an OCI registry
type OciRegistryRule struct {
// Name is the name of the rule
RuleName string `json:"name" yaml:"name"`
Expand All @@ -51,10 +53,12 @@ type OciRegistryRule struct {
SignatureVerification SignatureVerification `json:"signatureVerification,omitempty" yaml:"signatureVerification,omitempty"`
}

// Name returns the name of the OciRegistryRule
func (r OciRegistryRule) Name() string {
return r.RuleName
}

// Artifact defines the artifact to be validated
type Artifact struct {
// Ref is the path to the artifact in the host registry that should be validated.
// An individual artifact can take any of the following forms:
Expand All @@ -72,12 +76,14 @@ type Artifact struct {
LayerValidation bool `json:"layerValidation,omitempty" yaml:"layerValidation,omitempty"`
}

// Auth defines the authentication information for the registry
type Auth struct {
// SecretName is the name of the Kubernetes Secret that exists in the same namespace as the OciValidator
// and that contains the credentials used to authenticate to the OCI Registry
SecretName string `json:"secretName" yaml:"secretName"`
}

// SignatureVerification defines the provider and secret name to verify the signatures of artifacts in an OCI registry
type SignatureVerification struct {
// Provider specifies the technology used to sign the OCI Artifact
// +kubebuilder:validation:Enum=cosign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ spec:
properties:
ociRegistryRules:
items:
description: OciRegistryRule defines the validation rule for an
OCI registry
properties:
artifacts:
description: Artifacts is a slice of artifacts in the host registry
that should be validated.
items:
description: Artifact defines the artifact to be validated
properties:
layerValidation:
description: |-
Expand Down
5 changes: 4 additions & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Package constants contains the constants used in validator-plugin-oci
package constants

const (
// PluginCode is the constant for the plugin code
PluginCode string = "OCI"

// OciRegistry is the OCI registry string
OciRegistry string = "oci-registry"
// EcrRegistry is the ECR registry string
EcrRegistry string = "ecr-registry"
)
10 changes: 4 additions & 6 deletions internal/controller/ocivalidator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ func (r *OciValidatorReconciler) secretKeyAuth(req ctrl.Request, rule v1alpha1.O
// no secrets found, set creds to empty string
r.Log.V(0).Error(err, fmt.Sprintf("Auth secret %s not found for rule %s", secretName, rule.Name()))
return "", ""
} else {
r.Log.V(0).Error(err, fmt.Sprintf("Failed to fetch auth secret %s for rule %s", secretName, rule.Name()))
return "", ""
}
r.Log.V(0).Error(err, fmt.Sprintf("Failed to fetch auth secret %s for rule %s", secretName, rule.Name()))
return "", ""
}

errMalformedSecret := fmt.Errorf("malformed secret %s/%s", authSecret.Namespace, authSecret.Name)
Expand Down Expand Up @@ -174,10 +173,9 @@ func (r *OciValidatorReconciler) signaturePubKeys(req ctrl.Request, rule v1alpha
// no secrets found, set creds to empty string
r.Log.V(0).Error(err, fmt.Sprintf("Public Keys secret %s not found for rule %s", secretName, rule.Name()))
return pubKeys
} else {
r.Log.V(0).Error(err, fmt.Sprintf("Failed to fetch Public Keys secret %s for rule %s", secretName, rule.Name()))
return pubKeys
}
r.Log.V(0).Error(err, fmt.Sprintf("Failed to fetch Public Keys secret %s for rule %s", secretName, rule.Name()))
return pubKeys
}

for k, data := range pubKeysSecret.Data {
Expand Down
23 changes: 0 additions & 23 deletions internal/types/types.go

This file was deleted.

3 changes: 3 additions & 0 deletions internal/validators/oci_validator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package validators defines the OCI registry rule service and implements the reconcile function for the OCI registry rule.
package validators

import (
Expand Down Expand Up @@ -32,10 +33,12 @@ const (
verificationTimeout = 60 * time.Second
)

// OciRuleService defines the service for OCI registry rules
type OciRuleService struct {
log logr.Logger
}

// NewOciRuleService creates a new OCI registry rule service
func NewOciRuleService(log logr.Logger) *OciRuleService {
return &OciRuleService{
log: log,
Expand Down
1 change: 1 addition & 0 deletions internal/verifier/verifier.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package verifier contains the verifier interface and the cosign verifier implementation.
package verifier

import (
Expand Down

0 comments on commit 3170449

Please sign in to comment.