selfprivacy-rest-api/selfprivacy_api/graphql/mutations/ssh_mutations.py

55 lines
1.4 KiB
Python
Raw Normal View History

2022-07-21 00:23:59 +03:00
#!/usr/bin/env python3
"""Users management module"""
# pylint: disable=too-few-public-methods
import strawberry
2022-07-31 22:06:48 +03:00
from selfprivacy_api.graphql import IsAuthenticated
2022-07-31 00:02:19 +03:00
from selfprivacy_api.graphql.mutations.ssh_utils import (
create_ssh_key,
2022-07-31 22:06:48 +03:00
remove_ssh_key,
2022-07-31 00:02:19 +03:00
)
2022-07-25 02:59:43 +03:00
from selfprivacy_api.graphql.common_types.user import (
UserMutationReturn,
get_user_by_username,
)
2022-07-22 13:33:32 +03:00
2022-07-21 00:23:59 +03:00
@strawberry.input
2022-07-29 18:21:00 +03:00
class SshMutationInput:
2022-07-21 00:23:59 +03:00
"""Input type for ssh mutation"""
username: str
ssh_key: str
2022-07-21 00:23:59 +03:00
@strawberry.type
class SshMutations:
2022-07-21 00:23:59 +03:00
"""Mutations ssh"""
@strawberry.mutation(permission_classes=[IsAuthenticated])
2022-07-31 22:06:48 +03:00
def add_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
"""Add a new ssh key"""
2022-07-22 13:33:32 +03:00
2022-07-31 00:02:19 +03:00
success, message, code = create_ssh_key(ssh_input.username, ssh_input.ssh_key)
2022-07-21 00:23:59 +03:00
2022-07-31 00:02:19 +03:00
return UserMutationReturn(
success=success,
message=message,
code=code,
user=get_user_by_username(ssh_input.username),
)
2022-07-21 00:23:59 +03:00
@strawberry.mutation(permission_classes=[IsAuthenticated])
2022-07-31 22:06:48 +03:00
def remove_ssh_key(self, ssh_input: SshMutationInput) -> UserMutationReturn:
"""Remove ssh key from user"""
2022-07-21 00:23:59 +03:00
2022-07-31 22:06:48 +03:00
success, message, code = remove_ssh_key(ssh_input.username, ssh_input.ssh_key)
2022-07-21 00:23:59 +03:00
return UserMutationReturn(
2022-07-31 00:02:19 +03:00
success=success,
message=message,
code=code,
user=get_user_by_username(ssh_input.username),
2022-07-21 00:23:59 +03:00
)