@@ -47,7 +47,21 @@ class V1AssetNotFoundError(V1Error): pass
47
47
class V1Server (object ):
48
48
"Accesses a V1 HTTP server as a client of the XML API protocol"
49
49
50
- def __init__ (self , address = "localhost" , instance = "VersionOne.Web" , username = '' , password = '' , scheme = "http" , instance_url = None , logparent = None , loglevel = logging .ERROR ):
50
+ def __init__ (self , address = "localhost" , instance = "VersionOne.Web" , username = '' , password = '' , token = None , scheme = "http" , instance_url = None , logparent = None , loglevel = logging .ERROR ):
51
+ """
52
+ If *instance_url* is set its value will override address, instance,
53
+ scheme and object's instance_url attributes.
54
+ If *token* is not None a HTTP header will be added to each request.
55
+ :param address: target hostname
56
+ :param instance: instance
57
+ :param username: credentials (username)
58
+ :param password: credentials (password)
59
+ :param token: credentials (authentication token)
60
+ :param scheme: HTTP scheme
61
+ :param instance_url: instance URL
62
+ :param logparent: logger prefix
63
+ :param loglevel: logging level
64
+ """
51
65
if instance_url :
52
66
self .instance_url = instance_url
53
67
parsed = urlparse (instance_url )
@@ -66,6 +80,8 @@ def __init__(self, address="localhost", instance="VersionOne.Web", username='',
66
80
self .logger .setLevel (loglevel )
67
81
self .username = username
68
82
self .password = password
83
+ if token :
84
+ self .token = token
69
85
self ._install_opener ()
70
86
71
87
def _install_opener (self ):
@@ -74,6 +90,9 @@ def _install_opener(self):
74
90
password_manager .add_password (None , base_url , self .username , self .password )
75
91
handlers = [HandlerClass (password_manager ) for HandlerClass in AUTH_HANDLERS ]
76
92
self .opener = urllib2 .build_opener (* handlers )
93
+ if self .token :
94
+ self .opener .addheaders .append (
95
+ ('Authorization' , 'Bearer {token}' .format (token = self .token )))
77
96
self .opener .add_handler (HTTPCookieProcessor ())
78
97
79
98
def http_get (self , url ):
0 commit comments