diff options
Diffstat (limited to 'asdctool/src/main/resources/scripts/python/user/exportUsers.py')
-rw-r--r-- | asdctool/src/main/resources/scripts/python/user/exportUsers.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/asdctool/src/main/resources/scripts/python/user/exportUsers.py b/asdctool/src/main/resources/scripts/python/user/exportUsers.py index e32a3b0a21..9e695ad8fd 100644 --- a/asdctool/src/main/resources/scripts/python/user/exportUsers.py +++ b/asdctool/src/main/resources/scripts/python/user/exportUsers.py @@ -4,17 +4,17 @@ from StringIO import StringIO import json -################################################################################################################################################ -# # -# Export all active users to file - for 1602+ # -# # -# activation : # -# python exportUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ] # -# # -# shortest activation (be host = localhost, be port = 8080): # # -# python exportUsers.py [-f <output file> | --ofile=<output file> ] # -# # -################################################################################################################################################ +#################################################################################################################################################################################### +# # +# Export all active users to file - for 1602+ # +# # +# activation : # +# python exportUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # +# python exportUsers.py [-f <output file> | --ofile=<output file> ] # +# # +#################################################################################################################################################################################### ALL_USERS_SUFFIX = '/sdc2/rest/v1/user/users' @@ -25,19 +25,23 @@ def errorAndExit(errorCode, errorDesc): print("status=" + str(errorCode)) sys.exit(errorCode) -def getUsers(beHost, bePort, adminUser): +def getUsers(scheme, beHost, bePort, adminUser): try: buffer = StringIO() c = pycurl.Curl() - url = 'http://' + beHost + ':' + bePort + ALL_USERS_SUFFIX + url = scheme + '://' + beHost + ':' + bePort + ALL_USERS_SUFFIX print(url) c.setopt(c.URL, url) c.setopt(c.WRITEFUNCTION, buffer.write) #c.setopt(c.WRITEFUNCTION, lambda x: None) adminHeader = 'USER_ID: ' + adminUser c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader]) + + if scheme == 'https': + c.setopt(c.SSL_VERIFYPEER, 0) + res = c.perform() #print(res) @@ -63,7 +67,7 @@ def getUsers(beHost, bePort, adminUser): def usage(): - print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ]' + print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ]' def main(argv): print 'Number of arguments:', len(sys.argv), 'arguments.' @@ -72,9 +76,10 @@ def main(argv): beHost = 'localhost' bePort = '8080' outputfile = None + scheme = 'http' try: - opts, args = getopt.getopt(argv,"i:p:f:h:",["ip=","port=","ofile="]) + opts, args = getopt.getopt(argv,"i:p:f:h:s:",["ip=","port=","ofile=","scheme="]) except getopt.GetoptError: usage() errorAndExit(2, 'Invalid input') @@ -90,14 +95,16 @@ def main(argv): bePort = arg elif opt in ("-f", "--ofile"): outputfile = arg + elif opt in ("-s", "--scheme"): + scheme = arg - print 'be host =',beHost,', be port =', bePort,', output file =',outputfile + print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', output file =',outputfile if ( outputfile == None ): usage() sys.exit(3) - users = getUsers(beHost, bePort, adminHeader) + users = getUsers(scheme, beHost, bePort, adminHeader) error = users[1] body = users[0] |