@@ -31,23 +31,58 @@ def getCommandOutput(command):
3131 return data
3232
3333##############################################
34- def getFCSR () :
34+ def getCerts () -> str :
3535##############################################
36- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun" ])
36+ cert_path = os .getenv ('X509_USER_CERT' , '' )
37+ key_path = os .getenv ('X509_USER_KEY' , '' )
38+
39+ certs = ""
40+ if cert_path :
41+ certs += f' --cert { cert_path } '
42+ else :
43+ print ("No certificate, nor proxy provided for Tier0 access" )
44+ if key_path :
45+ certs += f' --key { key_path } '
46+ return certs
47+
48+ ##############################################
49+ def build_curl_command (url , proxy = "" , certs = "" , timeout = 30 , retries = 3 , user_agent = "MyUserAgent" ):
50+ ##############################################
51+ """Builds the curl command with the appropriate proxy, certs, and options."""
52+ cmd = f'/usr/bin/curl -k -L --user-agent "{ user_agent } " '
53+
54+ if proxy :
55+ cmd += f'--proxy { proxy } '
56+ else :
57+ cmd += f'{ certs } '
58+
59+ cmd += f'--connect-timeout { timeout } --retry { retries } { url } '
60+ return cmd
61+
62+ ##############################################
63+ def getFCSR (proxy = "" , certs = "" ):
64+ ##############################################
65+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/firstconditionsaferun"
66+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
67+ out = subprocess .check_output (cmd , shell = True )
3768 response = json .loads (out )["result" ][0 ]
3869 return int (response )
3970
4071##############################################
41- def getPromptGT ():
72+ def getPromptGT (proxy = "" , certs = "" ):
4273##############################################
43- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config" ])
74+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/reco_config"
75+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
76+ out = subprocess .check_output (cmd , shell = True )
4477 response = json .loads (out )["result" ][0 ]['global_tag' ]
4578 return response
4679
4780##############################################
48- def getExpressGT ():
81+ def getExpressGT (proxy = "" , certs = "" ):
4982##############################################
50- out = subprocess .check_output (["curl" , "-k" , "-s" , "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config" ])
83+ url = "https://cmsweb.cern.ch/t0wmadatasvc/prod/express_config"
84+ cmd = build_curl_command (url , proxy = proxy , certs = certs )
85+ out = subprocess .check_output (cmd , shell = True )
5186 response = json .loads (out )["result" ][0 ]['global_tag' ]
5287 return response
5388
@@ -68,13 +103,33 @@ def getExpressGT():
68103 default = - 1 ,
69104 help = 'sinces to copy from validation tag' ,
70105 )
71-
106+
107+ parser .add_option ('-p' , '--proxy' ,
108+ dest = 'proxy' ,
109+ default = "" ,
110+ help = 'proxy to use for curl requests' ,
111+ )
112+
113+ parser .add_option ('-u' , '--user-mode' ,
114+ dest = 'user_mode' ,
115+ action = 'store_true' ,
116+ default = False ,
117+ help = 'Enable user mode with specific X509 user certificate and key' )
118+
72119 (options , arguments ) = parser .parse_args ()
73120
121+ if options .user_mode :
122+ os .environ ['X509_USER_KEY' ] = os .path .expanduser ('~/.globus/userkey.pem' )
123+ os .environ ['X509_USER_CERT' ] = os .path .expanduser ('~/.globus/usercert.pem' )
124+ print ("User mode enabled. Using X509_USER_KEY and X509_USER_CERT from ~/.globus/" )
125+
126+ certs = ""
127+ if not options .proxy :
128+ certs = getCerts ()
74129
75- FCSR = getFCSR ()
76- promptGT = getPromptGT ()
77- expressGT = getExpressGT ()
130+ FCSR = getFCSR (proxy = options . proxy , certs = certs )
131+ promptGT = getPromptGT (proxy = options . proxy , certs = certs )
132+ expressGT = getExpressGT (proxy = options . proxy , certs = certs )
78133 print ("Current FCSR:" ,FCSR ,"| Express Global Tag" ,expressGT ,"| Prompt Global Tag" ,promptGT )
79134
80135 con = conddb .connect (url = conddb .make_url ("pro" ))
0 commit comments