Skip to content

Commit 455b4a2

Browse files
committed
fix: bucket config
1 parent 6ff082f commit 455b4a2

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

influxdb/buckets.sls

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
jq:
55
pkg.installed
66
7+
{% if "remote" in influxdb %}
8+
{%- set base_url = "https://" ~ influxdb['remote']['host'] ~ ":" ~ influxdb['remote']['port'] %}
9+
{% endif %}
10+
711
{%- if "bucket" in influxdb %}
812
{%- for config in influxdb["bucket"] %}
913
{% if "remote" not in influxdb %}
@@ -19,32 +23,37 @@ influxdb_bucket_{{ config['name'] }}:
1923
- pkg: jq
2024
{%- set bucket = salt['cmd.shell']("influx bucket list --json | jq -r '.[] | select(.name == \"" + config['name'] + "\").id'") %}
2125
{% else %}
26+
{%- set orgID = salt['cmd.shell']("curl -s -f -H'Authorization: Token " ~ influxdb['user']['admin']['token'] ~ "' '" ~ base_url ~ "/api/v2/orgs' | jq -r '.orgs[0].id'") %}
27+
2228
get_bucket_{{ config['name'] }}:
2329
http.query:
24-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets/{{ config['name'] }}'
30+
- name: '{{ base_url }}/api/v2/buckets?name={{ config['name'] }}'
2531
- status: 200
2632
- method: GET
2733
- header_dict:
2834
Authorization: Token {{ influxdb['user']['admin']['token'] }}
2935
3036
{%- set bucket_data = {
31-
name: config['name'],
32-
description: config['description'] | default('A bucket for ' + config['name']),
33-
orgID: config['orgID'],
34-
retentionRules: [],
35-
rp: config['retention_policy']
37+
'name': config['name'],
38+
'description': config['description'] | default('A bucket for ' + config['name']),
39+
'orgID': orgID,
40+
'rp': config['retention_policy'] | default('0'),
3641
} %}
3742
create_bucket_{{ config['name'] }}:
3843
http.query:
39-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/buckets'
40-
- status: 200
44+
- name: '{{ base_url }}/api/v2/buckets'
45+
- status: 201
4146
- method: POST
4247
- data: '{{ bucket_data | tojson }}'
4348
- header_dict:
4449
Authorization: Token {{ influxdb['user']['admin']['token'] }}
4550
- onfail:
4651
- http: get_bucket_{{ config['name'] }}
47-
{%- set bucket = salt['cmd.shell']("curl -s -f -H'Authorization: Token {{ influxdb['user']['admin']['token'] }}' https://{{ influxdb['remote']['host'] }}/api/v2/buckets | jq -r '.[] | select(.name == \"" + config['name'] + "\").id'") %}
52+
{%- set bucket = salt['cmd.shell']("curl -s -f -H'Authorization: Token " ~ influxdb['user']['admin']['token'] ~ "' '" ~ base_url ~ "/api/v2/buckets' | jq -r '.buckets[] | select(.name == \"" + config['name'] + "\").id'") %}
53+
54+
testb_{{ config['name'] }}_{{ bucket }}:
55+
cmd.run:
56+
- name: echo {{ bucket }}
4857
{% endif %}
4958
5059
{%- if 'mapping' in config and bucket %}

influxdb/users.sls

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ influxdb_user_{{ loop.index0 }}:
1717
{% endif %}
1818
1919
{% if "user" in influxdb and "remote" in influxdb %}
20+
{%- set base_url = "https://" ~ influxdb['remote']['host'] ~ "':" ~ influxdb['remote']['port'] %}
2021
{% for name,config in influxdb["user"].items() %}
2122
get_user_{{ loop.index0 }}:
2223
http.query:
23-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users/{{ name }}'
24+
- name: '{{ base_url }}/api/v2/users/{{ name }}'
2425
- status: 200
2526
- method: GET
2627
- header_dict:
2728
Authorization: Token {{ influxdb['user']['admin']['token'] }}
2829
2930
create_user_{{ loop.index0 }}:
3031
http.query:
31-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users'
32+
- name: '{{ base_url }}/api/v2/users'
3233
- status: 200
3334
- method: POST
3435
- data: '{"name": "{{ name }}"}'
@@ -40,7 +41,7 @@ create_user_{{ loop.index0 }}:
4041
{% if "password" in config %}
4142
set_password_{{ loop.index0 }}:
4243
http.query:
43-
- name: 'https://{{ influxdb['remote']['host'] }}/api/v2/users{{ name }}/password'
44+
- name: '{{ base_url }}/api/v2/users/{{ name }}/password'
4445
- status: 200
4546
- method: POST
4647
- data: '{"password": "{{ config["password"] }}"}'

0 commit comments

Comments
 (0)