Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3843:17c757bd74bc
component AP gateway: `getAPAccountFromId` now works with local IDs:
rel 370
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 14 Jul 2022 12:55:30 +0200 |
parents | 943901372eba |
children | 65e5718e7710 |
comparison
equal
deleted
inserted
replaced
3842:943901372eba | 3843:17c757bd74bc |
---|---|
1049 | 1049 |
1050 @async_lru(maxsize=LRU_MAX_SIZE) | 1050 @async_lru(maxsize=LRU_MAX_SIZE) |
1051 async def getAPAccountFromId(self, actor_id: str) -> str: | 1051 async def getAPAccountFromId(self, actor_id: str) -> str: |
1052 """Retrieve AP account from the ID URL | 1052 """Retrieve AP account from the ID URL |
1053 | 1053 |
1054 Works with external or local actor IDs. | |
1054 @param actor_id: AP ID of the actor (URL to the actor data) | 1055 @param actor_id: AP ID of the actor (URL to the actor data) |
1055 """ | 1056 @return: AP handle |
1057 """ | |
1058 if self.isLocalURL(actor_id): | |
1059 url_type, url_args = self.parseAPURL(actor_id) | |
1060 if url_type != "actor" or not url_args: | |
1061 raise exceptions.DataError( | |
1062 f"invalid local actor ID: {actor_id}" | |
1063 ) | |
1064 account = url_args[0] | |
1065 try: | |
1066 account_user, account_host = account.split('@') | |
1067 except ValueError: | |
1068 raise exceptions.DataError( | |
1069 f"invalid account from url: {actor_id}" | |
1070 ) | |
1071 if not account_user or account_host != self.public_url: | |
1072 raise exceptions.DataError( | |
1073 f"{account!r} is not a valid local account (from {actor_id})" | |
1074 ) | |
1075 return account | |
1076 | |
1056 url_parsed = parse.urlparse(actor_id) | 1077 url_parsed = parse.urlparse(actor_id) |
1057 actor_data = await self.getActorData(actor_id) | 1078 actor_data = await self.getActorData(actor_id) |
1058 username = actor_data.get("preferredUsername") | 1079 username = actor_data.get("preferredUsername") |
1059 if not username: | 1080 if not username: |
1060 raise exceptions.DataError( | 1081 raise exceptions.DataError( |