Merge "Add base for compression and encryption"
This commit is contained in:
commit
4bb6a26ad8
28
ekko/storage/_compression_drivers/lzma_.py
Normal file
28
ekko/storage/_compression_drivers/lzma_.py
Normal file
@ -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)
|
26
ekko/storage/_compression_drivers/noop.py
Normal file
26
ekko/storage/_compression_drivers/noop.py
Normal file
@ -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
|
28
ekko/storage/_compression_drivers/zlib_.py
Normal file
28
ekko/storage/_compression_drivers/zlib_.py
Normal file
@ -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)
|
@ -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)
|
||||
|
26
ekko/storage/_encryption_drivers/noop.py
Normal file
26
ekko/storage/_encryption_drivers/noop.py
Normal file
@ -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
|
44
ekko/storage/compression_drivers.py
Normal file
44
ekko/storage/compression_drivers.py
Normal file
@ -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()
|
@ -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))
|
||||
|
41
ekko/storage/encryption_drivers.py
Normal file
41
ekko/storage/encryption_drivers.py
Normal file
@ -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()
|
@ -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 =
|
||||
|
Loading…
x
Reference in New Issue
Block a user