143
142
return self._check(context, action, target)
146
class ImageRepoProxy(glance.domain.ImageRepoProxy):
148
def __init__(self, context, policy, image_repo):
149
self._context = context
150
self._policy = policy
151
self._image_repo = image_repo
152
super(ImageRepoProxy, self).__init__(image_repo)
154
def get(self, *args, **kwargs):
155
self._policy.enforce(self._context, 'get_image', {})
156
image = self._image_repo.get(*args, **kwargs)
157
return ImageProxy(image, self._context, self._policy)
145
class ImageRepoProxy(glance.domain.proxy.Repo):
147
def __init__(self, image_repo, context, policy):
148
self.context = context
150
self.image_repo = image_repo
151
proxy_kwargs = {'context': self.context, 'policy': self.policy}
152
super(ImageRepoProxy, self).__init__(image_repo,
153
item_proxy_class=ImageProxy,
154
item_proxy_kwargs=proxy_kwargs)
156
def get(self, image_id):
157
self.policy.enforce(self.context, 'get_image', {})
158
return super(ImageRepoProxy, self).get(image_id)
159
160
def list(self, *args, **kwargs):
160
self._policy.enforce(self._context, 'get_images', {})
161
images = self._image_repo.list(*args, **kwargs)
162
return [ImageProxy(i, self._context, self._policy)
165
def save(self, *args, **kwargs):
166
self._policy.enforce(self._context, 'modify_image', {})
167
return self._image_repo.save(*args, **kwargs)
169
def add(self, *args, **kwargs):
170
self._policy.enforce(self._context, 'add_image', {})
171
return self._image_repo.add(*args, **kwargs)
174
class ImageProxy(glance.domain.ImageProxy):
161
self.policy.enforce(self.context, 'get_images', {})
162
return super(ImageRepoProxy, self).list(*args, **kwargs)
164
def save(self, image):
165
self.policy.enforce(self.context, 'modify_image', {})
166
return super(ImageRepoProxy, self).save(image)
168
def add(self, image):
169
self.policy.enforce(self.context, 'add_image', {})
170
return super(ImageRepoProxy, self).add(image)
173
class ImageProxy(glance.domain.proxy.Image):
176
175
def __init__(self, image, context, policy):
178
self._context = context
179
self._policy = policy
177
self.context = context
180
179
super(ImageProxy, self).__init__(image)
183
182
def visibility(self):
184
return self._image.visibility
183
return self.image.visibility
186
185
@visibility.setter
187
186
def visibility(self, value):
188
187
if value == 'public':
189
self._policy.enforce(self._context, 'publicize_image', {})
190
self._image.visibility = value
188
self.policy.enforce(self.context, 'publicize_image', {})
189
self.image.visibility = value
192
191
def delete(self):
193
self._policy.enforce(self._context, 'delete_image', {})
194
return self._image.delete()
197
class ImageFactoryProxy(object):
192
self.policy.enforce(self.context, 'delete_image', {})
193
return self.image.delete()
195
def get_data(self, *args, **kwargs):
196
self.policy.enforce(self.context, 'download_image', {})
197
return self.image.get_data(*args, **kwargs)
200
class ImageFactoryProxy(glance.domain.proxy.ImageFactory):
199
202
def __init__(self, image_factory, context, policy):
200
203
self.image_factory = image_factory
201
204
self.context = context
202
205
self.policy = policy
206
proxy_kwargs = {'context': self.context, 'policy': self.policy}
207
super(ImageFactoryProxy, self).__init__(image_factory,
208
proxy_class=ImageProxy,
209
proxy_kwargs=proxy_kwargs)
204
211
def new_image(self, **kwargs):
205
212
if kwargs.get('visibility') == 'public':
206
213
self.policy.enforce(self.context, 'publicize_image', {})
207
image = self.image_factory.new_image(**kwargs)
214
return super(ImageFactoryProxy, self).new_image(**kwargs)