Skip to content

Commit fdf6ffd

Browse files
committed
feat: add v1 auths
1 parent 87f32f7 commit fdf6ffd

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

influxdb/users.sls

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,45 @@ grant_user_{{ name }}_to_{{ bucket }}:
120120
Authorization: Token {{ influxdb['user']['admin']['token'] }}
121121
- onfail:
122122
- http: check_grant_user_{{ name }}_to_{{ bucket }}
123+
124+
{%- set token = '-'.join([name, access, bucket]) -%}
125+
{%- set auth_data = {
126+
'token': token,
127+
'description': 'Grant ' ~ name ~ ' ' ~ access ~ ' access to bucket ' ~ bucket,
128+
'orgID': orgID,
129+
'userID': id,
130+
'permissions': [{
131+
'action': 'write' if access != 'read' else 'read',
132+
'resource': [{
133+
'id': bucketID,
134+
'name': bucket,
135+
'orgID': orgID,
136+
'type': "buckets"
137+
}]
138+
}]
139+
} -%}
140+
141+
check_auth_user_{{ name }}_to_{{ bucket }}:
142+
http.query:
143+
- name: '{{ base_url }}/private/legacy/authorizations?token={{ token }}'
144+
- status: 200
145+
- method: GET
146+
- match: '"{{ token }}"'
147+
- match_type: string
148+
- header_dict:
149+
Authorization: Token {{ influxdb['user']['admin']['token'] }}
150+
151+
auth_user_{{ name }}_to_{{ bucket }}:
152+
http.query:
153+
- name: '{{ base_url }}/private/legacy/authorizations'
154+
- status: 201
155+
- method: POST
156+
- data: '{{ auth_data | tojson }}'
157+
- header_dict:
158+
Authorization: Token {{ influxdb['user']['admin']['token'] }}
159+
- onfail:
160+
- http: check_auth_user_{{ name }}_to_{{ bucket }}
161+
123162
{%- endfor %}
124163
{% endif %}
125164

0 commit comments

Comments
 (0)