mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-18 12:48:07 +00:00
add user confirmation to container reset (#202)
This commit is contained in:
@ -54,6 +54,16 @@ def wsl_path(path: str) -> str:
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def user_confirmation(message: str) -> bool:
|
||||||
|
answer: Optional[str] = None
|
||||||
|
while answer not in ["y", "n"]:
|
||||||
|
answer = input(message).strip()
|
||||||
|
|
||||||
|
if answer == "n":
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Endpoint:
|
class Endpoint:
|
||||||
endpoint: str
|
endpoint: str
|
||||||
|
|
||||||
@ -275,17 +285,25 @@ class Containers(Endpoint):
|
|||||||
return self._req_model_list("GET", responses.ContainerInfoBase)
|
return self._req_model_list("GET", responses.ContainerInfoBase)
|
||||||
|
|
||||||
def reset(
|
def reset(
|
||||||
self, container_types: Optional[List[enums.ContainerType]] = None
|
self,
|
||||||
|
*,
|
||||||
|
container_types: Optional[
|
||||||
|
List[enums.ContainerType]
|
||||||
|
] = enums.ContainerType.reset_defaults(),
|
||||||
|
yes: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Reset containers unless specified.
|
"""
|
||||||
[Caution]: It can lead to unexpected results.
|
Reset containers by container type (NOTE: This may cause unexpected issues with existing fuzzing jobs)
|
||||||
The default conatiners are listed ContainerType.reset_defaults
|
|
||||||
"""
|
"""
|
||||||
if not container_types:
|
if not container_types:
|
||||||
container_types = enums.ContainerType.reset_defaults()
|
return
|
||||||
|
|
||||||
if not container_types:
|
message = "Confirm deleting container types: %s (specify y or n): " % (
|
||||||
raise Exception("Container type is None")
|
",".join(x.name for x in container_types)
|
||||||
|
)
|
||||||
|
if not yes and not user_confirmation(message):
|
||||||
|
self.logger.warning("not deleting containers")
|
||||||
|
return
|
||||||
|
|
||||||
for container in self.list():
|
for container in self.list():
|
||||||
if (
|
if (
|
||||||
@ -1335,16 +1353,6 @@ class Onefuzz:
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _user_confirmation(self, message: str) -> bool:
|
|
||||||
answer: Optional[str] = None
|
|
||||||
while answer not in ["y", "n"]:
|
|
||||||
answer = input(message).strip()
|
|
||||||
|
|
||||||
if answer == "n":
|
|
||||||
self.logger.info("not stopping")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _delete_components(
|
def _delete_components(
|
||||||
self,
|
self,
|
||||||
containers: bool = False,
|
containers: bool = False,
|
||||||
@ -1387,7 +1395,7 @@ class Onefuzz:
|
|||||||
self.scalesets.shutdown(scaleset.scaleset_id, now=True)
|
self.scalesets.shutdown(scaleset.scaleset_id, now=True)
|
||||||
|
|
||||||
if containers:
|
if containers:
|
||||||
self.containers.reset()
|
self.containers.reset(yes=True)
|
||||||
|
|
||||||
def reset(
|
def reset(
|
||||||
self,
|
self,
|
||||||
@ -1451,7 +1459,8 @@ class Onefuzz:
|
|||||||
message = "Confirm stopping %s (specify y or n): " % (
|
message = "Confirm stopping %s (specify y or n): " % (
|
||||||
", ".join(sorted(to_delete))
|
", ".join(sorted(to_delete))
|
||||||
)
|
)
|
||||||
if not yes and not self._user_confirmation(message):
|
if not yes and not user_confirmation(message):
|
||||||
|
self.logger.warning("not resetting")
|
||||||
return
|
return
|
||||||
|
|
||||||
self._delete_components(
|
self._delete_components(
|
||||||
|
Reference in New Issue
Block a user