Skip to content

Commit

Permalink
adding functions to mark required flags
Browse files Browse the repository at this point in the history
Signed-off-by: chaosinthecrd <[email protected]>
  • Loading branch information
ChaosInTheCRD committed Jan 9, 2024
1 parent 6b61f30 commit 273c249
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
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 @@ type RunOptions struct {
AttestorOptSetters map[string][]func(attestation.Attestor) (attestation.Attestor, error)
}

var RequiredRunFlags = []string{
"outfile",
"step",
}

func (ro *RunOptions) AddFlags(cmd *cobra.Command) {
ro.SignerOptions.AddFlags(cmd)
ro.ArchivistaOptions.AddFlags(cmd)
Expand All @@ -44,6 +49,10 @@ func (ro *RunOptions) AddFlags(cmd *cobra.Command) {
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)
}

attestationRegistrations := attestation.RegistrationEntries()
ro.AttestorOptSetters = addFlagsFromRegistry("attestor", attestationRegistrations, cmd)
}
Expand Down
6 changes: 6 additions & 0 deletions options/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type SignOptions struct {
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")
Expand Down
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 @@ type VerifyOptions struct {
CAPaths []string
}

var RequiredVerifyFlags = []string{
"policy",
}

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 @@ func (vo *VerifyOptions) AddFlags(cmd *cobra.Command) {
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)
}
}

0 comments on commit 273c249

Please sign in to comment.