forked from docker-archive/docker-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcs.py
46 lines (32 loc) · 1.12 KB
/
gcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gevent.monkey
gevent.monkey.patch_all()
import logging
import boto.gs.connection
import boto.gs.key
import cache_lru
from boto_base import BotoStorage
logger = logging.getLogger(__name__)
class GSStorage(BotoStorage):
def __init__(self, config):
BotoStorage.__init__(self, config)
def makeConnection(self):
return boto.gs.connection.GSConnection(
self._config.gs_access_key,
self._config.gs_secret_key,
is_secure=(self._config.gs_secure is True))
def makeKey(self, path):
return boto.gs.key.Key(self._boto_bucket, path)
@cache_lru.put
def put_content(self, path, content):
path = self._init_path(path)
key = self.makeKey(path)
key.set_contents_from_string(content)
return path
def stream_write(self, path, fp):
# Minimum size of upload part size on GS is 5MB
buffer_size = 5 * 1024 * 1024
if self.buffer_size > buffer_size:
buffer_size = self.buffer_size
path = self._init_path(path)
key = self.makeKey(path)
key.set_contents_from_string(fp.read())