import etcd class etcdWrapper(object): """ Generalises some etcd actions """ def __init__(self, client, base): self.client = client self.base = base def read_key_or_none(self, path, recursive=False): try: data = self.client.read(path, recursive=recursive) except etcd.EtcdKeyNotFound: return None except Exception: abort(Response(status=400, response="Error connecting to etcd")) return data def get_user_key_or_none(self, user, key): path = "{}/user/{}/{}".format(self.base, user, key) return self.read_key_or_none(path) def set_user_key(self, user, key, value): path = "{}/user/{}/{}".format(self.base, user, key) self.client.write(path, value)