소스 검색

gMerge branch 'master' of wiscigt.powertheword.com:andrej.studen/labkeyinterface

Andrej Studen/Merlin 4 년 전
부모
커밋
312d058d2c
1개의 변경된 파일68개의 추가작업 그리고 0개의 파일을 삭제
  1. 68 0
      pythonScripts/loadCertificatesFromZip.py

+ 68 - 0
pythonScripts/loadCertificatesFromZip.py

@@ -0,0 +1,68 @@
+import sys
+import os
+import pathlib
+import zipfile
+import json
+
+if len(sys.argv)<2:
+    print("Use {}/scripts/runPython.sh {} file.zip".\
+            format(os.path.expanduser('~'),sys.argv[0]))
+    sys.exit(0)
+
+scriptPath=pathlib.Path(__file__)
+upOne=str(scriptPath.parents[1])
+
+sys.path.insert(0,upOne)
+import labkeyInterface
+
+setupDir=os.path.join(os.path.expanduser('~'),'.labkey')
+if not os.path.isdir(setupDir):
+    os.mkdir(setupDir)
+
+zpath=pathlib.Path(sys.argv[1])
+user=zpath.stem
+userDir=os.path.join(setupDir,user)
+
+if not os.path.isdir(userDir):
+    os.mkdir(userDir)
+
+#unzip .key, and .crt files to userDir
+caName=None
+with zipfile.ZipFile(sys.argv[1],'r') as zipObj:
+    zipObj.extract(user+'.crt',userDir)
+    zipObj.extract(user+'.key',userDir)
+    zipList=zipObj.namelist()
+    for f in zipList:
+        if f.find('CA')>-1:
+            caName=f
+            zipObj.extract(f,userDir)
+
+#create and dump a config object
+SSLconfig={}
+SSLconfig['user']=os.path.join(userDir,user+'.crt')
+SSLconfig['key']=os.path.join(userDir,user+'.key')
+SSLconfig['ca']=os.path.join(userDir,caName)
+connectionConfig={}
+connectionConfig['SSL']=SSLconfig
+connectionConfig['host']='https://merlin.fmf.uni-lj.si'
+labkeyConfig={}
+labkeyConfig['user']='guest'
+labkeyConfig['password']='notUsed'
+connectionConfig['labkey']=labkeyConfig
+
+#generate a testNetwork.json file
+nfile=os.path.join(setupDir,'testNetwork.json')
+with open(nfile,'w') as f:
+    json.dump(connectionConfig,f,indent=3)
+
+
+net=labkeyInterface.labkeyInterface()
+net.init(nfile)
+csrf=net.getCSRF()
+if csrf==None:
+    print("Failed")
+else:
+    print("Success: {}".format(csrf))
+
+print("Done")
+