Validate scriban from cli (#2800)

* Add validate scriban endpoint to cli

* missed a file

* Lint -- I miss C#

* docs
This commit is contained in:
Teo Voinea
2023-02-06 08:32:49 -05:00
committed by GitHub
parent 8f418f692c
commit c1f6dfc366
9 changed files with 109 additions and 63 deletions

View File

@ -529,10 +529,11 @@ class Containers(Endpoint):
) -> None:
to_download: Dict[str, str] = {}
for task in tasks:
for container in task.config.containers:
info = self.onefuzz.containers.get(container.name)
name = os.path.join(container.type.name, container.name)
to_download[name] = info.sas_url
if task.config.containers is not None:
for container in task.config.containers:
info = self.onefuzz.containers.get(container.name)
name = os.path.join(container.type.name, container.name)
to_download[name] = info.sas_url
if output is None:
output = primitives.Directory(os.getcwd())
@ -1099,9 +1100,14 @@ class JobContainers(Endpoint):
containers = set()
tasks = self.onefuzz.tasks.list(job_id=job_id, state=[])
for task in tasks:
containers.update(
set(x.name for x in task.config.containers if x.type == container_type)
)
if task.config.containers is not None:
containers.update(
set(
x.name
for x in task.config.containers
if x.type == container_type
)
)
results: Dict[str, List[str]] = {}
for container in containers:
@ -1133,23 +1139,24 @@ class JobContainers(Endpoint):
containers = set()
to_delete = set()
for task in self.onefuzz.jobs.tasks.list(job_id=job.job_id):
for container in task.config.containers:
containers.add(container.name)
if container.type not in SAFE_TO_REMOVE:
continue
elif not only_job_specific:
to_delete.add(container.name)
elif only_job_specific and (
self.onefuzz.utils.build_container_name(
container_type=container.type,
project=job.config.project,
name=job.config.name,
build=job.config.build,
platform=task.os,
)
== container.name
):
to_delete.add(container.name)
if task.config.containers is not None:
for container in task.config.containers:
containers.add(container.name)
if container.type not in SAFE_TO_REMOVE:
continue
elif not only_job_specific:
to_delete.add(container.name)
elif only_job_specific and (
self.onefuzz.utils.build_container_name(
container_type=container.type,
project=job.config.project,
name=job.config.name,
build=job.config.build,
platform=task.os,
)
== container.name
):
to_delete.add(container.name)
to_keep = containers - to_delete
for container_name in to_keep:
@ -1713,6 +1720,17 @@ class InstanceConfigCmd(Endpoint):
)
class ValidateScriban(Endpoint):
"""Interact with Validate Scriban"""
endpoint = "ValidateScriban"
def post(
self, req: requests.TemplateValidationPost
) -> responses.TemplateValidationResponse:
return self._req_model("POST", responses.TemplateValidationResponse, data=req)
class Command:
def __init__(self, onefuzz: "Onefuzz", logger: logging.Logger):
self.onefuzz = onefuzz
@ -1803,6 +1821,7 @@ class Onefuzz:
self.webhooks = Webhooks(self)
self.tools = Tools(self)
self.instance_config = InstanceConfigCmd(self)
self.validate_scriban = ValidateScriban(self)
if self._backend.is_feature_enabled(PreviewFeature.job_templates.name):
self.job_templates = JobTemplates(self)