| #!/usr/bin/env python |
| # |
| # Autogenerated by Thrift Compiler (0.18.1) |
| # |
| # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
| # |
| # options string: py |
| # |
| |
| import sys |
| import pprint |
| if sys.version_info[0] > 2: |
| from urllib.parse import urlparse |
| else: |
| from urlparse import urlparse |
| from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient |
| from thrift.protocol.TBinaryProtocol import TBinaryProtocol |
| |
| from airavata.api.credential.store import CredentialStoreService |
| from airavata.api.credential.store.ttypes import * |
| |
| if len(sys.argv) <= 1 or sys.argv[1] == '--help': |
| print('') |
| print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]') |
| print('') |
| print('Functions:') |
| print(' CredentialSummary getCredentialSummary(string tokenId, string gatewayId)') |
| print(' getAllCredentialSummaries(SummaryType type, accessibleTokenIds, string gatewayId)') |
| print(' string addSSHCredential(SSHCredential sshCredential)') |
| print(' string addCertificateCredential(CertificateCredential certificateCredential)') |
| print(' string addPasswordCredential(PasswordCredential passwordCredential)') |
| print(' SSHCredential getSSHCredential(string tokenId, string gatewayId)') |
| print(' CertificateCredential getCertificateCredential(string tokenId, string gatewayId)') |
| print(' PasswordCredential getPasswordCredential(string tokenId, string gatewayId)') |
| print(' getAllCredentialSummaryForGateway(SummaryType type, string gatewayId)') |
| print(' getAllCredentialSummaryForUserInGateway(SummaryType type, string gatewayId, string userId)') |
| print(' getAllPWDCredentialsForGateway(string gatewayId)') |
| print(' bool deleteSSHCredential(string tokenId, string gatewayId)') |
| print(' bool deletePWDCredential(string tokenId, string gatewayId)') |
| print(' string getAPIVersion()') |
| print('') |
| sys.exit(0) |
| |
| pp = pprint.PrettyPrinter(indent=2) |
| host = 'localhost' |
| port = 9090 |
| uri = '' |
| framed = False |
| ssl = False |
| validate = True |
| ca_certs = None |
| keyfile = None |
| certfile = None |
| http = False |
| argi = 1 |
| |
| if sys.argv[argi] == '-h': |
| parts = sys.argv[argi + 1].split(':') |
| host = parts[0] |
| if len(parts) > 1: |
| port = int(parts[1]) |
| argi += 2 |
| |
| if sys.argv[argi] == '-u': |
| url = urlparse(sys.argv[argi + 1]) |
| parts = url[1].split(':') |
| host = parts[0] |
| if len(parts) > 1: |
| port = int(parts[1]) |
| else: |
| port = 80 |
| uri = url[2] |
| if url[4]: |
| uri += '?%s' % url[4] |
| http = True |
| argi += 2 |
| |
| if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed': |
| framed = True |
| argi += 1 |
| |
| if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl': |
| ssl = True |
| argi += 1 |
| |
| if sys.argv[argi] == '-novalidate': |
| validate = False |
| argi += 1 |
| |
| if sys.argv[argi] == '-ca_certs': |
| ca_certs = sys.argv[argi+1] |
| argi += 2 |
| |
| if sys.argv[argi] == '-keyfile': |
| keyfile = sys.argv[argi+1] |
| argi += 2 |
| |
| if sys.argv[argi] == '-certfile': |
| certfile = sys.argv[argi+1] |
| argi += 2 |
| |
| cmd = sys.argv[argi] |
| args = sys.argv[argi + 1:] |
| |
| if http: |
| transport = THttpClient.THttpClient(host, port, uri) |
| else: |
| if ssl: |
| socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile) |
| else: |
| socket = TSocket.TSocket(host, port) |
| if framed: |
| transport = TTransport.TFramedTransport(socket) |
| else: |
| transport = TTransport.TBufferedTransport(socket) |
| protocol = TBinaryProtocol(transport) |
| client = CredentialStoreService.Client(protocol) |
| transport.open() |
| |
| if cmd == 'getCredentialSummary': |
| if len(args) != 2: |
| print('getCredentialSummary requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.getCredentialSummary(args[0], args[1],)) |
| |
| elif cmd == 'getAllCredentialSummaries': |
| if len(args) != 3: |
| print('getAllCredentialSummaries requires 3 args') |
| sys.exit(1) |
| pp.pprint(client.getAllCredentialSummaries(eval(args[0]), eval(args[1]), args[2],)) |
| |
| elif cmd == 'addSSHCredential': |
| if len(args) != 1: |
| print('addSSHCredential requires 1 args') |
| sys.exit(1) |
| pp.pprint(client.addSSHCredential(eval(args[0]),)) |
| |
| elif cmd == 'addCertificateCredential': |
| if len(args) != 1: |
| print('addCertificateCredential requires 1 args') |
| sys.exit(1) |
| pp.pprint(client.addCertificateCredential(eval(args[0]),)) |
| |
| elif cmd == 'addPasswordCredential': |
| if len(args) != 1: |
| print('addPasswordCredential requires 1 args') |
| sys.exit(1) |
| pp.pprint(client.addPasswordCredential(eval(args[0]),)) |
| |
| elif cmd == 'getSSHCredential': |
| if len(args) != 2: |
| print('getSSHCredential requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.getSSHCredential(args[0], args[1],)) |
| |
| elif cmd == 'getCertificateCredential': |
| if len(args) != 2: |
| print('getCertificateCredential requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.getCertificateCredential(args[0], args[1],)) |
| |
| elif cmd == 'getPasswordCredential': |
| if len(args) != 2: |
| print('getPasswordCredential requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.getPasswordCredential(args[0], args[1],)) |
| |
| elif cmd == 'getAllCredentialSummaryForGateway': |
| if len(args) != 2: |
| print('getAllCredentialSummaryForGateway requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.getAllCredentialSummaryForGateway(eval(args[0]), args[1],)) |
| |
| elif cmd == 'getAllCredentialSummaryForUserInGateway': |
| if len(args) != 3: |
| print('getAllCredentialSummaryForUserInGateway requires 3 args') |
| sys.exit(1) |
| pp.pprint(client.getAllCredentialSummaryForUserInGateway(eval(args[0]), args[1], args[2],)) |
| |
| elif cmd == 'getAllPWDCredentialsForGateway': |
| if len(args) != 1: |
| print('getAllPWDCredentialsForGateway requires 1 args') |
| sys.exit(1) |
| pp.pprint(client.getAllPWDCredentialsForGateway(args[0],)) |
| |
| elif cmd == 'deleteSSHCredential': |
| if len(args) != 2: |
| print('deleteSSHCredential requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.deleteSSHCredential(args[0], args[1],)) |
| |
| elif cmd == 'deletePWDCredential': |
| if len(args) != 2: |
| print('deletePWDCredential requires 2 args') |
| sys.exit(1) |
| pp.pprint(client.deletePWDCredential(args[0], args[1],)) |
| |
| elif cmd == 'getAPIVersion': |
| if len(args) != 0: |
| print('getAPIVersion requires 0 args') |
| sys.exit(1) |
| pp.pprint(client.getAPIVersion()) |
| |
| else: |
| print('Unrecognized method %s' % cmd) |
| sys.exit(1) |
| |
| transport.close() |