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

fix port issues for CONTAINER_HOST #16526

Merged
merged 1 commit into from
Nov 17, 2022

Conversation

cdoern
Copy link
Contributor

@cdoern cdoern commented Nov 15, 2022

if no port is specified for an ssh style url, default to 22

resolves #16509

Signed-off-by: Charlie Doern [email protected]

Does this PR introduce a user-facing change?

fix port validation for CONTAINER_HOST

port, err := strconv.Atoi(_url.Port())
if err != nil {
return nil, err
port := 22
Copy link
Member

Choose a reason for hiding this comment

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

You could read /etc/services for this, but I think this is fine.
LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hesitant since there are a bunch of different ssh related lines in there it seems but I can do this if we want

return nil, err
port := 22
if _url.Port() != "" {
port, err = strconv.Atoi(_url.Port())
Copy link
Member

Choose a reason for hiding this comment

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

you could just do port, _ =

Copy link
Contributor Author

@cdoern cdoern Nov 15, 2022

Choose a reason for hiding this comment

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

sure, but I will leave the if since atoi returns 0 on failure

@baude
Copy link
Member

baude commented Nov 15, 2022

one NIT ... else LGTM

@rhatdan
Copy link
Member

rhatdan commented Nov 15, 2022

/approve
/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 15, 2022
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 15, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 15, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cdoern, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 15, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 15, 2022
return nil, err
port := 22
if _url.Port() != "" {
port, _ = strconv.Atoi(_url.Port())
Copy link
Member

Choose a reason for hiding this comment

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

Why is the error ignored? This will set the port to 0 on errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I will add the error check back in

Comment on lines 285 to 286
cmd = exec.Command("export", "CONTAINER_HOST", fmt.Sprintf("ssh://%s@localhost", u.Username))
_, err = Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Copy link
Member

Choose a reason for hiding this comment

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

export and unset are not commands, they are shell built-ins.
you need os.Setenv(0 and os .Unsetenv().
But I don't see how this tests anything "--connection", "QA" should overwrite the env var, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes, I knew I was doing that part wrong! As for the --connection, not sure if this makes a difference as I think the env var has priority but just in case I will try without it

_, err = Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

err = os.Unsetenv("CONTAINER_HOST")
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be defer os.Unsetenv("CONTAINER_HOST") right after the setenv call, otherwise you will leak the env on test errors.

if no port is specified for an ssh style url, default to 22

resolves containers#16509

Signed-off-by: Charlie Doern <[email protected]>
@Luap99
Copy link
Member

Luap99 commented Nov 16, 2022

/lgtm
/hold

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 16, 2022
@Luap99
Copy link
Member

Luap99 commented Nov 17, 2022

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 17, 2022
@openshift-merge-robot openshift-merge-robot merged commit 44a9014 into containers:main Nov 17, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman remote error: strconv.Atoi: parsing "": invalid syntax
5 participants