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(
|
case class JoinTournamentRequest(
|
||||||
tournamentId: String,
|
tournamentId: String,
|
||||||
botToken: String,
|
botToken: Option[String],
|
||||||
difficulty: String,
|
difficulty: String,
|
||||||
serverUrl: Option[String],
|
serverUrl: Option[String],
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -39,6 +39,6 @@ class TournamentJoinResource:
|
|||||||
Response.ok(resp).build()
|
Response.ok(resp).build()
|
||||||
case Left(err) =>
|
case Left(err) =>
|
||||||
Response
|
Response
|
||||||
.status(Response.Status.BAD_GATEWAY)
|
.status(Response.Status.BAD_REQUEST)
|
||||||
.entity(s"""{"error":"$err"}""")
|
.entity(s"""{"error":"$err"}""")
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
+14
-9
@@ -82,18 +82,23 @@ class TournamentBotGamePlayer:
|
|||||||
|
|
||||||
def joinTournament(
|
def joinTournament(
|
||||||
tournamentId: String,
|
tournamentId: String,
|
||||||
botToken: String,
|
botToken: Option[String],
|
||||||
difficulty: String,
|
difficulty: String,
|
||||||
serverUrl: String,
|
serverUrl: String,
|
||||||
): Either[String, String] =
|
): Either[String, String] =
|
||||||
TournamentBotConfig.jwtSubject(botToken) match
|
val resolvedToken = botToken.filter(_.nonEmpty)
|
||||||
case None => Left("Invalid bot token — could not extract subject")
|
.orElse(System.getenv().asScala.get("TOURNAMENT_BOT_TOKEN").filter(_.nonEmpty))
|
||||||
case Some(botId) =>
|
resolvedToken match
|
||||||
val cfg = TournamentBotConfig(serverUrl, tournamentId, botToken, botId, difficulty)
|
case None => Left("No bot token provided and TOURNAMENT_BOT_TOKEN not configured")
|
||||||
if join(cfg) then
|
case Some(token) =>
|
||||||
startAsync(cfg)
|
TournamentBotConfig.jwtSubject(token) match
|
||||||
Right(botId)
|
case None => Left("Invalid bot token — could not extract subject")
|
||||||
else Left("Failed to join tournament")
|
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 =
|
private def startAsync(cfg: TournamentBotConfig): Unit =
|
||||||
val thread = new Thread(() => streamLoop(cfg), s"TournamentBot-${cfg.tournamentId}")
|
val thread = new Thread(() => streamLoop(cfg), s"TournamentBot-${cfg.tournamentId}")
|
||||||
|
|||||||
Reference in New Issue
Block a user