fix(official-bots): make botToken optional, fall back to env, fix 502 status
Build & Test (NowChessSystems) TeamCity build finished
Build & Test (NowChessSystems) TeamCity build finished
botToken in JoinTournamentRequest is now Option[String]. When absent the service resolves it from TOURNAMENT_BOT_TOKEN env var so official-bot join requests no longer need a token in the body. Response status on join failure changed from BAD_GATEWAY (502) to BAD_REQUEST (400). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ package de.nowchess.bot.resource
|
||||
|
||||
case class JoinTournamentRequest(
|
||||
tournamentId: String,
|
||||
botToken: String,
|
||||
botToken: Option[String],
|
||||
difficulty: String,
|
||||
serverUrl: Option[String],
|
||||
)
|
||||
|
||||
+1
-1
@@ -39,6 +39,6 @@ class TournamentJoinResource:
|
||||
Response.ok(resp).build()
|
||||
case Left(err) =>
|
||||
Response
|
||||
.status(Response.Status.BAD_GATEWAY)
|
||||
.status(Response.Status.BAD_REQUEST)
|
||||
.entity(s"""{"error":"$err"}""")
|
||||
.build()
|
||||
|
||||
+14
-9
@@ -82,18 +82,23 @@ class TournamentBotGamePlayer:
|
||||
|
||||
def joinTournament(
|
||||
tournamentId: String,
|
||||
botToken: String,
|
||||
botToken: Option[String],
|
||||
difficulty: String,
|
||||
serverUrl: String,
|
||||
): Either[String, String] =
|
||||
TournamentBotConfig.jwtSubject(botToken) match
|
||||
case None => Left("Invalid bot token — could not extract subject")
|
||||
case Some(botId) =>
|
||||
val cfg = TournamentBotConfig(serverUrl, tournamentId, botToken, botId, difficulty)
|
||||
if join(cfg) then
|
||||
startAsync(cfg)
|
||||
Right(botId)
|
||||
else Left("Failed to join tournament")
|
||||
val resolvedToken = botToken.filter(_.nonEmpty)
|
||||
.orElse(System.getenv().asScala.get("TOURNAMENT_BOT_TOKEN").filter(_.nonEmpty))
|
||||
resolvedToken match
|
||||
case None => Left("No bot token provided and TOURNAMENT_BOT_TOKEN not configured")
|
||||
case Some(token) =>
|
||||
TournamentBotConfig.jwtSubject(token) match
|
||||
case None => Left("Invalid bot token — could not extract subject")
|
||||
case Some(botId) =>
|
||||
val cfg = TournamentBotConfig(serverUrl, tournamentId, token, botId, difficulty)
|
||||
if join(cfg) then
|
||||
startAsync(cfg)
|
||||
Right(botId)
|
||||
else Left("Failed to join tournament")
|
||||
|
||||
private def startAsync(cfg: TournamentBotConfig): Unit =
|
||||
val thread = new Thread(() => streamLoop(cfg), s"TournamentBot-${cfg.tournamentId}")
|
||||
|
||||
Reference in New Issue
Block a user