Пример #1
0
 def getEmail(self, dn):
     # get DN
     _logger.debug("getDN for %s" % dn)
     dbProxy = DBProxy()
     distinguishedName = dbProxy.cleanUserID(dn)
     _logger.debug("DN = %s" % distinguishedName)
     if distinguishedName == "":
         _logger.error("cannot get DN for %s" % dn)
         return ""
     # get email from MetaDB
     mailAddrInDB, dbUptime = self.taskBuffer.getEmailAddr(
         distinguishedName, withUpTime=True)
     _logger.debug("email in MetaDB : '%s'" % mailAddrInDB)
     notSendMail = False
     if mailAddrInDB not in [None, '']:
         # email mortification is suppressed
         if mailAddrInDB.split(':')[0] == 'notsend':
             notSendMail = True
     # avoid too frequently lookup
     if dbUptime is not None and datetime.datetime.utcnow(
     ) - dbUptime < datetime.timedelta(hours=1):
         _logger.debug("no lookup")
         if notSendMail or mailAddrInDB in [None, '']:
             return 'notsend'
         else:
             return mailAddrInDB.split(':')[-1]
     # get email from DQ2
     try:
         tmpStatus, userInfo = rucioAPI.finger(dn)
         if tmpStatus:
             mailAddr = userInfo['email']
             _logger.debug("email from DDM : '%s'" % mailAddr)
         else:
             mailAddr = None
             _logger.error(
                 "failed to get email from DDM : {}".format(userInfo))
         if mailAddr is None:
             mailAddr = ''
         # make email field to update DB
         mailAddrToDB = ''
         if notSendMail:
             mailAddrToDB += 'notsend:'
         mailAddrToDB += mailAddr
         # update database
         _logger.debug("update email for %s to %s" %
                       (distinguishedName, mailAddrToDB))
         self.taskBuffer.setEmailAddr(distinguishedName, mailAddrToDB)
         if notSendMail:
             return 'notsend'
         return mailAddr
     except Exception as e:
         _logger.error("getEmail failed with {} {}".format(
             str(e), traceback.format_exc()))
     return ""
Пример #2
0
 def getEmail(self, dn):
     # get DN
     _logger.debug("getDN for %s" % dn)
     dbProxy = DBProxy()
     distinguishedName = dbProxy.cleanUserID(dn)
     _logger.debug("DN = %s" % distinguishedName)
     if distinguishedName == "":
         _logger.error("cannot get DN for %s" % dn)
         return ""
     # get email from MetaDB
     mailAddrInDB, dbUptime = self.taskBuffer.getEmailAddr(
         distinguishedName, withUpTime=True)
     _logger.debug("email in MetaDB : '%s'" % mailAddrInDB)
     notSendMail = False
     if mailAddrInDB not in [None, '']:
         # email mortification is suppressed
         if mailAddrInDB.split(':')[0] == 'notsend':
             notSendMail = True
     # avoid too frequently lookup
     if dbUptime is not None and datetime.datetime.utcnow(
     ) - dbUptime < datetime.timedelta(hours=1):
         _logger.debug("no lookup")
         if notSendMail or mailAddrInDB in [None, '']:
             return 'notsend'
         else:
             return mailAddrInDB.split(':')[-1]
     # get email from DQ2
     realDN = re.sub('/CN=limited proxy', '', dn)
     realDN = re.sub('(/CN=proxy)+', '', realDN)
     try:
         tmpStatus, userInfo = rucioAPI.finger(realDN)
         mailAddr = userInfo['email']
         _logger.debug("email from DDM : '%s'" % mailAddr)
         if mailAddr is None:
             mailAddr = ''
         # make email field to update DB
         mailAddrToDB = ''
         if notSendMail:
             mailAddrToDB += 'notsend:'
         mailAddrToDB += mailAddr
         # update database
         _logger.debug("update email for %s to %s" %
                       (distinguishedName, mailAddrToDB))
         self.taskBuffer.setEmailAddr(distinguishedName, mailAddrToDB)
         if notSendMail:
             return 'notsend'
         return mailAddr
     except Exception:
         errType, errValue = sys.exc_info()[:2]
         _logger.error("%s %s" % (errType, errValue))
     return ""