~ubuntu-branches/ubuntu/raring/glance/raring-proposed

« back to all changes in this revision

Viewing changes to glance/api/policy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-03-20 07:42:22 UTC
  • mfrom: (1.1.50)
  • Revision ID: package-import@ubuntu.com-20130320074222-d8oochgvhjooh1a5
Tags: 1:2013.1~rc1-0ubuntu1
[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org.

[ Chuck Short ]
* New upstrem release
* debian/control: Clean up build-dependencies:
  - Drop python-argparse referenced in pydist-overrides
  - Drop python-swift no longer needed.
  - Drop python-dateutils no longer needed.
  - Drop python-glacneclient no longer needed.
  - Added python-anyjson to build-depends.
  - Use python-keystoneclient instead of python-keystone.
  - Added python-lxml to build-depends.
  - Added python-swiftclientto build-depends.
  - Added python-passlib to build-depends.
* debian/rules: Set the PYTHONPATH for the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from oslo.config import cfg
24
24
 
25
25
from glance.common import exception
26
 
from glance.common import utils
27
 
import glance.domain
 
26
import glance.domain.proxy
28
27
import glance.openstack.common.log as logging
29
28
from glance.openstack.common import policy
30
29
 
143
142
        return self._check(context, action, target)
144
143
 
145
144
 
146
 
class ImageRepoProxy(glance.domain.ImageRepoProxy):
147
 
 
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)
153
 
 
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):
 
146
 
 
147
    def __init__(self, image_repo, context, policy):
 
148
        self.context = context
 
149
        self.policy = policy
 
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)
 
155
 
 
156
    def get(self, image_id):
 
157
        self.policy.enforce(self.context, 'get_image', {})
 
158
        return super(ImageRepoProxy, self).get(image_id)
158
159
 
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)
163
 
                for i in images]
164
 
 
165
 
    def save(self, *args, **kwargs):
166
 
        self._policy.enforce(self._context, 'modify_image', {})
167
 
        return self._image_repo.save(*args, **kwargs)
168
 
 
169
 
    def add(self, *args, **kwargs):
170
 
        self._policy.enforce(self._context, 'add_image', {})
171
 
        return self._image_repo.add(*args, **kwargs)
172
 
 
173
 
 
174
 
class ImageProxy(glance.domain.ImageProxy):
 
161
        self.policy.enforce(self.context, 'get_images', {})
 
162
        return super(ImageRepoProxy, self).list(*args, **kwargs)
 
163
 
 
164
    def save(self, image):
 
165
        self.policy.enforce(self.context, 'modify_image', {})
 
166
        return super(ImageRepoProxy, self).save(image)
 
167
 
 
168
    def add(self, image):
 
169
        self.policy.enforce(self.context, 'add_image', {})
 
170
        return super(ImageRepoProxy, self).add(image)
 
171
 
 
172
 
 
173
class ImageProxy(glance.domain.proxy.Image):
175
174
 
176
175
    def __init__(self, image, context, policy):
177
 
        self._image = image
178
 
        self._context = context
179
 
        self._policy = policy
 
176
        self.image = image
 
177
        self.context = context
 
178
        self.policy = policy
180
179
        super(ImageProxy, self).__init__(image)
181
180
 
182
181
    @property
183
182
    def visibility(self):
184
 
        return self._image.visibility
 
183
        return self.image.visibility
185
184
 
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
191
190
 
192
191
    def delete(self):
193
 
        self._policy.enforce(self._context, 'delete_image', {})
194
 
        return self._image.delete()
195
 
 
196
 
 
197
 
class ImageFactoryProxy(object):
 
192
        self.policy.enforce(self.context, 'delete_image', {})
 
193
        return self.image.delete()
 
194
 
 
195
    def get_data(self, *args, **kwargs):
 
196
        self.policy.enforce(self.context, 'download_image', {})
 
197
        return self.image.get_data(*args, **kwargs)
 
198
 
 
199
 
 
200
class ImageFactoryProxy(glance.domain.proxy.ImageFactory):
198
201
 
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)
203
210
 
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)
208
 
        return image
 
214
        return super(ImageFactoryProxy, self).new_image(**kwargs)