diff --git a/changelogs/fragments/fix_slashes_in_datasources.yml b/changelogs/fragments/fix_slashes_in_datasources.yml new file mode 100644 index 00000000..e677ba6a --- /dev/null +++ b/changelogs/fragments/fix_slashes_in_datasources.yml @@ -0,0 +1,2 @@ +bugfixes: +- Fix issue with datasource names that could not contain slashes (#125) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index b289211e..fd0b7309 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -630,11 +630,11 @@ def switch_organisation(self, org_id): def datasource_by_name(self, name): datasource_exists = False ds = {} - url = "/api/datasources/name/%s" % quote(name) + url = "/api/datasources/name/%s" % quote(name, safe='') return self._send_request(url, headers=self.headers, method='GET') def delete_datasource(self, name): - url = "/api/datasources/name/%s" % quote(name) + url = "/api/datasources/name/%s" % quote(name, safe='') self._send_request(url, headers=self.headers, method='DELETE') def update_datasource(self, ds_id, data): diff --git a/tests/integration/targets/grafana_datasource/tasks/elastic.yml b/tests/integration/targets/grafana_datasource/tasks/elastic.yml index 1d472df6..344d61c8 100644 --- a/tests/integration/targets/grafana_datasource/tasks/elastic.yml +++ b/tests/integration/targets/grafana_datasource/tasks/elastic.yml @@ -1,7 +1,7 @@ - name: Create elasticsearch datasource register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -35,19 +35,19 @@ - result.datasource.jsonData.timeField == '@timestamp' - not result.datasource.jsonData.tlsAuth - result.datasource.jsonData.tlsAuthWithCACert - - result.datasource.name == 'datasource-elastic' + - result.datasource.name == 'datasource/elastic' - result.datasource.orgId == 1 - result.datasource.password == '' - result.datasource.type == 'elasticsearch' - result.datasource.url == 'https://elastic.company.com:9200' - result.datasource.user == '' - not result.datasource.withCredentials - - "result.msg == 'Datasource datasource-elastic created'" + - "result.msg == 'Datasource datasource/elastic created'" - name: Check elasticsearch datasource creation idempotency register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -81,7 +81,7 @@ - result.datasource.jsonData.timeField == '@timestamp' - not result.datasource.jsonData.tlsAuth - result.datasource.jsonData.tlsAuthWithCACert - - result.datasource.name == 'datasource-elastic' + - result.datasource.name == 'datasource/elastic' - result.datasource.orgId == 1 - result.datasource.password == '' - result.datasource.type == 'elasticsearch' @@ -92,7 +92,7 @@ - name: update elasticsearch datasource creation register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -126,7 +126,7 @@ - result.datasource.jsonData.timeField == '@timestamp' - not result.datasource.jsonData.tlsAuth - result.datasource.jsonData.tlsAuthWithCACert - - result.datasource.name == 'datasource-elastic' + - result.datasource.name == 'datasource/elastic' - result.datasource.orgId == 1 - result.datasource.password == '' - result.datasource.type == 'elasticsearch' @@ -137,7 +137,7 @@ - name: update elasticsearch datasource (ignoring secureJsonData) register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -176,7 +176,7 @@ - result.datasource.jsonData.timeField == '@timestamp' - not result.datasource.jsonData.tlsAuth - result.datasource.jsonData.tlsAuthWithCACert - - result.datasource.name == 'datasource-elastic' + - result.datasource.name == 'datasource/elastic' - result.datasource.orgId == 1 - result.datasource.password == '' - result.datasource.type == 'elasticsearch' @@ -188,7 +188,7 @@ - name: update elasticsearch datasource (including secureJsonData) register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -227,7 +227,7 @@ - result.datasource.jsonData.timeField == '@timestamp' - not result.datasource.jsonData.tlsAuth - result.datasource.jsonData.tlsAuthWithCACert - - result.datasource.name == 'datasource-elastic' + - result.datasource.name == 'datasource/elastic' - result.datasource.orgId == 1 - result.datasource.password == '' - result.datasource.type == 'elasticsearch' @@ -241,7 +241,7 @@ - name: Delete elasticsearch datasource register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" @@ -266,7 +266,7 @@ - name: Delete elasticsearch datasource (idempotency) register: result grafana_datasource: - name: datasource-elastic + name: "datasource/elastic" grafana_url: "{{ grafana_url }}" grafana_user: "{{ grafana_username }}" grafana_password: "{{ grafana_password }}" diff --git a/tests/integration/targets/grafana_datasource/tasks/issues.yml b/tests/integration/targets/grafana_datasource/tasks/issues.yml new file mode 100644 index 00000000..88508955 --- /dev/null +++ b/tests/integration/targets/grafana_datasource/tasks/issues.yml @@ -0,0 +1,46 @@ +--- + +- name: test datasource name with slash + register: result + grafana_datasource: + name: "datasource/elastic" + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_username }}" + grafana_password: "{{ grafana_password }}" + org_id: '1' + ds_type: elasticsearch + ds_url: https://elastic.company.com:9200 + database: '[logstash_]YYYY.MM.DD' + basic_auth_user: grafana + basic_auth_password: '******' + time_field: '@timestamp' + time_interval: 1m + interval: Daily + es_version: 56 + max_concurrent_shard_requests: 42 + tls_ca_cert: /etc/ssl/certs/ca.pem + +- assert: + that: + - result.changed + - result.datasource.basicAuth + - result.datasource.basicAuthUser == 'grafana' + - result.datasource.access == 'proxy' + - result.datasource.database == '[logstash_]YYYY.MM.DD' + - not result.datasource.isDefault + - result.datasource.jsonData.esVersion == 56 + - result.datasource.jsonData.interval == 'Daily' + - result.datasource.jsonData.maxConcurrentShardRequests == 42 + - result.datasource.jsonData.timeField == '@timestamp' + - not result.datasource.jsonData.tlsAuth + - not result.datasource.jsonData.tlsAuthWithCACert + - result.datasource.name == 'datasource/elastic' + - result.datasource.orgId == 1 + - result.datasource.password == '' + - result.datasource.type == 'elasticsearch' + - result.datasource.url == 'https://elastic.company.com:9200' + - result.datasource.user == '' + - not result.datasource.withCredentials + - "result.msg == 'Datasource datasource/elastic created'" + +...