Skip to content

Commit 9a86025

Browse files
committed
Changing KRB5CCNAME to AUTHTOKEN
1 parent ba2844a commit 9a86025

1 file changed

Lines changed: 46 additions & 10 deletions

File tree

bin/stashcp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,45 @@ def doWriteBack(source, destination):
2929
:param str source: The location of the local file
3030
:param str destination: The location of the remote file
3131
"""
32+
start1 = int(time.time()*1000)
3233

33-
# Get the scitoken content
34-
if 'KRB5CCNAME' in os.environ:
34+
# Get the scitoken content
35+
scitoken_file = None
36+
if 'AUTHTOKEN' in os.environ:
3537
# First, try to split the environment variable:
36-
# Format: KRB5CCNAME=FILE:/var/lib/condor/execute/dir_24688/nobody.cc
37-
if ':' in os.environ['KRB5CCNAME']:
38+
# Format: AUTHTOKEN=FILE:/var/lib/condor/execute/dir_24688/nobody.cc
39+
if ':' in os.environ['AUTHTOKEN']:
3840
# Try splitting
39-
scitoken_file = os.environ['KRB5CCNAME'].split(':', 1)
41+
scitoken_file = os.environ['AUTHTOKEN'].split(':', 1)[1]
4042
if not os.path.exists(scitoken_file):
43+
logging.error("Unable to find file %s" % scitoken_file)
4144
scitoken_file = None
4245
if scitoken_file == None:
4346
# Splitting failed, now try just looking at the os.environ:
44-
scitoken_file = os.environ['KRB5CCNAME']
47+
scitoken_file = os.environ['AUTHTOKEN']
4548
if not os.path.exists(scitoken_file):
4649
scitoken_file = None
47-
logging.error("Unable to find SciToken file, environment variable KRB5CCNAME=%s, but file not found" % (os.environ['KRB5CCNAME']))
50+
logging.error("Unable to find SciToken file, environment variable AUTHTOKEN=%s, but file not found" % (os.environ['AUTHTOKEN']))
51+
if scitoken_file == None:
52+
try:
53+
if os.path.exists("%s.cc" % (os.getlogin())):
54+
scitokens_file = "%s.cc" % (os.getlogin())
55+
else:
56+
logging.error("Unable to find scitokens in the current directory")
57+
except OSError as ose:
58+
logging.error("OS error when trying to get login information, possibly running in stashcp. Moving on to globbing for *.cc file")
59+
if scitoken_file == None:
60+
# Look for the cc file with glob
61+
import glob
62+
results = glob.glob("*.cc")
63+
if len(results) > 0:
64+
scitoken_file = results[0]
65+
else:
66+
logging.error("Unable to find scitokens file with glob")
4867
return 1
68+
4969
else:
50-
logging.error("Unable to find SciToken file, environment variable \"KRB5CCNAME\" not found.")
70+
logging.error("Unable to find SciToken file, environment variable \"AUTHTOKEN\" not found.")
5171
return 1
5272

5373
with open(scitoken_file, 'r') as scitoken_obj:
@@ -60,8 +80,24 @@ def doWriteBack(source, destination):
6080
(stdout, stderr) = curl.communicate()
6181
curl_exit=curl.returncode
6282
if curl_exit != 0:
63-
print stdout
64-
print stderr
83+
logging.error(stdout)
84+
logging.error(stderr)
85+
86+
# Send the payload
87+
payload = {
88+
'filename': source,
89+
'sitename': sitename,
90+
'timestamp': end1,
91+
'host': writeback_host,
92+
'upload_size': os.stat(source).st_size,
93+
'status': 'Success',
94+
'tries': 1,
95+
'start1': start1,
96+
'end1': end1,
97+
'cache': 'None',
98+
'writeback': 'True'
99+
}
100+
es_send(payload)
65101
return curl_exit
66102

67103

0 commit comments

Comments
 (0)