Skip to content

Commit

Permalink
Merge branch 'release/v0.10.2'
Browse files Browse the repository at this point in the history
* release/v0.10.2:
  Bump version from 0.10.1 to 0.10.2
  Fix: wrong version in virtual environment (#142)
  Add command `get-event` (#140)
  build(deps-dev): bump mypy from 0.902 to 0.910 (#138)
  build(deps-dev): bump isort from 5.8.0 to 5.9.1 (#134)
  build(deps-dev): bump types-requests from 0.1.13 to 2.25.0 (#135)
  Rewrite API handler (#137)
  Add start switch to deploy argument (#133)
  build(deps-dev): bump types-requests from 0.1.12 to 0.1.13 (#131)
  build(deps-dev): bump types-pkg-resources from 0.1.2 to 0.1.3 (#130)
  build(deps-dev): bump types-requests from 0.1.11 to 0.1.12 (#128)
  build(deps-dev): bump types-tabulate from 0.1.0 to 0.1.1 (#126)
  build(deps-dev): bump types-paramiko from 0.1.6 to 0.1.7 (#129)
  build(deps): bump gitpython from 3.1.17 to 3.1.18 (#127)
  build(deps-dev): bump types-toml from 0.1.2 to 0.1.3 (#125)
  • Loading branch information
MichaelSasser committed Jun 24, 2021
2 parents d6d2446 + e7e7bc8 commit 3fa15d8
Show file tree
Hide file tree
Showing 25 changed files with 560 additions and 490 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ repos:
# - id: double-quote-string-fixer (KEEP DISABLED)
# Makes sure files end in a newline and only a newline.
- id: end-of-file-fixer
exclude: "^CHANGELOG.rst"
# Removes "# -*- coding: utf-8 -*-" on the top of python files.
- id: fix-encoding-pragma
args: [ "--remove" ]
Expand Down Expand Up @@ -134,6 +135,8 @@ repos:
hooks:
- id: pydocstyle
args: [ "--ignore=D10,D21,D202" ]
additional_dependencies:
- toml

# static type checking with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
Expand All @@ -146,6 +149,7 @@ repos:
- types-requests
- types-tabulate
- types-paramiko
- types-attrs

- repo: https://github.com/econchick/interrogate
rev: 1.4.0
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ This is the changelog of MatrixCtl. You can find the issue tracker on
`GitHub <https://github.com/MichaelSasser/matrixctl/issues>`_.

.. towncrier release notes start
0.10.2 (2021-06-24)
===================

Features & Improvements
-----------------------

- Add start/restart switch to the deploy subcommand to start/restart the server
right after the deployment. (`#132
<https://github.com/MichaelSasser/matrixctl/issues/132>`_)
- Added the new command ``get-event``, which gets an event by ``event_id`` from
the Database and prints it as JSON. (`#139
<https://github.com/MichaelSasser/matrixctl/issues/139>`_)


Miscellaneous
-------------

- Rewritten API handler. (`#136
<https://github.com/MichaelSasser/matrixctl/issues/136>`_)
- Fixed: Wrong version while developing in virtual environment. (`#141
<https://github.com/MichaelSasser/matrixctl/issues/141>`_)


0.10.1 (2021-06-17)
===================

Expand Down Expand Up @@ -103,3 +127,4 @@ Miscellaneous
GitHub
<https://github.com/MichaelSasser/matrixctl/releases>`_. (`#61
<https://github.com/MichaelSasser/matrixctl/issues/61>`_)

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ usage: matrixctl [-h] [--version] [-d]
...
positional arguments:
{adduser,deluser,adduser-jitsi,deluser-jitsi,user,users,purge-history,rooms,delroom,update,upload,deploy,server-notice,start,restart,maintenance,check,version}
{adduser,deluser,adduser-jitsi,deluser-jitsi,user,users,purge-history,rooms,delroom,update,upload,deploy,server-notice,get-event,start,restart,maintenance,check,version}
adduser Add a new matrix user
deluser Deletes a user
adduser-jitsi Add a new jitsi user
Expand All @@ -39,6 +39,7 @@ positional arguments:
upload Upload a file.
deploy Provision and deploy
server-notice Send a server notice
get-event get an event from the DB
start Starts all OCI containers
stop Stops all OCI containers
restart Restarts all OCI containers (alias for start)
Expand Down
3 changes: 0 additions & 3 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
Changelog
=========

.. include:: ../../CHANGELOG.rst
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"sphinx.ext.inheritance_diagram",
]

suppress_warnings: list[str] = ["autosectionlabel.*"]

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
# "numpy": ("https://www.numpy.org/devdocs", None),
Expand Down
8 changes: 8 additions & 0 deletions docs/source/matrixctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ server-notice
:undoc-members:
:show-inheritance:

get-event
---------

.. automodule:: matrixctl.get_event
:members:
:undoc-members:
:show-inheritance:

Helpers
=======

Expand Down
7 changes: 5 additions & 2 deletions matrixctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

from __future__ import annotations

from importlib.metadata import version
from pathlib import Path

from single_source import get_version


__author__: str = "Michael Sasser"
__email__: str = "[email protected]"
__version__: str = version("matrixctl")
__version__: str = (
get_version(__name__, Path(__file__).parent.parent) or "Unknown"
)

HOME: str = str(Path.home())

Expand Down
4 changes: 3 additions & 1 deletion matrixctl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from matrixctl.deluser import subparser_deluser
from matrixctl.deluser_jitsi import subparser_deluser_jitsi
from matrixctl.deploy import subparser_deploy
from matrixctl.get_event import subparser_get_event
from matrixctl.maintenance import subparser_maintenance
from matrixctl.purge_history import subparser_purge_history
from matrixctl.rooms import subparser_rooms
Expand Down Expand Up @@ -98,6 +99,7 @@ def setup_parser() -> argparse.ArgumentParser:
subparser_upload,
subparser_deploy,
subparser_server_notice,
subparser_get_event,
subparser_start,
subparser_stop,
subparser_restart, # alias for start
Expand Down Expand Up @@ -130,7 +132,7 @@ def setup_logging(debug_mode: bool) -> None:
# %(asctime)s %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s

coloredlogs.install(
level="DEBUG" if debug_mode else "INFO",
level="DEBUG" if debug_mode else "WARNING",
fmt=(
"%(asctime)s %(name)s:%(lineno)d [%(funcName)s] %(levelname)s "
"%(message)s"
Expand Down
24 changes: 15 additions & 9 deletions matrixctl/adduser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

from .errors import InternalResponseError
from .handlers.ansible import ansible_run
from .handlers.api import API
from .handlers.api import RequestBuilder
from .handlers.api import request
from .handlers.toml import TOML
from .password_helpers import ask_password
from .password_helpers import ask_question
Expand Down Expand Up @@ -103,7 +104,6 @@ def adduser(arg: Namespace) -> int:
"""

toml: TOML = TOML()
api: API = API(toml.get("API", "Domain"), toml.get("API", "Token"))

while True:
passwd_generated: bool = False
Expand Down Expand Up @@ -139,13 +139,19 @@ def adduser(arg: Namespace) -> int:
"admin": "yes" if arg.admin else "no",
},
)
else:
try:
api.url.path = f"users/@{arg.user}:{toml.get('API','Domain')}"
api.method = "PUT"
api.request({"password": arg.passwd, "admin": arg.admin})
except InternalResponseError:
logger.error("The User was not added.")
return 0

req: RequestBuilder = RequestBuilder(
domain=toml.get("API", "Domain"),
token=toml.get("API", "Token"),
path=f"users/@{arg.user}:{toml.get('API','Domain')}",
data={"password": arg.passwd, "admin": arg.admin},
method="PUT",
)
try:
request(req)
except InternalResponseError:
logger.error("The User was not added.")

return 0

Expand Down
17 changes: 11 additions & 6 deletions matrixctl/delroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from argparse import _SubParsersAction as SubParsersAction

from .errors import InternalResponseError
from .handlers.api import API
from .handlers.api import RequestBuilder
from .handlers.api import request
from .handlers.toml import TOML


Expand Down Expand Up @@ -77,13 +78,17 @@ def delroom(arg: Namespace) -> int:
"""
toml: TOML = TOML()
api: API = API(toml.get("API", "Domain"), toml.get("API", "Token"))
api.method = "POST"
api.url.path = "purge_room"
api.url.api_version = "v1"
req: RequestBuilder = RequestBuilder(
token=toml.get("API", "Token"),
domain=toml.get("API", "Domain"),
path="purge_room",
method="POST",
api_version="v1",
data={"room_id": arg.RoomID},
)

try:
api.request({"room_id": arg.RoomID}).json()
request(req).json()
except InternalResponseError as e:
if "json" in dir(e.payload):
try:
Expand Down
18 changes: 12 additions & 6 deletions matrixctl/deluser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from argparse import _SubParsersAction as SubParsersAction

from .errors import InternalResponseError
from .handlers.api import API
from .handlers.api import RequestBuilder
from .handlers.api import request
from .handlers.toml import TOML


Expand Down Expand Up @@ -73,12 +74,17 @@ def deluser(arg: Namespace) -> int:
"""
toml: TOML = TOML()
api: API = API(toml.get("API", "Domain"), toml.get("API", "Token"))

req: RequestBuilder = RequestBuilder(
token=toml.get("API", "Token"),
domain=toml.get("API", "Domain"),
path=f"deactivate/@{arg.user}:{toml.get('API','Domain')}",
api_version="v1",
method="POST",
data={"erase": True},
)
try:
api.url.path = f"deactivate/@{arg.user}:{toml.get('API','Domain')}"
api.url.api_version = "v1"
api.method = "POST"
api.request({"erase": True})
request(req)
except InternalResponseError:
logger.error("The user was not deleted.")

Expand Down
12 changes: 10 additions & 2 deletions matrixctl/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ def subparser_deploy(subparsers: SubParsersAction) -> None:
parser: ArgumentParser = subparsers.add_parser(
"deploy", help="Provision and deploy"
)

parser.add_argument( # Done with tags / Does not use matrixctl.start !
"-s",
"--start",
action="store_true",
help="Start/Restart after the deployment",
)
parser.set_defaults(func=deploy)


def deploy(_: Namespace) -> int:
def deploy(arg: Namespace) -> int:
"""Deploy the ansible playbook.
Parameters
Expand All @@ -72,9 +79,10 @@ def deploy(_: Namespace) -> int:
"""
logger.debug("deploy")
toml: TOML = TOML()

ansible_run(
playbook=toml.get("ANSIBLE", "Playbook"),
tags="setup-all",
tags="setup-all,start" if arg.start else "setup-all",
)

return 0
Expand Down
Loading

0 comments on commit 3fa15d8

Please sign in to comment.