comparison libervia/server/restricted_bridge.py @ 1509:106bae41f5c8

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:11 +0200
parents e739600267cd
children a3ca1bab6eb1
comparison
equal deleted inserted replaced
1508:ec3ad9abf9f9 1509:106bae41f5c8
20 from sat.core import exceptions 20 from sat.core import exceptions
21 from libervia.server.constants import Const as C 21 from libervia.server.constants import Const as C
22 22
23 23
24 class RestrictedBridge: 24 class RestrictedBridge:
25 """Bridge with limited access, which can be used in browser 25 """bridge with limited access, which can be used in browser
26 26
27 Only a few method are implemented, with potentially dangerous argument controlled. 27 Only a few method are implemented, with potentially dangerous argument controlled.
28 Security limit is used 28 Security limit is used
29 """ 29 """
30 30
31 def __init__(self, host): 31 def __init__(self, host):
32 self.host = host 32 self.host = host
33 self.security_limit = C.SECURITY_LIMIT 33 self.security_limit = C.SECURITY_LIMIT
34 34
35 def noServiceProfile(self, profile): 35 def no_service_profile(self, profile):
36 """Raise an error if service profile is used""" 36 """Raise an error if service profile is used"""
37 if profile == C.SERVICE_PROFILE: 37 if profile == C.SERVICE_PROFILE:
38 raise exceptions.PermissionError( 38 raise exceptions.PermissionError(
39 "This action is not allowed for service profile" 39 "This action is not allowed for service profile"
40 ) 40 )
41 41
42 async def getContacts(self, profile): 42 async def contacts_get(self, profile):
43 return await self.host.bridgeCall("getContacts", profile) 43 return await self.host.bridge_call("contacts_get", profile)
44 44
45 async def identityGet(self, entity, metadata_filter, use_cache, profile): 45 async def identity_get(self, entity, metadata_filter, use_cache, profile):
46 return await self.host.bridgeCall( 46 return await self.host.bridge_call(
47 "identityGet", entity, metadata_filter, use_cache, profile) 47 "identity_get", entity, metadata_filter, use_cache, profile)
48 48
49 async def identitiesGet(self, entities, metadata_filter, profile): 49 async def identities_get(self, entities, metadata_filter, profile):
50 return await self.host.bridgeCall( 50 return await self.host.bridge_call(
51 "identitiesGet", entities, metadata_filter, profile) 51 "identities_get", entities, metadata_filter, profile)
52 52
53 async def identitiesBaseGet(self, profile): 53 async def identities_base_get(self, profile):
54 return await self.host.bridgeCall( 54 return await self.host.bridge_call(
55 "identitiesBaseGet", profile) 55 "identities_base_get", profile)
56 56
57 async def psNodeDelete(self, service_s, node, profile): 57 async def ps_node_delete(self, service_s, node, profile):
58 self.noServiceProfile(profile) 58 self.no_service_profile(profile)
59 return await self.host.bridgeCall( 59 return await self.host.bridge_call(
60 "psNodeDelete", service_s, node, profile) 60 "ps_node_delete", service_s, node, profile)
61 61
62 async def psNodeAffiliationsSet(self, service_s, node, affiliations, profile): 62 async def ps_node_affiliations_set(self, service_s, node, affiliations, profile):
63 self.noServiceProfile(profile) 63 self.no_service_profile(profile)
64 return await self.host.bridgeCall( 64 return await self.host.bridge_call(
65 "psNodeAffiliationsSet", service_s, node, affiliations, profile) 65 "ps_node_affiliations_set", service_s, node, affiliations, profile)
66 66
67 async def psItemRetract(self, service_s, node, item_id, notify, profile): 67 async def ps_item_retract(self, service_s, node, item_id, notify, profile):
68 self.noServiceProfile(profile) 68 self.no_service_profile(profile)
69 return await self.host.bridgeCall( 69 return await self.host.bridge_call(
70 "psItemRetract", service_s, node, item_id, notify, profile) 70 "ps_item_retract", service_s, node, item_id, notify, profile)
71 71
72 async def mbPreview(self, service_s, node, data, profile): 72 async def mb_preview(self, service_s, node, data, profile):
73 return await self.host.bridgeCall( 73 return await self.host.bridge_call(
74 "mbPreview", service_s, node, data, profile) 74 "mb_preview", service_s, node, data, profile)
75 75
76 async def listSet(self, service_s, node, values, schema, item_id, extra, profile): 76 async def list_set(self, service_s, node, values, schema, item_id, extra, profile):
77 self.noServiceProfile(profile) 77 self.no_service_profile(profile)
78 return await self.host.bridgeCall( 78 return await self.host.bridge_call(
79 "listSet", service_s, node, values, "", item_id, "", profile) 79 "list_set", service_s, node, values, "", item_id, "", profile)
80 80
81 81
82 async def fileHTTPUploadGetSlot( 82 async def file_http_upload_get_slot(
83 self, filename, size, content_type, upload_jid, profile): 83 self, filename, size, content_type, upload_jid, profile):
84 self.noServiceProfile(profile) 84 self.no_service_profile(profile)
85 return await self.host.bridgeCall( 85 return await self.host.bridge_call(
86 "fileHTTPUploadGetSlot", filename, size, content_type, 86 "file_http_upload_get_slot", filename, size, content_type,
87 upload_jid, profile) 87 upload_jid, profile)
88 88
89 async def fileSharingDelete( 89 async def file_sharing_delete(
90 self, service_jid, path, namespace, profile): 90 self, service_jid, path, namespace, profile):
91 self.noServiceProfile(profile) 91 self.no_service_profile(profile)
92 return await self.host.bridgeCall( 92 return await self.host.bridge_call(
93 "fileSharingDelete", service_jid, path, namespace, profile) 93 "file_sharing_delete", service_jid, path, namespace, profile)
94 94
95 async def interestsRegisterFileSharing( 95 async def interests_file_sharing_register(
96 self, service, repos_type, namespace, path, name, extra_s, profile 96 self, service, repos_type, namespace, path, name, extra_s, profile
97 ): 97 ):
98 self.noServiceProfile(profile) 98 self.no_service_profile(profile)
99 if extra_s: 99 if extra_s:
100 # we only allow "thumb_url" here 100 # we only allow "thumb_url" here
101 extra = data_format.deserialise(extra_s) 101 extra = data_format.deserialise(extra_s)
102 if "thumb_url" in extra: 102 if "thumb_url" in extra:
103 extra_s = data_format.serialise({"thumb_url": extra["thumb_url"]}) 103 extra_s = data_format.serialise({"thumb_url": extra["thumb_url"]})
104 else: 104 else:
105 extra_s = "" 105 extra_s = ""
106 106
107 return await self.host.bridgeCall( 107 return await self.host.bridge_call(
108 "interestsRegisterFileSharing", service, repos_type, namespace, path, name, 108 "interests_file_sharing_register", service, repos_type, namespace, path, name,
109 extra_s, profile 109 extra_s, profile
110 ) 110 )
111 111
112 async def interestRetract( 112 async def interest_retract(
113 self, service_jid, item_id, profile 113 self, service_jid, item_id, profile
114 ): 114 ):
115 self.noServiceProfile(profile) 115 self.no_service_profile(profile)
116 return await self.host.bridgeCall( 116 return await self.host.bridge_call(
117 "interestRetract", service_jid, item_id, profile) 117 "interest_retract", service_jid, item_id, profile)
118 118
119 async def psInvite( 119 async def ps_invite(
120 self, invitee_jid_s, service_s, node, item_id, name, extra_s, profile 120 self, invitee_jid_s, service_s, node, item_id, name, extra_s, profile
121 ): 121 ):
122 self.noServiceProfile(profile) 122 self.no_service_profile(profile)
123 return await self.host.bridgeCall( 123 return await self.host.bridge_call(
124 "psInvite", invitee_jid_s, service_s, node, item_id, name, extra_s, profile 124 "ps_invite", invitee_jid_s, service_s, node, item_id, name, extra_s, profile
125 ) 125 )
126 126
127 async def FISInvite( 127 async def fis_invite(
128 self, invitee_jid_s, service_s, repos_type, namespace, path, name, extra_s, 128 self, invitee_jid_s, service_s, repos_type, namespace, path, name, extra_s,
129 profile 129 profile
130 ): 130 ):
131 self.noServiceProfile(profile) 131 self.no_service_profile(profile)
132 if extra_s: 132 if extra_s:
133 # we only allow "thumb_url" here 133 # we only allow "thumb_url" here
134 extra = data_format.deserialise(extra_s) 134 extra = data_format.deserialise(extra_s)
135 if "thumb_url" in extra: 135 if "thumb_url" in extra:
136 extra_s = data_format.serialise({"thumb_url": extra["thumb_url"]}) 136 extra_s = data_format.serialise({"thumb_url": extra["thumb_url"]})
137 else: 137 else:
138 extra_s = "" 138 extra_s = ""
139 139
140 return await self.host.bridgeCall( 140 return await self.host.bridge_call(
141 "FISInvite", invitee_jid_s, service_s, repos_type, namespace, path, name, 141 "fis_invite", invitee_jid_s, service_s, repos_type, namespace, path, name,
142 extra_s, profile 142 extra_s, profile
143 ) 143 )
144 144
145 async def FISAffiliationsSet( 145 async def fis_affiliations_set(
146 self, service_s, namespace, path, affiliations, profile 146 self, service_s, namespace, path, affiliations, profile
147 ): 147 ):
148 self.noServiceProfile(profile) 148 self.no_service_profile(profile)
149 return await self.host.bridgeCall( 149 return await self.host.bridge_call(
150 "FISAffiliationsSet", service_s, namespace, path, affiliations, profile 150 "fis_affiliations_set", service_s, namespace, path, affiliations, profile
151 ) 151 )
152 152
153 async def invitationSimpleCreate( 153 async def invitation_simple_create(
154 self, invitee_email, invitee_name, url_template, extra_s, profile 154 self, invitee_email, invitee_name, url_template, extra_s, profile
155 ): 155 ):
156 self.noServiceProfile(profile) 156 self.no_service_profile(profile)
157 return await self.host.bridgeCall( 157 return await self.host.bridge_call(
158 "invitationSimpleCreate", invitee_email, invitee_name, url_template, extra_s, 158 "invitation_simple_create", invitee_email, invitee_name, url_template, extra_s,
159 profile 159 profile
160 ) 160 )