def build_corp_user_mce( self, dn: str, attrs: dict, manager_ldap: Optional[str]) -> Optional[MetadataChangeEvent]: """ Create the MetadataChangeEvent via DN and attributes. """ ldap_user = guess_person_ldap(attrs) full_name = attrs["cn"][0].decode() first_name = attrs["givenName"][0].decode() last_name = attrs["sn"][0].decode() email = (attrs["mail"][0]).decode() if "mail" in attrs else ldap_user display_name = ((attrs["displayName"][0]).decode() if "displayName" in attrs else full_name) department = ((attrs["departmentNumber"][0]).decode() if "departmentNumber" in attrs else None) title = attrs["title"][0].decode() if "title" in attrs else None manager_urn = f"urn:li:corpuser:{manager_ldap}" if manager_ldap else None return MetadataChangeEvent(proposedSnapshot=CorpUserSnapshotClass( urn=f"urn:li:corpuser:{ldap_user}", aspects=[ CorpUserInfoClass( active=True, email=email, fullName=full_name, firstName=first_name, lastName=last_name, departmentName=department, displayName=display_name, title=title, managerUrn=manager_urn, ) ], ))
def create_owner_entity_mce(owner: str) -> MetadataChangeEventClass: clean_name = clean_owner_name(owner) return MetadataChangeEventClass(proposedSnapshot=CorpUserSnapshotClass( urn=owner_name_to_urn(clean_name), aspects=[ CorpUserInfoClass( active=True, displayName=owner, fullName=owner, email=f"{clean_name}[email protected]", ) ], ))
def _map_azure_ad_user_to_corp_user(self, azure_ad_user): full_name = (str(azure_ad_user.get("givenName", "")) + " " + str(azure_ad_user.get("surname", ""))) return CorpUserInfoClass( active=True, displayName=azure_ad_user.get("displayName", full_name), firstName=azure_ad_user.get("givenName", None), lastName=azure_ad_user.get("surname", None), fullName=full_name, email=azure_ad_user.get("mail"), title=azure_ad_user.get("jobTitle", None), countryCode=azure_ad_user.get("mobilePhone", None), )
def _map_okta_user_profile(self, profile: UserProfile) -> CorpUserInfoClass: # TODO: Extract user's manager if provided. # Source: https://developer.okta.com/docs/reference/api/users/#default-profile-properties full_name = f"{profile.firstName} {profile.lastName}" return CorpUserInfoClass( active=True, displayName=profile.displayName if profile.displayName is not None else full_name, firstName=profile.firstName, lastName=profile.lastName, fullName=full_name, email=profile.email, title=profile.title, countryCode=profile.countryCode, departmentName=profile.department, )
def to_datahub_user( self, user: PowerBiAPI.User) -> List[MetadataChangeProposalWrapper]: """ Map PowerBi user to datahub user """ LOGGER.info("Converting user {}(id={}) to datahub's user".format( user.displayName, user.id)) # Create an URN for user user_urn = builder.make_user_urn(user.get_urn_part()) user_info_instance = CorpUserInfoClass( displayName=user.displayName, email=user.emailAddress, title=user.displayName, active=True, ) info_mcp = self.new_mcp( entity_type=Constant.CORP_USER, entity_urn=user_urn, aspect_name=Constant.CORP_USER_INFO, aspect=user_info_instance, ) # removed status mcp status_mcp = self.new_mcp( entity_type=Constant.CORP_USER, entity_urn=user_urn, aspect_name=Constant.STATUS, aspect=StatusClass(removed=False), ) user_key = CorpUserKeyClass(username=user.id) user_key_mcp = self.new_mcp( entity_type=Constant.CORP_USER, entity_urn=user_urn, aspect_name=Constant.CORP_USER_KEY, aspect=user_key, ) return [info_mcp, status_mcp, user_key_mcp]