~ubuntu-cloud-archive/ubuntu/precise/keystone/trunk

« back to all changes in this revision

Viewing changes to keystone/contrib/ec2/core.py

  • Committer: Chuck Short
  • Date: 2012-11-26 19:24:17 UTC
  • mfrom: (34.1.3 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20121126192417-zqx5ntbbmcduz3wb
* New upstream release for the Ubuntu Cloud Archive.
* debian/tests/test_overrides.conf: Update for Grizzly test suite.
* debian/control: Drop python-nova.
* New upstream release.
* debian/rules: FTBFS if there is a missing binary.
* debian/rules: Temporarily pass the tests since you need to run
  keystone in order to run the tests.
* debian/patches/*: Refrehsed.
* New upstream release.
* debian/control: Ensure keystoneclient is upgraded with keystone,
  require python-keystoneclient >= 1:0.1.3. (LP: #1073273)

Show diffs side-by-side

added added

removed removed

Lines of Context:
168
168
            context=context,
169
169
            user_id=user_ref['id'],
170
170
            tenant_id=tenant_ref['id'])
 
171
 
 
172
        # TODO(termie): optimize this call at some point and put it into the
 
173
        #               the return for metadata
 
174
        # fill out the roles in the metadata
 
175
        roles = metadata_ref.get('roles', [])
 
176
        if not roles:
 
177
            raise exception.Unauthorized(message='User not valid for tenant.')
 
178
        roles_ref = [self.identity_api.get_role(context, role_id)
 
179
                     for role_id in roles]
 
180
 
171
181
        catalog_ref = self.catalog_api.get_catalog(
172
182
            context=context,
173
183
            user_id=user_ref['id'],
180
190
                                    tenant=tenant_ref,
181
191
                                    metadata=metadata_ref))
182
192
 
183
 
        # TODO(termie): optimize this call at some point and put it into the
184
 
        #               the return for metadata
185
 
        # fill out the roles in the metadata
186
 
        roles_ref = []
187
 
        for role_id in metadata_ref.get('roles', []):
188
 
            roles_ref.append(self.identity_api.get_role(context, role_id))
189
 
 
190
193
        # TODO(termie): make this a util function or something
191
194
        # TODO(termie): i don't think the ec2 middleware currently expects a
192
195
        #               full return, but it contains a note saying that it
291
294
            token_ref = self.token_api.get_token(
292
295
                context=context,
293
296
                token_id=context['token_id'])
294
 
        except exception.TokenNotFound:
295
 
            raise exception.Unauthorized()
296
 
        token_user_id = token_ref['user'].get('id')
297
 
        if not token_user_id == user_id:
298
 
            raise exception.Forbidden()
 
297
        except exception.TokenNotFound as e:
 
298
            raise exception.Unauthorized(e)
 
299
 
 
300
        if token_ref['user'].get('id') != user_id:
 
301
            raise exception.Forbidden('Token belongs to another user')
299
302
 
300
303
    def _is_admin(self, context):
301
304
        """Wrap admin assertion error return statement.
321
324
        """
322
325
        cred_ref = self.ec2_api.get_credential(context, credential_id)
323
326
        if not user_id == cred_ref['user_id']:
324
 
            raise exception.Forbidden()
 
327
            raise exception.Forbidden('Credential belongs to another user')
325
328
 
326
329
    def _assert_valid_user_id(self, context, user_id):
327
330
        """Ensure a valid user id.