The apikey is now optional

Grafana 2.1.0 added basic auth support. With that in mind, the api key
is now optional.

Change-Id: Ie186fa9ce48ca4ae222f75345e9b660f5ffa2909
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2015-09-17 11:43:07 -04:00
parent f83e3e45d8
commit 8029107fc8
3 changed files with 9 additions and 6 deletions

View File

@ -97,4 +97,4 @@
#url = http://grafana.example.org
# API key for access grafana. (string value)
#apikey =
#apikey = <None>

View File

@ -23,7 +23,7 @@ grafana_opts = [
'url', default='http://grafana.example.org',
help='URL for grafana server.'),
cfg.StrOpt(
'apikey', default='',
'apikey', default=None,
help='API key for access grafana.'),
]

View File

@ -21,12 +21,15 @@ except ImportError:
class Grafana(object):
def __init__(self, url, key):
def __init__(self, url, key=None):
self.url = urljoin(url, 'api/dashboards/db')
self.session = requests.Session()
self.session.headers.update({
'Authorization': 'Bearer %s' % key,
})
# NOTE(pabelanger): Grafana 2.1.0 added basic auth support so now the
# api key is optional.
if key:
self.session.headers.update({
'Authorization': 'Bearer %s' % key,
})
def create_dashboard(self, data, overwrite=False):
data['overwrite'] = overwrite