Skip to content

Add other url formats for certificate inspect - #653

Merged
areed merged 6 commits into
smallstep:masterfrom
1984gobrr:add-other-url-formats
Mar 29, 2022
Merged

areed merged 6 commits into
smallstep:masterfrom
1984gobrr:add-other-url-formats

Conversation

@1984gobrr

Copy link
Copy Markdown
Contributor

Add other url formats with default port has requested in #459

@github-actions github-actions Bot added the needs triage Waiting for discussion / prioritization by team label Mar 21, 2022
Comment thread command/certificate/remote.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you tested the behavior with unpassed port number? Does it reliably error put? If not, we should error check this one, or set the defaults of those to 443.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By default unpassed port are set to 443

addr = net.JoinHostPort(addr, "443")

I just set the default to 443 in the map, it make more sense.

Comment thread command/certificate/remote.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also add some relevant documentations about the additions, including in the ussage part.

@1984gobrr
1984gobrr force-pushed the add-other-url-formats branch from 8f96da6 to 76ee643 Compare March 22, 2022 20:47
@1984gobrr
1984gobrr force-pushed the add-other-url-formats branch 2 times, most recently from c7eeb29 to 569e87a Compare March 22, 2022 21:35
@maraino
maraino requested a review from areed March 23, 2022 17:12

@areed areed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test cases in remote_test.go also need to be updated

Comment thread command/certificate/remote.go Outdated
}
if _, _, err := net.SplitHostPort(u.Host); err != nil {
port := uint64(urlPrefixes[prefix])
u.Host += ":" + strconv.FormatUint(port, 10)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you use net.JoinHostPort here to handle IPv6

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

46f908a

Comment thread command/certificate/remote.go Outdated
func trimURL(ref string) (string, bool, error) {
tmp := strings.ToLower(ref)
for _, prefix := range urlPrefixes {
for prefix, _ := range urlPrefixes {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
for prefix, _ := range urlPrefixes {
for prefix := range urlPrefixes {

This is what the linter is looking for

@LecrisUT LecrisUT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also more documentation is found in command/certificate/inspect

if err != nil {
return "", false, errors.Wrapf(err, "error parsing URL '%s'", ref)
}
if _, _, err := net.SplitHostPort(u.Host); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the sake of consistency, please use and return the err object, even if it would logically be handled by the previous one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand.

I think this error should not be returned, it is the same code as :

if _, _, err := net.SplitHostPort(addr); err != nil {
addr = net.JoinHostPort(addr, "443")
}

Please clarify what you want 😃

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean do a similar err return as the lines above

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks correct as is since the err is used to detect the case where there is no port provided.

@maraino
maraino requested a review from areed March 28, 2022 22:43
@areed
areed merged commit c0ddcde into smallstep:master Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs triage Waiting for discussion / prioritization by team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants