Skip to content

Commit 94022b5

Browse files
Merge pull request #196 from censys/adh/update-delete-comments
feat(api): Update and Delete Comment Support
2 parents 8413cce + a198974 commit 94022b5

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

censys/search/v2/api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,34 @@ def add_comment(self, document_id: str, contents: str) -> dict:
317317
self.view_path + document_id + "/comments", data={"contents": contents}
318318
)["result"]
319319

320+
def delete_comment(self, document_id: str, comment_id: str) -> dict:
321+
"""Delete comment from a document.
322+
323+
Args:
324+
document_id (str): The ID of the document you are requesting.
325+
comment_id (str): The ID of the comment you are requesting.
326+
327+
Returns:
328+
dict: The result set returned.
329+
"""
330+
return self._delete(self.view_path + document_id + "/comments/" + comment_id)
331+
332+
def update_comment(self, document_id: str, comment_id: str, contents: str) -> dict:
333+
"""Update comment from a document.
334+
335+
Args:
336+
document_id (str): The ID of the document you are requesting.
337+
comment_id (str): The ID of the comment you are requesting.
338+
contents (str): The contents of the comment.
339+
340+
Returns:
341+
dict: The result set returned.
342+
"""
343+
return self._put(
344+
self.view_path + document_id + "/comments/" + comment_id,
345+
data={"contents": contents},
346+
)
347+
320348
# Tags
321349

322350
def list_all_tags(self) -> List[dict]:

docs/usage-v2.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,34 @@ Below we show an example using the :attr:`CensysHosts <censys.search.v2.CensysHo
197197
comment = h.add_comment("1.1.1.1", "This is a test comment")
198198
print(comment)
199199
200+
``update_comment``
201+
^^^^^^^^^^^^^^^^^^
202+
203+
Below we show an example using the :attr:`CensysHosts <censys.search.v2.CensysHosts>` index.
204+
205+
.. code:: python
206+
207+
from censys.search import CensysHosts
208+
209+
h = CensysHosts()
210+
211+
# Update a comment to a host.
212+
comment = h.update_comment("1.1.1.1", 101, "This is an updated test comment")
213+
214+
``delete_comment``
215+
^^^^^^^^^^^^^^^^^^
216+
217+
Below we show an example using the :attr:`CensysCerts <censys.search.v2.CensysCerts>` index.
218+
219+
.. code:: python
220+
221+
from censys.search import CensysCerts
222+
223+
c = CensysCerts()
224+
225+
# Delete a comment for a certificate.
226+
c.delete_comment("fb444eb8e68437bae06232b9f5091bccff62a768ca09e92eb5c9c2cf9d17c426", 102)
227+
200228
Tags
201229
----
202230

tests/search/v2/test_comments.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,22 @@ def test_add_comment(self):
7878
)
7979
results = self.api.add_comment(self.document_id, TEST_COMMENT)
8080
assert results == ADD_COMMENTS_RESPONSE["result"]
81+
82+
def test_delete_comment(self):
83+
self.responses.add(
84+
responses.DELETE,
85+
f"{self.base_url}/{self.index}/{self.document_id}/comments/comment-id",
86+
status=209,
87+
)
88+
self.api.delete_comment(self.document_id, "comment-id")
89+
90+
def test_update_comment(self):
91+
self.responses.add(
92+
responses.PUT,
93+
f"{self.base_url}/{self.index}/{self.document_id}/comments/comment-id",
94+
status=200,
95+
json={"code": 200, "status": "OK"},
96+
match=[responses.json_params_matcher({"contents": TEST_COMMENT})],
97+
)
98+
results = self.api.update_comment(self.document_id, "comment-id", TEST_COMMENT)
99+
assert results == {"code": 200, "status": "OK"}

0 commit comments

Comments
 (0)