Skip to content

Commit

Permalink
Add new options to httpapi connection (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos authored Aug 4, 2023
1 parent f6d1b9d commit 46dcfcd
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/httpapi_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
minor_changes:
- httpapi - Add additional option ``ca_path``, ``client_cert``, ``client_key``, and
``http_agent`` that are available in open_url but not to httpapi.
(https://github.com/ansible-collections/ansible.netcommon/issues/528)
76 changes: 76 additions & 0 deletions docs/ansible.netcommon.httpapi_connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ Parameters
<div>This option allows the become method to be specified in for handling privilege escalation. Typically the become_method value is set to <code>enable</code> but could be defined as other values.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>ca_path</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">path</span>
</div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 5.2.0</div>
</td>
<td>
</td>
<td>
<div>var: ansible_httpapi_ca_path</div>
</td>
<td>
<div>Path to CA cert bundle to use.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand All @@ -105,6 +124,44 @@ Parameters
<div>This option will have no effect on ansible-core&lt;2.14 but a warning will be emitted.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>client_cert</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">-</span>
</div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 5.2.0</div>
</td>
<td>
</td>
<td>
<div>var: ansible_httpapi_client_cert</div>
</td>
<td>
<div>PEM formatted certificate chain file to be used for SSL client authentication. This file can also include the key as well, and if the key is included, <em>client_key</em> is not required</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>client_key</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">-</span>
</div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 5.2.0</div>
</td>
<td>
</td>
<td>
<div>var: ansible_httpapi_client_key</div>
</td>
<td>
<div>PEM formatted file that contains the private key to be used for SSL client authentication. If <em>client_cert</em> contains both the certificate and key, this option is not required.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand All @@ -125,6 +182,25 @@ Parameters
<div>Specifies the remote device FQDN or IP address to establish the HTTP(S) connection to.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>http_agent</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">-</span>
</div>
<div style="font-style: italic; font-size: small; color: darkgreen">added in 5.2.0</div>
</td>
<td>
</td>
<td>
<div>var: ansible_httpapi_http_agent</div>
</td>
<td>
<div>User-Agent to use in the request.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
36 changes: 34 additions & 2 deletions plugins/connection/httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@
- When specified, I(password) is ignored.
vars:
- name: ansible_httpapi_session_key
ca_path:
description:
- Path to CA cert bundle to use.
type: path
version_added: 5.2.0
vars:
- name: ansible_httpapi_ca_path
client_cert:
description:
- PEM formatted certificate chain file to be used for SSL client
authentication. This file can also include the key as well, and if the key
is included, I(client_key) is not required
version_added: 5.2.0
vars:
- name: ansible_httpapi_client_cert
client_key:
description:
- PEM formatted file that contains the private key to be used for SSL client
authentication. If I(client_cert) contains both the certificate and key,
this option is not required.
version_added: 5.2.0
vars:
- name: ansible_httpapi_client_key
http_agent:
description: User-Agent to use in the request.
version_added: 5.2.0
vars:
- name: ansible_httpapi_http_agent
use_ssl:
type: boolean
description:
Expand Down Expand Up @@ -279,10 +307,14 @@ def send(self, path, data, retries=None, **kwargs):
Sends the command to the device over api
"""
url_kwargs = dict(
headers={},
use_proxy=self.get_option("use_proxy"),
timeout=self.get_option("persistent_command_timeout"),
validate_certs=self.get_option("validate_certs"),
use_proxy=self.get_option("use_proxy"),
headers={},
http_agent=self.get_option("http_agent"),
client_cert=self.get_option("client_cert"),
client_key=self.get_option("client_key"),
ca_path=self.get_option("ca_path"),
)
url_kwargs.update(kwargs)

Expand Down

0 comments on commit 46dcfcd

Please sign in to comment.