-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from napse-invest/dev
Release 12/03/2024 (Initial launch)
- Loading branch information
Showing
129 changed files
with
2,101 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,4 +167,5 @@ cython_debug/ | |
secrets.json | ||
full-requirements.txt | ||
.ruff_cache/ | ||
*.sqlite3 | ||
*.sqlite3 | ||
dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.2.2 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
entry: ruff check --force-exclude --config .github/pyproject.toml | ||
# Run the formatter. | ||
- id: ruff-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from typing import ClassVar | ||
|
||
from rest_framework import serializers | ||
|
||
from django_napse.core.models.bots.architecture import Architecture | ||
|
||
|
||
class ArchitectureSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
"""Serialize an Architecture instance.""" | ||
|
||
class Meta: # noqa: D106 | ||
model = Architecture | ||
fields = "__all__" | ||
read_only_fields = [ | ||
read_only_fields: ClassVar[list[str]] = [ | ||
"id", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
from typing import ClassVar | ||
|
||
from rest_framework import serializers | ||
|
||
from django_napse.core.models.bots.config import BotConfig | ||
|
||
|
||
class ConfigSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
"""Serialize a BotConfig instance.""" | ||
|
||
class Meta: # noqa: D106 | ||
model = BotConfig | ||
fields = "__all__" | ||
read_only_fields = [ | ||
read_only_fields: ClassVar[list[str]] = [ | ||
"uuid", | ||
"immutable", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
from typing import ClassVar | ||
|
||
from rest_framework import serializers | ||
|
||
from django_napse.api.bots.serializers.strategy_serializer import StrategySerializer | ||
from django_napse.core.models.bots.plugin import Plugin | ||
|
||
|
||
class PluginSerializer(serializers.ModelSerializer): | ||
"""Serialize a Plugin instance.""" | ||
|
||
strategy = StrategySerializer() | ||
|
||
class Meta: | ||
class Meta: # noqa: D106 | ||
model = Plugin | ||
fields = "__all__" | ||
read_only_fields = [ | ||
read_only_fields: ClassVar[list[str]] = [ | ||
"id", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from rest_framework.viewsets import GenericViewSet | ||
|
||
from django_napse.auth.models import NapseAPIKey | ||
from django_napse.core.models import NapseSpace | ||
from django_napse.core.models import Space | ||
from django_napse.utils.errors import APIError | ||
|
||
if TYPE_CHECKING: | ||
from rest_framework.request import Request | ||
|
||
|
||
class CustomViewSet(GenericViewSet): | ||
def get_api_key(self, request): | ||
"""Base of all ViewSets.""" | ||
|
||
def get_api_key(self, request: Request) -> NapseAPIKey: | ||
"""Return the api key from the request.""" | ||
try: | ||
return NapseAPIKey.objects.get_from_key(request.META["HTTP_AUTHORIZATION"].split()[1]) | ||
except NapseAPIKey.DoesNotExist as e: | ||
raise APIError.InvalidAPIKey() from e | ||
raise APIError.InvalidAPIKey from e | ||
except KeyError as e: | ||
raise APIError.NoAPIKey() from e | ||
raise APIError.NoAPIKey from e | ||
|
||
def get_space(self, request) -> NapseSpace | None: | ||
def get_space(self, request: Request) -> Space | None: | ||
"""Return the space from the request.""" | ||
try: | ||
return NapseSpace.objects.get(uuid=request.query_params["space"]) | ||
except NapseSpace.DoesNotExist: | ||
return Space.objects.get(uuid=request.query_params["space"]) | ||
except Space.DoesNotExist: | ||
return None |
Oops, something went wrong.