Exemplo n.º 1
0
    def test_default(self):
        dst = '/path/will/be/ignored/BlobStoreTest.test_default.txt'
        bs = BlobStore()
        bs.save(dst, self.tiny_sample)

        # outputs to cwd
        with open('BlobStoreTest.test_default.txt', 'rt') as f:
            contents = f.read()
            self.assertEqual(contents, 'aaaabbbb')
Exemplo n.º 2
0
    def test_save_blob(self, mock_s3):
        mock_s3.return_value = mock_s3
        mock_s3.exists.return_value = False

        blob_name = 'argh12456789'

        bs = BlobStore('s3')
        bs.save_blob(blob_name, self.tiny_sample)

        mock_s3.exists.assert_called_once_with('data/ar/argh12456789')
        mock_s3.upload_file.assert_called_once_with(self.tiny_sample, 'data/ar/argh12456789')
Exemplo n.º 3
0
    def test_s3_file_exists(self, mock_s3):
        mock_s3.return_value = mock_s3
        mock_s3.exists.return_value = True

        dst = 'full/path/coolfile.txt'

        bs = BlobStore('s3')
        bs.save(dst, self.tiny_sample)

        mock_s3.exists.assert_called_once_with('full/path/coolfile.txt')
        self.assertEqual(mock_s3.upload_file.call_count, 0)
Exemplo n.º 4
0
    def test_s3(self, mock_s3):
        mock_s3.return_value = mock_s3
        mock_s3.exists.return_value = False

        dst = 'full/path/coolfile.txt'

        bs = BlobStore('s3')
        bs.save(dst, self.tiny_sample)

        mock_s3.exists.assert_called_once_with('full/path/coolfile.txt')
        mock_s3.upload_file.assert_called_once_with(self.tiny_sample, 'full/path/coolfile.txt')
Exemplo n.º 5
0
    def test_s3_and_b2(self, mock_s3, mock_b2):
        mock_b2.return_value = mock_b2
        mock_b2.exists.return_value = False
        mock_s3.return_value = mock_s3
        mock_s3.exists.return_value = True

        dst = 'full/path/coolfile.txt'

        bs = BlobStore('s3, b2')
        bs.save(dst, self.tiny_sample)

        mock_b2.exists.assert_called_once_with('full/path/coolfile.txt')
        mock_b2.upload_file.assert_called_once_with(self.tiny_sample, 'full/path/coolfile.txt')

        mock_s3.exists.assert_called_once_with('full/path/coolfile.txt')
        self.assertEqual(mock_s3.upload_file.call_count, 0)
Exemplo n.º 6
0
Arquivo: pog.py Projeto: sz3/pog
def main():
    args = docopt(__doc__, version='Pog 0.1.4')
    chunk_size = parse_size(args.get('--chunk-size'))
    compresslevel = int(args.get('--compresslevel'))
    concurrency = int(args.get('--concurrency'))
    store_absolute_paths = args.get('--store-absolute-paths')

    secret, crypto_box = get_asymmetric_encryption(
        args.get('--decryption-keyfile'), args.get('--encryption-keyfile'))
    if not crypto_box and not secret:
        secret = get_secret(args.get('--keyfile'))

    decrypt = (args.get('--decrypt') or args.get('--dump-manifest')
               or args.get('--dump-manifest-index')
               or args.get('--decryption-keyfile'))
    if decrypt:
        consume = args.get('--consume')
        d = Decryptor(secret, crypto_box, consume)
        if args.get('--dump-manifest'):
            d.dump_manifest(*args['<INPUTS>'])
        elif args.get('--dump-manifest-index'):
            d.dump_manifest_index(*args['<INPUTS>'])
        else:
            d.decrypt(*args['<INPUTS>'])
    else:
        bs = BlobStore(args.get('--save-to'))
        en = Encryptor(secret, crypto_box, chunk_size, compresslevel,
                       concurrency, store_absolute_paths, bs)
        en.encrypt(*args['<INPUTS>'])
Exemplo n.º 7
0
Arquivo: pog.py Projeto: sz3/pog
 def __init__(self,
              secret,
              crypto_box=None,
              chunk_size=100000000,
              compresslevel=3,
              concurrency=8,
              store_absolute_paths=False,
              blob_store=None):
     self.secret = sha256(secret).digest()
     self.index_box = nacl_SecretBox(secret)
     self.box = crypto_box or self.index_box
     self.chunk_size = chunk_size
     self.compresslevel = compresslevel
     self.concurrency = concurrency
     self.store_absolute_paths = store_absolute_paths
     self.blob_store = blob_store or BlobStore()
Exemplo n.º 8
0
 def test_parse_save_to(self):
     bs = BlobStore()
     self.assertEqual(bs._parse_save_to('b2'), [('b2', None)])
     self.assertEqual(bs._parse_save_to('b2:bucket2'), [('b2', 'bucket2')])
     self.assertEqual(bs._parse_save_to('b2://bucket2'), [('b2', 'bucket2')])
     self.assertEqual(bs._parse_save_to('b2://bucket2/'), [('b2', 'bucket2')])
     self.assertEqual(bs._parse_save_to('local:/home/user/'), [('local', '/home/user')])
     self.assertEqual(bs._parse_save_to('./local-save.sh'), [('./local-save.sh', None)])
     self.assertEqual(bs._parse_save_to('b2,s3'), [('b2', None), ('s3', None)])
     self.assertEqual(bs._parse_save_to(
         'b2,s3,./local-save.sh'),
         [('b2', None), ('s3', None), ('./local-save.sh', None)],
     )
     self.assertEqual(bs._parse_save_to(
         'b2,b2:onebuck/,b2://twobucks,s3://fitty,local:/home/user/'),
         [('b2', None), ('b2', 'onebuck'), ('b2', 'twobucks'), ('s3', 'fitty'), ('local', '/home/user')],
     )