Skip to content

Commit

Permalink
Release 0.15.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Dec 4, 2022
2 parents 41c0e85 + 448c59e commit 824cbdc
Show file tree
Hide file tree
Showing 63 changed files with 487 additions and 192 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ jobs:
if [ $? -ne 0 ]; then
exit 1
fi
- name: Lint with flake8
working-directory: api/tacticalrmm
run: |
flake8 --config .flake8 .
if [ $? -ne 0 ]; then
exit 1
fi
- name: Run django tests
env:
Expand Down
12 changes: 12 additions & 0 deletions api/tacticalrmm/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
ignore = E501,W503,E722,E203
exclude =
.mypy*
.pytest*
.git
demo_data.py
manage.py
*/__pycache__/*
*/env/*
/usr/local/lib/*
**/migrations/*
2 changes: 1 addition & 1 deletion api/tacticalrmm/accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_delete(self):
r = self.client.delete(url)
self.assertEqual(r.status_code, 200)

url = f"/accounts/893452/users/"
url = "/accounts/893452/users/"
r = self.client.delete(url)
self.assertEqual(r.status_code, 404)

Expand Down
3 changes: 2 additions & 1 deletion api/tacticalrmm/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def delete(self, request, pk):

class UserActions(APIView):
permission_classes = [IsAuthenticated, AccountsPerms]

# reset password
def post(self, request):
user = get_object_or_404(User, pk=request.data["id"])
Expand Down Expand Up @@ -267,7 +268,7 @@ def post(self, request):
request.data["key"] = get_random_string(length=32).upper()
serializer = APIKeySerializer(data=request.data)
serializer.is_valid(raise_exception=True)
obj = serializer.save()
serializer.save()
return Response("The API Key was added")


Expand Down
8 changes: 6 additions & 2 deletions api/tacticalrmm/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ def do_update(self, *, token: str = "", force: bool = False) -> str:

@property
def status(self) -> str:
offline = djangotime.now() - djangotime.timedelta(minutes=self.offline_time)
overdue = djangotime.now() - djangotime.timedelta(minutes=self.overdue_time)
now = djangotime.now()
offline = now - djangotime.timedelta(minutes=self.offline_time)
overdue = now - djangotime.timedelta(minutes=self.overdue_time)

if self.last_seen is not None:
if (self.last_seen < offline) and (self.last_seen > overdue):
Expand Down Expand Up @@ -539,6 +540,7 @@ def run_script(
run_on_any: bool = False,
history_pk: int = 0,
run_as_user: bool = False,
env_vars: list[str] = [],
) -> Any:

from scripts.models import Script
Expand All @@ -560,6 +562,7 @@ def run_script(
"shell": script.shell,
},
"run_as_user": run_as_user,
"env_vars": env_vars,
}

if history_pk != 0:
Expand Down Expand Up @@ -800,6 +803,7 @@ async def nats_cmd(
options = {
"servers": f"tls://{settings.ALLOWED_HOSTS[0]}:{nats_std_port}",
"user": "tacticalrmm",
"name": "trmm-django",
"password": settings.SECRET_KEY,
"connect_timeout": 3,
"max_reconnect_attempts": 2,
Expand Down
2 changes: 2 additions & 0 deletions api/tacticalrmm/agents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def run_script_email_results_task(
args: list[str] = [],
history_pk: int = 0,
run_as_user: bool = False,
env_vars: list[str] = [],
):
agent = Agent.objects.get(pk=agentpk)
script = Script.objects.get(pk=scriptpk)
Expand All @@ -165,6 +166,7 @@ def run_script_email_results_task(
wait=True,
history_pk=history_pk,
run_as_user=run_as_user,
env_vars=env_vars,
)
if r == "timeout":
DebugLog.error(
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/agents/tests/test_agent_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_agent_update_permissions(self, update_task, mock_token):
agents = baker.make_recipe("agents.agent", _quantity=5)
other_agents = baker.make_recipe("agents.agent", _quantity=7)

url = f"/agents/update/"
url = "/agents/update/"

data = {
"agent_ids": [agent.agent_id for agent in agents]
Expand Down
3 changes: 1 addition & 2 deletions api/tacticalrmm/agents/tests/test_agent_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest.mock import patch, AsyncMock
from unittest.mock import patch

from django.conf import settings
from rest_framework.response import Response

from agents.utils import generate_linux_install, get_agent_url
from tacticalrmm.test import TacticalTestCase
Expand Down
19 changes: 17 additions & 2 deletions api/tacticalrmm/agents/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def test_run_script(self, run_script, email_task):
"args": [],
"timeout": 15,
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -555,6 +556,7 @@ def test_run_script(self, run_script, email_task):
wait=True,
history_pk=hist.pk,
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand All @@ -567,6 +569,7 @@ def test_run_script(self, run_script, email_task):
"emailMode": "default",
"emails": ["admin@example.com", "bob@example.com"],
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}
r = self.client.post(url, data, format="json")
self.assertEqual(r.status_code, 200)
Expand All @@ -577,6 +580,7 @@ def test_run_script(self, run_script, email_task):
emails=[],
args=["abc", "123"],
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
email_task.reset_mock()

Expand All @@ -591,6 +595,7 @@ def test_run_script(self, run_script, email_task):
emails=["admin@example.com", "bob@example.com"],
args=["abc", "123"],
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)

# test fire and forget
Expand All @@ -600,6 +605,7 @@ def test_run_script(self, run_script, email_task):
"args": ["hello", "world"],
"timeout": 22,
"run_as_user": True,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -614,6 +620,7 @@ def test_run_script(self, run_script, email_task):
timeout=25,
history_pk=hist.pk,
run_as_user=True,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand All @@ -629,6 +636,7 @@ def test_run_script(self, run_script, email_task):
"custom_field": custom_field.pk,
"save_all_output": True,
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -644,6 +652,7 @@ def test_run_script(self, run_script, email_task):
wait=True,
history_pk=hist.pk,
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand All @@ -662,6 +671,7 @@ def test_run_script(self, run_script, email_task):
"custom_field": custom_field.pk,
"save_all_output": False,
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -677,6 +687,7 @@ def test_run_script(self, run_script, email_task):
wait=True,
history_pk=hist.pk,
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand All @@ -697,6 +708,7 @@ def test_run_script(self, run_script, email_task):
"custom_field": custom_field.pk,
"save_all_output": False,
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -712,6 +724,7 @@ def test_run_script(self, run_script, email_task):
wait=True,
history_pk=hist.pk,
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand All @@ -729,6 +742,7 @@ def test_run_script(self, run_script, email_task):
"args": ["hello", "world"],
"timeout": 22,
"run_as_user": False,
"env_vars": ["hello=world", "foo=bar"],
}

r = self.client.post(url, data, format="json")
Expand All @@ -744,6 +758,7 @@ def test_run_script(self, run_script, email_task):
wait=True,
history_pk=hist.pk,
run_as_user=False,
env_vars=["hello=world", "foo=bar"],
)
run_script.reset_mock()

Expand Down Expand Up @@ -1272,9 +1287,9 @@ def test_get_agent_history_permissions(self):

sites = baker.make("clients.Site", _quantity=2)
agent = baker.make_recipe("agents.agent", site=sites[0])
history = baker.make("agents.AgentHistory", agent=agent, _quantity=5)
history = baker.make("agents.AgentHistory", agent=agent, _quantity=5) # noqa
unauthorized_agent = baker.make_recipe("agents.agent", site=sites[1])
unauthorized_history = baker.make(
unauthorized_history = baker.make( # noqa
"agents.AgentHistory", agent=unauthorized_agent, _quantity=6
)

Expand Down
11 changes: 4 additions & 7 deletions api/tacticalrmm/agents/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import tempfile
import urllib.parse
from io import StringIO
from pathlib import Path

from django.conf import settings
Expand Down Expand Up @@ -70,11 +70,8 @@ def generate_linux_install(
for i, j in replace.items():
text = text.replace(i, j)

with tempfile.NamedTemporaryFile() as fp:
with open(fp.name, "w") as f:
f.write(text)
f.write("\n")

text += "\n"
with StringIO(text) as fp:
return FileResponse(
open(fp.name, "rb"), as_attachment=True, filename="linux_agent_install.sh"
fp.read(), as_attachment=True, filename="linux_agent_install.sh"
)
Loading

0 comments on commit 824cbdc

Please sign in to comment.