def create_user_aad(queue_entry): """Creates a given user in AAD.""" headers = AUTH.check_token("POST") if headers: url = ("%s/%s/users", GRAPH_URL, GRAPH_VERSION) try: aad_user = outbound_user_creation_filter(queue_entry["data"], "azure") except ValueError: LOGGER.warning( "Unable to create user in AAD, displayName and email required: %s", queue_entry, ) raise ExpectedError( "Unable to create user without display name and email.") aad_user["passwordProfile"] = { "password": str(uuid4())[:16], "forceChangePasswordNextSignIn": True, } response = requests.post(url=url, headers=headers, json=aad_user) if response.status_code == 201: delete_entry_queue(queue_entry["id"], "outbound_queue") else: LOGGER.warning("Unable to create user in AAD: %s", queue_entry) raise ExpectedError("Unable to create user.")
def get_last_sync(source, sync_type): """ Search and get last sync entry from the specified source. Throws ExpectedError if sync_tracker table has not been initialized. """ try: LOGGER.info("Connecting to RethinkDB...") conn = connect_to_db() LOGGER.info("Successfully connected to RethinkDB!") last_sync = ( r.table("sync_tracker") .filter({"source": source, "sync_type": sync_type}) .max("timestamp") .coerce_to("object") .run(conn) ) conn.close() return last_sync except (r.ReqlOpFailedError, r.ReqlDriverError) as err: raise ExpectedError(err) except r.ReqlNonExistenceError: LOGGER.debug("The sync_tracker table is empty.") except Exception as err: LOGGER.warning(type(err).__name__) raise err
def create_group_aad(queue_entry): """Creates a given group in aad.""" headers = AUTH.check_token("POST") if headers: url = ("%s/%s/groups", GRAPH_URL, GRAPH_VERSION) try: aad_group = outbound_group_creation_filter(queue_entry["data"], "azure") except ValueError: LOGGER.warning("Unable to create group in AAD, mailNickname: %s", queue_entry) raise ExpectedError( "Unable to create group without display name and email.") response = requests.post(url=url, headers=headers, json=aad_group) if response.status_code == 201: delete_entry_queue(queue_entry["id"], "outbound_queue") else: LOGGER.warning("Unable to create group in AAD: %s", queue_entry) raise ExpectedError("Unable to create group.")
def peek_at_queue(table_name, provider_id): """Returns a single entry from table_name with the oldest timestamp and matching provider_id.""" try: queue_entry = (r.table(table_name).filter({ "provider_id": provider_id }).min("timestamp").coerce_to("object").run()) return queue_entry except (r.ReqlNonExistenceError, r.ReqlOpFailedError, r.ReqlDriverError) as err: raise ExpectedError(err) except Exception as err: LOGGER.warning(type(err).__name__) raise err
def get_last_delta_sync(provider_id, sync_type): """Search and get last delta sync entry from the specified provider.""" try: last_sync = (r.table("sync_tracker").filter({ "provider_id": provider_id, "sync_type": sync_type }).max("timestamp").coerce_to("object").run()) return last_sync except r.ReqlNonExistenceError: return None except (r.ReqlOpFailedError, r.ReqlDriverError) as err: raise ExpectedError(err) except Exception as err: LOGGER.warning(type(err).__name__) raise err
def get_last_sync(source, sync_type): """ Search and get last sync entry from the specified source. Throws ExpectedError if sync_tracker table has not been initialized. """ try: last_sync = (r.table("sync_tracker").filter({ "source": source, "sync_type": sync_type }).coerce_to("array").run()) return last_sync except (r.ReqlOpFailedError, r.ReqlDriverError) as err: raise ExpectedError(err) except Exception as err: LOGGER.warning(type(err).__name__) raise err