Allow images to be filtered by project ID

A new parameter MURANO_IMAGE_FILTER_PROJECT_ID has been added which, when
given, will filter the list of public Murano images to the given project
ID. Private images owned by the user are also included.

Change-Id: I20ad609e48cc786f46214efc0d308b8d1b0f6ea9
Closes-Bug: #1717439
This commit is contained in:
Andy Botting 2017-09-18 11:33:30 +10:00
parent bfacdc6ccf
commit 09110be37e
3 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,7 @@
import json import json
from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -27,6 +28,14 @@ LOG = logging.getLogger(__name__)
def filter_murano_images(images, request=None): def filter_murano_images(images, request=None):
# filter images by project owner
filter_project = getattr(settings, 'MURANO_IMAGE_FILTER_PROJECT_ID', None)
if filter_project:
project_ids = [filter_project]
if request:
project_ids.append(request.user.tenant_id)
images = filter(
lambda x: getattr(x, 'owner', None) in project_ids, list(images))
# filter out the snapshot image type # filter out the snapshot image type
images = filter( images = filter(
lambda x: getattr(x, 'image_type', None) != 'snapshot', list(images)) lambda x: getattr(x, 'image_type', None) != 'snapshot', list(images))

View File

@ -15,6 +15,10 @@ DISPLAY_MURANO_REPO_URL = 'http://apps.openstack.org/#tab=murano-apps'
# in the main accordion navigation # in the main accordion navigation
# MURANO_DASHBOARD_NAME = "App Catalog" # MURANO_DASHBOARD_NAME = "App Catalog"
# Filter the list of Murano images displayed to be only those owned by this
# project ID
# MURANO_IMAGE_FILTER_PROJECT_ID =
# Specify a maximum number of limit packages. # Specify a maximum number of limit packages.
# PACKAGES_LIMIT = 100 # PACKAGES_LIMIT = 100

View File

@ -0,0 +1,5 @@
---
features:
- A new parameter MURANO_IMAGE_FILTER_PROJECT_ID has been added which, when
given, will filter the list of public Murano images to the given project
ID