| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Dismissed as stale. Please tell us if the issue persists! |
Sorry, something went wrong.
|
This is still very much sought after by my team. Let me know if you need anything for this to be merged. |
Sorry, something went wrong.
|
Thanks @seiimonn, we'll take a look and get back to you! |
Sorry, something went wrong.
|
Hi @Ickerday - anything I can do to support on this? |
Sorry, something went wrong.
|
Hi We plan to give this a look, we are going to figure out which way is the best to implement this (we might go with this change) but in the meantime can you rebase this on top of the develop branch? |
Sorry, something went wrong.
|
Thanks, once again i would ask you to rebase this, since i would like to see this being also tested with the tests i have introduced for #683. Please add in tests/system/test_cre_apps.py TestJSONCustomRestEndpointsSpecialMethodHelpers a test case for PUT and PATCH, i assume they would look the same as test_POST. |
Sorry, something went wrong.
| message = {"method": method, "headers": all_headers} | ||
| path = path + UrlEncoded('?' + body, skip_encode=True) | ||
| message = {'method': method, | ||
| 'headers': all_headers} |
There was a problem hiding this comment.
Drop that change. It seems to only make the code non-formatted.
Sorry, something went wrong.
| **Example**:: | ||
|
|
||
| c = binding.connect(...) | ||
| c.post('saved/searches', name='boris', | ||
| search='search * earliest=-1m | head 1') == \\ | ||
| {'body': ...a response reader object..., | ||
| 'headers': [('content-length', '10455'), | ||
| ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'), | ||
| ('server', 'Splunkd'), | ||
| ('connection', 'close'), | ||
| ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'), | ||
| ('date', 'Fri, 11 May 2012 16:46:06 GMT'), | ||
| ('content-type', 'text/xml; charset=utf-8')], | ||
| 'reason': 'Created', | ||
| 'status': 201} | ||
| c.post('nonexistant/path') # raises HTTPError | ||
| c.logout() | ||
| # raises AuthenticationError: | ||
| c.put('saved/searches/boris', | ||
| search='search * earliest=-1m | head 1') | ||
| """ |
There was a problem hiding this comment.
I think we should change this example, splunk does not really support PUT/PATCH in its endpoints see: https://help.splunk.com/en/splunk-enterprise/leverage-rest-apis/rest-api-reference/10.0/introduction/endpoints-reference-list (that is the reason there were no such methods in the first place)
I think we should have an example that shows that it is used with custom rest endpoints, something like:
# Call an HTTP endpoint, exposed as Custom Rest Endpoint in a Splunk App.
# PUT /servicesNS/-/app_name/custom_rest_endpoint
service.put(
app="app_name",
path_segment="custom_rest_endpoint",
body=json.dumps({"key": "val"}),
headers=[("Content-Type", "application/json")],
)
Sorry, something went wrong.
| c = binding.connect(...) | ||
| c.post('saved/searches', name='boris', | ||
| search='search * earliest=-1m | head 1') == \\ | ||
| {'body': ...a response reader object..., | ||
| 'headers': [('content-length', '10455'), | ||
| ('expires', 'Fri, 30 Oct 1998 00:00:00 GMT'), | ||
| ('server', 'Splunkd'), | ||
| ('connection', 'close'), | ||
| ('cache-control', 'no-store, max-age=0, must-revalidate, no-cache'), | ||
| ('date', 'Fri, 11 May 2012 16:46:06 GMT'), | ||
| ('content-type', 'text/xml; charset=utf-8')], | ||
| 'reason': 'Created', | ||
| 'status': 201} | ||
| c.post('nonexistant/path') # raises HTTPError | ||
| c.logout() | ||
| # raises AuthenticationError: | ||
| c.patch('saved/searches/boris', | ||
| search='search * earliest=-1m | head 1') |
There was a problem hiding this comment.
Same here, lets change it, as above.
Sorry, something went wrong.
| :type headers: ``list`` of 2-tuples. | ||
| :param query: All other keyword arguments, which are used as query | ||
| parameters. | ||
| :param body: Parameters to be used in the post body. If specified, |
There was a problem hiding this comment.
| :param body: Parameters to be used in the post body. If specified, | |
| :param body: Parameters to be used in the put body. If specified, |
Sorry, something went wrong.
| :type headers: ``list`` of 2-tuples. | ||
| :param query: All other keyword arguments, which are used as query | ||
| parameters. | ||
| :param body: Parameters to be used in the post body. If specified, |
There was a problem hiding this comment.
| :param body: Parameters to be used in the post body. If specified, | |
| :param body: Parameters to be used in the patch body. If specified, |
Sorry, something went wrong.
| Some of Splunk's endpoints, such as ``receivers/simple`` and | ||
| ``receivers/stream``, require unstructured data in the PUT body | ||
| and all metadata passed as GET-style arguments. If you provide | ||
| a ``body`` argument to ``put``, it will be used as the PUT | ||
| body, and all other keyword arguments will be passed as | ||
| GET-style arguments in the URL. |
There was a problem hiding this comment.
Splunk does not support PUT method in its endpoints, so lets not mention that.
| Some of Splunk's endpoints, such as ``receivers/simple`` and | |
| ``receivers/stream``, require unstructured data in the PUT body | |
| and all metadata passed as GET-style arguments. If you provide | |
| a ``body`` argument to ``put``, it will be used as the PUT | |
| body, and all other keyword arguments will be passed as | |
| GET-style arguments in the URL. | |
| If you provide a ``body`` argument to ``put``, | |
| it will be used as the PUT body, and all other | |
| keyword arguments will be passed as GET-style | |
| arguments in the URL. |
Sorry, something went wrong.
| Some of Splunk's endpoints, such as ``receivers/simple`` and | ||
| ``receivers/stream``, require unstructured data in the PATCH body | ||
| and all metadata passed as GET-style arguments. If you provide | ||
| a ``body`` argument to ``patch``, it will be used as the PATCH | ||
| body, and all other keyword arguments will be passed as | ||
| GET-style arguments in the URL. |
There was a problem hiding this comment.
Same here.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The current SDK does not provide dedicated functions for sending PUT and PATCH requests to endpoints in Splunk. These operations were only possible using the generic request method, which had issues correctly formatting a body payload, especially for form-encoded data.
This change introduces helper functions for PUT and POST requests, along with a new _prepare_request_body_and_url function to streamline body and URL preparation logic. This ensures consistency, reduces redundancy, and resolves issues with incorrect payload formatting when making these requests.
Changes
Benefits