parsing encrypted netrc file
On 2020-06-23 01:47, Seb wrote:
> On Tue, 23 Jun 2020 00:40:28 +0100,
> MRAB <python at mrabarnett.plus.com> wrote:
>> On 2020-06-22 23:38, Seb wrote:
>>> What's the pythonic way to do this without polluting the user's
>>> directory with the decrypted file? I wrongly thought this should do
>>> import os.path as osp import gnupg import netrc import tempfile
>>> gpg = gnupg.GPG()
>>> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: with
>>> tempfile.NamedTemporaryFile("w+") as tf: status = gpg.decrypt_file(f,
>>> output=tf.name) info = netrc.netrc(tf.name)
>>> which fails as the temporary file doesn't even get created.
>> Are you sure it doesn't get created?
> Without using tempfile:
> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f:
> status = gpg.decrypt_file(f, output=".authinfo.txt")
> info = netrc.netrc(".authinfo.txt")
> I get the error:
> NetrcParseError: bad follower token 'port' (.authinfo.txt, line 1)
> which is interesting. The structure of ~/.authinfo.gpg is:
> machine my.server.com login user at foo.com password mypasswd port 587
> so it seems this is not what netrc.netrc expects.
Here's a page I found about ".netrc":
and here's a page I found about ".authinfo.gpg":
Can you see the subtle difference?