diff --git a/ekko/storage/_compression/__init__.py b/ekko/storage/_compression_drivers/__init__.py similarity index 100% rename from ekko/storage/_compression/__init__.py rename to ekko/storage/_compression_drivers/__init__.py diff --git a/ekko/storage/_compression_drivers/lzma_.py b/ekko/storage/_compression_drivers/lzma_.py new file mode 100644 index 0000000..2f69f6e --- /dev/null +++ b/ekko/storage/_compression_drivers/lzma_.py @@ -0,0 +1,28 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import lzma + +from ekko.storage import compression_drivers + + +class LZMACompression(compression_drivers.BaseCompression): + + @staticmethod + def compress(data): + return lzma.compress(data) + + @staticmethod + def decompress(data): + return lzma.decompress(data) diff --git a/ekko/storage/_compression_drivers/noop.py b/ekko/storage/_compression_drivers/noop.py new file mode 100644 index 0000000..2df82c4 --- /dev/null +++ b/ekko/storage/_compression_drivers/noop.py @@ -0,0 +1,26 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ekko.storage import compression_drivers + + +class NoopCompression(compression_drivers.BaseCompression): + + @staticmethod + def compress(data): + return data + + @staticmethod + def decompress(data): + return data diff --git a/ekko/storage/_compression_drivers/zlib_.py b/ekko/storage/_compression_drivers/zlib_.py new file mode 100644 index 0000000..64b0709 --- /dev/null +++ b/ekko/storage/_compression_drivers/zlib_.py @@ -0,0 +1,28 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import zlib + +from ekko.storage import compression_drivers + + +class ZlibCompression(compression_drivers.BaseCompression): + + @staticmethod + def compress(data): + return zlib.compress(data) + + @staticmethod + def decompress(data): + return zlib.decompress(data) diff --git a/ekko/storage/_drivers/local.py b/ekko/storage/_drivers/local.py index 03cb544..8464bb9 100644 --- a/ekko/storage/_drivers/local.py +++ b/ekko/storage/_drivers/local.py @@ -22,16 +22,15 @@ from ekko.storage import drivers class LocalStorage(drivers.BaseStorage): def put_data(self, data_segment): - data = data_segment[0] segment = data_segment[1] + data = self.wrap_data(data_segment[0], segment) + file_path = os.path.join( self.storage_location, str(uuid.UUID(bytes=segment.backupset_id)), str(segment.incremental) ) - mkpath(file_path) - file_output = os.path.join( file_path, str(segment.segment) diff --git a/ekko/storage/_encryption/__init__.py b/ekko/storage/_encryption_drivers/__init__.py similarity index 100% rename from ekko/storage/_encryption/__init__.py rename to ekko/storage/_encryption_drivers/__init__.py diff --git a/ekko/storage/_encryption_drivers/noop.py b/ekko/storage/_encryption_drivers/noop.py new file mode 100644 index 0000000..2d65bea --- /dev/null +++ b/ekko/storage/_encryption_drivers/noop.py @@ -0,0 +1,26 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ekko.storage import encryption_drivers + + +class NoopEncryption(encryption_drivers.BaseEncryption): + + @staticmethod + def encrypt(data, key=None): + return data + + @staticmethod + def decrypt(data, key=None): + return data diff --git a/ekko/storage/compression_drivers.py b/ekko/storage/compression_drivers.py new file mode 100644 index 0000000..1818a0c --- /dev/null +++ b/ekko/storage/compression_drivers.py @@ -0,0 +1,44 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import abc + +import six + + +@six.add_metaclass(abc.ABCMeta) +class BaseCompression(object): + """Base class for compression drivers + + :params data: Raw data to work with + """ + + def __init__(self): + pass + + @abc.abstractmethod + def compress(data): + """Compress data + + :returns: Compressed data + """ + raise NotImplementedError() + + @abc.abstractmethod + def decompress(data): + """Decompress data + + :returns: Decompressed data + """ + raise NotImplementedError() diff --git a/ekko/storage/drivers.py b/ekko/storage/drivers.py index 3e62152..515fb81 100644 --- a/ekko/storage/drivers.py +++ b/ekko/storage/drivers.py @@ -15,6 +15,7 @@ import abc import six +from stevedore import driver @six.add_metaclass(abc.ABCMeta) @@ -37,3 +38,37 @@ class BaseStorage(object): :returns: A generator with the segment objects """ raise NotImplementedError() + + @staticmethod + def unwrap_data(data, segment): + # NOTE(SamYaple): Unimplemented selection of compression/encryption + compression = driver.DriverManager( + namespace='ekko.storage.compression_drivers', + name='zlib', + invoke_on_load=True + ).driver + + encryption = driver.DriverManager( + namespace='ekko.storage.encryption_drivers', + name='noop', + invoke_on_load=True + ).driver + + return encryption.decrypt(compression.decompress(data)) + + @staticmethod + def wrap_data(data, segment): + # NOTE(SamYaple): Unimplemented selection of compression/encryption + compression = driver.DriverManager( + namespace='ekko.storage.compression_drivers', + name='zlib', + invoke_on_load=True + ).driver + + encryption = driver.DriverManager( + namespace='ekko.storage.encryption_drivers', + name='noop', + invoke_on_load=True + ).driver + + return encryption.encrypt(compression.compress(data)) diff --git a/ekko/storage/encryption_drivers.py b/ekko/storage/encryption_drivers.py new file mode 100644 index 0000000..9774ef9 --- /dev/null +++ b/ekko/storage/encryption_drivers.py @@ -0,0 +1,41 @@ +# Copyright 2016 Sam Yaple +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import abc + +import six + + +@six.add_metaclass(abc.ABCMeta) +class BaseEncryption(object): + """Base class for encryption drivers + + :params data: Raw data to work with + """ + + @abc.abstractmethod + def encrypt(data, key=None): + """Encrypt data + + :returns: Encrypted data + """ + raise NotImplementedError() + + @abc.abstractmethod + def decrypt(data, key=None): + """Decrypt data + + :returns: Decrypted data + """ + raise NotImplementedError() diff --git a/setup.cfg b/setup.cfg index d7183db..9aaceed 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,6 +27,12 @@ ekko.manifest.drivers = sqlite = ekko.manifest._drivers.sqlite:SQLiteManifest ekko.storage.drivers = local = ekko.storage._drivers.local:LocalStorage +ekko.storage.compression_drivers = + lzma = ekko.storage._compression_drivers.lzma_:LZMACompression + noop = ekko.storage._compression_drivers.noop:NoopCompression + zlib = ekko.storage._compression_drivers.zlib_:ZlibCompression +ekko.storage.encryption_drivers = + noop = ekko.storage._encryption_drivers.noop:NoopEncryption [files] packages =