diff --git a/inventory_provider/db/ims.py b/inventory_provider/db/ims.py index 96cb01cdb99a0d4e9dc0bef632612e74adfd1429..181cddf2c515f5685a8d62152267415ac97b1969 100644 --- a/inventory_provider/db/ims.py +++ b/inventory_provider/db/ims.py @@ -156,6 +156,18 @@ class IMS(object): return False + def _convert_keys(source): + if isinstance(source, list): + return [_convert_keys(x) for x in source] + elif isinstance(source, dict): + new = {} + for k, v in source.items(): + if isinstance(v, (dict, list)): + v = _convert_keys(v) + new[k.lower()] = v + return new + return source + while True: response = requests.get( url, @@ -165,7 +177,8 @@ class IMS(object): IMS._init_bearer_token(self.username, self.password) else: response.raise_for_status() - return_value = response.json() + orig = response.json() + return_value = _convert_keys(orig) if use_cache: IMS.cache[cache_key] = return_value diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 48ab115c15711abc3b7a14659a80e3139748250f..b60116a7f21f535f4fdf95e09d82eeb505a361d6 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -122,13 +122,13 @@ def otrs_get_customer_company_rows(ds): 'comments'] all_cus_comps = set() for customer in ds.get_all_entities('Customer'): - all_cus_comps.add(customer['Name']) - yield [customer['Name'].replace(' ', ''), customer['Name'], + all_cus_comps.add(customer['name']) + yield [customer['name'].replace(' ', ''), customer['name'], '', '', '', '', '', ''] for vendor in ds.get_all_entities('Vendor'): - if vendor['Name'] not in all_cus_comps: - all_cus_comps.add(vendor['Name']) - yield [vendor['Name'].replace(' ', ''), vendor['Name'], + if vendor['name'] not in all_cus_comps: + all_cus_comps.add(vendor['name']) + yield [vendor['name'].replace(' ', ''), vendor['name'], '', '', '', '', '', ''] @@ -142,7 +142,7 @@ def _is_valid_customer(cus): def otrs_get_customer_contacts(ds): def _get_customer_id2(t): - if t['Id'] == 3 or t['Name'] == 'EU NREN': + if t['id'] == 3 or t['name'] == 'EU NREN': return 'OTRS-GEANT-NREN' return '' @@ -153,21 +153,21 @@ def otrs_get_customer_contacts(ds): ims.CUSTOMER_PROPERTIES['CustomerType'] ]): - if customer['CustomerRelatedContacts']: + if customer['customerrelatedcontacts']: - for contact in customer['CustomerRelatedContacts']: + for contact in customer['customerrelatedcontacts']: t_customer_user = OrderedDict({ - 'email': contact['Contact']['Mail'], - 'username': contact['Contact']['Mail'], # TODO if tal_id is going to be present use that # noqa - 'customer_id': customer['Name'].replace(' ', ''), + 'email': contact['contact']['mail'], + 'username': contact['contact']['mail'], # TODO if tal_id is going to be present use that # noqa + 'customer_id': customer['name'].replace(' ', ''), 'customer_id_2': - _get_customer_id2(customer['CustomerType']), + _get_customer_id2(customer['customertype']), 'title': '', - 'firstname': contact['Contact']['Name'], + 'firstname': contact['contact']['name'], 'lastname': ' '.join(filter(None, [ - contact['Contact']['InFix'], - contact['Contact']['LastName'] + contact['contact']['infix'], + contact['contact']['lastname'] ])), 'phone': '', 'fax': '', @@ -193,16 +193,16 @@ def otrs_get_vendor_contacts(ds): ims.VENDOR_RELATED_CONTACT_PROPERTIES['Contact'] ]): t_customer_user = OrderedDict({ - 'email': vrc['Contact']['Mail'], - 'username': vrc['Contact']['Mail'], # TODO if tal_id is going to be present use that # noqa - 'customer_id': vrc['Vendor']['Name'].replace(' ', ''), + 'email': vrc['contact']['mail'], + 'username': vrc['contact']['mail'], # TODO if tal_id is going to be present use that # noqa + 'customer_id': vrc['vendor']['name'].replace(' ', ''), 'customer_id_2': '', 'title': '', - 'firstname': vrc['Contact']['Name'], + 'firstname': vrc['contact']['name'], 'lastname': ' '.join(filter(None, [ - vrc['Contact']['InFix'], - vrc['Contact']['LastName'] + vrc['contact']['infix'], + vrc['contact']['lastname'] ])), 'phone': '', 'fax': '', @@ -263,7 +263,6 @@ def otrs_get_customer_users_rows(ds, return_duplicates=False): if duplicate_emails: logger.info('Duplicate emails found in OTRS customer-user export: ' f'{duplicate_emails} - attempting to weed') - # weeded = [] for email in duplicate_emails: weeded = weed_duplicates(cus_by_email.pop(email)) if len(weeded) == 1: @@ -275,8 +274,6 @@ def otrs_get_customer_users_rows(ds, return_duplicates=False): ) if remaining_duplicates: - # need guidance what to do if this occurs, should we pick the first - # one for each, or ignore them completely? Ignoring them for now logger.error('Duplicate emails remain after weeding, ' f'{"including" if return_duplicates else "excluding"}' ' duplicates in returned data: ')