This repository has been archived by the owner on Mar 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetToken.py
executable file
·72 lines (58 loc) · 2.61 KB
/
GetToken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import getpass
import sys
from optparse import OptionParser
try:
from ZSI.client import AUTH
except ImportError:
print '==> Failed to import ZSI'
print '===> Please make sure you have it installed and locatable from PYTHONPATH'
print ' http://pywebsvcs.sourceforge.net/'
print
raise
class GetTokenError(Exception):
pass
class OptionsProxy(object):
def __init__(self, *args, **kwargs):
self.__dict__.update(kwargs)
def getToken(opts, password):
if not opts.production:
from staging import CommonService_client
from staging import CommonService_types
else:
from production import CommonService_client
from production import CommonService_types
locator = CommonService_client.CommonServiceLocator()
service = locator.getCommonServiceSoap(auth=(4, opts.user, password))
request = CommonService_client.GetClientTokenSoapIn()
request._request = CommonService_types.ns0.GetClientToken_Dec()
request._specification = CommonService_types.ns0.TokenSpecification_Def(opts.user)
request._specification._ClientIPAddress = opts.clientip
request._specification._TokenValidityDurationMinutes = int(opts.tokenvalidity)
result = service.GetClientToken(request)
if result.__class__.__name__ == 'GetClientTokenResponse_Holder':
return result._GetClientTokenResult
raise GetTokenError('Web service failed to return a proper response! %s' % result)
def main():
_op = OptionParser()
_op.add_option('--user', dest='user', help='User ID for Virtual Earth\'s Web Services')
_op.add_option('--production', dest='production', action='store_true', help='Generate a token for production use')
_op.add_option('--clientip', dest='clientip', default='0.0.0.0', help='Specify the ClientIPAddress argument for the CommonService.GetClientToken() API')
_op.add_option('--tokenvalidity', dest='tokenvalidity', default='480', help='Specify to TokenValidityDurationInMinutes argument for CommonService.GetClientToken(), must be between 15 and 480')
_op.add_option('--password', dest='password', default=None, help='Password for Virtual Earth\'s Web Services')
opts, args = _op.parse_args()
if not opts.user:
print '==> Missing "user" argument'
print
_op.print_help()
return -1
password = opts.password
if not opts.password:
password = getpass.getpass(prompt='Virtual Earth Password: ')
token = getToken(opts, password)
print '==> Generated token: %s' % token
return 0
if __name__ == '__main__':
rc = main()
sys.exit(rc)
# vim: set expandtab: