def enforceQuotas(self, tenantList, tenantsType, ldap_conn=None): """Enforce the quota for each tenant on the list. Args: tenantList (List): A list of tenants as JSON from Insightly. tenantsType (str): A description of the type of tenant, one of 'SDA', 'FPA' or 'FPA (CRA)'. """ map(lambda t: self._enforceQuota(sanitize(t['PROJECT_NAME']), self._getTenantQuota(t, tenantsType), ldap_conn), tenantList)
def mapProjectsToLDAP(project_list, project_type, tenant_list=False): """Create a payload for ldap_updater module calls. Generate a list of dictionaries mapping Insightly properties to LDAP attributes. Args: project_list (List): A list of projects as JSON from Insightly to be converted into LDAP-like dictionaries. project_type (List): A description of the type of project, one of 'SDA', 'FPA' or 'FPA (CRA)'. tenant_list (List, optional): A list of tenants as JSON from Insightly, i.e. projects on the 'OpenStack Tenant' category. Returns: List: The project list converted into dictionaries with the relevant LDAP attributes, including nested tenants. """ return map(lambda p: {'o': str(p['PROJECT_ID']), 'description': project_type, 'cn': sanitize(p['PROJECT_NAME']), 'owner': mapContactsToLDAP(filter(lambda owner: owner['CONTACT_ID'] in map(lambda c: c['CONTACT_ID'], filter(lambda o: o['CONTACT_ID'] is not None and extractOne(str(o['ROLE']), TECH_ROLE, score_cutoff=80), p['LINKS'])), USERS) )[:1], 'seeAlso': mapContactsToLDAP(filter(lambda admin: admin['CONTACT_ID'] in map(lambda c: c['CONTACT_ID'], filter(lambda a: a['CONTACT_ID'] is not None and extractOne(str(a['ROLE']), ADMIN_ROLE, score_cutoff=80), p['LINKS'])), USERS) ), 'member': mapContactsToLDAP(filter(lambda member: member['CONTACT_ID'] in map(lambda c: c['CONTACT_ID'], filter(lambda m: m[ 'CONTACT_ID'] is not None, p['LINKS'])), USERS) ), 'tenants': mapProjectsToLDAP(filter(lambda t: t['PROJECT_ID'] in map(lambda sp: sp['SECOND_PROJECT_ID'], filter(lambda l: l[ 'SECOND_PROJECT_ID'] is not None, p['LINKS'])), tenant_list), project_type + [LU.OS_TENANT]) if tenant_list else [], }, project_list) if project_list else []