From db0c023fd0d756912c3f575c6ac65e99fda573cc Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Mon, 2 Oct 2017 14:26:26 +0200 Subject: Add filter storage method Also remove de/encryption in cloud storage, can be provided with a filter storage --- storage/cloud/cloudstorage.go | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) (limited to 'storage/cloud') diff --git a/storage/cloud/cloudstorage.go b/storage/cloud/cloudstorage.go index 261a034..f93bb5c 100644 --- a/storage/cloud/cloudstorage.go +++ b/storage/cloud/cloudstorage.go @@ -5,7 +5,6 @@ package cloud import ( "bytes" "code.laria.me/petrific/config" - "code.laria.me/petrific/gpg" "code.laria.me/petrific/objects" "code.laria.me/petrific/storage" "errors" @@ -27,22 +26,9 @@ var ( NotFoundErr = errors.New("Object not found") // Cloud object could not be found ) -// Crypter provides de-/encrypting facilities for CloudBasedObjectStorage -type Crypter interface { - Encrypt([]byte) ([]byte, error) - Decrypt([]byte) ([]byte, error) -} - -// NopCrypter implements Crypter by not de/-encrypting at all -type NopCrypter struct{} - -func (NopCrypter) Encrypt(in []byte) ([]byte, error) { return in, nil } -func (NopCrypter) Decrypt(in []byte) ([]byte, error) { return in, nil } - type CloudBasedObjectStorage struct { - CS CloudStorage - Prefix string - Crypter Crypter + CS CloudStorage + Prefix string index storage.Index } @@ -94,24 +80,14 @@ func (cbos *CloudBasedObjectStorage) Init() error { } func (cbos CloudBasedObjectStorage) Get(id objects.ObjectId) ([]byte, error) { - b, err := cbos.CS.Get(cbos.objidToKey(id)) - if err != nil { - return []byte{}, err - } - - return cbos.Crypter.Decrypt(b) + return cbos.CS.Get(cbos.objidToKey(id)) } func (cbos CloudBasedObjectStorage) Has(id objects.ObjectId) (bool, error) { return cbos.CS.Has(cbos.objidToKey(id)) } -func (cbos CloudBasedObjectStorage) Set(id objects.ObjectId, typ objects.ObjectType, raw []byte) error { - b, err := cbos.Crypter.Encrypt(raw) - if err != nil { - return err - } - +func (cbos CloudBasedObjectStorage) Set(id objects.ObjectId, typ objects.ObjectType, b []byte) error { if err := cbos.CS.Put(cbos.objidToKey(id), b); err != nil { return err } @@ -159,8 +135,7 @@ func cloudStorageCreator(cloudCreator cloudObjectStorageCreator) storage.CreateS var cbos CloudBasedObjectStorage var storageconf struct { - Prefix string `toml:"prefix,omitempty"` - EncryptFor string `toml:"encrypt_for,omitempty"` + Prefix string `toml:"prefix,omitempty"` } if err := conf.GetStorageConfData(name, &storageconf); err != nil { @@ -169,13 +144,6 @@ func cloudStorageCreator(cloudCreator cloudObjectStorageCreator) storage.CreateS cbos.Prefix = storageconf.Prefix - if storageconf.EncryptFor != "" { - cbos.Crypter = gpg.Crypter{ - gpg.Encrypter{Key: storageconf.EncryptFor}, - gpg.Decrypter{}, - } - } - var err error if cbos.CS, err = cloudCreator(conf, name); err != nil { return nil, err -- cgit v1.2.3-70-g09d2