in src/lambdas/custodian_api_handler/handlers/job_handler.py [0:0]
def _get_rulesets_for_scan(self, tenant: Tenant, domain: RuleDomain,
license_key: str | None,
ruleset_names: set[RulesetName]
) -> tuple[list[RulesetName], License | None, list[RulesetName]]:
if license_key:
lic = self._license_service.get_nullable(license_key)
if not lic:
raise ResponseFactory(HTTPStatus.BAD_REQUEST).message(
f'License {license_key} not found'
).exc()
if not self._license_service.is_subject_applicable(
lic=lic, customer=tenant.customer_name, tenant_name=tenant.name):
raise ResponseFactory(HTTPStatus.FORBIDDEN).message(
f'License {license_key} is not applicable for '
f'tenant {tenant.name}'
).exc()
licenses = (lic, )
else:
licenses = self._get_tenant_licenses(tenant)
if licenses and all(l.is_expired() for l in licenses):
raise ResponseFactory(HTTPStatus.FORBIDDEN).message(
'All licenses have expired'
).exc()
standard_rulesets, lic, licensed_rulesets = self._resolve_rulesets(
tenant=tenant,
domain=domain,
ruleset_names=ruleset_names,
licenses=licenses
)
if not standard_rulesets and not licensed_rulesets:
raise ResponseFactory(HTTPStatus.BAD_REQUEST).message(
'No licensed and standard rulesets are found'
).exc()
if lic:
_LOG.debug('Making request to LM to ensure the job is allowed')
self.ensure_job_is_allowed(
tenant, lic.tenant_license_key(tenant.customer_name)
)
return standard_rulesets, lic, licensed_rulesets