Allow basic auth when datasource is adding
This patch fixes an issue to use basic auth when the datasource is
adding for the first time. It also adds a delay when service is started.
diff --git a/_states/grafana3_datasource.py b/_states/grafana3_datasource.py
index a66836b..dbb3312 100644
--- a/_states/grafana3_datasource.py
+++ b/_states/grafana3_datasource.py
@@ -127,12 +127,20 @@
ret['changes'] = None
ret['comment'] = 'Data source {0} already up-to-date'.format(name)
else:
- requests.post(
- '{0}/api/datasources'.format(profile['grafana_url']),
- data,
- headers=_get_headers(profile),
- timeout=profile.get('grafana_timeout', 3),
- )
+ if profile.get('grafana_token', False):
+ requests.post(
+ '{0}/api/datasources'.format(profile['grafana_url']),
+ data,
+ headers=_get_headers(profile),
+ timeout=profile.get('grafana_timeout', 3),
+ )
+ else:
+ requests.put(
+ '{0}/api/datasources'.format(profile['grafana_url']),
+ data,
+ auth=_get_auth(profile),
+ timeout=profile.get('grafana_timeout', 3),
+ )
ret['result'] = True
ret['comment'] = 'New data source {0} added'.format(name)
ret['changes'] = data