Add locks around password fetching

This commit is contained in:
Markus Unterwaditzer 2015-10-03 19:27:01 +02:00
parent f43ef436b7
commit d5254081f8
2 changed files with 17 additions and 1 deletions

View file

@ -4,7 +4,7 @@ import click
from . import AppContext
from .. import exceptions, log
from ..utils import expand_path
from ..utils import expand_path, synchronized
SUFFIX = '.fetch'
@ -31,6 +31,7 @@ def expand_fetch_params(config):
return config
@synchronized()
def _fetch_value(opts, key):
if not isinstance(opts, list):
raise ValueError('Invalid value for {}: Expected a list, found {!r}.'

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import functools
import os
import sys
import uuid
@ -178,3 +179,17 @@ def generate_href(ident=None, safe=SAFE_UID_CHARS):
return to_unicode(uuid.uuid4().hex)
else:
return ident
def synchronized(lock=None):
if lock is None:
from threading import Lock
lock = Lock()
def inner(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
with lock:
return f(*args, **kwargs)
return wrapper
return inner