-
Notifications
You must be signed in to change notification settings - Fork 178
cmd/scion-pki: improve CLI UX #4803
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| // ReadFileOrStdin reads the content of a file or stdin if the path is "-". | ||
| // It returns the content as a byte slice. | ||
| func ReadFileOrStdin(path string) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open for suggestions if there is a more suitable place to put this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's fine to keep it here.
Maybe worth adding:
// ReadFileOrStdin reads the content of a file or stdin if the path is "-".
// It returns the content as a byte slice.
// Follows UNIX utility syntax guidelines.
// See https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02c732967 to
4c0fc53
Compare
4c0fc53 to
16761f5
Compare
| types[typ] = true | ||
| } | ||
|
|
||
| ias := make(map[addr.IA]bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ias := make(map[addr.IA]bool) | |
| ias := make(map[addr.IA]bool, len(flags.ias)) |
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := runExtractCertificates(args[0], flags.out); err != nil { | ||
| types := make(map[cppki.CertType]bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sets can be used for types and ias (like map[cppki.CertType]struct{}) to reduce the ambiguity a bit.
The checks can then just be like:
if len(ias) > 0 && !ias[ia] {
continue
}| if err != nil { | ||
| return fmt.Errorf("invalid certificate %s: %w", cert.Subject.CommonName, err) | ||
| } | ||
| if len(types) > 0 && !types[typ] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if types contains typ then len(types) cannot be 0, right? Hence len(types) > 0 looks pointless to me, am I missing something?
romshark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some nitpicks.
I fixed the linter errors. I hope you don't mind the line breaking style.
ee983d1 to
c310456
Compare
The `scion-pki` CLI commands now support reading from stdin when the file path is set to `-`, where appropriate. This allows the user to pipe data directly into the command without the need to create temporary files. Furthermore, the `scion-pki trc extract certificates` command has two additional filtering options: `--type` and `--subject.isd-as`, allowing the user to filter the extracted certificates.
c310456 to
a469044
Compare
The
scion-pkiCLI commands now support reading from stdin when the file path is set to-, where appropriate. This allows the user to pipe data directly into the command without the need to create temporary files.Furthermore, the
scion-pki trc extract certificatescommand has two additional filtering options:--typeand--subject.isd-as, allowing the user to filter the extracted certificates.