def __call__()

in patch_scripts/3.3.0/patch_parent_scope.py [0:0]


    def __call__(self, tenant_names: Tuple[str, ...], types: List[str]):
        old_parents = ParentsCol('old_parents.json')
        new_parents = ParentsCol('new_parents.json')
        _LOG.info('Going to patch specific scopes')
        if not types:
            _LOG.warning('Concrete types are not provided. All the found '
                         'types will be patched')
        for name in tenant_names:
            tenant = Tenant.get_nullable(name)
            if not tenant:
                _LOG.warning(f'{name} - not found. Skipping')
                continue
            _LOG.info(f'Going to patch tenant: {name}')
            for parent_id in self.iter_tenant_parents(tenant, types):
                _LOG.info(f'Going to patch parent: {parent_id} for '
                          f'tenant: {name}')
                parent = self.get_parent(parent_id)
                if not parent:
                    _LOG.warning('Parent not found. Skipping')
                    continue
                old_parents.add(parent_id)
                meta = parent.meta.as_dict()
                meta.pop('scope', None)
                meta.pop('clouds', None)
                copy = Parent(
                    parent_id=str(uuid.uuid4()),
                    customer_id=parent.customer_id,
                    application_id=parent.application_id,
                    type=parent.type,
                    description=parent.description,
                    meta=meta,
                    is_deleted=False,
                    creation_timestamp=int(java_timestamp()),
                    type_scope=f'{parent.type}{COMPOUND_KEYS_SEPARATOR}{ParentScope.SPECIFIC}{COMPOUND_KEYS_SEPARATOR}{tenant.name}'
                )
                new_parents.add(copy.parent_id)
                _LOG.info(f'A new specific parent: '
                          f'{copy.parent_id}:{copy.type} will be created')
                copy.save()