add support for encryption key protected budget files
This commit is contained in:
parent
700659ff60
commit
6eb0beb355
2 changed files with 16 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ sops.templates."actualbudget-report-env".content = ''
|
|||
SMTP_PASSWORD=
|
||||
SMTP_HOST=
|
||||
SMTP_RECIPIENTS=
|
||||
BUDGET_ENCRYPTION_KEY=
|
||||
'';
|
||||
|
||||
services.actualbudget-report = {
|
||||
|
|
|
|||
23
main.go
23
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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue