示例#1
0
 def validate_alarm(alarm):
     project = v2_utils.get_auth_project(
         alarm.project_id if alarm.project_id != wtypes.Unset else None)
     for id in alarm.combination_rule.alarm_ids:
         alarms = list(pecan.request.storage.get_alarms(
             alarm_id=id, project=project))
         if not alarms:
             raise base.AlarmNotFound(id, project)
示例#2
0
文件: alarms.py 项目: sileht/aodh
 def _alarm(self):
     self.conn = pecan.request.alarm_storage_conn
     auth_project = rbac.get_limited_to_project(pecan.request.headers,
                                                pecan.request.enforcer)
     alarms = list(
         self.conn.get_alarms(alarm_id=self._id, project=auth_project))
     if not alarms:
         raise base.AlarmNotFound(alarm=self._id, auth_project=auth_project)
     return alarms[0]
示例#3
0
文件: alarms.py 项目: amar266/aodh
 def _enforce_rbac(self, rbac_directive):
     # TODO(sileht): We should be able to relax this since we
     # pass the alarm object to the enforcer.
     auth_project = rbac.get_limited_to_project(pecan.request.headers,
                                                pecan.request.enforcer)
     alarms = list(
         pecan.request.storage.get_alarms(alarm_id=self._id,
                                          project=auth_project))
     if not alarms:
         raise base.AlarmNotFound(alarm=self._id, auth_project=auth_project)
     alarm = alarms[0]
     target = {'user_id': alarm.user_id, 'project_id': alarm.project_id}
     rbac.enforce(rbac_directive, pecan.request.headers,
                  pecan.request.enforcer, target)
     return alarm
示例#4
0
文件: alarms.py 项目: yi-cloud/aodh
    def _enforce_rbac(self, rbac_directive):
        auth_project = pecan.request.headers.get('X-Project-Id')

        filters = {'alarm_id': self._id}
        if not rbac.is_admin(pecan.request.headers):
            filters['project_id'] = auth_project

        alarms = pecan.request.storage.get_alarms(**filters)
        if not alarms:
            raise base.AlarmNotFound(alarm=self._id, auth_project=None)

        alarm = alarms[0]
        target = {'user_id': alarm.user_id, 'project_id': alarm.project_id}
        rbac.enforce(rbac_directive, pecan.request.headers,
                     pecan.request.enforcer, target)
        return alarm