From 6eb0beb355259b8a7ef29202508b605dc97a61fc Mon Sep 17 00:00:00 2001 From: TheWanderingCrow Date: Sat, 27 Dec 2025 10:45:31 -0500 Subject: [PATCH] add support for encryption key protected budget files --- README.md | 1 + main.go | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0bec688..2829f18 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ sops.templates."actualbudget-report-env".content = '' SMTP_PASSWORD= SMTP_HOST= SMTP_RECIPIENTS= + BUDGET_ENCRYPTION_KEY= ''; services.actualbudget-report = { diff --git a/main.go b/main.go index 195a22a..945591e 100644 --- a/main.go +++ b/main.go @@ -32,10 +32,11 @@ import ( ) type BudgetClient struct { - baseUrl string - apiKey string - syncId string - fullUrl string + baseUrl string + apiKey string + syncId string + fullUrl string + encryptionKey string } type BudgetMonthsResponse struct { @@ -73,9 +74,12 @@ type BudgetMonthsResponse struct { } `json:"data"` } -func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetClient { +// Create budget client, you may pass empty strings to optional parameters +// Required: baseUrl, apiKey, syncId +// Optional: encryptionKey +func CreateBudgetClient(baseUrl string, apiKey string, syncId string, encryptionKey string) *BudgetClient { fullUrl := baseUrl + "/v1/budgets/" + syncId - client := BudgetClient{baseUrl, apiKey, syncId, fullUrl} + client := BudgetClient{baseUrl, apiKey, syncId, fullUrl, encryptionKey} return &client } @@ -111,7 +115,9 @@ func (b BudgetClient) GetBudgetMonths() *BudgetMonthsResponse { currentTime := time.Now() year, month := currentTime.Year(), int(currentTime.Month()) budgetMonth := fmt.Sprintf("%v-%v", year, month) - resp := b.callApi("GET", "/months/"+budgetMonth, nil) + resp := b.callApi("GET", "/months/"+budgetMonth, map[string]string{ + "budget-encryption-password": b.encryptionKey, + }) defer resp.Body.Close() if resp.StatusCode != http.StatusOK { log.Fatal("GetBudgetAmounts failed with: " + string(resp.Status)) @@ -139,11 +145,12 @@ func main() { var baseUrl = os.Getenv("BASE_URL") var apiKey = os.Getenv("API_KEY") var syncId = os.Getenv("SYNC_ID") + var encryptionKey = os.Getenv("BUDGET_ENCRYPTION_KEY") var smtpUsername = os.Getenv("SMTP_USERNAME") var smtpPassword = os.Getenv("SMTP_PASSWORD") var smtpHost = os.Getenv("SMTP_HOST") var smtpRecipients = os.Getenv("SMTP_RECIPIENTS") - client := CreateBudgetClient(baseUrl, apiKey, syncId) + client := CreateBudgetClient(baseUrl, apiKey, syncId, encryptionKey) if !client.BankSync() { log.Println("Bank Sync failed, information may not be up to date") }