Skip to content

Add swift package-registry command #3647

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 16 commits into from
Aug 31, 2021

Conversation

mattt
Copy link
Contributor

@mattt mattt commented Aug 4, 2021

This PR implements the swift package-registry command with its set and unset subcommands as described in "Registry configuration subcommands"

Motivation:

Implement SE-0292.

Modifications:

  • Add PackageRegistry library and test target containing
  • Create a RegistryConfiguration type in the PackageRegistry module
  • Create a new swift-package-registry executable target
  • Implement .netrc support (see Add swift package-registry command #3647 (comment))

Result:

With this change, Swift Package Manager will be able to read and write registry configuration files.

@mattt mattt requested review from tomerd and yim-lee August 4, 2021 18:22
@mattt
Copy link
Contributor Author

mattt commented Aug 4, 2021

@tomerd @yim-lee I spun this off from #3640 in the interest of taking incremental steps towards SE-0292 implementation. Let's focus on this chunk first, before moving onto the actual dependency resolution logic.

@tomerd tomerd self-assigned this Aug 4, 2021
@mattt
Copy link
Contributor Author

mattt commented Aug 5, 2021

@tomerd I started to implement .netrc support, but realized that this would require a lot more work. From SE-0292:

Specifying credentials for a custom registry

Some servers may require a username and password.
The user can provide credentials when setting a custom registry by passing the --login and --password options.

When credentials are provided, the corresponding object in the registries.json file includes a login key with the passed value. If the project's .netrc file has an existing entry for a given machine and login, it's updated with the new password; otherwise, a new entry is added. If no .netrc file exists, a new one is created and populated with the new entry.

Right now, the Netrc struct in swift-tools-support-core supports read-only access, but the feature described here requires updating the file with new entries. Adding new entries should be easy enough — just append it to the end of the file. However, updating existing entries is more difficult to get right.

How do you think we should proceed? I can think of a few possibilities:

  1. Defer: We temporarily remove the --login and --password options for the swift package-registry set command, and require users to manage credentials themselves. (This is what we have with the latest commit for this PR, ffebeb6)
  2. Append-only: We do the 80% solution and update .netrc files by adding a new machine only if it doesn't already exist. If there's already an entry for a machine, we bail and emit a warning. (If we do this, we should probably amend the proposal to describe this new behavior).
  3. Full authoring support: We go all the way and make a compliant .netrc file manager.

I suspect we don't really want to get in the business of .netrc file authoring, so option 3 is probably a no-go. I don't feel too strongly between 1 and 2. If you'd like, we can even do both — accept what we have now and punt on the 80% solution for later.

What do you think?

@mattt mattt marked this pull request as ready for review August 5, 2021 17:10
@mattt

This comment has been minimized.

@mattt

This comment has been minimized.

// MARK: -

private extension Decodable {
static func readFromJSONFile(in fileSystem: FileSystem, at path: AbsolutePath) throws -> Self {
Copy link
Contributor

@tomerd tomerd Aug 6, 2021

Choose a reason for hiding this comment

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

we typically prefer to put the visibility modifier on the method and not the extension, i.e.

extension Decodable {
     private static func readFromJSON ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally like ACL on private and fileprivate extensions, as it prevents helper APIs from leaking out to internal. But I'm happy to make this change if you feel strongly about it.

The only hitch is that the current .swiftformat configuration falls back to the default extensionAccessControl rule behavior of putting ACL on extensions rather than declarations. If we're still using this tool, should we update that to match project conventions?


import Commands

SwiftPackageRegistryTool.main()
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably transition to @main at this point.

@abertelrud @neonichu wdyt about a PR to move SwiftPM to tools version 5.5 and make use of some of the new capabilities?

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

looking great. added a couple of ideas about the configuration, happy to help with doing that in a separate PR if it helps.

@tomerd
Copy link
Contributor

tomerd commented Aug 6, 2021

Right now, the Netrc struct in swift-tools-support-core supports read-only access, but the feature described here requires updating the file with new entries. Adding new entries should be easy enough — just append it to the end of the file. However, updating existing entries is more difficult to get right.

How do you think we should proceed? I can think of a few possibilities:

  1. Defer: We temporarily remove the --login and --password options for the swift package-registry set command, and require users to manage credentials themselves. (This is what we have with the latest commit for this PR, ffebeb6)
  2. Append-only: We do the 80% solution and update .netrc files by adding a new machine only if it doesn't already exist. If there's already an entry for a machine, we bail and emit a warning. (If we do this, we should probably amend the proposal to describe this new behavior).
  3. Full authoring support: We go all the way and make a compliant .netrc file manager.
    I suspect we don't really want to get in the business of .netrc file authoring, so option 3 is probably a no-go. I don't feel too strongly between 1 and 2. If you'd like, we can even do both — accept what we have now and punt on the 80% solution for later.

What do you think?

I agree and think option 2 is sufficient at this point

@mattt
Copy link
Contributor Author

mattt commented Aug 9, 2021

@swift-ci Please smoke test

@mattt
Copy link
Contributor Author

mattt commented Aug 9, 2021

@tomerd Aside from the unresolved feedback threads and .netrc, is there anything else you'd like to see for this PR?

Re: .netrc handling — Could we implement this in a follow-up PR? There are a lot of moving pieces between #3640 and #3652 that impact how this would be implemented. Specifically, these two chunks:

https://github.com/apple/swift-package-manager/pull/3640/files#diff-134223fe78a1e46f08f8c1e9d166408b7105f941cb2cc4e844ebceb87a8f4ec8R1850

https://github.com/apple/swift-package-manager/pull/3652/files#diff-8d396837a0426c26967e471b82d8f2eaf31f9a7ae2e03308300799edbac4bd18L563

@tomerd tomerd added the WIP Work in progress label Aug 19, 2021
@mattt mattt force-pushed the package-registry-command branch from 05481e2 to d76923f Compare August 24, 2021 13:44
@mattt
Copy link
Contributor Author

mattt commented Aug 24, 2021

@swift-ci Please smoke test

@mattt
Copy link
Contributor Author

mattt commented Aug 24, 2021

@tomerd I just rebased my original PR to follow the pattern you introduced in #3670. Please take a look and let me know if you have any concerns with that approach.

Aside from the unresolved feedback threads and .netrc, is there anything else you'd like to see for this PR?

@mattt mattt requested a review from tomerd August 24, 2021 13:47
@mattt mattt added ready Author believes the PR is ready to be merged & any feedback has been addressed and removed WIP Work in progress labels Aug 25, 2021
Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

looks good. some leftovers that can be removed, I suspect, but looking great otherwise.

@mattt mattt force-pushed the package-registry-command branch from c7820d9 to 6aa9be2 Compare August 30, 2021 12:07
@mattt
Copy link
Contributor Author

mattt commented Aug 30, 2021

@swift-ci Please smoke test

@tomerd
Copy link
Contributor

tomerd commented Aug 30, 2021

@mattt @elsh will fix the API digester issue on linux and then we will merge this. does that work / is it ready?

@tomerd
Copy link
Contributor

tomerd commented Aug 31, 2021

@swift-ci smoke test

@mattt
Copy link
Contributor Author

mattt commented Aug 31, 2021

@tomerd Sounds good. Yes, this is all ready to be merged once CI is passing.

@tomerd tomerd merged commit 3ba72d1 into swiftlang:main Aug 31, 2021
@mattt mattt deleted the package-registry-command branch August 31, 2021 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants