From 2e610595689b265a039149221794023ed699c9e1 Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Sun, 21 Jun 2026 14:10:00 +0200 Subject: [PATCH] Simplify secret key fallbacks --- AUDIT.md | 1 + lib/bds/ai/secret_key.ex | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/AUDIT.md b/AUDIT.md index 3231ddc..678862f 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -32,6 +32,7 @@ after each item. - [x] `ai/chat.ex` - [x] `ai/openai_compatible_runtime.ex` - [x] `ai/one_shot.ex` +- [x] `ai/secret_key.ex` --- diff --git a/lib/bds/ai/secret_key.ex b/lib/bds/ai/secret_key.ex index 5c4bd3a..db4ef76 100644 --- a/lib/bds/ai/secret_key.ex +++ b/lib/bds/ai/secret_key.ex @@ -105,11 +105,7 @@ defmodule BDS.AI.SecretKey do keychain_create() {:error, reason} -> - Logger.warning( - "AI secret key: macOS Keychain unavailable (#{inspect(reason)}); falling back to the key file" - ) - - resolve_file() + fallback_to_key_file("AI secret key: macOS Keychain unavailable", inspect(reason)) end end @@ -157,12 +153,10 @@ defmodule BDS.AI.SecretKey do {:ok, key} {output, status} -> - Logger.warning( - "AI secret key: could not store the key in the Keychain " <> - "(status #{status}: #{String.trim(output)}); falling back to the key file" + fallback_to_key_file( + "AI secret key: could not store the key in the Keychain", + "status #{status}: #{String.trim(output)}" ) - - resolve_file() end end @@ -230,4 +224,9 @@ defmodule BDS.AI.SecretKey do defp config(key, default) do Application.get_env(:bds, __MODULE__, []) |> Keyword.get(key, default) end + + defp fallback_to_key_file(prefix, detail) do + Logger.warning(prefix <> " (" <> detail <> "); falling back to the key file") + resolve_file() + end end