From 17634f9be721c0f45c3effb786630ae444437334 Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Tue, 13 Feb 2024 17:27:25 +0900 Subject: [PATCH] Validate agent name and set default (#2483) --- config/config.exs | 2 +- lib/livebook/config.ex | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index e88c81a58..1e2045887 100644 --- a/config/config.exs +++ b/config/config.exs @@ -25,7 +25,7 @@ config :mime, :types, %{ config :livebook, teams_url: "https://teams.livebook.dev", - agent_name: nil, + agent_name: "livebook-agent", app_service_name: nil, app_service_url: nil, authentication_mode: :token, diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index a70043b36..70e68b8a6 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -594,7 +594,15 @@ defmodule Livebook.Config do Parses agent name from env. """ def agent_name!(env) do - System.get_env(env) + if agent_name = System.get_env(env) do + unless agent_name =~ ~r/^[a-z0-9_\-]+$/ do + abort!( + "expected #{env} to consist of lowercase alphanumeric characters, dashes and underscores, got: #{agent_name}" + ) + end + + agent_name + end end @doc """