def insert_to_db(data_dict, data_type): """Insert (Users | Groups) individually to RethinkDB from dict of data and begins delta sync timer.""" for entry in data_dict: entry_to_insert = {} entry_json = json.loads(entry.entry_to_json()) entry_attributes = entry_json["attributes"] for attribute in entry_attributes: if len(entry_attributes[attribute]) > 1: entry_to_insert[attribute] = entry_attributes[attribute] else: entry_to_insert[attribute] = entry_attributes[attribute][0] if data_type == "user": standardized_entry = inbound_user_filter(entry_to_insert, "ldap") elif data_type == "group": standardized_entry = inbound_group_filter(entry_to_insert, "ldap") inbound_entry = { "data": standardized_entry, "data_type": data_type, "sync_type": "initial", "timestamp": datetime.now().replace(tzinfo=timezone.utc).isoformat(), "provider_id": LDAP_DC, "raw": entry_json, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run() LOGGER.info( "Inserted %s %s records into inbound_queue.", str(len(data_dict)), data_type )
def insert_change_to_db(data, record_timestamp): """Insert change individually to rethinkdb from changelog eventhub of azure""" inbound_entry = { "data": data, "data_type": VALID_OPERATIONS[data["operation_name"]], "sync_type": "delta", "timestamp": record_timestamp, "provider_id": TENANT_ID, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run()
def insert_to_db(entry, data_type): """Insert user or group individually to RethinkDB from dict of data and begins delta sync timer.""" if data_type == "user": standard_entry = inbound_user_filter(entry, "ldap") elif data_type == "group": standard_entry = inbound_group_filter(entry, "ldap") else: LOGGER.warning("unsupported data type: %s", data_type) return inbound_entry = { "data": standard_entry, "data_type": data_type, "sync_type": "initial", "timestamp": r.now(), "provider_id": LDAP_DC, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run()
def insert_user_to_db(users_dict): """Insert users individually to rethinkdb from dict of users. This will also look up a user's manager.""" for user in users_dict["value"]: manager = fetch_user_manager(user["id"]) if manager: user["manager"] = manager["id"] else: user["manager"] = "" standardized_user = inbound_user_filter(user, "azure") inbound_entry = { "data": standardized_user, "data_type": "user", "sync_type": "initial", "timestamp": dt.now().isoformat(), "provider_id": TENANT_ID, "raw": user, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run()
def insert_group_to_db(groups_dict): """Insert groups individually to rethinkdb from dict of groups""" for group in groups_dict["value"]: owner = fetch_group_owner(group["id"]) if owner and "error" not in owner: group["owners"] = get_ids_from_list_of_dicts(owner["value"]) else: group["owners"] = [] group["members"] = get_ids_from_list_of_dicts(group["members"]) standardized_group = inbound_group_filter(group, "azure") inbound_entry = { "data": standardized_group, "data_type": "group", "sync_type": "initial", "timestamp": dt.now().isoformat(), "provider_id": TENANT_ID, "raw": group, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run()
def insert_to_db(data_dict, when_changed): """Insert (Users | Groups) individually to RethinkDB from dict of data and begins delta sync timer.""" insertion_counter = 0 for entry in data_dict: entry_to_insert = {} entry_json = json.loads(entry.entry_to_json()) entry_attributes = entry_json["attributes"] for attribute in entry_attributes: if len(entry_attributes[attribute]) > 1: entry_to_insert[attribute] = entry_attributes[attribute] else: entry_to_insert[attribute] = entry_attributes[attribute][0] if entry.whenChanged.value > when_changed: if "person" in entry.objectClass.value: data_type = "user" standardized_entry = inbound_user_filter( entry_to_insert, "ldap") else: data_type = "group" standardized_entry = inbound_group_filter( entry_to_insert, "ldap") entry_modified_timestamp = entry.whenChanged.value.strftime( "%Y-%m-%dT%H:%M:%S.%f+00:00") inbound_entry = { "data": standardized_entry, "data_type": data_type, "sync_type": "delta", "timestamp": entry_modified_timestamp, "provider_id": LDAP_DC, } add_transaction(inbound_entry) r.table("inbound_queue").insert(inbound_entry).run() sync_source = "ldap-" + data_type provider_id = LDAP_DC save_sync_time(provider_id, sync_source, "delta", entry_modified_timestamp) insertion_counter += 1 LOGGER.info("Inserted %s records into inbound_queue.", insertion_counter)