Blame SOURCES/0003-Remove-etcd-store.patch

66fe91
From c2a8008af30d045227058e3158e84c9415647760 Mon Sep 17 00:00:00 2001
66fe91
From: Christian Heimes <cheimes@redhat.com>
66fe91
Date: Fri, 31 Mar 2017 12:14:43 +0200
66fe91
Subject: [PATCH 3/4] Remove etcd store
66fe91
66fe91
---
66fe91
 custodia/store/etcdstore.py    | 123 -----------------------------------------
66fe91
 docs/source/plugins/stores.rst |   6 --
66fe91
 setup.py                       |   9 +--
66fe91
 3 files changed, 2 insertions(+), 136 deletions(-)
66fe91
 delete mode 100644 custodia/store/etcdstore.py
66fe91
66fe91
diff --git a/custodia/store/etcdstore.py b/custodia/store/etcdstore.py
66fe91
deleted file mode 100644
66fe91
index 759348b..0000000
66fe91
--- a/custodia/store/etcdstore.py
66fe91
+++ /dev/null
66fe91
@@ -1,123 +0,0 @@
66fe91
-# Copyright (C) 2015  Custodia Project Contributors - see LICENSE file
66fe91
-
66fe91
-from __future__ import print_function
66fe91
-
66fe91
-try:
66fe91
-    from etcd import (Client, EtcdException, EtcdNotFile, EtcdAlreadyExist,
66fe91
-                      EtcdKeyNotFound)
66fe91
-except ImportError:
66fe91
-    def Client(*args, **kwargs):
66fe91
-        raise RuntimeError("Etcd client is unavailable")
66fe91
-
66fe91
-    class EtcdException(Exception):
66fe91
-        pass
66fe91
-
66fe91
-    class EtcdNotFile(Exception):
66fe91
-        pass
66fe91
-
66fe91
-    class EtcdKeyNotFound(Exception):
66fe91
-        pass
66fe91
-
66fe91
-    class EtcdAlreadyExist(Exception):
66fe91
-        pass
66fe91
-
66fe91
-from custodia.plugin import CSStore, CSStoreError, CSStoreExists
66fe91
-from custodia.plugin import PluginOption
66fe91
-
66fe91
-
66fe91
-class EtcdStore(CSStore):
66fe91
-    etcd_server = PluginOption(str, '127.0.0.1', None)
66fe91
-    etcd_port = PluginOption(int, '4001', None)
66fe91
-    namespace = PluginOption(str, '/custodia', None)
66fe91
-
66fe91
-    def __init__(self, config, section):
66fe91
-        super(EtcdStore, self).__init__(config, section)
66fe91
-        # Initialize the DB by trying to create the default table
66fe91
-        try:
66fe91
-            self.etcd = Client(self.etcd_server, self.etcd_port)
66fe91
-            self.etcd.write(self.namespace, None, dir=True)
66fe91
-        except EtcdNotFile:
66fe91
-            # Already exists
66fe91
-            pass
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error creating namespace %s",
66fe91
-                                  self.namespace)
66fe91
-            raise CSStoreError('Error occurred while trying to init db')
66fe91
-
66fe91
-    def _absolute_key(self, key):
66fe91
-        """Get absolute path to key and validate key"""
66fe91
-        if '//' in key:
66fe91
-            raise ValueError("Invalid empty components in key '%s'" % key)
66fe91
-        parts = key.split('/')
66fe91
-        if set(parts).intersection({'.', '..'}):
66fe91
-            raise ValueError("Invalid relative components in key '%s'" % key)
66fe91
-        return '/'.join([self.namespace] + parts).replace('//', '/')
66fe91
-
66fe91
-    def get(self, key):
66fe91
-        self.logger.debug("Fetching key %s", key)
66fe91
-        try:
66fe91
-            result = self.etcd.get(self._absolute_key(key))
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error fetching key %s", key)
66fe91
-            raise CSStoreError('Error occurred while trying to get key')
66fe91
-        self.logger.debug("Fetched key %s got result: %r", key, result)
66fe91
-        return result.value  # pylint: disable=no-member
66fe91
-
66fe91
-    def set(self, key, value, replace=False):
66fe91
-        self.logger.debug("Setting key %s to value %s (replace=%s)",
66fe91
-                          key, value, replace)
66fe91
-        path = self._absolute_key(key)
66fe91
-        try:
66fe91
-            self.etcd.write(path, value, prevExist=replace)
66fe91
-        except EtcdAlreadyExist as err:
66fe91
-            raise CSStoreExists(str(err))
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error storing key %s", key)
66fe91
-            raise CSStoreError('Error occurred while trying to store key')
66fe91
-
66fe91
-    def span(self, key):
66fe91
-        path = self._absolute_key(key)
66fe91
-        self.logger.debug("Creating directory %s", path)
66fe91
-        try:
66fe91
-            self.etcd.write(path, None, dir=True, prevExist=False)
66fe91
-        except EtcdAlreadyExist as err:
66fe91
-            raise CSStoreExists(str(err))
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error storing key %s", key)
66fe91
-            raise CSStoreError('Error occurred while trying to store key')
66fe91
-
66fe91
-    def list(self, keyfilter='/'):
66fe91
-        path = self._absolute_key(keyfilter)
66fe91
-        if path != '/':
66fe91
-            path = path.rstrip('/')
66fe91
-        self.logger.debug("Listing keys matching %s", path)
66fe91
-        try:
66fe91
-            result = self.etcd.read(path, recursive=True)
66fe91
-        except EtcdKeyNotFound:
66fe91
-            return None
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error listing %s", keyfilter)
66fe91
-            raise CSStoreError('Error occurred while trying to list keys')
66fe91
-        self.logger.debug("Searched for %s got result: %r", path, result)
66fe91
-        value = set()
66fe91
-        for entry in result.get_subtree():
66fe91
-            if entry.key == path:
66fe91
-                continue
66fe91
-            name = entry.key[len(path):]
66fe91
-            if entry.dir and not name.endswith('/'):
66fe91
-                name += '/'
66fe91
-            value.add(name.lstrip('/'))
66fe91
-        return sorted(value)
66fe91
-
66fe91
-    def cut(self, key):
66fe91
-        self.logger.debug("Removing key %s", key)
66fe91
-        try:
66fe91
-            self.etcd.delete(self._absolute_key(key))
66fe91
-        except EtcdKeyNotFound:
66fe91
-            self.logger.debug("Key %s not found", key)
66fe91
-            return False
66fe91
-        except EtcdException:
66fe91
-            self.logger.exception("Error removing key %s", key)
66fe91
-            raise CSStoreError('Error occurred while trying to cut key')
66fe91
-        self.logger.debug("Key %s removed", key)
66fe91
-        return True
66fe91
diff --git a/docs/source/plugins/stores.rst b/docs/source/plugins/stores.rst
66fe91
index ed921ba..d715f31 100644
66fe91
--- a/docs/source/plugins/stores.rst
66fe91
+++ b/docs/source/plugins/stores.rst
66fe91
@@ -5,7 +5,6 @@ Stores
66fe91
    :nosignatures:
66fe91
 
66fe91
    custodia.store.sqlite.SqliteStore
66fe91
-   custodia.store.etcdstore.EtcdStore
66fe91
    custodia.store.encgen.EncryptedOverlay
66fe91
 
66fe91
 .. autoclass:: custodia.store.sqlite.SqliteStore
66fe91
@@ -13,11 +12,6 @@ Stores
66fe91
     :undoc-members:
66fe91
     :show-inheritance:
66fe91
 
66fe91
-.. autoclass:: custodia.store.etcdstore.EtcdStore
66fe91
-    :members:
66fe91
-    :undoc-members:
66fe91
-    :show-inheritance:
66fe91
-
66fe91
 .. autoclass:: custodia.store.encgen.EncryptedOverlay
66fe91
     :members:
66fe91
     :undoc-members:
66fe91
diff --git a/setup.py b/setup.py
66fe91
index a7c398a..c8f270d 100755
66fe91
--- a/setup.py
66fe91
+++ b/setup.py
66fe91
@@ -15,16 +15,12 @@ requirements = [
66fe91
     'requests'
66fe91
 ]
66fe91
 
66fe91
-# extra requirements
66fe91
-etcd_requires = ['python-etcd']
66fe91
-
66fe91
 # test requirements
66fe91
-test_requires = ['coverage', 'pytest'] + etcd_requires
66fe91
+test_requires = ['coverage', 'pytest']
66fe91
 
66fe91
 extras_require = {
66fe91
-    'etcd_store': etcd_requires,
66fe91
     'test': test_requires,
66fe91
-    'test_docs': ['docutils', 'markdown'] + etcd_requires,
66fe91
+    'test_docs': ['docutils', 'markdown'],
66fe91
     'test_pep8': ['flake8', 'flake8-import-order', 'pep8-naming'],
66fe91
     'test_pylint': ['pylint'] + test_requires,
66fe91
 }
66fe91
@@ -70,7 +66,6 @@ custodia_consumers = [
66fe91
 custodia_stores = [
66fe91
     'EncryptedOverlay = custodia.store.encgen:EncryptedOverlay',
66fe91
     'EncryptedStore = custodia.store.enclite:EncryptedStore',
66fe91
-    'EtcdStore = custodia.store.etcdstore:EtcdStore',
66fe91
     'SqliteStore = custodia.store.sqlite:SqliteStore',
66fe91
 ]
66fe91
 
66fe91
-- 
66fe91
2.9.3
66fe91