-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ApiKey: Add ApiKey authentication. (#103)
* ApiKey: Add ApiKey authentication and tests. Co-authored-by: andrefsp <[email protected]> Co-authored-by: Rhys Campbell <[email protected]>
- Loading branch information
1 parent
ea8b863
commit 4f9d11e
Showing
5 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
- vars: | ||
elastic_user: elastic | ||
elastic_password: secret | ||
elastic_port: 9200 | ||
elastic_api_key_name: "test-api-key" | ||
|
||
block: | ||
|
||
- name: Get Elasticsearch version | ||
ansible.builtin.uri: | ||
url: http://localhost:9200 | ||
method: GET | ||
user: "{{ elastic_user }}" | ||
password: "{{ elastic_password }}" | ||
return_content: yes | ||
headers: | ||
Content-Type: "application/json" | ||
register: es_version_response | ||
|
||
- name: Create an API key for Elasticsearch | ||
ansible.builtin.uri: | ||
url: "http://localhost:{{ elastic_port }}/_security/api_key" | ||
method: POST | ||
user: "{{ elastic_user }}" | ||
password: "{{ elastic_password }}" | ||
body_format: json | ||
body: | | ||
{ | ||
"name": "{{ elastic_api_key_name }}", | ||
"expiration": "1d", | ||
"role_descriptors": {} | ||
} | ||
headers: | ||
Content-Type: "application/json" | ||
return_content: yes | ||
register: api_key_response | ||
when: es_version_response.json.version.number[0] | int > 7 | ||
|
||
- assert: | ||
that: | ||
- api_key_response.json.name == "test-api-key" | ||
when: es_version_response.json.version.number[0] | int > 7 | ||
|
||
- name: Create an index using the api key | ||
community.elastic.elastic_index: | ||
name: myapikeyindex | ||
auth_method: "api_key" | ||
api_key_encoded: "{{ api_key_response.json.encoded }}" | ||
auth_scheme: "http" | ||
check_mode: yes | ||
register: result | ||
when: es_version_response.json.version.number[0] | int > 7 | ||
|
||
- assert: | ||
that: | ||
- result.msg == "The index 'myapikeyindex' was created." | ||
- result.changed == True | ||
when: es_version_response.json.version.number[0] | int > 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ | |
name: setup_elastic | ||
|
||
- import_tasks: 2-test-with-auth.yml | ||
|
||
- import_tasks: 103.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters