How to use the dirac.lib.credentials.getUsername function in DIRAC

To help you get started, we’ve selected a few DIRAC examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / SiteGateway.py View on Github external
def __getSelectionData(self):
    callback = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    if len(request.params) > 0:
      tmp = {}
      for i in request.params:
        tmp[i] = str(request.params[i])
      callback["extra"] = tmp
###
    RPC = getRPCClient("ResourceStatus/ResourceStatus")
    result = RPC.getSitesList()
    if result["OK"]:
      tier1 = gConfig.getValue("/Website/PreferredSites")
      if tier1:
        try:
          tier1 = tier1.split(", ")
        except:
          tier1 = list()
      else:
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / PilotSummary.py View on Github external
def __getSelectionData(self):
    callback = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    if len(request.params) > 0:
      tmp = {}
      for i in request.params:
        tmp[i] = str(request.params[i])
      callback["extra"] = tmp
###
    if lhcbUser == "Anonymous":
      callback["site"] = [["Insufficient rights"]]
    else:
      RPC = getRPCClient("WorkloadManagement/JobMonitoring")
      result = RPC.getSites()
      if result["OK"]:
        tier1 = gConfig.getValue("/Website/PreferredSites")
        if tier1:
          try:
            tier1 = tier1.split(", ")
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / Site.py View on Github external
def __getSelectionData(self):
    callback = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    if len(request.params) > 0:
      tmp = {}
      for i in request.params:
        tmp[i] = str(request.params[i])
      callback["extra"] = tmp
    RPC = getRPCClient("WorkloadManagement/WMSAdministrator")
    result = RPC.getSiteMaskSummary()
    gLogger.info("\033[0;31m ++ R ++ \033[0m",result)
    if result["OK"]:
      response = []
      tier1 = list(["LCG.CERN.ch","LCG.CNAF.it","LCG.GRIDKA.de","LCG.IN2P3.fr","LCG.NIKHEF.nl","LCG.PIC.es","LCG.RAL.uk","LCG.SARA.nl"])
      if len(result["Value"])>0:
        site = result["Value"]
#        gLogger.info("=====",initSite)
#        for key in sorted(initSite.iterkeys()):
#        keys = initSite.keys()
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / web / notifications.py View on Github external
def __refresh( self, forceRefresh = False ):
    userName = credentials.getUsername()
    if not forceRefresh and userName in self.__userTimestamp:
      if time.time() - self.__userTimestamp[ userName ] > self.__cacheTime:
        return
    gLogger.info( "Connecting to retrieve notification stats for user %s" % userName )
    ntf = self.getNtfClient()
    result = ntf.getNotifications( {}, [], 0, 0 )
    if not result[ 'OK' ]:
      gLogger.error( "Could not retrieve notifications", "for user %s: %s" % ( userName, result[ 'Message' ] ) )
      self.__stats[ userName ] = { 'totalNots' : 0 }
      self.__userTimestamp[ userName ] = time.time()
      self.__notifications[ userName ] = []
      return
    nots = result[ 'Value' ]
    self.__notifications[ userName ] = nots
    total = len( nots[ 'Records' ] )
    new = []
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / production / ProductionRequest.py View on Github external
def createProductionRequest(self,rdict):
    RPC = getRPCClient( "ProductionManagement/ProductionRequest" )

    rdict['RequestAuthor'] = credentials.getUsername()
    req = self.__fromlocal(rdict)

    result = RPC.createProductionRequest(req);
    return result
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / info / general.py View on Github external
def __sendMessage( self ):
  
    """
    This function is used to send a mail to specific group of DIRAC user
    Expected parameters from request are group, title, body
    """
    
    gLogger.info("Start message broadcasting")

    checkUserCredentials()
    dn = getUserDN()
    if not dn:
      error = "Certificate is not loaded in the browser or DN is absent"
      gLogger.error( "Service response: %s" % error )
      return { "success" : "false" , "error" : error }
    username = getUsername()
    if username == "anonymous":
      error = "Sending an anonymous message is forbidden"
      gLogger.error( "Service response: %s" % error )
      return { "success" : "false" , "error" : error }
    gLogger.info( "DN: %s" % dn )

    email = gConfig.getValue( "/Registry/Users/%s/Email" % username , "" )
    gLogger.debug( "/Registry/Users/%s/Email - '%s'" % ( username , email ) )
    emil = email.strip()
      
    if not email:
      error = "Can't find value for option /Registry/Users/%s/Email" % user
      gLogger.error( "Service response: %s" % error )
      return { "success" : "false" , "error" : error }

    test = [ "group" , "title" , "body" ]
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / jobs / PilotSummary.py View on Github external
def __request(self):
    req = {}
    lhcbGroup = credentials.getSelectedGroup()
    lhcbUser = str(credentials.getUsername())
    global pageNumber
    if request.params.has_key("id") and len(request.params["id"]) > 0:
      pageNumber = 0
      req["JobID"] = str(request.params["id"])
    elif request.params.has_key("expand") and len(request.params["expand"]) > 0:
      globalSort = [["GridSite","ASC"]]
      numberOfJobs = 500
      pageNumber = 0
      req["ExpandSite"] = str(request.params["expand"])
    else:
      result = gConfig.getOption("/Website/ListSeparator")
      if result["OK"]:
        separator = result["Value"]
      else:
        separator = ":::"
      pageNumber = 0
github DIRACGrid / -obsolete-DIRACWeb / dirac / controllers / info / general.py View on Github external
  @jsonify
  def proxyUpload(self):
    """
    Get p12 file and passwords as input. Split p12 to user key and certificate
    and creating proxy for groups user belongs to. Upload proxy to proxy store
    """
    # Otherwise the browser would offer to download a file
    response.headers['Content-type'] = "text/html"
    username = getUsername()
    gLogger.info("Start upload proxy out of p12 for user: %s" % (username))
    disclaimer  = "\nNo proxy was created\nYour private info was safely deleted"
    disclaimer  = disclaimer + " from DIRAC service"
    if username == "anonymous":
      error = "Please, send a registration request first"
      gLogger.error("Anonymous is not allowed")
      gLogger.debug("Service response: %s" % error)
      return {"success":"false","error":error}
    groupList = getAvailableGroups()
    groups = ", ".join(groupList)
    gLogger.info("Available groups for the user %s: %s" % (username,groups))
    if not len(groupList) > 0:
      gLogger.error("User is not registered in any group")
      error = "Seems that user %s is not register in any group" % username
      error = error + disclaimer
      gLogger.debug("Service response: %s" % error)