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

ctclient: Use Cobra library for command-line tools #901

Merged
merged 16 commits into from
Apr 25, 2022
Merged

ctclient: Use Cobra library for command-line tools #901

merged 16 commits into from
Apr 25, 2022

Conversation

pav-kv
Copy link
Contributor

@pav-kv pav-kv commented Apr 7, 2022

This change refactors the ctclient tool to use the widely adopted Cobra library
for handling CLI flags and subcommands.

Before:

$ ./ctclient -h
Usage of ./ctclient:
  -align_getentries
        Enable get-entries request alignment (default true)
  -alsologtostderr
        log to standard error as well as files
  -cert_chain string
        Name of file containing certificate chain as concatenated PEM files
  -chain
        Display entire certificate chain
  -first int
        First entry to get (default -1)
  -last int
        Last entry to get (default -1)
  -leaf_hash string
        Leaf hash to retrieve (as hex string or base64)
  -log_backtrace_at value
        when logging hits line file:N, emit a stack trace
  -log_dir string
        If non-empty, write log files in this directory
  -log_list string
        Location of master log list (URL or filename) (default "https://www.gstatic.com/ct/log_list/all_logs_list.json")
  -log_mmd duration
        Log's maximum merge delay (default 24h0m0s)
  -log_name string
        Name of log to retrieve information from --log_list for
  -log_uri string
        CT log base URI (default "https://ct.googleapis.com/rocketeer")
  -logtostderr
        log to standard error instead of files
  -prev_hash string
        Previous tree hash to check against (as hex string or base64)
  -prev_size uint
        Previous tree size to get consistency against
  -pub_key string
        Name of file containing log's public key
  -size uint
        Tree size to query at
  -skip_https_verify
        Skip verification of HTTPS transport connection
  -stderrthreshold value
        logs at or above this threshold go to stderr
  -text
        Display certificates as text (default true)
  -timestamp int
        Timestamp to use for inclusion checking
  -tree_hash string
        Tree hash to check against (as hex string or base64)
  -v value
        log level for V logs
  -vmodule value
        comma-separated list of pattern=N settings for file-filtered logging

After:

$ ./ctclient --help
A command line client for Certificate Transparency logs

Usage:
  ctclient [command]

Available Commands:
  bisect                Find a log entry by timestamp
  completion            Generate the autocompletion script for the specified shell
  get-consistency-proof Fetch and verify a consistency proof between two tree states
  get-entries           Fetch a range of entries in the log
  get-inclusion-proof   Fetch and verify the inclusion proof for an entry
  get-roots             Fetch the root certificates accepted by the log
  get-sth               Fetch the latest STH of the log
  help                  Help about any command
  upload                Submit a certificate (pre-)chain to the log

Flags:
...
Use "ctclient [command] --help" for more information about a command.
$ ./ctclient getentries --help
Fetch a range of entries in the log

Usage:
  ctclient get-entries {--log_uri uri | --log_name name [--log_list {file|uri}]} [--pub_key file] --first=idx [--last=idx] [flags]

Aliases:
  get-entries, getentries, entries

Flags:
      --chain       Display entire certificate chain
      --first int   First entry to get (default -1)
  -h, --help        help for get-entries
      --last int    Last entry to get (default -1)
      --text        Display certificates as text (default true)

Global Flags:
      --alsologtostderr                  log to standard error as well as files
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory
      --log_list string                  Location of master log list (URL or filename) (default "https://www.gstatic.com/ct/log_list/all_logs_list.json")
      --log_name string                  Name of log to retrieve information from --log_list for
      --log_uri string                   CT log base URI (default "https://ct.googleapis.com/rocketeer")
      --logtostderr                      log to standard error instead of files
      --pub_key string                   Name of file containing log's public key
      --skip_https_verify                Skip verification of HTTPS transport connection
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filter

Part of #900

Checklist

@pav-kv
Copy link
Contributor Author

pav-kv commented Apr 7, 2022

I recommend reviewing commit-by-commit. For now this is a structural change, with no behaviour changes (except the look of help hints).

Next steps will be refactoring each command, and improving usability.

Copy link
Member

@AlCutter AlCutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits - LVGTM in the grand scheme of things, thanks for doing this!

client/ctclient/cmd/ctclient.go Outdated Show resolved Hide resolved
client/ctclient/cmd/ctclient.go Outdated Show resolved Hide resolved
@pav-kv
Copy link
Contributor Author

pav-kv commented Apr 7, 2022

TODO in this PR:

  • A few typos.
  • glog flags.

@pav-kv
Copy link
Contributor Author

pav-kv commented Apr 14, 2022

Ping

1 similar comment
@pav-kv
Copy link
Contributor Author

pav-kv commented Apr 25, 2022

Ping

@pav-kv pav-kv merged commit 5fcf774 into google:master Apr 25, 2022
@pav-kv pav-kv deleted the ctclient_use_cobra branch April 25, 2022 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants