diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-06-04 06:48:22 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-04 06:48:22 +1000 |
| commit | 4d03dd58cd5d14b8f8094e2490034b31187aea2b (patch) | |
| tree | b42be5a26b1881fd81542d510a88aef8d4247d3b /plugins/httpapi | |
| parent | 6a660fbbb1a855ca88b4926eda118f28f61518ca (diff) | |
| parent | cc8b7230098feb057ce5d903ded00ac0a7e648c0 (diff) | |
| download | rest.vyos-4d03dd58cd5d14b8f8094e2490034b31187aea2b.tar.gz rest.vyos-4d03dd58cd5d14b8f8094e2490034b31187aea2b.zip | |
Merge pull request #3 from vyos/init
Init Collection
Diffstat (limited to 'plugins/httpapi')
| -rw-r--r-- | plugins/httpapi/vyos.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/plugins/httpapi/vyos.py b/plugins/httpapi/vyos.py index 1719254..07a60fe 100644 --- a/plugins/httpapi/vyos.py +++ b/plugins/httpapi/vyos.py @@ -1,6 +1,5 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- -# GNU General Public License v3.0+ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function @@ -90,13 +89,14 @@ class HttpApi(HttpApiBase): ) return key - def send_request(self, endpoint, **payload): + def send_request(self, data, **payload): # pylint: disable=arguments-renamed """POST to a VyOS REST endpoint. Args: - endpoint (str): API path, e.g. '/configure' or '/retrieve'. - Named 'endpoint' not 'path' to avoid collision - with the VyOS payload field also called 'path'. + data (str): API path, e.g. '/configure' or '/retrieve'. + Named 'data' to match the HttpApiBase signature. + Internally referred to as endpoint to avoid collision + with the VyOS payload field also called 'data'. **payload: VyOS API fields: op, path, value, url, file, etc. Returns: @@ -105,11 +105,16 @@ class HttpApi(HttpApiBase): Raises: ConnectionError: on HTTP error or VyOS success=false response. """ + endpoint = data + try: api_key = self._get_api_key() - body = json.dumps(payload) - form_data = urlencode({"data": body, "key": api_key}) + if "_raw_list" in payload: + body = json.dumps(payload["_raw_list"]) + else: + body = json.dumps(payload) + form_data = urlencode({"data": body, "key": api_key}) response, response_data = self.connection.send( endpoint, data=form_data, |
