Skip to content

Commit

Permalink
chore: remove ending period from error details
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin-li committed Aug 23, 2024
1 parent 8a010b1 commit aaba189
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/clusterresource/verifier_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func verifierAddOrReplace(spec configv1beta1.VerifierSpec, objectName string) er
verifierConfig, err := cutils.SpecToVerifierConfig(spec.Parameters.Raw, objectName, spec.Name, spec.ArtifactTypes, spec.Source)
if err != nil {
logrus.Error(err, "unable to convert crd specification to verifier config")
return re.ErrorCodeConfigInvalid.WithDetail("Unable to convert crd specification to verifier config.").WithError(err)
return re.ErrorCodeConfigInvalid.WithDetail("Unable to convert crd specification to verifier config").WithError(err)
}

return cutils.UpsertVerifier(spec.Version, spec.Address, constants.EmptyNamespace, objectName, verifierConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestVerifierAdd_WithParameters(t *testing.T) {
func TestVerifierAddOrReplace_PluginNotFound(t *testing.T) {
resetVerifierMap()
resource := "invalidplugin"
expectedMsg := "PLUGIN_NOT_FOUND: Plugin: pluginnotfound not found.: failed to find plugin \"pluginnotfound\" in paths [test/path]"
expectedMsg := "PLUGIN_NOT_FOUND: Plugin: pluginnotfound not found: failed to find plugin \"pluginnotfound\" in paths [test/path]"
var testVerifierSpec = getInvalidVerifierSpec()
err := verifierAddOrReplace(testVerifierSpec, resource)

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/namespaceresource/verifier_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func verifierAddOrReplace(spec configv1beta1.NamespacedVerifierSpec, objectName
verifierConfig, err := cutils.SpecToVerifierConfig(spec.Parameters.Raw, objectName, spec.Name, spec.ArtifactTypes, spec.Source)
if err != nil {
logrus.Error(err, "unable to convert crd specification to verifier config")
return re.ErrorCodeConfigInvalid.WithDetail("Unable to convert crd specification to verifier config.").WithError(err)
return re.ErrorCodeConfigInvalid.WithDetail("Unable to convert crd specification to verifier config").WithError(err)
}

return cutils.UpsertVerifier(spec.Version, spec.Address, namespace, objectName, verifierConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestVerifierAdd_WithParameters(t *testing.T) {
func TestVerifierAddOrReplace_PluginNotFound(t *testing.T) {
resetVerifierMap()
resource := "invalidplugin"
expectedMsg := "PLUGIN_NOT_FOUND: Plugin: pluginnotfound not found.: failed to find plugin \"pluginnotfound\" in paths [test/path]"
expectedMsg := "PLUGIN_NOT_FOUND: Plugin: pluginnotfound not found: failed to find plugin \"pluginnotfound\" in paths [test/path]"
var testVerifierSpec = getInvalidVerifierSpec()
err := verifierAddOrReplace(testVerifierSpec, resource, testNamespace)

Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (executor Executor) verifySubjectInternal(ctx context.Context, verifyParame
}
if executor.PolicyEnforcer.GetPolicyType(ctx) == pt.ConfigPolicy {
if len(verifierReports) == 0 {
return types.VerifyResult{}, errors.ErrorCodeNoVerifierReport.WithDetail("No verifier report generated.")
return types.VerifyResult{}, errors.ErrorCodeNoVerifierReport.WithDetail("No verifier report generated")
}
}
// If it requires embedded Rego Policy Engine make the decision, execute
Expand Down
6 changes: 3 additions & 3 deletions pkg/referrerstore/oras/oras.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (store *orasStore) GetReferenceManifest(ctx context.Context, subjectReferen

manifestBytes, err = io.ReadAll(manifestReader)
if err != nil {
return ocispecs.ReferenceManifest{}, re.ErrorCodeManifestInvalid.WithDetail("Failed to parse fetched manifest.").WithError(err)
return ocispecs.ReferenceManifest{}, re.ErrorCodeManifestInvalid.WithDetail("Failed to parse fetched manifest").WithError(err)
}

// push fetched manifest to local ORAS cache
Expand All @@ -344,12 +344,12 @@ func (store *orasStore) GetReferenceManifest(ctx context.Context, subjectReferen
if referenceDesc.Descriptor.MediaType == oci.MediaTypeImageManifest {
var imageManifest oci.Manifest
if err := json.Unmarshal(manifestBytes, &imageManifest); err != nil {
return ocispecs.ReferenceManifest{}, re.ErrorCodeDataDecodingFailure.WithDetail("Failed to parse manifest content in `application/vnd.oci.image.manifest.v1+json` mediatype.").WithError(err).WithRemediation("Please check if the manifest was created correctly.")
return ocispecs.ReferenceManifest{}, re.ErrorCodeDataDecodingFailure.WithDetail("Failed to parse manifest content in `application/vnd.oci.image.manifest.v1+json` mediatype").WithError(err).WithRemediation("Please check if the manifest was created correctly.")
}
referenceManifest = commonutils.OciManifestToReferenceManifest(imageManifest)
} else if referenceDesc.Descriptor.MediaType == ocispecs.MediaTypeArtifactManifest {
if err := json.Unmarshal(manifestBytes, &referenceManifest); err != nil {
return ocispecs.ReferenceManifest{}, re.ErrorCodeDataDecodingFailure.WithDetail("Failed to parse manifest content in `application/vnd.oci.artifact.manifest.v1+json` mediatype.").WithError(err).WithRemediation("Please check if the manifest was created correctly.")
return ocispecs.ReferenceManifest{}, re.ErrorCodeDataDecodingFailure.WithDetail("Failed to parse manifest content in `application/vnd.oci.artifact.manifest.v1+json` mediatype").WithError(err).WithRemediation("Please check if the manifest was created correctly.")
}
} else {
return ocispecs.ReferenceManifest{}, re.ErrorCodeGetReferenceManifestFailure.WithDetail(fmt.Sprintf("Unsupported manifest media type: %s", referenceDesc.Descriptor.MediaType)).WithRemediation("Please check if the manifest was created correctly.")
Expand Down
8 changes: 4 additions & 4 deletions pkg/verifier/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func CreateVerifierFromConfig(verifierConfig config.VerifierConfig, configVersio
if value, ok := verifierConfig[types.Name]; ok {
verifierTypeStr = value.(string)
} else {
return nil, re.ErrorCodeConfigInvalid.WithDetail("Name field is required in verifier config.")
return nil, re.ErrorCodeConfigInvalid.WithDetail("Name field is required in verifier config")
}

if value, ok := verifierConfig[types.Type]; ok {
verifierTypeStr = value.(string)
}

if strings.ContainsRune(verifierTypeStr, os.PathSeparator) {
return nil, re.ErrorCodeConfigInvalid.WithDetail(fmt.Sprintf("Invalid verifier plugin name [%s], [%v] is disallowed.", verifierTypeStr, os.PathSeparator))
return nil, re.ErrorCodeConfigInvalid.WithDetail(fmt.Sprintf("Invalid verifier plugin name [%s], [%v] is disallowed", verifierTypeStr, os.PathSeparator))
}

// if source is specified, download the plugin
Expand Down Expand Up @@ -94,7 +94,7 @@ func CreateVerifierFromConfig(verifierConfig config.VerifierConfig, configVersio
}

if _, err := pluginCommon.FindInPaths(verifierTypeStr, pluginBinDir); err != nil {
return nil, re.ErrorCodePluginNotFound.WithDetail(fmt.Sprintf("Plugin: %s not found.", verifierTypeStr)).WithError(err)
return nil, re.ErrorCodePluginNotFound.WithDetail(fmt.Sprintf("Plugin: %s not found", verifierTypeStr)).WithError(err)
}

pluginVersion := configVersion
Expand All @@ -117,7 +117,7 @@ func CreateVerifiersFromConfig(verifiersConfig config.VerifiersConfig, defaultPl
}

if len(verifiersConfig.Verifiers) == 0 {
return nil, re.ErrorCodeConfigInvalid.WithDetail("Verifiers config should have at least one verifier.")
return nil, re.ErrorCodeConfigInvalid.WithDetail("Verifiers config should have at least one verifier")
}

verifiers := make([]verifier.ReferenceVerifier, 0)
Expand Down
14 changes: 7 additions & 7 deletions pkg/verifier/notation/notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (f *notationPluginVerifierFactory) Create(_ string, verifierConfig config.V
}
conf, err := parseVerifierConfig(verifierConfig, namespace)
if err != nil {
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create notation verifier.").WithError(err)
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create notation verifier").WithError(err)
}

verifyService, err := getVerifierService(conf, pluginDirectory)
if err != nil {
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create Notation verifier.").WithError(err)
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create Notation verifier").WithError(err)
}

artifactTypes := strings.Split(conf.ArtifactTypes, ",")
Expand Down Expand Up @@ -142,12 +142,12 @@ func (v *notationPluginVerifier) Verify(ctx context.Context,

subjectDesc, err := store.GetSubjectDescriptor(ctx, subjectReference)
if err != nil {
return verifier.VerifierResult{IsSuccess: false}, re.ErrorCodeGetSubjectDescriptorFailure.WithDetail(fmt.Sprintf("Failed to resolve subject: %+v.", subjectReference)).WithError(err)
return verifier.VerifierResult{IsSuccess: false}, re.ErrorCodeGetSubjectDescriptorFailure.WithDetail(fmt.Sprintf("Failed to resolve subject: %+v", subjectReference)).WithError(err)
}

referenceManifest, err := store.GetReferenceManifest(ctx, subjectReference, referenceDescriptor)
if err != nil {
return verifier.VerifierResult{IsSuccess: false}, re.ErrorCodeGetReferenceManifestFailure.WithDetail(fmt.Sprintf("Failed to resolve reference manifest: %+v.", referenceDescriptor)).WithError(err)
return verifier.VerifierResult{IsSuccess: false}, re.ErrorCodeGetReferenceManifestFailure.WithDetail(fmt.Sprintf("Failed to resolve reference manifest: %+v", referenceDescriptor)).WithError(err)
}

if len(referenceManifest.Blobs) != 1 {
Expand Down Expand Up @@ -182,7 +182,7 @@ func getVerifierService(conf *NotationPluginVerifierConfig, pluginDirectory stri
}
verifier, err := notationVerifier.New(&conf.TrustPolicyDoc, store, NewRatifyPluginManager(pluginDirectory))
if err != nil {
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create Notation verifier.").WithError(err)
return nil, re.ErrorCodePluginInitFailure.WithDetail("Failed to create Notation verifier").WithError(err)
}
return verifier, nil
}
Expand All @@ -202,11 +202,11 @@ func parseVerifierConfig(verifierConfig config.VerifierConfig, _ string) (*Notat

verifierConfigBytes, err := json.Marshal(verifierConfig)
if err != nil {
return nil, re.ErrorCodeConfigInvalid.WithDetail("Failed to marshal verifierConfig to bytes.").WithError(err)
return nil, re.ErrorCodeConfigInvalid.WithDetail("Failed to marshal verifierConfig to bytes").WithError(err)
}

if err := json.Unmarshal(verifierConfigBytes, &conf); err != nil {
return nil, re.ErrorCodeConfigInvalid.WithDetail(fmt.Sprintf("Failed to unmarshal to notationPluginVerifierConfig from: %+v.", verifierConfig)).WithError(err)
return nil, re.ErrorCodeConfigInvalid.WithDetail(fmt.Sprintf("Failed to unmarshal to notationPluginVerifierConfig from: %+v", verifierConfig)).WithError(err)
}

defaultCertsDir := paths.Join(homedir.Get(), ratifyconfig.ConfigFileDir, defaultCertPath)
Expand Down

0 comments on commit aaba189

Please sign in to comment.