forked from monash-merc/mytardisfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_api_key
executable file
·37 lines (27 loc) · 1.26 KB
/
my_api_key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# Filename: my_api_key
# Author: James Wettenhall <[email protected]>
# Location: /usr/local/bin/ on MyTardis server
# Description: This script is part of the CVL MyTardis SSHFS mounting prototype.
import sys
import os
import getpass
# This script should be run as user 'mytardis' via sudo. All users have permission
# to run it as sudo without a password, thanks to this line in /etc/sudoers:
# ALL ALL=NOPASSWD: /usr/local/bin/get_owned_and_shared_mytardis_experiment_ids
if getpass.getuser()!="mytardis" or "SUDO_USER" not in os.environ:
print "Usage: sudo -u mytardis /usr/local/bin/my_api_key"
os._exit(1)
sys.path.append("/opt/mytardis/current/")
for egg in os.listdir("/opt/mytardis/current/eggs/"):
sys.path.append("/opt/mytardis/current/eggs/" + egg)
from django.core.management import setup_environ
from tardis import settings
setup_environ(settings)
from tardis.tardis_portal.models import UserAuthentication
from tastypie.models import ApiKey
userAuth = UserAuthentication.objects.get(username=os.environ['SUDO_USER'], \
authenticationMethod='cvl_ldap')
myTardisUser = userAuth.userProfile.user
key = ApiKey.objects.get(user__username=myTardisUser.username)
print "ApiKey " + myTardisUser.username + ":" + str(key.key)