Skip to content

Preserve port when computing the login URL #6711

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

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

Palleas
Copy link
Contributor

@Palleas Palleas commented Jul 14, 2023

When using a registry URL that contains a port, ensure the port is preserved when computing the login URL.

Motivation:

Currently if you run the following

swift package-registry set https://packages.example.com:8081
swift package-registry login --token XYZ

You might get something like

Error: Unable to connect to server: https://packages.example.com

That's because the login url is built like this and ignores the port: URL(string: "https://\(host)\(loginAPIPath ?? "/login")")

Modifications:

  • Use URLComponents to build the login URL (which maintains the port)
  • Add a testing target for SwiftPackageRegistryTool

Result:

SPM can use registry URLs with ports.

I do have a question though, the registry authentication configuration dingus currently uses the host as the key:
https://github.com/apple/swift-package-manager/blob/main/Sources/PackageRegistryTool/PackageRegistryTool%2BAuth.swift#L234-L237

I suspect it's pretty unlikely that someone would use multiple registries available at the same host on different ports, but should I update that, as well?

@yim-lee
Copy link
Contributor

yim-lee commented Jul 14, 2023

@swift-ci please test

import XCTest
@testable import PackageRegistryTool

final class PackageRegistryToolTests: XCTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

These new tests can go into CommandsTests/PackageRegistryToolTests.swift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roger that, done!

@yim-lee
Copy link
Contributor

yim-lee commented Jul 14, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor

yim-lee commented Jul 14, 2023

I suspect it's pretty unlikely that someone would use multiple registries available at the same host on different ports, but should I update that, as well?

I agree that it's unlikely to have multiple registries on the same host.

If we were to support/fix this however, I don't know if using host:port instead of just host is good enough. What if instead of different ports, different paths (e.g., /staging-1, /staging-2) on the same host are used for multiple registries? Using (registry) URLs as keys could make things tricky in RegistryClient. But then I think distinguishing registries by paths is even less likely to happen than ports.

I think changing from host to host:port is pretty straight-forward--the :port portion should only be added if registryURL.port is non-nil, so I am open to us making that change. I don't think the change is a MUST though.

@Palleas
Copy link
Contributor Author

Palleas commented Jul 14, 2023

I think changing from host to host:port is pretty straight-forward--the :port portion should only be added if registryURL.port is non-nil, so I am open to us making that change. I don't think the change is a MUST though.

Done!

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows platform


}

func testCreateLoginURLMaintainsPort() {
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows platform

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please smoke test

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows platform

1 similar comment
@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows platform

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@swift-ci please test Windows platform

@yim-lee
Copy link
Contributor

yim-lee commented Jul 17, 2023

@Palleas This looks good to merge! Can you please create a PR for the release/5.9 branch also?

@Palleas
Copy link
Contributor Author

Palleas commented Jul 18, 2023

@Palleas This looks good to merge! Can you please create a PR for the release/5.9 branch also?

Here you go! #6715

@yim-lee
Copy link
Contributor

yim-lee commented Jul 18, 2023

@Palleas Thank you!

@yim-lee yim-lee merged commit d8e22aa into swiftlang:main Jul 18, 2023
@Palleas Palleas deleted the romain/keep-port branch July 18, 2023 03:25
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.

3 participants