Update for sr.ht unified config

This commit is contained in:
Drew DeVault 2018-09-02 18:07:34 -04:00
parent 324fba48c0
commit 66c22baf60
7 changed files with 74 additions and 63 deletions

55
config.example.ini Normal file
View File

@ -0,0 +1,55 @@
[sr.ht]
#
# The name of your network of sr.ht-based sites
site-name=sr.ht
#
# Contact information for the site owners
owner-name=Drew DeVault
owner-email=sir@cmpwn.com
#
# The source code for your fork of sr.ht
source-url=https://git.sr.ht/~sircmpwn/srht
#
# A secret key to encrypt session cookies with
secret-key=CHANGEME
[mail]
#
# Outgoing SMTP settings
smtp-host=
smtp-port=
smtp-user=
smtp-password=
smtp-from=
#
# Application exceptions are emailed to this address
error-to=
error-from=
#
# Your PGP key information (DO NOT mix up pub and priv here)
# You must remove the password from your secret key, if present.
# You can do this with gpg --edit-key [key-id], then use the passwd
# command and do not enter a new password.
pgp-privkey=
pgp-pubkey=
pgp-key-id=
[todo.sr.ht]
#
# URL todo.sr.ht is being served at (protocol://domain)
origin=http://todo.sr.ht.local
#
# Address and port to bind the debug server to
debug-host=0.0.0.0
debug-port=5003
#
# Configures the SQLAlchemy connection string for the database.
connection-string=postgresql://postgres@localhost/todo.sr.ht
#
# todo.sr.ht's OAuth client ID and secret for meta.sr.ht
# Register your client at meta.example.org/oauth
oauth-client-id=CHANGEME
oauth-client-secret=CHANGEME
[meta.sr.ht]
origin=http://meta.sr.ht.local

View File

@ -1,43 +0,0 @@
#
# todo.sr.ht config
[server]
#
# Specifies the protocol (usually http or https) meta.sr.ht runs with.
protocol=http
#
# Specifies the domain name meta.sr.ht is running on.
domain=todo.sr.ht.local
#
# A secret key to encrypt session cookies with.
secret-key=CHANGEME
[debug]
#
# Address and port to bind the debug server to.
debug-host=0.0.0.0
debug-port=5003
[sr.ht]
#
# Configures the SQLAlchemy connection string for the database.
connection-string=postgresql://postgres@localhost/todo.sr.ht
#
# The name of your network of sr.ht-based sites
site-name=sr.ht
[network]
#
# Location of other sites in your network
#
# This isn't a hardcoded list, add or remove entries as you like. The upstream
# sites do know about each other and will omit integrations if you leave out
# the relevant site. Only meta is required.
meta=http://meta.sr.ht.local
git=http://git.sr.ht.local
builds=http://builds.sr.ht.local
todo=http://todo.sr.ht.local
[meta.sr.ht]
oauth-client-id=CHANGEME
oauth-client-secret=CHANGEME

4
run.py
View File

@ -6,6 +6,6 @@ import os
app.static_folder = os.path.join(os.getcwd(), "static") app.static_folder = os.path.join(os.getcwd(), "static")
if __name__ == '__main__': if __name__ == '__main__':
app.run(host=cfg("debug", "debug-host"), app.run(host=cfg("todo.sr.ht", "debug-host"),
port=cfgi("debug", "debug-port"), port=cfgi("todo.sr.ht", "debug-port"),
debug=True) debug=True)

View File

@ -1,19 +1,15 @@
from jinja2 import Markup from jinja2 import Markup
from srht.flask import SrhtFlask from srht.flask import SrhtFlask
from srht.config import cfg, load_config from srht.config import cfg
load_config("todo")
from srht.database import DbSession from srht.database import DbSession
db = DbSession(cfg("sr.ht", "connection-string"))
db = DbSession(cfg("todo.sr.ht", "connection-string"))
from todosrht.types import User from todosrht.types import User
from todosrht.types import TicketAccess, TicketStatus, TicketResolution from todosrht.types import TicketAccess, TicketStatus, TicketResolution
from todosrht.types import TicketSeen from todosrht.types import TicketSeen
db.init()
from todosrht.blueprints.html import html db.init()
from todosrht.blueprints.tracker import tracker
from todosrht.blueprints.ticket import ticket
def render_status(ticket, access): def render_status(ticket, access):
if TicketAccess.edit in access: if TicketAccess.edit in access:
@ -31,16 +27,20 @@ def render_status(ticket, access):
class TodoApp(SrhtFlask): class TodoApp(SrhtFlask):
def __init__(self): def __init__(self):
super().__init__("todo", __name__) super().__init__("todo.sr.ht", __name__)
self.url_map.strict_slashes = False self.url_map.strict_slashes = False
from todosrht.blueprints.html import html
from todosrht.blueprints.tracker import tracker
from todosrht.blueprints.ticket import ticket
self.register_blueprint(html) self.register_blueprint(html)
self.register_blueprint(tracker) self.register_blueprint(tracker)
self.register_blueprint(ticket) self.register_blueprint(ticket)
meta_client_id = cfg("meta.sr.ht", "oauth-client-id") meta_client_id = cfg("todo.sr.ht", "oauth-client-id")
meta_client_secret = cfg("meta.sr.ht", "oauth-client-secret") meta_client_secret = cfg("todo.sr.ht", "oauth-client-secret")
self.configure_meta_auth(meta_client_id, meta_client_secret) self.configure_meta_auth(meta_client_id, meta_client_secret)
@self.context_processor @self.context_processor

View File

@ -10,7 +10,7 @@ import requests
html = Blueprint('html', __name__) html = Blueprint('html', __name__)
meta_uri = cfg("network", "meta") meta_uri = cfg("meta.sr.ht", "origin")
def filter_authorized_events(events): def filter_authorized_events(events):
events = (events events = (events

View File

@ -5,8 +5,7 @@ import pystache
from srht.config import cfg, cfgi from srht.config import cfg, cfgi
from flask_login import current_user from flask_login import current_user
protocol = cfg("server", "protocol") origin = cfg("todo.sr.ht", "origin")
domain = cfg("server", "domain")
def notify(sub, template, subject, headers, **kwargs): def notify(sub, template, subject, headers, **kwargs):
encrypt_key = None encrypt_key = None
@ -21,7 +20,7 @@ def notify(sub, template, subject, headers, **kwargs):
body = html.parser.HTMLParser().unescape(\ body = html.parser.HTMLParser().unescape(\
pystache.render(f.read(), { pystache.render(f.read(), {
'user': current_user, 'user': current_user,
'root': '{}://{}'.format(protocol, domain), 'root': origin,
**kwargs **kwargs
})) }))
send_email(body, to, subject, encrypt_key=encrypt_key, **headers) send_email(body, to, subject, encrypt_key=encrypt_key, **headers)

View File

@ -4,14 +4,14 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<p> <p>
Welcome to {{cfg("server", "domain")}}. This is a part of the Welcome to {{domain}}. This is a part of the
<a href="{{cfg("network", "meta")}}"> <a href="{{cfg("meta.sr.ht", "origin")}}">
{{cfg("sr.ht", "site-name")}} network {{cfg("sr.ht", "site-name")}} network
</a> </a>
and provides ticket tracking services to members. If you already have and provides ticket tracking services to members. If you already have
an account, you can an account, you can
<a href="{{oauth_url}}">log in here</a>. New users can <a href="{{oauth_url}}">log in here</a>. New users can
<a href="{{cfg("network", "meta")}}">register here</a>. <a href="{{cfg("meta.sr.ht", "origin")}}">register here</a>.
</p> </p>
</div> </div>
</div> </div>