Skip to content

Commit

Permalink
typing pedantry, updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Apr 21, 2024
1 parent 9224a38 commit 530549e
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 300 deletions.
6 changes: 4 additions & 2 deletions admin_scripts/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path

import aiohttp
from pydantic import BaseModel, HttpUrl
from pydantic import BaseModel, HttpUrl, TypeAdapter

SERVER = "http://localhost:8000"
USERNAME = "admin"
Expand Down Expand Up @@ -77,7 +77,9 @@ def save_level(path: Path, level: Level) -> None:

async def main(path: Path) -> None:
async with aiohttp.ClientSession() as session:
next_page: HttpUrl | None = HttpUrl(f"{SERVER}/api/levels")
next_page: HttpUrl | None = TypeAdapter(HttpUrl).validate_strings(
f"{SERVER}/api/levels"
)

while next_page is not None:
async with session.get(
Expand Down
82 changes: 41 additions & 41 deletions azure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ resource "azurerm_mssql_database" "treasure" {
transparent_data_encryption_enabled = true
}

resource "azurerm_redis_cache" "cache" {
resource "azurerm_redis_cache" "treasure" {
name = "${var.app_name}-cache"
location = var.region
resource_group_name = azurerm_resource_group.treasure.name
Expand All @@ -101,6 +101,8 @@ resource "azurerm_redis_cache" "cache" {
minimum_tls_version = "1.2"

redis_configuration {
# active_directory_authentication_enabled = true
enable_authentication = true
}
}

Expand Down Expand Up @@ -136,8 +138,8 @@ resource "azurerm_linux_web_app" "treasure" {
GM_API_KEY = var.google_maps_api_key
PRE_BUILD_COMMAND = "prebuild.sh"
SECRET_KEY = random_password.secret_key.result
CACHE_PASSWORD = azurerm_redis_cache.cache.primary_access_key
CACHE_URL = azurerm_redis_cache.cache.hostname
CACHE_PASSWORD = azurerm_redis_cache.treasure.primary_access_key
CACHE_URL = azurerm_redis_cache.treasure.hostname
}

https_only = true
Expand All @@ -158,6 +160,15 @@ resource "azurerm_linux_web_app" "treasure" {
}
}

# Pointless without <https://github.com/django/channels_redis/issues/386>.
# resource "azurerm_redis_cache_access_policy_assignment" "treasure" {
# name = var.app_name
# redis_cache_id = azurerm_redis_cache.treasure.id
# access_policy_name = "Data Owner"
# object_id = azurerm_linux_web_app.treasure.identity.0.principal_id
# object_id_alias = "Treasure hunt"
# }

resource "azurerm_role_assignment" "storage_contributor" {
scope = azurerm_storage_account.treasure.id
role_definition_name = "Storage Blob Data Contributor"
Expand Down Expand Up @@ -189,7 +200,7 @@ resource "azurerm_redis_firewall_rule" "treasure" {
for_each = toset(azurerm_linux_web_app.treasure.possible_outbound_ip_address_list)
name = "appservice_${replace(each.key, "/\\./", "_")}"
resource_group_name = azurerm_resource_group.treasure.name
redis_cache_name = azurerm_redis_cache.cache.name
redis_cache_name = azurerm_redis_cache.treasure.name
start_ip = each.key
end_ip = each.key
}
10 changes: 8 additions & 2 deletions hunt/chat/consumers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING, TypedDict
from typing import TYPE_CHECKING, Any, TypedDict

from asgiref.sync import sync_to_async
from channels.generic.websocket import AsyncJsonWebsocketConsumer

from hunt.models import ChatMessage, Level

if TYPE_CHECKING:
from channels.layers import BaseChannelLayer
from django.contrib.auth.models import User

class UserMessage(TypedDict):
Expand All @@ -21,6 +22,7 @@ def __init__(self) -> None:
self.team: User | None = None
self.level: Level | None = None
self.room_group: str | None = None
self.channel_layer: BaseChannelLayer

async def connect(self) -> None:
user: User = self.scope["user"]
Expand Down Expand Up @@ -51,7 +53,11 @@ async def disconnect(
await self.channel_layer.group_discard(self.room_group, self.channel_name)

# Receive message from WebSocket
async def receive_json(self, content: UserMessage) -> None:
async def receive_json(
self,
content: UserMessage,
**kwargs: Any, # noqa: ARG002
) -> None:
message = content["message"]
username = content["username"]

Expand Down
Loading

0 comments on commit 530549e

Please sign in to comment.