Skip to content

Commit

Permalink
fix load match command and webhook cvars
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwizi committed Apr 24, 2024
1 parent 96228c5 commit 6bf4c3d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cs2-battle-bot-api"
version = "0.0.30"
version = "0.0.31"
description = ""
authors = ["Adrian Ciolek <[email protected]>"]
readme = "README.md"
Expand Down
15 changes: 2 additions & 13 deletions src/matches/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/matches/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/matches/tests/test_matches_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ 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()

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"



Expand Down

0 comments on commit 6bf4c3d

Please sign in to comment.