Skip to content

Update command-line interface for .netrc file handling #3763

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 9 commits into from
Sep 30, 2021

Conversation

mattt
Copy link
Contributor

@mattt mattt commented Sep 24, 2021

This PR updates how .netrc file handling behavior is configured in swift-package command and its subcommands.

Motivation:

When resolving dependencies through a registry (SE-0292), users will often need to authenticate with the configured server. Because .netrc files are the prescribed way to store and manage credentials, it makes sense for them to be read by default, rather than being opt-in behavior.

Modifications:

  • Default / invert --netrc to true, such that users instead opt-out with --no-netrc
  • Deprecate and hide the --netrc-optional flag, such that passing it is a no-op
  • Add help messages for the --netrc flag and --netrc-file-path option

Result:

Before:

$ swift package
[...]
OPTIONS:
[...]
 --netrc
  --netrc-optional
  --netrc-file <netrc-file>

After:

$ swift package
[...]
OPTIONS:
[...]
  --netrc/--no-netrc      Load credentials from a .netrc file (default: true)
  --netrc-file <netrc-file>
                          Specify the .netrc file path. 

@mattt
Copy link
Contributor Author

mattt commented Sep 24, 2021

@swift-ci Please smoke test

@neonichu
Copy link
Contributor

Isn't netrc optional the behavior we want? I don't think we should force every user to having to provide a netrc file.

@tomerd
Copy link
Contributor

tomerd commented Sep 28, 2021

i think the semantics we want is:

  1. if the user has a netrc file, we use it, unless they opt out with --disable-netrc (or similar flag)
  2. if there is no netrc file, we dont fail, just continue to operate without auth.
  3. in situations which require auth (don't think we have any yet), if no auth provider exists (netrc or otherwise), we emit a domain specific error at the call site

@neonichu @abertelrud @mattt does that match tour expectations?

Don't emit error if .netrc file isn't found in default location
@mattt
Copy link
Contributor Author

mattt commented Sep 28, 2021

@neonichu @tomerd Yes, that's what I was going for, but e824ef7 had the incorrect logic. 😓 The version in 85fa08a should be correct:

https://github.com/apple/swift-package-manager/blob/85fa08a36f214f51d9d5f915b0e322d3fb2806d0/Sources/Commands/SwiftTool.swift#L491-L502

To your third point: Yes — authentication errors should be emitted by the HTTP client responsible for downloading the binary artifact / source archive. Swift Package Manager can't know if credentials are needed or the provided ones are invalid until they connect to the remote server.

@mattt

This comment has been minimized.

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.

couple of questions but semantics seems right me. @neonichu @abertelrud wdyt?

@mattt
Copy link
Contributor Author

mattt commented Sep 29, 2021

@swift-ci Please smoke test

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.

lgtm

Remove deprecation annotation for netrcOptional property
Emit warnings when specifying deprecated --netrc and --netrc-optional flags

Update command tests for new netrc options

Fix tests to assert throwing errors
@mattt
Copy link
Contributor Author

mattt commented Sep 30, 2021

@tomerd Following up on your thread with @natecook1000, I found a reasonable solution with the following properties:

  • --enable-netrc and --disable-netrc flags with mutual exclusivity
  • --netrc-file-path that emits an error when the path doesn't exist, and is mutually exclusive with --disable-netrc
  • Hidden --netrc and --netrc-optional flags that emit warnings when specified

So the new command-line interface is:

USAGE: swift package <options> <subcommand>

OPTIONS:
...
  --enable-netrc/--disable-netrc
                          Load credentials from a .netrc file (default: true)
  --netrc-file <netrc-file>
                          Specify the .netrc file path. 

I also found a bug in the existing unit tests, where do / catch blocks were used instead of XCTAssertThrows, which don't fail when an expected error isn't thrown. Maybe something to audit across our test suite at some point.

@mattt
Copy link
Contributor Author

mattt commented Sep 30, 2021

@swift-ci Please smoke test

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.

this is great

@tomerd tomerd merged commit 8a5c51d into swiftlang:main Sep 30, 2021
@mattt mattt deleted the deprecate-netrc-flag branch September 30, 2021 17:10
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.

4 participants