summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-08-18 08:56:38 +0200
committerMichał Górny <mgorny@gentoo.org>2020-08-18 08:57:19 +0200
commit9980de271de4f8f5e993e2b634d0e8d7753e382f (patch)
treeaad20e3de01d10340962bd7d42d015730e6b537e
parentd486f37657a7640891d92103475c57ba6a3dff1a (diff)
downloadgemato-9980de271de4f8f5e993e2b634d0e8d7753e382f.tar.gz
openpgp: Support overriding proxy in env
Closes: https://github.com/mgorny/gemato/issues/12 Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--gemato/cli.py5
-rw-r--r--gemato/openpgp.py11
2 files changed, 11 insertions, 5 deletions
diff --git a/gemato/cli.py b/gemato/cli.py
index 021057d..3b5786e 100644
--- a/gemato/cli.py
+++ b/gemato/cli.py
@@ -89,6 +89,8 @@ class BaseOpenPGPMixin(object):
subp.add_argument('-K', '--openpgp-key',
help='Use only the OpenPGP key(s) from a specific file')
+ subp.add_argument('--proxy',
+ help='Use HTTP proxy')
def parse_args(self, args, argp):
super(BaseOpenPGPMixin, self).parse_args(args, argp)
@@ -99,7 +101,8 @@ class BaseOpenPGPMixin(object):
env_class = gemato.openpgp.OpenPGPEnvironment
else:
env_class = gemato.openpgp.OpenPGPSystemEnvironment
- self.openpgp_env = env_class(debug=args.debug)
+ self.openpgp_env = env_class(debug=args.debug,
+ proxy=args.proxy)
if args.openpgp_key is not None:
with io.open(args.openpgp_key, 'rb') as f:
diff --git a/gemato/openpgp.py b/gemato/openpgp.py
index c854d1a..2efef8d 100644
--- a/gemato/openpgp.py
+++ b/gemato/openpgp.py
@@ -40,7 +40,7 @@ class OpenPGPSystemEnvironment(object):
__slots__ = ['debug']
- def __init__(self, debug=False):
+ def __init__(self, debug=False, proxy=None):
self.debug = debug
def __enter__(self):
@@ -183,10 +183,11 @@ class OpenPGPEnvironment(OpenPGPSystemEnvironment):
or use as a context manager (via 'with').
"""
- __slots__ = ['_home']
+ __slots__ = ['_home', 'proxy']
- def __init__(self, debug=False):
+ def __init__(self, debug=False, proxy=None):
super(OpenPGPEnvironment, self).__init__(debug=debug)
+ self.proxy = proxy
self._home = tempfile.mkdtemp(prefix='gemato.')
with open(os.path.join(self._home, 'dirmngr.conf'), 'w') as f:
@@ -221,7 +222,7 @@ debug-level guru
self.close()
def clone(self):
- return OpenPGPEnvironment(debug=self.debug)
+ return OpenPGPEnvironment(debug=self.debug, proxy=self.proxy)
@staticmethod
def _rmtree_error_handler(func, path, exc_info):
@@ -385,5 +386,7 @@ debug-level guru
def _spawn_gpg(self, options, stdin=''):
env_override = {'GNUPGHOME': self.home}
+ if self.proxy is not None:
+ env_override['http_proxy'] = self.proxy
return (super(OpenPGPEnvironment, self)
._spawn_gpg(options, stdin, env_override))