git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

parsing encrypted netrc file


On 2020-06-22 23:38, Seb wrote:
> Hello,
> 
> What's the pythonic way to do this without polluting the user's
> directory with the decrypted file?  I wrongly thought this should do it:
> 
> 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?

I'm wondering whether you need to flush the file before passing it to 
netrc to ensure that all of the decrypted data is there on disk for reader.

I'm also wondering whether the file is shareable.