Subject: Re: [PATCH] Add contrib/credentials/netrc with GPG support, try #2

From: Ted Zlatanov <[email-masked]>
Date: Mon, 04 Feb 2013 18:42:05 -0500

On Mon, 4 Feb 2013 18:23:17 -0500 Jeff King <[email-masked]> wrote: 

>> Perhaps "-r $file", if you say "is not accessible"?

JK> Even better: look at whether opening the file was successful. Though I
JK> guess that is complicated by the use of gpg, who will probably not
JK> distinguish ENOENT from other failures for us.

Yup.  I think the outcome for the user will be the same, so this is
mostly for debugging, right?  And we do look at the outcome of opening
the file, and die if that failed (which would change if your suggestion
below is implemented).

JK> I was trying not to be too nit-picky with my review, but here is how I
JK> would have written the outer logic of the script:

JK>   my $tokens = read_credential_data_from_stdin();
JK>   if ($options{file}) {
JK>           my @entries = load_netrc($options{file})
JK>                   or die "unable to open $options{file}: $!";
JK>           check_netrc($tokens, @entries);
JK>   }
JK>   else {
JK>           foreach my $ext ('.gpg', '') {
JK>                   foreach my $base (qw(authinfo netrc)) {
JK>                           my @entries = load_netrc("$base$ext")
JK>                                   or next;
JK>                           if (check_netrc($tokens, @entries)) {
JK>                                   last;
JK>                           }
JK>                   }
JK>           }
JK>   }

JK> I.e., to fail on "-f", but otherwise treat unreadable auto-selected
JK> files as a no-op, for whatever reason.

JK> I'd also consider checking all files if they are available, in case
JK> the user has multiple (e.g., they keep low-quality junk unencrypted
JK> but some high-security passwords in a .gpg file). Not that likely,
JK> but not any harder to implement.

I think that makes everything more complicated, and the user can name a
specific netrc file in the helper spec if he wants it.  It's too
automagic for me.  But if you and Junio feel this is the right approach,
I'll rewrite to basically allow --file to take a list of filenames and
default that list to the base list of ~/.{authinfo,netrc}{,.gpg}

Ted