Merge branch 'git-commit-debug' of https://github.com/wtsi-hgi/arvados
[arvados.git] / sdk / pam / arvados_pam.py
index 84eef244cbe14f3bef29106881b27eee6b247038..b38e54f0460bdad0f004584d5cc0fcd6be88afec 100644 (file)
@@ -14,25 +14,31 @@ def auth_log(msg):
 
 def check_arvados_token(requested_username, token):
     auth_log("%s %s" % (requested_username, token))
-    ARVADOS_API_HOST='4xphq.arvadosapi.com' ## FIXME replace with puppet
-    # BUG: hostname stored on the API is just "foo.shell", not "foo.shell.zzzzz.arvadosapi.com"!
-    my_hostname='shell' ## FIXME replace with puppet
 
     try:
-       arv = arvados.api('v1',host=ARVADOS_API_HOST, token=token, cache=None)
+        f=file('/etc/default/arvados_pam')
+        config=dict([l.split('=') for l in f.readlines() if not l.startswith('#') or l.strip()==""])
+        arvados_api_host=config['ARVADOS_API_HOST'].strip()
+        hostname=config['HOSTNAME'].strip()
     except Exception as e:
-       auth_log(str(e))
-       return False
+        auth_log("problem getting default values  %s" % e)
+        return False
+
+    try:
+        arv = arvados.api('v1',host=arvados_api_host, token=token, cache=None)
+    except Exception as e:
+        auth_log(str(e))
+        return False
 
     try:
-       matches = arv.virtual_machines().list(filters=[['hostname','=',my_hostname]]).execute()['items']
+        matches = arv.virtual_machines().list(filters=[['hostname','=',hostname]]).execute()['items']
     except Exception as e:
-       auth_log(str(e))
-       return False
+        auth_log(str(e))
+        return False
 
 
     if len(matches) != 1:
-        auth_log("libpam_arvados could not dertermine vm uuid for '%s'" % my_hostname)
+        auth_log("libpam_arvados could not determine vm uuid for '%s'" % hostname)
         return False
 
     this_vm_uuid = matches[0]['uuid']