1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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")
|