Skip to content

fix: Meraki-only setup blocked by Mist-hardcoded init and $HOME env loader#54

Merged
ravinald merged 1 commit into
mainfrom
fix/meraki-only-setup
May 14, 2026
Merged

fix: Meraki-only setup blocked by Mist-hardcoded init and $HOME env loader#54
ravinald merged 1 commit into
mainfrom
fix/meraki-only-setup

Conversation

@ravinald
Copy link
Copy Markdown
Owner

Summary

Two bugs that together stopped a Meraki-only deployment from running wifimgr -e refresh all, even though no Mist code path is involved.

1. xdg.FindEnvFile() ignored \$HOME/.env.wifimgr

The loader searched only:

  • ./.env.wifimgr (CWD)
  • \$XDG_CONFIG_HOME/wifimgr/.env.wifimgr

A .env.wifimgr in \$HOME — the most common dotenv convention (ssh, gitconfig, dotenv libraries) — was invisible. WIFIMGR_PASSWORD lives there for many users, so without it the encrypted Meraki api_key couldn't decrypt and the run continued in a half-initialized state.

Fix: search \$HOME between CWD (project override) and XDG (system fallback). Purely additive.

2. initializeAPI hard-required a Mist API

cmd/root.go walked the registry looking for Vendor == \"mist\" to build the legacy single-Mist globalClient. If none existed, it killed init with:

Error: no Mist API credentials found - ensure api.mist is configured and -e flag is used

Multi-vendor commands (refresh, show, search) never touch globalClient — they use the registry directly. So a Meraki-only setup couldn't reach any command, including ones that don't need Mist at all.

Fix:

  • Skip globalClient construction when no Mist API is configured. Still build globalConfig with Files populated, so paths-only consumers work.

  • Add requireMistClient(commandName) and wire it into the four legacy Mist-only entry points (apply, set ap, backup, site ap). They emit a clean message instead of nil-derefing if invoked without a Mist API:

    \"apply\" requires a Mist API to be configured. Add a 'mist' entry under 'apis' in your wifimgr config, or use a multi-vendor command (refresh, show, search) that works with any configured vendor.

Test plan

  • go test ./... — all green
  • internal/xdg/TestFindEnvFile — adds "env file in HOME" and "HOME takes precedence over XDG" cases; sandboxes \$HOME so the test no longer reads the developer's real dotfile
  • Manual on admin1 (Meraki-only): wifimgr -e refresh all runs to completion

…oader

Two bugs in the init path stop a Meraki-only (or Ubiquiti-only)
deployment from running multi-vendor commands like `refresh all`,
even though those commands don't need a Mist client at all.

1. xdg.FindEnvFile() only searches CWD and $XDG_CONFIG_HOME/wifimgr/.
   The most common dotenv location, $HOME/.env.wifimgr, is invisible
   to the loader. WIFIMGR_PASSWORD lives in that file, so when it
   doesn't get into the process env, credential decryption silently
   skips and the user sees:

     Failed to load .env.wifimgr file: env file not found

   Add $HOME to the search path between CWD (project override) and
   XDG (system fallback). Purely additive — existing CWD and XDG
   placements keep working.

2. cmd/root.go's initializeAPI hard-required a Mist API in the
   registry. The legacy globalClient (single-Mist api.Client) is
   built from the first Vendor=="mist" entry, and if none exists,
   init bails with:

     Error: no Mist API credentials found - ensure api.mist is
     configured and -e flag is used

   Multi-vendor commands (refresh, show, search) never touch
   globalClient — they go straight to the registry. Make the
   legacy construction conditional: skip globalClient when no Mist
   API is configured, but still build globalConfig with the Files
   section populated so non-API-touching code paths work.

   Add a requireMistClient(commandName) guard and wire it into the
   four legacy entry points (apply, set ap, backup, site ap) so
   they emit a clear error instead of nil-dereferencing if invoked
   without a Mist API.

Test plan:
- internal/xdg: TestFindEnvFile gains "env file in HOME" and
  "HOME takes precedence over XDG" cases; sandboxes $HOME so the
  test never sees the developer's real dotfile.
- Meraki-only manual flow:
    wifimgr -e refresh all
  No longer errors on missing Mist credentials.
@ravinald ravinald merged commit 3c295c8 into main May 14, 2026
7 checks passed
@ravinald ravinald deleted the fix/meraki-only-setup branch May 14, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant