Compare commits
No commits in common. "main" and "v2.0.1" have entirely different histories.
3 changed files with 18 additions and 32 deletions
|
|
@ -15,7 +15,7 @@ Then in your configuration (using sops-nix, you will need to adjust it if you us
|
|||
nixpkgs.overlays = [ inputs.actualbudget-report.overlays.default ];
|
||||
|
||||
imports = [
|
||||
inputs.actualbudget-report.nixosModules.default
|
||||
inputs.actualbudget-report.nixosModules.default;
|
||||
];
|
||||
|
||||
# Fill out all the following environment variables for the service
|
||||
|
|
@ -26,9 +26,7 @@ sops.templates."actualbudget-report-env".content = ''
|
|||
SMTP_USERNAME=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_HOST=
|
||||
SMTP_PORT=
|
||||
SMTP_RECIPIENTS=
|
||||
BUDGET_ENCRYPTION_KEY=
|
||||
'';
|
||||
|
||||
services.actualbudget-report = {
|
||||
|
|
|
|||
14
flake.nix
14
flake.nix
|
|
@ -24,15 +24,7 @@
|
|||
"aarch64-darwin"
|
||||
"x86_64-darwin"
|
||||
];
|
||||
flake = {
|
||||
nixosModules.default = ./modules/actualbudget-report;
|
||||
hydraJobs = {
|
||||
inherit (self)
|
||||
packages
|
||||
;
|
||||
|
||||
};
|
||||
};
|
||||
flake.nixosModules.default = ./modules/actualbudget-report;
|
||||
perSystem =
|
||||
{
|
||||
config,
|
||||
|
|
@ -50,8 +42,8 @@
|
|||
domain = "git.wanderingcrow.net";
|
||||
owner = "TheWanderingCrow";
|
||||
repo = "actualbudget-report";
|
||||
rev = "v2.0.2";
|
||||
hash = "sha256-vnd1RvlMD4WOLtXpIOiPxuDxvHoBQVTP/8l/OMWR5No=";
|
||||
rev = "v0.1";
|
||||
hash = "sha256-1Z3+Efx0MCsZhfz49nKsdaWgyVt9+7kekwgfQyaYUxQ=";
|
||||
};
|
||||
vendorHash = "sha256-NHTKwUSIbNCUco88JbHOo3gt6S37ggee+LWNbHaRGEs=";
|
||||
};
|
||||
|
|
|
|||
32
main.go
32
main.go
|
|
@ -32,11 +32,10 @@ import (
|
|||
)
|
||||
|
||||
type BudgetClient struct {
|
||||
baseUrl string
|
||||
apiKey string
|
||||
syncId string
|
||||
fullUrl string
|
||||
encryptionKey string
|
||||
baseUrl string
|
||||
apiKey string
|
||||
syncId string
|
||||
fullUrl string
|
||||
}
|
||||
|
||||
type BudgetMonthsResponse struct {
|
||||
|
|
@ -74,12 +73,9 @@ type BudgetMonthsResponse struct {
|
|||
} `json:"data"`
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func CreateBudgetClient(baseUrl string, apiKey string, syncId string) *BudgetClient {
|
||||
fullUrl := baseUrl + "/v1/budgets/" + syncId
|
||||
client := BudgetClient{baseUrl, apiKey, syncId, fullUrl, encryptionKey}
|
||||
client := BudgetClient{baseUrl, apiKey, syncId, fullUrl}
|
||||
return &client
|
||||
}
|
||||
|
||||
|
|
@ -115,9 +111,7 @@ func (b BudgetClient) GetBudgetMonths() *BudgetMonthsResponse {
|
|||
currentTime := time.Now()
|
||||
year, month := currentTime.Year(), int(currentTime.Month())
|
||||
budgetMonth := fmt.Sprintf("%v-%02d", year, month)
|
||||
resp := b.callApi("GET", "/months/"+budgetMonth, map[string]string{
|
||||
"budget-encryption-password": b.encryptionKey,
|
||||
})
|
||||
resp := b.callApi("GET", "/months/"+budgetMonth, nil)
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
temp, _ := io.ReadAll(resp.Body)
|
||||
|
|
@ -146,13 +140,11 @@ 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 smtpPort = os.Getenv("SMTP_PORT")
|
||||
var smtpRecipients = os.Getenv("SMTP_RECIPIENTS")
|
||||
client := CreateBudgetClient(baseUrl, apiKey, syncId, encryptionKey)
|
||||
client := CreateBudgetClient(baseUrl, apiKey, syncId)
|
||||
if !client.BankSync() {
|
||||
log.Println("Bank Sync failed, information may not be up to date")
|
||||
}
|
||||
|
|
@ -186,8 +178,12 @@ func main() {
|
|||
message := []byte(subject + mime + body + categories.String())
|
||||
|
||||
var auth smtp.Auth
|
||||
auth = smtp.PlainAuth("", smtpUsername, smtpPassword, smtpHost)
|
||||
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, smtpUsername, strings.Split(smtpRecipients, ","), []byte(message))
|
||||
if os.Getenv("ENVIRONMENT") == "dev" {
|
||||
auth = nil
|
||||
} else {
|
||||
auth = smtp.PlainAuth("", smtpUsername, smtpPassword, smtpHost)
|
||||
}
|
||||
err := smtp.SendMail(smtpHost, auth, smtpUsername, strings.Split(smtpRecipients, ","), []byte(message))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue