Skip to content

Commit

Permalink
added update_cold_storage_purge_date to archive client (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: Juliya Smith <yingthi@live.com>
  • Loading branch information
ceciliastevens and antazoey committed Apr 28, 2020
1 parent 0a8881e commit 562b43b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta

- `departure_date` is now an optional parameter for `sdk.detectionlists.departing_employee.add()`.

- Added `sdk.archives.update_cold_storage_purge_date()`, allowing the changing of the date at which a cold storage archive will be purged.

## 1.0.0 - 2020-04-21

### Changed
Expand Down
6 changes: 6 additions & 0 deletions src/py42/_internal/clients/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ def get_web_restore_info(self, src_guid, dest_guid):
uri = u"/api/WebRestoreInfo"
params = {u"srcGuid": src_guid, u"destGuid": dest_guid}
return self._session.get(uri, params=params)

def update_cold_storage_purge_date(self, archive_guid, purge_date):
uri = u"/api/coldStorage/{0}".format(archive_guid)
params = {u"idType": u"guid"}
data = {u"archiveHoldExpireDate": purge_date}
return self._session.put(uri, params=params, data=json.dumps(data))
13 changes: 13 additions & 0 deletions src/py42/modules/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ def get_all_device_restore_history(self, days, device_id):
that each contain a page of restore history.
"""
return self._archive_client.get_all_restore_history(days, u"computerId", device_id)

def update_cold_storage_purge_date(self, archive_guid, purge_date):
"""Updates the cold storage purge date for a specified archive.
`REST Documentation <https://console.us.code42.com/apidocviewer/#ColdStorage-put>`__
Args:
archive_guid (str): The identification number of the archive that should be updated
purge_date (str): The date on which the archive should be purged in yyyy-MM-dd format
Returns:
:class:`py42.response.Py42Response`: the response from the ColdStorage API.
"""
return self._archive_client.update_cold_storage_purge_date(archive_guid, purge_date)
12 changes: 12 additions & 0 deletions tests/_internal/clients/test_archive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from requests import Response
import json

import py42.settings
from py42._internal.clients.archive import ArchiveClient
Expand Down Expand Up @@ -43,3 +44,14 @@ def test_get_all_calls_get_expected_number_of_times(
pass
py42.settings.items_per_page = 1000
assert mock_session.get.call_count == 3

def test_update_cold_storage_purge_date_calls_coldstorage_with_expected_data(
self, mock_session
):
client = ArchiveClient(mock_session)
client.update_cold_storage_purge_date(u"123", u"2020-04-24")
mock_session.put.assert_called_once_with(
u"/api/coldStorage/123",
params={u"idType": u"guid"},
data=json.dumps({u"archiveHoldExpireDate": u"2020-04-24"}),
)
9 changes: 9 additions & 0 deletions tests/modules/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ def test_get_all_device_restore_history_calls_get_all_restore_history_with_expec
archive._archive_client.get_all_restore_history.assert_called_once_with(
self._TEST_DAYS, "computerId", self._TEST_ID
)

def test_update_cold_storage_purge_date_calls_update_cold_storage_with_expected_data(
self, mocker
):
archive = _get_module(mocker)
archive.update_cold_storage_purge_date(u"123", u"2020-04-24")
archive._archive_client.update_cold_storage_purge_date.assert_called_once_with(
u"123", u"2020-04-24"
)

0 comments on commit 562b43b

Please sign in to comment.