Skip to content

Commit 484eb38

Browse files
committed
Add username/password authentication
1 parent 82e44e5 commit 484eb38

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

hawkular/metrics.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import codecs
2020
import time
2121
import collections
22+
import base64
2223

2324
try:
2425
import simplejson as json
@@ -86,7 +87,9 @@ def __init__(self,
8687
path='hawkular/metrics',
8788
scheme='http',
8889
cafile=None,
89-
token=None):
90+
token=None,
91+
username=None,
92+
password=None):
9093
"""
9194
A new instance of HawkularMetricsClient is created with the following defaults:
9295
@@ -107,6 +110,8 @@ def __init__(self,
107110
self.cafile = cafile
108111
self.scheme = scheme
109112
self.token = token
113+
self.username = username
114+
self.password = password
110115

111116
opener = build_opener(HawkularHTTPErrorProcessor())
112117
install_opener(opener)
@@ -156,6 +161,8 @@ def _http(self, url, method, data=None):
156161

157162
if self.token is not None:
158163
req.add_header('Authorization', 'Bearer {0}'.format(self.token))
164+
elif self.username is not None:
165+
req.add_header('Authorization', 'Basic {0}'.format(base64.b64encode(self.username + b':' + self.password)))
159166

160167
if not isinstance(data, str):
161168
data = json.dumps(data, indent=2)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
setup(name='hawkular-client',
21-
version='0.4.3',
21+
version='0.4.4',
2222
description='Python client to communicate with Hawkular server over HTTP(S)',
2323
author='Michael Burman',
2424
author_email='miburman@redhat.com',

0 commit comments

Comments
 (0)