Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 1fe7191

Browse files
author
Olivier Gambier
committed
Enhanced arguments handling
Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent 3be0e0b commit 1fe7191

File tree

1 file changed

+46
-6
lines changed
  • depends/docker-registry-core/docker_registry/core

1 file changed

+46
-6
lines changed

depends/docker-registry-core/docker_registry/core/driver.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
__all__ = ["fetch", "available", "Base"]
3030

31+
import functools
3132
import logging
3233
import pkgutil
34+
import urllib
3335

3436
import docker_registry.drivers
3537

@@ -39,6 +41,26 @@
3941
logger = logging.getLogger(__name__)
4042

4143

44+
def check(value):
45+
value = str(value)
46+
if value == '..':
47+
value = '%2E%2E'
48+
return urllib.quote_plus(value)
49+
50+
51+
def filter_args(f):
52+
@functools.wraps(f)
53+
def wrapper(*args, **kwargs):
54+
args = list(args)
55+
ref = args.pop(0)
56+
args = [check(arg) for arg in args]
57+
args.insert(0, ref)
58+
for key, value in kwargs.iteritems():
59+
kwargs[key] = check(value)
60+
return f(*args, **kwargs)
61+
return wrapper
62+
63+
4264
class Base(object):
4365

4466
"""Storage is a convenience class...
@@ -59,6 +81,10 @@ class Base(object):
5981
repositories = 'repositories'
6082
images = 'images'
6183

84+
def _repository_path(self, namespace, repository):
85+
return '{0}/{1}/{2}'.format(
86+
self.repositories, namespace, repository)
87+
6288
# Set the IO buffer to 128kB
6389
buffer_size = 128 * 1024
6490
# By default no storage plugin supports it
@@ -68,60 +94,74 @@ def __init__(self, path=None, config=None):
6894
pass
6995

7096
# FIXME(samalba): Move all path resolver in each module (out of the base)
97+
@filter_args
7198
def images_list_path(self, namespace, repository):
72-
repository_path = self.repository_path(
99+
repository_path = self._repository_path(
73100
namespace=namespace, repository=repository)
74101
return '{0}/_images_list'.format(repository_path)
75102

103+
@filter_args
76104
def image_json_path(self, image_id):
77105
return '{0}/{1}/json'.format(self.images, image_id)
78106

107+
@filter_args
79108
def image_mark_path(self, image_id):
80109
return '{0}/{1}/_inprogress'.format(self.images, image_id)
81110

111+
@filter_args
82112
def image_checksum_path(self, image_id):
83113
return '{0}/{1}/_checksum'.format(self.images, image_id)
84114

115+
@filter_args
85116
def image_layer_path(self, image_id):
86117
return '{0}/{1}/layer'.format(self.images, image_id)
87118

119+
@filter_args
88120
def image_ancestry_path(self, image_id):
89121
return '{0}/{1}/ancestry'.format(self.images, image_id)
90122

123+
@filter_args
91124
def image_files_path(self, image_id):
92125
return '{0}/{1}/_files'.format(self.images, image_id)
93126

127+
@filter_args
94128
def image_diff_path(self, image_id):
95129
return '{0}/{1}/_diff'.format(self.images, image_id)
96130

131+
@filter_args
97132
def repository_path(self, namespace, repository):
98133
return '{0}/{1}/{2}'.format(
99134
self.repositories, namespace, repository)
100135

136+
@filter_args
101137
def tag_path(self, namespace, repository, tagname=None):
102-
repository_path = self.repository_path(
138+
repository_path = self._repository_path(
103139
namespace=namespace, repository=repository)
104140
if not tagname:
105141
return repository_path
106142
return '{0}/tag_{1}'.format(repository_path, tagname)
107143

144+
@filter_args
108145
def repository_json_path(self, namespace, repository):
109-
repository_path = self.repository_path(
146+
repository_path = self._repository_path(
110147
namespace=namespace, repository=repository)
111148
return '{0}/json'.format(repository_path)
112149

150+
@filter_args
113151
def repository_tag_json_path(self, namespace, repository, tag):
114-
repository_path = self.repository_path(
152+
repository_path = self._repository_path(
115153
namespace=namespace, repository=repository)
116154
return '{0}/tag{1}_json'.format(repository_path, tag)
117155

156+
@filter_args
118157
def index_images_path(self, namespace, repository):
119-
repository_path = self.repository_path(
158+
repository_path = self._repository_path(
120159
namespace=namespace, repository=repository)
121160
return '{0}/_index_images'.format(repository_path)
122161

162+
@filter_args
123163
def private_flag_path(self, namespace, repository):
124-
repository_path = self.repository_path(
164+
repository_path = self._repository_path(
125165
namespace=namespace, repository=repository)
126166
return '{0}/_private'.format(repository_path)
127167

0 commit comments

Comments
 (0)