Add provisioning API config (ref #154)
This commit is contained in:
@@ -33,6 +33,17 @@ appservice:
|
||||
# implicitly.
|
||||
external: https://example.com/public
|
||||
|
||||
# Provisioning API part of the web server for automated portal creation and fetching information.
|
||||
# Used by things like Dimension (https://dimension.t2bot.io/).
|
||||
provisioning:
|
||||
# Whether or not the provisioning API should be enabled.
|
||||
enabled: true
|
||||
# The prefix to use in the provisioning API endpoints.
|
||||
prefix: /_matrix/provision
|
||||
# The shared secret to authorize users of the API.
|
||||
# You can generate a decent secret with `pwgen -snc 32 1`
|
||||
shared_secret: "Very secret shared secret"
|
||||
|
||||
# The unique ID of this appservice.
|
||||
id: telegram
|
||||
# Username of the appservice bot.
|
||||
|
||||
@@ -39,6 +39,7 @@ from .portal import init as init_portal
|
||||
from .puppet import init as init_puppet
|
||||
from .formatter import init as init_formatter
|
||||
from .public import PublicBridgeWebsite
|
||||
from .provisioning_api import ProvisioningAPI
|
||||
from .context import Context
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -74,9 +75,9 @@ db_factory = orm.sessionmaker(bind=db_engine)
|
||||
db_session = orm.scoping.scoped_session(db_factory)
|
||||
Base.metadata.bind = db_engine
|
||||
|
||||
telethon_session_container = AlchemySessionContainer(engine=db_engine, session=db_session,
|
||||
table_base=Base, table_prefix="telethon_",
|
||||
manage_tables=False)
|
||||
session_container = AlchemySessionContainer(engine=db_engine, session=db_session,
|
||||
table_base=Base, table_prefix="telethon_",
|
||||
manage_tables=False)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
@@ -85,11 +86,16 @@ appserv = AppService(config["homeserver.address"], config["homeserver.domain"],
|
||||
config["appservice.bot_username"], log="mau.as", loop=loop,
|
||||
verify_ssl=config["homeserver.verify_ssl"])
|
||||
|
||||
context = Context(appserv, db_session, config, loop, None, None, telethon_session_container)
|
||||
context = Context(appserv, db_session, config, loop, None, None, session_container)
|
||||
|
||||
if config["appservice.public.enabled"]:
|
||||
public = PublicBridgeWebsite(loop)
|
||||
appserv.app.add_subapp(config.get("appservice.public.prefix", "/public"), public.app)
|
||||
appserv.app.add_subapp(config["appservice.public.prefix"] or "/public", public.app)
|
||||
|
||||
if config["appservice.provisioning.enabled"]:
|
||||
provisioning_api = ProvisioningAPI(loop)
|
||||
appserv.app.add_subapp(config["appservice.provisioning.prefix"] or "/_matrix/provisioning",
|
||||
provisioning_api.app)
|
||||
|
||||
with appserv.run(config["appservice.hostname"], config["appservice.port"]) as start:
|
||||
init_db(db_session)
|
||||
|
||||
@@ -328,5 +328,5 @@ class AbstractUser:
|
||||
def init(context):
|
||||
global config, MAX_DELETIONS
|
||||
AbstractUser.az, AbstractUser.db, config, AbstractUser.loop, _ = context
|
||||
AbstractUser.session_container = context.telethon_session_container
|
||||
AbstractUser.session_container = context.session_container
|
||||
MAX_DELETIONS = config.get("bridge.max_telegram_delete", 10)
|
||||
|
||||
@@ -159,6 +159,10 @@ class Config(DictWithRecursion):
|
||||
copy("appservice.public.prefix")
|
||||
copy("appservice.public.external")
|
||||
|
||||
copy("appservice.provisioning.enabled")
|
||||
copy("appservice.provisioning.prefix")
|
||||
copy("appservice.provisioning.shared_secret")
|
||||
|
||||
copy("appservice.id")
|
||||
copy("appservice.bot_username")
|
||||
copy("appservice.bot_displayname")
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
|
||||
|
||||
class Context:
|
||||
def __init__(self, az, db, config, loop, bot, mx, telethon_session_container):
|
||||
def __init__(self, az, db, config, loop, bot, mx, session_container):
|
||||
self.az = az
|
||||
self.db = db
|
||||
self.config = config
|
||||
self.loop = loop
|
||||
self.bot = bot
|
||||
self.mx = mx
|
||||
self.telethon_session_container = telethon_session_container
|
||||
self.session_container = session_container
|
||||
|
||||
def __iter__(self):
|
||||
yield self.az
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# -*- coding: future_fstrings -*-
|
||||
# mautrix-telegram - A Matrix-Telegram puppeting bridge
|
||||
# Copyright (C) 2018 Tulir Asokan
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from aiohttp import web
|
||||
import logging
|
||||
|
||||
|
||||
class ProvisioningAPI:
|
||||
log = logging.getLogger("mau.provisioning")
|
||||
|
||||
def __init__(self, loop):
|
||||
self.loop = loop
|
||||
|
||||
self.app = web.Application(loop=loop)
|
||||
Reference in New Issue
Block a user