Skip to content

Commit 4da023d

Browse files
[ENG-23767] Support backing up all policies of a given type
1 parent 7c188ca commit 4da023d

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

onefuse/backups.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def key_exists(self, in_dict: dict, key: str):
214214
else:
215215
return False
216216

217-
def backup_policies(self, backups_path: str):
217+
def backup_policies(self, backups_path: str, type: str = None):
218218
"""
219219
Back up all OneFuse policies from the OneFuse instance used when
220220
instantiating the OneFuseBackups class
@@ -225,9 +225,19 @@ def backup_policies(self, backups_path: str):
225225
Path to back the files up to. Examples:
226226
Windows: 'C:\\temp\\onefuse_backups\\'
227227
Linux: '/tmp/onefuse_backups/'
228+
type: str
228229
"""
229230
# Gather policies from OneFuse, store them under BACKUPS_PATH
230-
for policy_type in self.policy_types:
231+
policy_types = self.policy_types
232+
if type:
233+
if type in policy_types:
234+
policy_types = [type]
235+
else:
236+
error_string = (
237+
f'Policy type not found. Type {type} should be one of {policy_types}'
238+
)
239+
raise OneFuseError(error_string)
240+
for policy_type in policy_types:
231241
self.ofm.logger.info(f'Backing up policy_type: {policy_type}')
232242
response = self.ofm.get(f'/{policy_type}/')
233243
next_exists = self.create_json_files(response, policy_type,

0 commit comments

Comments
 (0)