From edf75ae2df1c7a9952c95f0ce7e3a4b4e02fd6f3 Mon Sep 17 00:00:00 2001 From: Maxime Lagresle Date: Mon, 30 Sep 2024 17:48:57 +0200 Subject: [PATCH] better handling of device identifier storing errors --- internal/provider/provider.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 307a7a4..1b9be36 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -336,7 +336,17 @@ func getOrGenerateDeviceIdentifier(ctx context.Context) (string, error) { } deviceId := embedded.NewDeviceIdentifier() - os.WriteFile(".bitwarden/device_identifier", []byte(deviceId), 0600) + err = os.Mkdir(".bitwarden", 0700) + if err != nil { + tflog.Error(ctx, "Failed to create .bitwarden directory", map[string]interface{}{"error": err}) + return "", err + } + err = os.WriteFile(".bitwarden/device_identifier", []byte(deviceId), 0600) + if err != nil { + tflog.Error(ctx, "Failed to store device identifier", map[string]interface{}{"error": err}) + return "", err + } + tflog.Info(ctx, "Generated device identifier", map[string]interface{}{"device_id": deviceId}) return deviceId, nil }