~sircmpwn/builds.sr.ht

builds.sr.ht/buildsrht/app.py -rw-r--r-- 1.7 KiB
edac5158Ryan Gonzalez images/fedora: Install dnf-plugins-core 3 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from buildsrht.types import JobStatus, OAuthToken, User
from datetime import datetime, timedelta
from flask import session
from humanize import naturalsize
from srht.config import cfg
from srht.database import DbSession
from srht.flask import SrhtFlask
from srht.oauth import AbstractOAuthService, DelegatedScope

db = DbSession(cfg("builds.sr.ht", "connection-string"))
db.init()

client_id = cfg("builds.sr.ht", "oauth-client-id")
client_secret = cfg("builds.sr.ht", "oauth-client-secret")

class BuildOAuthService(AbstractOAuthService):
    def __init__(self):
        super().__init__(client_id, client_secret, delegated_scopes=[
            DelegatedScope("jobs", "build jobs", True),
        ], user_class=User, token_class=OAuthToken)

class BuildApp(SrhtFlask):
    def __init__(self):
        super().__init__("builds.sr.ht", __name__,
                oauth_service=BuildOAuthService())

        from buildsrht.blueprints.admin import admin
        from buildsrht.blueprints.api import api
        from buildsrht.blueprints.jobs import jobs
        from buildsrht.blueprints.secrets import secrets
        from srht.graphql import gql_blueprint

        self.register_blueprint(admin)
        self.register_blueprint(api)
        self.register_blueprint(jobs)
        self.register_blueprint(secrets)
        self.register_blueprint(gql_blueprint)

        from buildsrht.runner import builds_queue_metrics_collector
        self.metrics_registry.register(builds_queue_metrics_collector)

        @self.context_processor
        def inject():
            return {
                "datetime": datetime,
                "timedelta": timedelta,
                "JobStatus": JobStatus,
                "naturalsize": naturalsize,
            }

app = BuildApp()