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

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