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

Fixing incorrect error message on Verify #350

Merged
merged 13 commits into from
May 3, 2024
Merged
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .

addtlAttestors, err := attestation.Attestors(ro.Attestations)
if err != nil {
return fmt.Errorf("failed to create attestors := %w", err)
return fmt.Errorf("failed to create attestors: %w", err)
}

attestors = append(attestors, addtlAttestors...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const (
// we need to abstract where keys are coming from, etc
func runVerify(ctx context.Context, vo options.VerifyOptions) error {
if vo.KeyPath == "" && len(vo.CAPaths) == 0 {
return fmt.Errorf("must suply public key or ca paths")
return fmt.Errorf("must supply public key or ca paths")
}

var verifier cryptoutil.Verifier
Expand Down
9 changes: 9 additions & 0 deletions options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
AttestorOptSetters map[string][]func(attestation.Attestor) (attestation.Attestor, error)
}

var RequiredRunFlags = []string{
"outfile",
jkjell marked this conversation as resolved.
Show resolved Hide resolved
"step",
}

func (ro *RunOptions) AddFlags(cmd *cobra.Command) {
ro.SignerOptions.AddFlags(cmd)
ro.ArchivistaOptions.AddFlags(cmd)
Expand All @@ -44,6 +49,10 @@
cmd.Flags().BoolVar(&ro.Tracing, "trace", false, "Enable tracing for the command")
cmd.Flags().StringSliceVar(&ro.TimestampServers, "timestamp-servers", []string{}, "Timestamp Authority Servers to use when signing envelope")

for _, flag := range RequiredRunFlags {
cmd.MarkFlagRequired(flag)

Check failure on line 53 in options/run.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cmd.MarkFlagRequired` is not checked (errcheck)
}

attestationRegistrations := attestation.RegistrationEntries()
ro.AttestorOptSetters = addFlagsFromRegistry("attestor", attestationRegistrations, cmd)
}
Expand Down
10 changes: 10 additions & 0 deletions options/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@
TimestampServers []string
}

var RequiredSignFlags = []string{
"infile",
"outfile",
"datatype",
}

func (so *SignOptions) AddFlags(cmd *cobra.Command) {
so.SignerOptions.AddFlags(cmd)
cmd.Flags().StringVarP(&so.DataType, "datatype", "t", "https://witness.testifysec.com/policy/v0.1", "The URI reference to the type of data being signed. Defaults to the Witness policy type")
cmd.Flags().StringVarP(&so.OutFilePath, "outfile", "o", "", "File to write signed data. Defaults to stdout")
cmd.Flags().StringVarP(&so.InFilePath, "infile", "f", "", "Witness policy file to sign")
cmd.Flags().StringSliceVar(&so.TimestampServers, "timestamp-servers", []string{}, "Timestamp Authority Servers to use when signing envelope")

for _, flag := range RequiredSignFlags {
cmd.MarkFlagRequired(flag)

Check failure on line 41 in options/sign.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cmd.MarkFlagRequired` is not checked (errcheck)
}
}
11 changes: 10 additions & 1 deletion options/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package options

import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"
)

type VerifyOptions struct {
ArchivistaOptions ArchivistaOptions
Expand All @@ -26,6 +28,10 @@
CAPaths []string
}

var RequiredVerifyFlags = []string{
"policy",
ChaosInTheCRD marked this conversation as resolved.
Show resolved Hide resolved
}

func (vo *VerifyOptions) AddFlags(cmd *cobra.Command) {
vo.ArchivistaOptions.AddFlags(cmd)
cmd.Flags().StringVarP(&vo.KeyPath, "publickey", "k", "", "Path to the policy signer's public key")
Expand All @@ -35,4 +41,7 @@
cmd.Flags().StringSliceVarP(&vo.AdditionalSubjects, "subjects", "s", []string{}, "Additional subjects to lookup attestations")
cmd.Flags().StringSliceVarP(&vo.CAPaths, "policy-ca", "", []string{}, "Paths to CA certificates to use for verifying the policy")

for _, flag := range RequiredVerifyFlags {
cmd.MarkFlagRequired(flag)

Check failure on line 45 in options/verify.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cmd.MarkFlagRequired` is not checked (errcheck)
}
}