Login to servers that don't honor the uri spec for V1::Instance

Pleroma, Akkoma, and other servers do not follow the Mastodon spec
for the 'uri' attribute which specifies that it contains the domain
name of the instance. Instead, they return a complete URI.

As a workaround, we now detect this situation and parse out the
domain from the URI when necessary. This fixes issue #347.

Thanks to @laleanor for their patch and @rjp for ideas on how to
make it work with GotoSocial and other servers
pull/366/head
Daniel Schwarz 2023-05-26 17:53:15 -04:00
rodzic 6ce728e020
commit 9cd5c69a7e
5 zmienionych plików z 59 dodań i 1 usunięć

24
.vscode/launch.json vendored 100644
Wyświetl plik

@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 9000
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"justMyCode": false
}
]
}

Wyświetl plik

@ -6,3 +6,4 @@ sphinx
sphinx-autobuild
twine
wheel
debugpy

Wyświetl plik

@ -7,6 +7,7 @@ from getpass import getpass
from toot import api, config, DEFAULT_INSTANCE, User, App
from toot.exceptions import ApiError, ConsoleError
from toot.output import print_out
from urllib.parse import urlparse
def register_app(domain, base_url):
@ -46,8 +47,20 @@ def get_instance_domain(base_url):
f"running Mastodon version <yellow>{instance['version']}</yellow>"
)
# Pleroma and its forks return an actual URI here, rather than a
# domain name like Mastodon. This is contrary to the spec.¯
# in that case, parse out the domain and return it.
parsed_uri = urlparse(instance["uri"])
if parsed_uri.netloc:
# Pleroma, Akkoma, GotoSocial, etc.
return parsed_uri.netloc
else:
# Others including Mastodon servers
return parsed_uri.path
# NB: when updating to v2 instance endpoint, this field has been renamed to `domain`
return instance["uri"]
def create_user(app, access_token):

Wyświetl plik

@ -10,6 +10,7 @@ from itertools import chain
from toot import config, commands, CLIENT_NAME, CLIENT_WEBSITE, __version__
from toot.exceptions import ApiError, ConsoleError
from toot.output import print_out, print_err
from .debugger import initialize_debugger
VISIBILITY_CHOICES = ["public", "unlisted", "private", "direct"]
VISIBILITY_CHOICES_STR = ", ".join(f"'{v}'" for v in VISIBILITY_CHOICES)
@ -178,6 +179,12 @@ common_args = [
"action": 'store_true',
"default": False,
}),
(["--debugger"], {
"help": "launch with vscode debugpy",
"action": 'store_true',
"default": False,
}),
]
# Arguments added to commands which require authentication
@ -901,6 +908,9 @@ def run_command(app, user, name, args):
def main():
if "--debugger" in sys.argv:
initialize_debugger()
# Enable debug logging if --debug is in args
if "--debug" in sys.argv:
filename = os.getenv("TOOT_LOG_FILE")

10
toot/debugger.py 100644
Wyświetl plik

@ -0,0 +1,10 @@
def initialize_debugger():
import multiprocessing
if multiprocessing.current_process().pid > 1:
import debugpy
debugpy.listen(("0.0.0.0", 9000))
print("VSCode Debugger is ready to be attached on port 9000, press F5", flush=True)
debugpy.wait_for_client()
print("VSCode Debugger is now attached", flush=True)