2018-05-21 15:04:53 +00:00
|
|
|
import subprocess
|
2018-05-18 18:41:41 +00:00
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
from pymongo import MongoClient
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from utils.key import Key
|
|
|
|
from utils.actor_service import ActorService
|
|
|
|
from utils.object_service import ObjectService
|
|
|
|
|
2018-05-21 15:04:53 +00:00
|
|
|
def noop():
|
|
|
|
pass
|
2018-05-18 18:41:41 +00:00
|
|
|
|
2018-05-21 15:04:53 +00:00
|
|
|
|
|
|
|
CUSTOM_CACHE_HOOKS = False
|
|
|
|
try:
|
|
|
|
from cache_hooks import purge as custom_cache_purge_hook
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
custom_cache_purge_hook = noop
|
|
|
|
|
|
|
|
VERSION = subprocess.check_output(['git', 'describe', '--always']).split()[0].decode('utf-8')
|
2018-05-18 18:41:41 +00:00
|
|
|
|
|
|
|
CTX_AS = 'https://www.w3.org/ns/activitystreams'
|
|
|
|
CTX_SECURITY = 'https://w3id.org/security/v1'
|
|
|
|
AS_PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'
|
|
|
|
HEADERS = [
|
|
|
|
'application/activity+json',
|
|
|
|
'application/ld+json;profile=https://www.w3.org/ns/activitystreams',
|
|
|
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
'application/ld+json',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
with open('config/me.yml') as f:
|
|
|
|
conf = yaml.load(f)
|
|
|
|
|
|
|
|
USERNAME = conf['username']
|
|
|
|
NAME = conf['name']
|
|
|
|
DOMAIN = conf['domain']
|
|
|
|
SCHEME = 'https' if conf.get('https', True) else 'http'
|
|
|
|
BASE_URL = SCHEME + '://' + DOMAIN
|
|
|
|
ID = BASE_URL
|
|
|
|
SUMMARY = conf['summary']
|
|
|
|
ICON_URL = conf['icon_url']
|
|
|
|
PASS = conf['pass']
|
2018-05-26 07:50:59 +00:00
|
|
|
PUBLIC_INSTANCES = conf.get('public_instances', [])
|
2018-05-25 21:57:29 +00:00
|
|
|
# TODO(tsileo): choose dark/light style
|
2018-05-21 19:10:21 +00:00
|
|
|
THEME_COLOR = conf.get('theme_color')
|
2018-05-18 18:41:41 +00:00
|
|
|
|
|
|
|
USER_AGENT = (
|
|
|
|
f'{requests.utils.default_user_agent()} '
|
|
|
|
f'(microblog.pub/{VERSION}; +{BASE_URL})'
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO(tsileo): use 'mongo:27017;
|
|
|
|
# mongo_client = MongoClient(host=['mongo:27017'])
|
|
|
|
mongo_client = MongoClient(
|
|
|
|
host=[os.getenv('MICROBLOGPUB_MONGODB_HOST', 'localhost:27017')],
|
|
|
|
)
|
|
|
|
|
|
|
|
DB = mongo_client['{}_{}'.format(USERNAME, DOMAIN.replace('.', '_'))]
|
|
|
|
KEY = Key(USERNAME, DOMAIN, create=True)
|
|
|
|
|
|
|
|
ME = {
|
|
|
|
"@context": [
|
|
|
|
CTX_AS,
|
|
|
|
CTX_SECURITY,
|
|
|
|
],
|
|
|
|
"type": "Person",
|
|
|
|
"id": ID,
|
|
|
|
"following": ID+"/following",
|
|
|
|
"followers": ID+"/followers",
|
|
|
|
"liked": ID+"/liked",
|
|
|
|
"inbox": ID+"/inbox",
|
|
|
|
"outbox": ID+"/outbox",
|
|
|
|
"preferredUsername": USERNAME,
|
|
|
|
"name": NAME,
|
|
|
|
"summary": SUMMARY,
|
|
|
|
"endpoints": {},
|
|
|
|
"url": ID,
|
|
|
|
"icon": {
|
|
|
|
"mediaType": "image/png",
|
|
|
|
"type": "Image",
|
|
|
|
"url": ICON_URL,
|
|
|
|
},
|
|
|
|
"publicKey": {
|
|
|
|
"id": ID+"#main-key",
|
|
|
|
"owner": ID,
|
|
|
|
"publicKeyPem": KEY.pubkey_pem,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
print(ME)
|
|
|
|
|
|
|
|
ACTOR_SERVICE = ActorService(USER_AGENT, DB.actors_cache, ID, ME, DB.instances)
|
|
|
|
OBJECT_SERVICE = ObjectService(USER_AGENT, DB.objects_cache, DB.inbox, DB.outbox, DB.instances)
|