Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
aa8cce58
Commit
aa8cce58
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
Add query_user/alias APIs.
parent
ce8bc642
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/appservice/api.py
+43
-4
43 additions, 4 deletions
synapse/appservice/api.py
synapse/handlers/appservice.py
+16
-10
16 additions, 10 deletions
synapse/handlers/appservice.py
with
59 additions
and
14 deletions
synapse/appservice/api.py
+
43
−
4
View file @
aa8cce58
...
@@ -12,25 +12,64 @@
...
@@ -12,25 +12,64 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
from
twisted.internet
import
defer
from
twisted.web.client
import
PartialDownloadError
from
synapse.http.client
import
SimpleHttpClient
class
ApplicationServiceApi
(
object
):
import
logging
import
urllib
logger
=
logging
.
getLogger
(
__name__
)
class
ApplicationServiceApi
(
SimpleHttpClient
):
"""
This class manages HS -> AS communications, including querying and
"""
This class manages HS -> AS communications, including querying and
pushing.
pushing.
"""
"""
def
__init__
(
self
,
hs
):
def
__init__
(
self
,
hs
):
super
(
ApplicationServiceApi
,
self
).
__init__
(
hs
)
self
.
hs_token
=
"
_hs_token_
"
# TODO extract hs token
self
.
hs_token
=
"
_hs_token_
"
# TODO extract hs token
@defer.inlineCallbacks
def
query_user
(
self
,
service
,
user_id
):
def
query_user
(
self
,
service
,
user_id
):
pass
uri
=
service
.
url
+
(
"
/users/%s
"
%
urllib
.
quote
(
user_id
))
response
=
None
try
:
response
=
yield
self
.
get_json
(
uri
,
{
"
access_token
"
:
self
.
hs_token
})
if
response
:
# just an empty json object
defer
.
returnValue
(
True
)
except
PartialDownloadError
as
e
:
if
e
.
status
==
404
:
defer
.
returnValue
(
False
)
return
logger
.
warning
(
"
query_user to %s received %s
"
,
(
uri
,
e
.
status
))
@defer.inlineCallbacks
def
query_alias
(
self
,
service
,
alias
):
def
query_alias
(
self
,
service
,
alias
):
pass
uri
=
service
.
url
+
(
"
/rooms/%s
"
%
urllib
.
quote
(
alias
))
response
=
None
try
:
response
=
yield
self
.
get_json
(
uri
,
{
"
access_token
"
:
self
.
hs_token
})
logger
.
info
(
"
%s
"
,
response
[
0
])
if
response
:
# just an empty json object
defer
.
returnValue
(
True
)
except
PartialDownloadError
as
e
:
if
e
.
status
==
404
:
defer
.
returnValue
(
False
)
return
logger
.
warning
(
"
query_alias to %s received %s
"
,
(
uri
,
e
.
status
))
def
push_bulk
(
self
,
service
,
events
):
def
push_bulk
(
self
,
service
,
events
):
pass
pass
@defer.inlineCallbacks
def
push
(
self
,
service
,
event
):
def
push
(
self
,
service
,
event
):
pass
response
=
yield
self
.
push_bulk
(
service
,
[
event
])
defer
.
returnValue
(
response
)
This diff is collapsed.
Click to expand it.
synapse/handlers/appservice.py
+
16
−
10
View file @
aa8cce58
...
@@ -55,10 +55,14 @@ class ApplicationServicesHandler(object):
...
@@ -55,10 +55,14 @@ class ApplicationServicesHandler(object):
logger
.
info
(
"
Updating application service info...
"
)
logger
.
info
(
"
Updating application service info...
"
)
yield
self
.
store
.
update_app_service
(
app_service
)
yield
self
.
store
.
update_app_service
(
app_service
)
logger
.
info
(
"
Sending ping to %s...
"
,
app_service
.
url
)
yield
self
.
appservice_api
.
query_alias
(
app_service
,
"
ping
"
)
def
unregister
(
self
,
token
):
def
unregister
(
self
,
token
):
logger
.
info
(
"
Unregister as_token=%s
"
,
token
)
logger
.
info
(
"
Unregister as_token=%s
"
,
token
)
yield
self
.
store
.
unregister_app_service
(
token
)
yield
self
.
store
.
unregister_app_service
(
token
)
@defer.inlineCallbacks
def
get_services_for_event
(
self
,
event
,
restrict_to
=
""
):
def
get_services_for_event
(
self
,
event
,
restrict_to
=
""
):
"""
Retrieve a list of application services interested in this event.
"""
Retrieve a list of application services interested in this event.
...
@@ -71,14 +75,15 @@ class ApplicationServicesHandler(object):
...
@@ -71,14 +75,15 @@ class ApplicationServicesHandler(object):
"""
"""
# We need to know the aliases associated with this event.room_id, if any
# We need to know the aliases associated with this event.room_id, if any
alias_list
=
[]
# TODO
alias_list
=
[]
# TODO
services
=
yield
self
.
store
.
get_app_services
()
interested_list
=
[
interested_list
=
[
s
for
s
in
self
.
store
.
get_app_
services
()
if
(
s
for
s
in
services
if
(
s
.
is_interested
(
event
,
restrict_to
,
alias_list
)
s
.
is_interested
(
event
,
restrict_to
,
alias_list
)
)
)
]
]
return
interested_list
defer
.
returnValue
(
interested_list
)
@defer.inlineCallbacks
def
notify_interested_services
(
self
,
event
):
def
notify_interested_services
(
self
,
event
):
"""
Notifies (pushes) all application services interested in this event.
"""
Notifies (pushes) all application services interested in this event.
...
@@ -89,7 +94,7 @@ class ApplicationServicesHandler(object):
...
@@ -89,7 +94,7 @@ class ApplicationServicesHandler(object):
event(Event): The event to push out to interested services.
event(Event): The event to push out to interested services.
"""
"""
# Gather interested services
# Gather interested services
services
=
self
.
get_services_for_event
(
event
)
services
=
yield
self
.
get_services_for_event
(
event
)
if
len
(
services
)
==
0
:
if
len
(
services
)
==
0
:
return
# no services need notifying
return
# no services need notifying
...
@@ -97,14 +102,14 @@ class ApplicationServicesHandler(object):
...
@@ -97,14 +102,14 @@ class ApplicationServicesHandler(object):
# all services which match that user regex.
# all services which match that user regex.
unknown_user
=
False
# TODO check
unknown_user
=
False
# TODO check
if
unknown_user
:
if
unknown_user
:
user_query_services
=
self
.
get_services_for_event
(
user_query_services
=
yield
self
.
get_services_for_event
(
event
=
event
,
event
=
event
,
restrict_to
=
ApplicationService
.
NS_USERS
restrict_to
=
ApplicationService
.
NS_USERS
)
)
for
user_service
in
user_query_services
:
for
user_service
in
user_query_services
:
# this needs to block XXX: Need to feed response back to caller
# this needs to block XXX: Need to feed response back to caller
is_known_user
=
self
.
appservice_api
.
query_user
(
is_known_user
=
yield
self
.
appservice_api
.
query_user
(
user_service
,
event
user_service
,
event
.
sender
)
)
if
is_known_user
:
if
is_known_user
:
# the user exists now,so don't query more ASes.
# the user exists now,so don't query more ASes.
...
@@ -114,14 +119,15 @@ class ApplicationServicesHandler(object):
...
@@ -114,14 +119,15 @@ class ApplicationServicesHandler(object):
# API for all services which match that room alias regex.
# API for all services which match that room alias regex.
unknown_room_alias
=
False
# TODO check
unknown_room_alias
=
False
# TODO check
if
unknown_room_alias
:
if
unknown_room_alias
:
alias_query_services
=
self
.
get_services_for_event
(
alias
=
"
something
"
# TODO
alias_query_services
=
yield
self
.
get_services_for_event
(
event
=
event
,
event
=
event
,
restrict_to
=
ApplicationService
.
NS_ALIASES
restrict_to
=
ApplicationService
.
NS_ALIASES
)
)
for
alias_service
in
alias_query_services
:
for
alias_service
in
alias_query_services
:
# this needs to block XXX: Need to feed response back to caller
# this needs to block XXX: Need to feed response back to caller
is_known_alias
=
self
.
appservice_api
.
query_alias
(
is_known_alias
=
yield
self
.
appservice_api
.
query_alias
(
alias_service
,
event
alias_service
,
alias
)
)
if
is_known_alias
:
if
is_known_alias
:
# the alias exists now so don't query more ASes.
# the alias exists now so don't query more ASes.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment