diff --git a/pyproject.toml b/pyproject.toml index 9809f4f..f492653 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cs2-battle-bot-api" -version = "0.0.30" +version = "0.0.31" description = "" authors = ["Adrian Ciolek "] readme = "README.md" diff --git a/src/matches/models.py b/src/matches/models.py index 1371c91..2a31400 100644 --- a/src/matches/models.py +++ b/src/matches/models.py @@ -141,17 +141,9 @@ class Match(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - @property - def config_url(self): - return f"{settings.HOST_URL}/api/matches/{self.pk}/config/" - - @property - def webhook_url(self): - return f"{settings.HOST_URL}/api/matches/webhook/" - @property def api_key_header(self): - return "Bearer" + return "Authorization" @property def load_match_command_name(self): @@ -193,15 +185,12 @@ def get_connect_command(self): def get_author_token(self): return UserModel.objects.get(player__discord_user=self.author).get_token() - def get_load_match_command(self): - return f'{self.load_match_command_name} "{self.config_url}" "{self.api_key_header}" "{self.get_author_token()}"' - def create_webhook_cvars(self, webhook_url: str): self.cvars = self.cvars or {} self.cvars.update({ "matchzy_remote_log_url": webhook_url, "matchzy_remote_log_header_key": self.api_key_header, - "matchzy_remote_log_header_value": self.get_author_token(), + "matchzy_remote_log_header_value": f"Bearer {self.get_author_token()}", }) self.save() diff --git a/src/matches/serializers.py b/src/matches/serializers.py index df74c59..4fa5576 100644 --- a/src/matches/serializers.py +++ b/src/matches/serializers.py @@ -89,7 +89,7 @@ def get_webhook_url(self, obj) -> str: def get_load_match_command(self, obj) -> str: config_url = self.get_config_url(obj) - return f'{obj.load_match_command_name} "{config_url}" "{obj.api_key_header}" "{obj.get_author_token()}"' + return f'{obj.load_match_command_name} "{config_url}" "{obj.api_key_header}" "Bearer {obj.get_author_token()}"' def get_config(self, obj) -> MatchConfigSerializer: return MatchConfigSerializer(obj.get_config()).data diff --git a/src/matches/tests/test_matches_models.py b/src/matches/tests/test_matches_models.py index 48fce50..479f44d 100644 --- a/src/matches/tests/test_matches_models.py +++ b/src/matches/tests/test_matches_models.py @@ -60,7 +60,7 @@ def test_match_model(teams_with_players, default_author, with_server, match_type assert match_config["cvars"] == new_match.cvars assert match_config["cvars"]["matchzy_remote_log_url"] == reverse_lazy("match-webhook", args=[new_match.pk], request=request) assert match_config["cvars"]["matchzy_remote_log_header_key"] == new_match.api_key_header - assert match_config["cvars"]["matchzy_remote_log_header_value"] == new_match.get_author_token() + assert match_config["cvars"]["matchzy_remote_log_header_value"] == f"Bearer {new_match.get_author_token()}" connect_command = new_match.get_connect_command() assert connect_command == "" if with_server is False else server.get_connect_string() @@ -68,12 +68,8 @@ def test_match_model(teams_with_players, default_author, with_server, match_type author_token = new_match.get_author_token() assert author_token == Token.objects.get(user=default_author).key - assert new_match.config_url == f"{settings.HOST_URL}/api/matches/{new_match.pk}/config/" assert new_match.load_match_command_name == "matchzy_loadmatch_url" - assert new_match.api_key_header == "Bearer" - - assert new_match.webhook_url == f"{settings.HOST_URL}/api/matches/webhook/" - assert new_match.get_load_match_command() == f'matchzy_loadmatch_url "{new_match.config_url}" "Bearer" "{author_token}"' + assert new_match.api_key_header == "Authorization"