Add remove job by uid endpoint

This commit is contained in:
inexcode 2022-08-22 21:45:00 +04:00
parent 2e22ad7219
commit 50a309e2a2
6 changed files with 91 additions and 34 deletions

View file

@ -0,0 +1,27 @@
"""Manipulate jobs"""
# pylint: disable=too-few-public-methods
import strawberry
from selfprivacy_api.graphql.mutations.mutation_interface import GenericMutationReturn
from selfprivacy_api.jobs import Jobs
@strawberry.type
class JobMutations:
"""Mutations related to jobs"""
@strawberry.mutation
def remove_job(self, job_id: str) -> GenericMutationReturn:
"""Remove a job from the queue"""
result = Jobs().remove_by_uuid(job_id)
if result:
return GenericMutationReturn(
success=True,
code=200,
message="Job removed",
)
return GenericMutationReturn(
success=False,
code=404,
message="Job not found",
)

View file

@ -22,6 +22,7 @@ class SystemDomainInfo:
domain: str
hostname: str
provider: DnsProvider
@strawberry.field
def required_dns_records(self) -> typing.List[DnsRecord]:
"""Collect all required DNS records for all services"""
@ -37,7 +38,6 @@ class SystemDomainInfo:
]
def get_system_domain_info() -> SystemDomainInfo:
"""Get basic system domain info"""
with ReadUserData() as user_data:

View file

@ -130,6 +130,12 @@ class Jobs:
return job
def remove(self, job: Job) -> None:
"""
Remove a job from the jobs list.
"""
self.remove_by_uuid(str(job.uid))
def remove_by_uuid(self, job_uuid: str) -> bool:
"""
Remove a job from the jobs list.
"""
@ -137,9 +143,10 @@ class Jobs:
if "jobs" not in user_data:
user_data["jobs"] = []
for i, j in enumerate(user_data["jobs"]):
if j["uid"] == str(job.uid):
if j["uid"] == job_uuid:
del user_data["jobs"][i]
break
return True
return False
@staticmethod
def update(

View file

@ -42,34 +42,35 @@ def get_disabled_services() -> list[Service]:
def get_services_by_location(location: str) -> list[Service]:
return [service for service in services if service.get_location() == location]
def get_all_required_dns_records() -> list[ServiceDnsRecord]:
ip4 = network_utils.get_ip4()
ip6 = network_utils.get_ip6()
dns_records: list[ServiceDnsRecord] = [
ServiceDnsRecord(
type="A",
name="api",
content=ip4,
ttl=3600,
),
ServiceDnsRecord(
type="AAAA",
name="api",
content=ip6,
ttl=3600,
),
ServiceDnsRecord(
type="A",
name="meet",
content=ip4,
ttl=3600,
),
ServiceDnsRecord(
type="AAAA",
name="meet",
content=ip6,
ttl=3600,
),
ServiceDnsRecord(
type="A",
name="api",
content=ip4,
ttl=3600,
),
ServiceDnsRecord(
type="AAAA",
name="api",
content=ip6,
ttl=3600,
),
ServiceDnsRecord(
type="A",
name="meet",
content=ip4,
ttl=3600,
),
ServiceDnsRecord(
type="AAAA",
name="meet",
content=ip6,
ttl=3600,
),
]
for service in get_enabled_services():
dns_records += service.get_dns_records()

View file

@ -163,7 +163,10 @@ class MailServer(Service):
type="TXT", name="_dmarc", content=f"v=DMARC1; p=none", ttl=18000
),
ServiceDnsRecord(
type="TXT", name=domain, content=f"v=spf1 a mx ip4:{ip4} -all", ttl=18000
type="TXT",
name=domain,
content=f"v=spf1 a mx ip4:{ip4} -all",
ttl=18000,
),
ServiceDnsRecord(
type="TXT", name="selector._domainkey", content=dkim_record, ttl=18000

View file

@ -220,7 +220,9 @@ domainInfo {
"""
def dns_record(record_type="A", name="test-domain.tld", content=None, ttl=3600, priority=None):
def dns_record(
record_type="A", name="test-domain.tld", content=None, ttl=3600, priority=None
):
if content is None:
if record_type == "A":
content = "157.90.247.192"
@ -298,7 +300,12 @@ def test_graphql_get_domain(
)
assert is_dns_record_in_array(
dns_records,
dns_record(name="test-domain.tld", record_type="MX", content="test-domain.tld", priority=10),
dns_record(
name="test-domain.tld",
record_type="MX",
content="test-domain.tld",
priority=10,
),
)
assert is_dns_record_in_array(
dns_records,
@ -517,7 +524,10 @@ def test_graphql_get_auto_upgrade(authorized_client, turned_on):
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
)
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is True
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"]
is True
)
def test_graphql_get_auto_upgrade_on_undefined(authorized_client, undefined_config):
@ -533,7 +543,10 @@ def test_graphql_get_auto_upgrade_on_undefined(authorized_client, undefined_conf
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
)
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"]
is False
)
def test_graphql_get_auto_upgrade_without_vlaues(authorized_client, no_values):
@ -549,7 +562,10 @@ def test_graphql_get_auto_upgrade_without_vlaues(authorized_client, no_values):
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is True
)
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"]
is False
)
def test_graphql_get_auto_upgrade_turned_off(authorized_client, turned_off):
@ -565,7 +581,10 @@ def test_graphql_get_auto_upgrade_turned_off(authorized_client, turned_off):
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["enable"] is False
)
assert response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"] is False
assert (
response.json()["data"]["system"]["settings"]["autoUpgrade"]["allowReboot"]
is False
)
API_CHANGE_AUTO_UPGRADE_SETTINGS = """