Skip to content

Commit 64980bd

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Pass the actual target in volumes policy"
2 parents c5c3cee + abeb47b commit 64980bd

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

nova/api/openstack/compute/volumes.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def __init__(self):
104104
def show(self, req, id):
105105
"""Return data about the given volume."""
106106
context = req.environ['nova.context']
107-
context.can(vol_policies.POLICY_NAME % 'show')
107+
context.can(vol_policies.POLICY_NAME % 'show',
108+
target={'project_id': context.project_id})
108109

109110
try:
110111
vol = self.volume_api.get(context, id)
@@ -119,7 +120,8 @@ def show(self, req, id):
119120
def delete(self, req, id):
120121
"""Delete a volume."""
121122
context = req.environ['nova.context']
122-
context.can(vol_policies.POLICY_NAME % 'delete')
123+
context.can(vol_policies.POLICY_NAME % 'delete',
124+
target={'project_id': context.project_id})
123125

124126
try:
125127
self.volume_api.delete(context, id)
@@ -134,7 +136,8 @@ def delete(self, req, id):
134136
def index(self, req):
135137
"""Returns a summary list of volumes."""
136138
context = req.environ['nova.context']
137-
context.can(vol_policies.POLICY_NAME % 'list')
139+
context.can(vol_policies.POLICY_NAME % 'list',
140+
target={'project_id': context.project_id})
138141
return self._items(req, entity_maker=_translate_volume_summary_view)
139142

140143
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@@ -143,7 +146,8 @@ def index(self, req):
143146
def detail(self, req):
144147
"""Returns a detailed list of volumes."""
145148
context = req.environ['nova.context']
146-
context.can(vol_policies.POLICY_NAME % 'detail')
149+
context.can(vol_policies.POLICY_NAME % 'detail',
150+
target={'project_id': context.project_id})
147151
return self._items(req, entity_maker=_translate_volume_detail_view)
148152

149153
def _items(self, req, entity_maker):
@@ -161,7 +165,8 @@ def _items(self, req, entity_maker):
161165
def create(self, req, body):
162166
"""Creates a new volume."""
163167
context = req.environ['nova.context']
164-
context.can(vol_policies.POLICY_NAME % 'create')
168+
context.can(vol_policies.POLICY_NAME % 'create',
169+
target={'project_id': context.project_id})
165170

166171
vol = body['volume']
167172

@@ -576,7 +581,8 @@ def __init__(self):
576581
def show(self, req, id):
577582
"""Return data about the given snapshot."""
578583
context = req.environ['nova.context']
579-
context.can(vol_policies.POLICY_NAME % 'snapshots:show')
584+
context.can(vol_policies.POLICY_NAME % 'snapshots:show',
585+
target={'project_id': context.project_id})
580586

581587
try:
582588
vol = self.volume_api.get_snapshot(context, id)
@@ -591,7 +597,8 @@ def show(self, req, id):
591597
def delete(self, req, id):
592598
"""Delete a snapshot."""
593599
context = req.environ['nova.context']
594-
context.can(vol_policies.POLICY_NAME % 'snapshots:delete')
600+
context.can(vol_policies.POLICY_NAME % 'snapshots:delete',
601+
target={'project_id': context.project_id})
595602

596603
try:
597604
self.volume_api.delete_snapshot(context, id)
@@ -604,7 +611,8 @@ def delete(self, req, id):
604611
def index(self, req):
605612
"""Returns a summary list of snapshots."""
606613
context = req.environ['nova.context']
607-
context.can(vol_policies.POLICY_NAME % 'snapshots:list')
614+
context.can(vol_policies.POLICY_NAME % 'snapshots:list',
615+
target={'project_id': context.project_id})
608616
return self._items(req, entity_maker=_translate_snapshot_summary_view)
609617

610618
@wsgi.Controller.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@@ -613,7 +621,8 @@ def index(self, req):
613621
def detail(self, req):
614622
"""Returns a detailed list of snapshots."""
615623
context = req.environ['nova.context']
616-
context.can(vol_policies.POLICY_NAME % 'snapshots:detail')
624+
context.can(vol_policies.POLICY_NAME % 'snapshots:detail',
625+
target={'project_id': context.project_id})
617626
return self._items(req, entity_maker=_translate_snapshot_detail_view)
618627

619628
def _items(self, req, entity_maker):
@@ -631,7 +640,8 @@ def _items(self, req, entity_maker):
631640
def create(self, req, body):
632641
"""Creates a new snapshot."""
633642
context = req.environ['nova.context']
634-
context.can(vol_policies.POLICY_NAME % 'snapshots:create')
643+
context.can(vol_policies.POLICY_NAME % 'snapshots:create',
644+
target={'project_id': context.project_id})
635645

636646
snapshot = body['snapshot']
637647
volume_id = snapshot['volume_id']

0 commit comments

Comments
 (0)