Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:18

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2017-2019
0009 
0010 from pilot.util.container import execute
0011 
0012 import logging
0013 logger = logging.getLogger(__name__)
0014 
0015 
0016 def get_distinguished_name():
0017     """
0018     Get the user DN.
0019     Note: the DN is also sent by the server to the pilot in the job description (produserid).
0020 
0021     :return: User DN (string).
0022     """
0023 
0024     dn = ""
0025     executable = 'arcproxy -i subject'
0026     exit_code, stdout, stderr = execute(executable)
0027     if exit_code != 0 or "ERROR:" in stderr:
0028         logger.warning("arcproxy failed: ec=%d, stdout=%s, stderr=%s" % (exit_code, stdout, stderr))
0029 
0030         if "command not found" in stderr or "Can not find certificate file" in stderr:
0031             logger.warning("arcproxy experienced a problem (will try voms-proxy-info instead)")
0032 
0033             # Default to voms-proxy-info
0034             executable = 'voms-proxy-info -subject'
0035             exit_code, stdout, stderr = execute(executable)
0036 
0037     if exit_code == 0:
0038         dn = stdout
0039         logger.info('DN = %s' % dn)
0040         cn = "/CN=proxy"
0041         if not dn.endswith(cn):
0042             logger.info("DN does not end with %s (will be added)" % cn)
0043             dn += cn
0044 
0045     else:
0046         logger.warning("user=self set but cannot get proxy: %d, %s" % (exit_code, stdout))
0047 
0048     return dn