Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_comp_ap_gateway/constants.py @ 4108:238e305f2306
plugin JID Search: JID search plugin, first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 06 Jul 2023 11:34:51 +0200 |
parents | ec9bed9df74f |
children | 7067b0d73183 |
rev | line source |
---|---|
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia ActivityPub Gateway |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 IMPORT_NAME = "ap-gateway" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 CONF_SECTION = f"component {IMPORT_NAME}" |
4105
ec9bed9df74f
compoent AP gateway: add forgotten contant
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
22 CONTENT_TYPE_WEBFINGER = "application/jrd+json; charset=utf-8" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 CONTENT_TYPE_AP = "application/activity+json; charset=utf-8" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 TYPE_ACTOR = "actor" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 TYPE_INBOX = "inbox" |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
26 TYPE_SHARED_INBOX = "shared_inbox" |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
27 TYPE_OUTBOX = "outbox" |
3764
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
28 TYPE_FOLLOWERS = "followers" |
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
29 TYPE_FOLLOWING = "following" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 TYPE_ITEM = "item" |
3792
865167c34b82
comp AP gateway: convert pubsub item retractation to AP `Delete` activity:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
31 TYPE_TOMBSTONE = "Tombstone" |
3832
201a22bfbb74
component AP gateway: convert AP mention to XEP-0372 mentions:
Goffi <goffi@goffi.org>
parents:
3824
diff
changeset
|
32 TYPE_MENTION = "Mention" |
3865
59fbb66b2923
component AP gateway: handle XMPP attachments -> AP likes conversion:
Goffi <goffi@goffi.org>
parents:
3846
diff
changeset
|
33 TYPE_LIKE = "Like" |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
34 TYPE_REACTION = "EmojiReact" |
3904 | 35 TYPE_EVENT = "Event" |
36 TYPE_JOIN = "Join" | |
37 TYPE_LEAVE = "Leave" | |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 MEDIA_TYPE_AP = "application/activity+json" |
3846
cc13efdd8360
component AP gateway: return item when `item` URL is used:
Goffi <goffi@goffi.org>
parents:
3844
diff
changeset
|
39 NS_AP = "https://www.w3.org/ns/activitystreams" |
cc13efdd8360
component AP gateway: return item when `item` URL is used:
Goffi <goffi@goffi.org>
parents:
3844
diff
changeset
|
40 NS_AP_PUBLIC = f"{NS_AP}#Public" |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3764
diff
changeset
|
41 # 3 values can be used, see https://www.w3.org/TR/activitypub/#public-addressing |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3764
diff
changeset
|
42 PUBLIC_TUPLE = (NS_AP_PUBLIC, "as:Public", "Public") |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
43 AP_REQUEST_TYPES = { |
3764
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
44 "GET": {TYPE_ACTOR, TYPE_OUTBOX, TYPE_FOLLOWERS, TYPE_FOLLOWING}, |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
45 "POST": {"inbox"}, |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
46 } |
4012
d538b07cddf3
plugin AP gateway: fix exception on HEAD requests
Goffi <goffi@goffi.org>
parents:
3904
diff
changeset
|
47 AP_REQUEST_TYPES["HEAD"] = AP_REQUEST_TYPES["GET"] |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
48 # headers to check for signature |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
49 SIGN_HEADERS = { |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
50 # headers needed for all HTTP methods |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
51 None: [ |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
52 # tuples are equivalent headers/pseudo headers, one of them must be present |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
53 ("date", "(created)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
54 ("digest", "(request-target)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
55 ], |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
56 b"GET": ["host"], |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
57 b"POST": ["digest"] |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
58 } |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
59 PAGE_SIZE = 10 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
60 HS2019 = "hs2019" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
61 # delay after which a signed request is not accepted anymore |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
62 SIGN_EXP = 12*60*60 # 12 hours (same value as for Mastodon) |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
63 |
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
64 LRU_MAX_SIZE = 200 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
65 ACTIVITY_TYPES = ( |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
66 "Accept", "Add", "Announce", "Arrive", "Block", "Create", "Delete", "Dislike", "Flag", |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
67 "Follow", "Ignore", "Invite", "Join", "Leave", "Like", "Listen", "Move", "Offer", |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
68 "Question", "Reject", "Read", "Remove", "TentativeReject", "TentativeAccept", |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
69 "Travel", "Undo", "Update", "View", |
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
70 # non-standard activities |
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
71 "EmojiReact" |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
72 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
73 ACTIVITY_TYPES_LOWER = [a.lower() for a in ACTIVITY_TYPES] |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
74 ACTIVITY_OBJECT_MANDATORY = ( |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
75 "Create", "Update", "Delete", "Follow", "Add", "Remove", "Like", "Block", "Undo" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
76 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
77 ACTIVITY_TARGET_MANDATORY = ("Add", "Remove") |
3793
b5c9021020df
component AP gateway: convert `Delete` AP activities to corresponding Pubsub `retract`:
Goffi <goffi@goffi.org>
parents:
3792
diff
changeset
|
78 # activities which can be used with Shared Inbox (i.e. with no account specified) |
b5c9021020df
component AP gateway: convert `Delete` AP activities to corresponding Pubsub `retract`:
Goffi <goffi@goffi.org>
parents:
3792
diff
changeset
|
79 # must be lowercase |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
80 ACTIVIY_NO_ACCOUNT_ALLOWED = ( |
3904 | 81 "create", "update", "delete", "announce", "undo", "like", "emojireact", "join", |
82 "leave" | |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
83 ) |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
84 # maximum number of parents to retrieve when comments_max_depth option is set |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
85 COMMENTS_MAX_PARENTS = 100 |
3824
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
86 # maximum size of avatar, in bytes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
87 MAX_AVATAR_SIZE = 1024 * 1024 * 5 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
88 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
89 # storage prefixes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
90 ST_AVATAR = "[avatar]" |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
91 ST_AP_CACHE = "[AP_item_cache]" |