From 583852334f919dbb24147fa88cafb24653252301 Mon Sep 17 00:00:00 2001 From: psic4t Date: Thu, 23 Feb 2023 17:57:53 +0100 Subject: [PATCH] Allow external password provider --- README.md | 7 +++++++ defines.go | 9 +++++---- main.go | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90e2c2d..0b8916c 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,13 @@ liner: [[ $(qcal -cron 15 2>/dev/null) ]] && notify-send "Next Appointment:" "\n $(qcal -cron 15)" || true +### External password command + +Instead of putting your password in the config file you can specify an +external command to resolve your password. Put a line like this in your +calendar config and leave the "Password" field empty: + + "PasswordCommand":"rbw get email-provider" ## About diff --git a/defines.go b/defines.go index 3c5c30e..f39b578 100644 --- a/defines.go +++ b/defines.go @@ -24,7 +24,7 @@ var endDateUTC string var summary string var toFile bool var elements []Event -var qcalversion string = "0.8.9" +var qcalversion string = "0.9.0" var colorBlock string = "|" var currentDot string = "•" @@ -57,9 +57,10 @@ const ( type configStruct struct { Calendars []struct { - Url string - Username string - Password string + Url string + Username string + Password string + PasswordCmd string } Timezone string DefaultNumDays int diff --git a/main.go b/main.go index d7e070f..3528015 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "log" "net/http" + "os" + "os/exec" "sort" "strconv" "strings" @@ -36,7 +38,20 @@ func fetchCalData(calNo int, wg *sync.WaitGroup) { req, _ := http.NewRequest(reqType, config.Calendars[calNo].Url, strings.NewReader(xmlBody)) if config.Calendars[calNo].Username != "" { - req.SetBasicAuth(config.Calendars[calNo].Username, config.Calendars[calNo].Password) + var pw string + if config.Calendars[calNo].PasswordCmd == "" { + pw = config.Calendars[calNo].Password + } else { + cmd := exec.Command("sh", "-c", config.Calendars[calNo].PasswordCmd) + cmd.Stdin = os.Stdin + output, err := cmd.Output() + if err != nil { + log.Fatal(err) + } + pw = strings.TrimSpace(string(output)) + } + + req.SetBasicAuth(config.Calendars[calNo].Username, pw) req.Header.Add("Depth", "1") // needed for SabreDAV req.Header.Add("Prefer", "return-minimal") req.Header.Add("Content-Type", "application/xml; charset=utf-8") -- 2.38.5