From 81944ab3d4f9607d15cfa42a1ac2385abebe243b Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Tue, 10 May 2022 10:04:14 +0100 Subject: [PATCH] ctclient fails if any unexpected arguments are found (#926) All of the parameterization to the subcommands is performed by flags. However, as the subcommands themselves are selected via normal arguments (no hyphens), this can lead to newcomers (e.g. me) believing that the log to fetch from could also be a bare argument. On something like get-entries, there was no way to know that the logname was ignored. Now, this will explode and the user gets the option to reconsider how they are specifying the parameters. e.g. `go run github.com/google/certificate-transparency-go/client/ctclient@master get-entries submariner --first 35494500 --last 35494590` looks very reasonable and returns data, but it isn't from submariner. #900 --- client/ctclient/cmd/bisect.go | 1 + client/ctclient/cmd/get_consistency_proof.go | 1 + client/ctclient/cmd/get_entries.go | 1 + client/ctclient/cmd/get_inclusion_proof.go | 1 + client/ctclient/cmd/get_roots.go | 1 + client/ctclient/cmd/get_sth.go | 1 + client/ctclient/cmd/upload.go | 1 + 7 files changed, 7 insertions(+) diff --git a/client/ctclient/cmd/bisect.go b/client/ctclient/cmd/bisect.go index 5e59d36617..9c9ee2a082 100644 --- a/client/ctclient/cmd/bisect.go +++ b/client/ctclient/cmd/bisect.go @@ -29,6 +29,7 @@ func init() { Use: fmt.Sprintf("bisect %s --timestamp=ts [--chain] [--text=false]", connectionFlags), Aliases: []string{"find-timestamp"}, Short: "Find a log entry by timestamp", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runBisect(cmd.Context()) }, diff --git a/client/ctclient/cmd/get_consistency_proof.go b/client/ctclient/cmd/get_consistency_proof.go index b52ca629ab..f37dde086f 100644 --- a/client/ctclient/cmd/get_consistency_proof.go +++ b/client/ctclient/cmd/get_consistency_proof.go @@ -39,6 +39,7 @@ func init() { Use: fmt.Sprintf("get-consistency-proof %s --size=N --tree_hash=hash --prev_size=N --prev_hash=hash", connectionFlags), Aliases: []string{"getconsistencyproof", "consistency-proof", "consistency"}, Short: "Fetch and verify a consistency proof between two tree states", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runGetConsistencyProof(cmd.Context()) }, diff --git a/client/ctclient/cmd/get_entries.go b/client/ctclient/cmd/get_entries.go index f9e567ccf5..7da7ef8fe1 100644 --- a/client/ctclient/cmd/get_entries.go +++ b/client/ctclient/cmd/get_entries.go @@ -39,6 +39,7 @@ func init() { Use: fmt.Sprintf("get-entries %s --first=idx [--last=idx]", connectionFlags), Aliases: []string{"getentries", "entries"}, Short: "Fetch a range of entries in the log", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runGetEntries(cmd.Context()) }, diff --git a/client/ctclient/cmd/get_inclusion_proof.go b/client/ctclient/cmd/get_inclusion_proof.go index 8f8f201560..6e4411b990 100644 --- a/client/ctclient/cmd/get_inclusion_proof.go +++ b/client/ctclient/cmd/get_inclusion_proof.go @@ -46,6 +46,7 @@ func init() { Use: fmt.Sprintf("get-inclusion-proof %s {--leaf_hash=hash | --cert_chain=file} [--timestamp=ts] [--size=N]", connectionFlags), Aliases: []string{"getinclusionproof", "inclusion-proof", "inclusion"}, Short: "Fetch and verify the inclusion proof for an entry", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runGetInclusionProof(cmd.Context()) }, diff --git a/client/ctclient/cmd/get_roots.go b/client/ctclient/cmd/get_roots.go index f3255799aa..b94646298e 100644 --- a/client/ctclient/cmd/get_roots.go +++ b/client/ctclient/cmd/get_roots.go @@ -26,6 +26,7 @@ func init() { Use: fmt.Sprintf("get-roots %s", connectionFlags), Aliases: []string{"getroots", "roots"}, Short: "Fetch the root certificates accepted by the log", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runGetRoots(cmd.Context()) }, diff --git a/client/ctclient/cmd/get_sth.go b/client/ctclient/cmd/get_sth.go index 39db612df2..65b1b0ac1a 100644 --- a/client/ctclient/cmd/get_sth.go +++ b/client/ctclient/cmd/get_sth.go @@ -27,6 +27,7 @@ func init() { Use: fmt.Sprintf("get-sth %s", connectionFlags), Aliases: []string{"sth"}, Short: "Fetch the latest STH of the log", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runGetSTH(cmd.Context()) }, diff --git a/client/ctclient/cmd/upload.go b/client/ctclient/cmd/upload.go index d090f5fe32..be17b7451f 100644 --- a/client/ctclient/cmd/upload.go +++ b/client/ctclient/cmd/upload.go @@ -33,6 +33,7 @@ func init() { Use: fmt.Sprintf("upload %s --cert_chain=file [--log_mmd=dur]", connectionFlags), Aliases: []string{"add-chain"}, Short: "Submit a certificate (pre-)chain to the log", + Args: cobra.MaximumNArgs(0), Run: func(cmd *cobra.Command, _ []string) { runUpload(cmd.Context()) },