This commit is contained in:
saces 2026-03-13 15:41:51 +01:00
parent 8df08611a9
commit bf3d383615
4 changed files with 40 additions and 15 deletions

View file

@ -1,18 +1,30 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
from _pygomx import lib, ffi
import json
import click
from _pygomx import ffi, lib
def whoami():
if len(sys.argv) != 3:
print("usage: ", sys.argv[0], " url accesstoken")
return 1
@click.command()
@click.option("-u", "--url", "hs_url", metavar="url", help="homeserver url")
@click.option("-t", "--token", "token", metavar="token", help="access token")
def whoami(hs_url, token):
"""this token belongs to?"""
url = sys.argv[1].encode(encoding="utf-8")
tk = sys.argv[2].encode(encoding="utf-8")
if hs_url is None and token is None:
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
r = lib.cliv0_whoami(url, tk)
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
result_dict = json.loads(result)
hs_url = result_dict["Matrixhost"]
token = result_dict["Token"]
r = lib.cliv0_whoami(
hs_url.encode(encoding="utf-8"), token.encode(encoding="utf-8")
)
result = ffi.string(r)
lib.FreeCString(r)
print(result)
print(result.decode("utf-8"))