authorization.py (glance-20.0.0) | : | authorization.py (glance-20.0.1) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
from glance.common import store_utils | from glance.common import store_utils | |||
import glance.domain.proxy | import glance.domain.proxy | |||
from glance.i18n import _ | from glance.i18n import _ | |||
CONF = cfg.CONF | CONF = cfg.CONF | |||
LOG = logging.getLogger(__name__) | LOG = logging.getLogger(__name__) | |||
def lazy_update_store_info(func): | def lazy_update_store_info(func): | |||
"""Update store information in location metadata""" | """Update store information in location metadata""" | |||
@functools.wraps(func) | @functools.wraps(func) | |||
def wrapped(context, image, **kwargs): | def wrapped(context, image, image_repo, **kwargs): | |||
if CONF.enabled_backends: | if CONF.enabled_backends: | |||
store_utils.update_store_in_locations( | store_utils.update_store_in_locations( | |||
image.locations, image.image_id) | image, image_repo) | |||
return func(context, image, **kwargs) | return func(context, image, image_repo, **kwargs) | |||
return wrapped | return wrapped | |||
def is_image_mutable(context, image): | def is_image_mutable(context, image): | |||
"""Return True if the image is mutable in this context.""" | """Return True if the image is mutable in this context.""" | |||
if context.is_admin: | if context.is_admin: | |||
return True | return True | |||
if image.owner is None or context.owner is None: | if image.owner is None or context.owner is None: | |||
return False | return False | |||
return image.owner == context.owner | return image.owner == context.owner | |||
@lazy_update_store_info | @lazy_update_store_info | |||
def proxy_image(context, image): | def proxy_image(context, image, image_repo): | |||
if is_image_mutable(context, image): | if is_image_mutable(context, image): | |||
return ImageProxy(image, context) | return ImageProxy(image, context) | |||
else: | else: | |||
return ImmutableImageProxy(image, context) | return ImmutableImageProxy(image, context) | |||
def is_member_mutable(context, member): | def is_member_mutable(context, member): | |||
"""Return True if the image is mutable in this context.""" | """Return True if the image is mutable in this context.""" | |||
if context.is_admin: | if context.is_admin: | |||
return True | return True | |||
skipping to change at line 120 | skipping to change at line 120 | |||
def __init__(self, image_repo, context): | def __init__(self, image_repo, context): | |||
self.context = context | self.context = context | |||
self.image_repo = image_repo | self.image_repo = image_repo | |||
proxy_kwargs = {'context': self.context} | proxy_kwargs = {'context': self.context} | |||
super(ImageRepoProxy, self).__init__(image_repo, | super(ImageRepoProxy, self).__init__(image_repo, | |||
item_proxy_class=ImageProxy, | item_proxy_class=ImageProxy, | |||
item_proxy_kwargs=proxy_kwargs) | item_proxy_kwargs=proxy_kwargs) | |||
def get(self, image_id): | def get(self, image_id): | |||
image = self.image_repo.get(image_id) | image = self.image_repo.get(image_id) | |||
return proxy_image(self.context, image) | return proxy_image(self.context, image, self.image_repo) | |||
def list(self, *args, **kwargs): | def list(self, *args, **kwargs): | |||
images = self.image_repo.list(*args, **kwargs) | images = self.image_repo.list(*args, **kwargs) | |||
return [proxy_image(self.context, i) for i in images] | return [proxy_image(self.context, i, self.image_repo) for i in images] | |||
def _validate_image_accepts_members(visibility): | def _validate_image_accepts_members(visibility): | |||
if visibility != 'shared': | if visibility != 'shared': | |||
message = _("Only shared images have members.") | message = _("Only shared images have members.") | |||
raise exception.Forbidden(message) | raise exception.Forbidden(message) | |||
class ImageMemberRepoProxy(glance.domain.proxy.MemberRepo): | class ImageMemberRepoProxy(glance.domain.proxy.MemberRepo): | |||
def __init__(self, member_repo, image, context): | def __init__(self, member_repo, image, context): | |||
self.member_repo = member_repo | self.member_repo = member_repo | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 6 lines changed or added |