mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-02 14:16:38 +00:00
add system nixos tasks
This commit is contained in:
parent
337cf29884
commit
206589d5ad
|
@ -1,10 +1,12 @@
|
|||
"""System management mutations"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
import subprocess
|
||||
import typing
|
||||
import pytz
|
||||
import strawberry
|
||||
from selfprivacy_api.graphql import IsAuthenticated
|
||||
from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||
GenericMutationReturn,
|
||||
MutationReturnInterface,
|
||||
)
|
||||
from selfprivacy_api.utils import WriteUserData
|
||||
|
@ -84,3 +86,48 @@ class SystemMutations:
|
|||
enableAutoUpgrade=auto_upgrade,
|
||||
allowReboot=allow_reboot,
|
||||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def run_system_rebuild(self) -> GenericMutationReturn:
|
||||
rebuild_result = subprocess.Popen(
|
||||
["systemctl", "start", "sp-nixos-rebuild.service"], start_new_session=True
|
||||
)
|
||||
rebuild_result.communicate()[0]
|
||||
return GenericMutationReturn(
|
||||
success=True,
|
||||
message="Starting rebuild system",
|
||||
code=200,
|
||||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def run_system_rollback(self) -> GenericMutationReturn:
|
||||
rollback_result = subprocess.Popen(
|
||||
["systemctl", "start", "sp-nixos-rollback.service"], start_new_session=True
|
||||
)
|
||||
rollback_result.communicate()[0]
|
||||
return GenericMutationReturn(
|
||||
success=True,
|
||||
message="Starting rebuild system",
|
||||
code=200,
|
||||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def run_system_upgrade(self) -> GenericMutationReturn:
|
||||
upgrade_result = subprocess.Popen(
|
||||
["systemctl", "start", "sp-nixos-upgrade.service"], start_new_session=True
|
||||
)
|
||||
upgrade_result.communicate()[0]
|
||||
return GenericMutationReturn(
|
||||
success=True,
|
||||
message="Starting rebuild system",
|
||||
code=200,
|
||||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def reboot_system(self) -> GenericMutationReturn:
|
||||
subprocess.Popen(["reboot"], start_new_session=True)
|
||||
return GenericMutationReturn(
|
||||
success=True,
|
||||
message="System reboot has started",
|
||||
code=200,
|
||||
)
|
||||
|
|
|
@ -53,7 +53,7 @@ def mock_subprocess_check_output(mocker):
|
|||
|
||||
|
||||
API_REBUILD_SYSTEM_MUTATION = """
|
||||
mutation rebuildSystem() {
|
||||
mutation rebuildSystem {
|
||||
runSystemRebuild {
|
||||
success
|
||||
message
|
||||
|
@ -98,7 +98,7 @@ def test_graphql_system_rebuild(authorized_client, mock_subprocess_popen):
|
|||
|
||||
|
||||
API_UPGRADE_SYSTEM_MUTATION = """
|
||||
mutation upgradeSystem() {
|
||||
mutation upgradeSystem {
|
||||
runSystemUpgrade {
|
||||
success
|
||||
message
|
||||
|
@ -143,7 +143,7 @@ def test_graphql_system_upgrade(authorized_client, mock_subprocess_popen):
|
|||
|
||||
|
||||
API_ROLLBACK_SYSTEM_MUTATION = """
|
||||
mutation rollbackSystem() {
|
||||
mutation rollbackSystem {
|
||||
runSystemRollback {
|
||||
success
|
||||
message
|
Loading…
Reference in a new issue