Simplify secret key fallbacks

This commit is contained in:
2026-06-21 14:10:00 +02:00
parent 936a20a03e
commit 2e61059568
2 changed files with 10 additions and 10 deletions

View File

@@ -32,6 +32,7 @@ after each item.
- [x] `ai/chat.ex` - [x] `ai/chat.ex`
- [x] `ai/openai_compatible_runtime.ex` - [x] `ai/openai_compatible_runtime.ex`
- [x] `ai/one_shot.ex` - [x] `ai/one_shot.ex`
- [x] `ai/secret_key.ex`
--- ---

View File

@@ -105,11 +105,7 @@ defmodule BDS.AI.SecretKey do
keychain_create() keychain_create()
{:error, reason} -> {:error, reason} ->
Logger.warning( fallback_to_key_file("AI secret key: macOS Keychain unavailable", inspect(reason))
"AI secret key: macOS Keychain unavailable (#{inspect(reason)}); falling back to the key file"
)
resolve_file()
end end
end end
@@ -157,12 +153,10 @@ defmodule BDS.AI.SecretKey do
{:ok, key} {:ok, key}
{output, status} -> {output, status} ->
Logger.warning( fallback_to_key_file(
"AI secret key: could not store the key in the Keychain " <> "AI secret key: could not store the key in the Keychain",
"(status #{status}: #{String.trim(output)}); falling back to the key file" "status #{status}: #{String.trim(output)}"
) )
resolve_file()
end end
end end
@@ -230,4 +224,9 @@ defmodule BDS.AI.SecretKey do
defp config(key, default) do defp config(key, default) do
Application.get_env(:bds, __MODULE__, []) |> Keyword.get(key, default) Application.get_env(:bds, __MODULE__, []) |> Keyword.get(key, default)
end end
defp fallback_to_key_file(prefix, detail) do
Logger.warning(prefix <> " (" <> detail <> "); falling back to the key file")
resolve_file()
end
end end