def update_license_activation()

in src/lambdas/custodian_license_updater/handler.py [0:0]


    def update_license_activation(self, lic: License, rulesets: list[Ruleset]):
        clouds = {ruleset.cloud for ruleset in rulesets}
        if 'GCP' in clouds:
            clouds.remove('GCP')
            clouds.add('GOOGLE')
        if 'KUBERNETES' in clouds:
            # todo because currently we cannot create parent with cloud
            #  KUBERNETES SO activating for all
            clouds.clear()
        for customer, data in lic.customers.items():
            # TODO maybe move this block to some service
            am = data.get('attachment_model')
            all_tenants = False
            excluded_tenants = []
            tenant_names = []
            if am == PROHIBITED_ATTACHMENT:
                excluded_tenants = data.get('tenants')
                all_tenants = True
            else:  # permitted
                tenants = data.get('tenants')
                if tenants:
                    tenant_names = tenants
                else:
                    all_tenants = True

            payload = ResolveParentsPayload(
                parents=list(self.get_all_activations(lic.license_key, customer)),
                tenant_names=set(tenant_names),
                exclude_tenants=set(excluded_tenants),
                clouds=clouds,
                all_tenants=all_tenants
            )
            to_keep, to_delete = split_into_to_keep_to_delete(payload)
            for parent in to_delete:
                self.parent_service.force_delete(parent)
            to_create = build_parents(
                payload=payload,
                parent_service=self.parent_service,
                application_id=lic.license_key,
                customer_id=customer,
                type_=ParentType.CUSTODIAN_LICENSES,
                created_by='sre',
            )
            for parent in to_create:
                self.parent_service.save(parent)