Files
horizon/openstack_dashboard/dashboards/project/api_access/tables.py
Akihiro Motoki 67410193b3 Sync nova policy
Based on nova commit 32c8ac6b7dfe4ca0c211cbce7c5a67d88558126f

The new file was generated by oslopolicy-sample-generator:
  oslopolicy-sample-generator --namespace nova --format json

nova uses policy-in-code now, so there is a lot of differences.
Sorted version diff is http://paste.openstack.org/show/628742/

All policies with "@" have been dropped.
Dropped policies used in horizon are:
  os_compute_api:os-certificates:create
  os_compute_api:os-scheduler-hints:discoverable
  os_compute_api:os-server-groups:discoverable

[discoverable]
"discoverable" policies are related to nova API extensions
but the API extension mechanism has gone in Nova Queens,
so these policies now make no sense in Nova.
In Horizon side, we are still use a bit older API version
to launch instance, so it seems some fallback policies are needed
and they are added as conf/nova_policy.d.

[os_compute_api:os-certificates:create]
No corresponding policy is found, so the related policy check is dropped.
EC2 API is provided as a separate project from nova.
I guess this is the reason the policy was dropped.
DownloadEC2 action referred to it, but we already checks EC2 service
is available so I believe the policy can be dropped safely.

[openstack_dashboard.test.unit.api.rest.test_policy]
Unit tests are updated according to the nova policy change.
Note that test_rule_alone previously succeeded because it used
non-existing policy and fallbacked to 'default' rule.
The rule is changed to a policy for non-admin user.

Change-Id: I68f91bc29b20a4ecd613fc75735d38b9a48162ee
2018-02-05 05:57:02 +09:00

125 lines
4.2 KiB
Python

# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.conf import settings
from django.template.defaultfilters import title
from django.utils.translation import ugettext_lazy as _
from openstack_auth import utils
from horizon import tables
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.api_access import forms
from openstack_dashboard import policy
def pretty_service_names(name):
name = name.replace('-', ' ')
if name in ['ec2', 's3']:
name = name.upper()
else:
name = title(name)
return name
class DownloadEC2(tables.LinkAction):
name = "download_ec2"
verbose_name = _("EC2 Credentials")
verbose_name_plural = _("EC2 Credentials")
icon = "download"
url = "horizon:project:api_access:ec2"
def allowed(self, request, datum=None):
return api.base.is_service_enabled(request, 'ec2')
class DownloadCloudsYaml(tables.LinkAction):
name = "download_clouds_yaml"
verbose_name = _("OpenStack clouds.yaml File")
verbose_name_plural = _("OpenStack clouds.yaml File")
icon = "download"
url = "horizon:project:api_access:clouds.yaml"
class DownloadOpenRC(tables.LinkAction):
name = "download_openrc"
verbose_name = _("OpenStack RC File (Identity API v3)")
verbose_name_plural = _("OpenStack RC File (Identity API v3)")
icon = "download"
url = "horizon:project:api_access:openrc"
def allowed(self, request, datum=None):
return utils.get_keystone_version() >= 3
class DownloadOpenRCv2(tables.LinkAction):
name = "download_openrc_v2"
verbose_name = _("OpenStack RC File (Identity API v2.0)")
verbose_name_plural = _("OpenStack RC File (Identity API v2.0)")
icon = "download"
url = "horizon:project:api_access:openrcv2"
def allowed(self, request, datum=None):
return settings.SHOW_KEYSTONE_V2_RC
class ViewCredentials(tables.LinkAction):
name = "view_credentials"
verbose_name = _("View Credentials")
classes = ("ajax-modal", )
icon = "eye"
url = "horizon:project:api_access:view_credentials"
class RecreateCredentials(tables.LinkAction):
name = "recreate_credentials"
verbose_name = _("Recreate EC2 Credentials")
classes = ("ajax-modal",)
icon = "refresh"
url = "horizon:project:api_access:recreate_credentials"
policy_rules = (("compute", "os_compute_api:certificates:create"))
action_type = "danger"
def allowed(self, request, datum=None):
try:
target = {"target.credential.user_id": request.user.id}
if (api.base.is_service_enabled(request, 'ec2') and
forms.get_ec2_credentials(request) and
policy.check((("identity", "identity:ec2_create_credential"),
("identity", "identity:ec2_delete_credential")),
request, target=target)):
return True
except Exception:
pass
return False
class EndpointsTable(tables.DataTable):
api_name = tables.Column('type',
verbose_name=_("Service"),
filters=(pretty_service_names,))
api_endpoint = tables.Column('public_url',
verbose_name=_("Service Endpoint"))
class Meta(object):
name = "endpoints"
verbose_name = _("API Endpoints")
multi_select = False
table_actions = (ViewCredentials, RecreateCredentials)
table_actions_menu = (DownloadCloudsYaml,
DownloadOpenRCv2,
DownloadOpenRC,
DownloadEC2)
table_actions_menu_label = _('Download OpenStack RC File')