Validate agent name and set default (#2483)

This commit is contained in:
ByeongUk Choi 2024-02-13 17:27:25 +09:00 committed by GitHub
parent efc17fb01f
commit 17634f9be7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -25,7 +25,7 @@ config :mime, :types, %{
config :livebook, config :livebook,
teams_url: "https://teams.livebook.dev", teams_url: "https://teams.livebook.dev",
agent_name: nil, agent_name: "livebook-agent",
app_service_name: nil, app_service_name: nil,
app_service_url: nil, app_service_url: nil,
authentication_mode: :token, authentication_mode: :token,

View file

@ -594,7 +594,15 @@ defmodule Livebook.Config do
Parses agent name from env. Parses agent name from env.
""" """
def agent_name!(env) do 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 end
@doc """ @doc """