Exemplo n.º 1
0
    def _getUserEmails(self):

        policyActions = RssConfiguration.getPolicyActions()
        if not policyActions['OK']:
            return policyActions
        try:
            notificationGroups = policyActions['Value'][
                self.actionName]['notificationGroups']
        except KeyError:
            return S_ERROR('%s/notificationGroups not found' % self.actionName)

        notifications = RssConfiguration.getNotifications()
        if not notifications['OK']:
            return notifications
        notifications = notifications['Value']

        userEmails = []

        for notificationGroupName in notificationGroups:
            try:
                userEmails.extend(
                    notifications[notificationGroupName]['users'])
            except KeyError:
                gLogger.error('%s not present' % notificationGroupName)

        return S_OK(userEmails)
Exemplo n.º 2
0
 def __getPolicyActionsThatApply( decisionParams ):
   '''
     Method that matches the input dictionary with the policy actions 
     configuration in the CS. It returns a list of policy actions names that 
     matched.
   '''
   
   policyActionsThatApply = []
   
   # Get policies configuration metadata from CS.
   policyActionsConfig = RssConfiguration.getPolicyActions()
   if not policyActionsConfig[ 'OK' ]:
     return policyActionsConfig
   policyActionsConfig = policyActionsConfig[ 'Value' ]
   
   # Get policies that match the given decissionParameters
   for policyActionName, policyActionConfig in policyActionsConfig.items():
     policyMatch = Utils.configMatch( decisionParams, policyActionConfig )
     if policyMatch:
       policyActionsThatApply.append( policyActionName )
              
   return S_OK( policyActionsThatApply )
Exemplo n.º 3
0
  def _getUserEmails( self ):

    policyActions = RssConfiguration.getPolicyActions()
    if not policyActions[ 'OK' ]:
      return policyActions
    try:
      notificationGroups = policyActions[ 'Value' ][ self.actionName ][ 'notificationGroups' ]
    except KeyError:
      return S_ERROR( '%s/notificationGroups not found' % self.actionName )  
    
    notifications = RssConfiguration.getNotifications()
    if not notifications[ 'OK' ]:
      return notifications
    notifications = notifications[ 'Value' ]  

    userEmails = []
    
    for notificationGroupName in notificationGroups:
      try:
        userEmails.extend( notifications[ notificationGroupName ][ 'users' ] ) 
      except KeyError:
        gLogger.error( '%s not present' % notificationGroupName )

    return S_OK( userEmails )
Exemplo n.º 4
0
    def __getPolicyActionsThatApply2(decissionParams, singlePolicyResults,
                                     policyCombinedResults):
        '''
      Method that matches the input dictionary with the policy actions 
      configuration in the CS. It returns a list of policy actions names that 
      matched.
    '''

        policyActionsThatApply = []

        # Get policies configuration metadata from CS.
        policyActionsConfig = RssConfiguration.getPolicyActions()
        if not policyActionsConfig['OK']:
            return policyActionsConfig
        policyActionsConfig = policyActionsConfig['Value']

        # Let's create a dictionary to use it with configMatch
        policyResults = {}
        for policyResult in singlePolicyResults:
            try:
                policyResults[policyResult['Policy']
                              ['name']] = policyResult['Status']
            except KeyError:
                continue

        # Get policies that match the given decissionParameters
        for policyActionName, policyActionConfig in policyActionsConfig.items(
        ):

            # The parameter policyType is mandatory. If not present, we pick policyActionName
            try:
                policyActionType = policyActionConfig['actionType'][0]
            except KeyError:
                policyActionType = policyActionName
                #continue

            # We get matchParams to be compared against decissionParams
            policyActionMatchParams = policyActionConfig.get('matchParams', {})
            policyMatch = Utils.configMatch(decissionParams,
                                            policyActionMatchParams)
            #policyMatch = Utils.configMatch( decissionParams, policyActionConfig )
            if not policyMatch:
                continue

            # Let's check single policy results
            # Assumed structure:
            # ...
            # policyResults
            # <PolicyName> = <PolicyResult1>,<PolicyResult2>...
            policyActionPolicyResults = policyActionConfig.get(
                'policyResults', {})
            policyResultsMatch = Utils.configMatch(policyResults,
                                                   policyActionPolicyResults)
            if not policyResultsMatch:
                continue

            # combinedResult
            # \Status = X,Y
            # \Reason = asdasd,asdsa
            policyActionCombinedResult = policyActionConfig.get(
                'combinedResult', {})
            policyCombinedMatch = Utils.configMatch(
                policyCombinedResults, policyActionCombinedResult)
            if not policyCombinedMatch:
                continue

            #policyActionsThatApply.append( policyActionName )
            # They may not be necessarily the same
            policyActionsThatApply.append((policyActionName, policyActionType))

        return S_OK(policyActionsThatApply)
Exemplo n.º 5
0
 def __getPolicyActionsThatApply2( decisionParams, singlePolicyResults,
                                   policyCombinedResults ):
   '''
     Method that matches the input dictionary with the policy actions 
     configuration in the CS. It returns a list of policy actions names that 
     matched.
   '''
   
   policyActionsThatApply = []
   
   # Get policies configuration metadata from CS.
   policyActionsConfig = RssConfiguration.getPolicyActions()
   if not policyActionsConfig[ 'OK' ]:
     return policyActionsConfig
   policyActionsConfig = policyActionsConfig[ 'Value' ]
   
   # Let's create a dictionary to use it with configMatch
   policyResults = {}
   for policyResult in singlePolicyResults:
     try:
       policyResults[ policyResult[ 'Policy' ][ 'name' ] ] = policyResult[ 'Status' ]
     except KeyError:
       continue
   
   # Get policies that match the given decissionParameters
   for policyActionName, policyActionConfig in policyActionsConfig.items():
     
     # The parameter policyType is mandatory. If not present, we pick policyActionName
     try:
       policyActionType = policyActionConfig[ 'actionType' ][ 0 ]
     except KeyError:
       policyActionType = policyActionName
       #continue
     
     # We get matchParams to be compared against decisionParams
     policyActionMatchParams = policyActionConfig.get( 'matchParams', {} )
     policyMatch = Utils.configMatch( decisionParams, policyActionMatchParams )
     # policyMatch = Utils.configMatch( decisionParams, policyActionConfig )
     if not policyMatch:
       continue
   
     # Let's check single policy results
     # Assumed structure:
     # ...
     # policyResults
     # <PolicyName> = <PolicyResult1>,<PolicyResult2>...
     policyActionPolicyResults = policyActionConfig.get( 'policyResults', {} )
     policyResultsMatch = Utils.configMatch( policyResults, policyActionPolicyResults )
     if not policyResultsMatch:
       continue
     
     # combinedResult
     # \Status = X,Y
     # \Reason = asdasd,asdsa
     policyActionCombinedResult = policyActionConfig.get( 'combinedResult', {} )
     policyCombinedMatch = Utils.configMatch( policyCombinedResults, policyActionCombinedResult )
     if not policyCombinedMatch:
       continue
           
     #policyActionsThatApply.append( policyActionName )
     # They may not be necessarily the same
     policyActionsThatApply.append( ( policyActionName, policyActionType ) )    
     
   return S_OK( policyActionsThatApply )
Exemplo n.º 6
0
 def getPolicyActionsThatApply( self, decisionParams, singlePolicyResults, policyCombinedResults ):
   """ Method that returns the actions to be triggered based on the original 
   decision parameters ( decisionParams ), which also can apply to the method
   `getPoliciesThatApply`, each one of the policy results ( singlePolicyResults )
   and the combined policy results ( policyCombinedResults ) as computed on the `PDP`.
   
   examples:
     >>> iGetter.getPolicyActionsThatApply( { 'name' : 'SiteA' },[],{} )[ 'Value' ]
         [ ( 'BanSiteA', 'BanSite' ) ]
     >>> iGetter.getPolicyActionsThatApply( { 'name' : 'SiteA' },[],
                                            { 'Status' : 'Active', 'Reason' : 'Blah' } )[ 'Value' ]
         [ ( 'BanSiteA', 'BanSite' ), ( 'EmailActive2Banned', 'EmailAction' ) ]    
     
   :Parameters:
     **decisionParams** - `dict`  
       dictionary with the parameters to match policies ( and actions in this case )
     **singlePolicyResults** - `list( dict )`
       list containing the dictionaries returned by the policies evaluated
     **policyCombinedResults** - `dict`
       dictionary containing the combined result of the policies evaluation
   
   :return: S_OK( list ) / S_ERROR
       
   """
   
   policyActionsThatApply = []
   
   # Get policies configuration metadata from CS.
   policyActionsConfig = RssConfiguration.getPolicyActions()
   if not policyActionsConfig[ 'OK' ]:
     return policyActionsConfig
   policyActionsConfig = policyActionsConfig[ 'Value' ]
   
   # Let's create a dictionary to use it with configMatch
   policyResults = self._getPolicyResults( singlePolicyResults )
   
   # Get policies that match the given decissionParameters
   for policyActionName, policyActionConfig in policyActionsConfig.iteritems():
     
     # The parameter policyType is mandatory. If not present, we pick policyActionName
     try:
       policyActionType = policyActionConfig[ 'actionType' ][ 0 ]
     except KeyError:
       policyActionType = policyActionName
     
     # We get matchParams to be compared against decissionParams
     policyActionMatchParams = policyActionConfig.get( 'matchParams', {} )
     if not Utils.configMatch( decisionParams, policyActionMatchParams ):
       continue
   
     # Let's check single policy results
     # Assumed structure:
     # ...
     # policyResults
     # <PolicyName> = <PolicyResult1>,<PolicyResult2>...
     policyActionPolicyResults = policyActionConfig.get( 'policyResults', {} )
     if not Utils.configMatch( policyResults, policyActionPolicyResults ):
       continue
     
     # combinedResult
     # \Status = X,Y
     # \Reason = asdasd,asdsa
     policyActionCombinedResult = policyActionConfig.get( 'combinedResult', {} )
     if not Utils.configMatch( policyCombinedResults, policyActionCombinedResult ):
       continue
           
     # They may not be necessarily the same
     policyActionsThatApply.append( ( policyActionName, policyActionType ) )    
     
   return S_OK( policyActionsThatApply )