Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions desktop/dotenv.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log/slog"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -85,8 +86,10 @@ func upsertEnvFile(path, key, value string) error {
}
if err := fileutil.ReplaceFile(tmpPath, path); err != nil {
os.Remove(tmpPath)
slog.Warn("dotenv: write failed", "path", path, "key", key, "err", err)
return err
}
slog.Debug("dotenv: upserted", "path", path, "key", key)
return os.Setenv(key, value)
}

Expand Down Expand Up @@ -183,11 +186,14 @@ func promoteProviderKeysToCredentials(cfg *config.Config) {
}
val := os.Getenv(env)
if val == "" {
slog.Debug("promote: key not in env", "env", env)
continue
}
if err := upsertEnvFile(credPath, env, val); err != nil {
slog.Warn("promote: write failed", "env", env, "err", err)
continue
}
slog.Info("promote: key migrated to credentials", "env", env)
have[env] = true
removeHomeEnvKey(env)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/config/dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"bufio"
"log/slog"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -40,10 +41,12 @@ func loadDotEnvForRoot(root string) {
func loadDotEnvFile(path string) {
f, err := os.Open(path)
if err != nil {
slog.Debug("config: dotenv file not loaded", "path", path, "err", err)
return
}
defer f.Close()

count := 0
sc := bufio.NewScanner(f)
for sc.Scan() {
line := strings.TrimSpace(sc.Text())
Expand All @@ -62,6 +65,10 @@ func loadDotEnvFile(path string) {
}
if _, exists := os.LookupEnv(key); !exists {
os.Setenv(key, val)
count++
}
}
if count > 0 {
slog.Info("config: dotenv loaded", "path", path, "keys", count)
}
}
Loading