turn password flag into password file

This commit is contained in:
Serge Bazanski 2024-09-30 23:55:37 +02:00
parent c437d4388e
commit d8e3da9d45
2 changed files with 15 additions and 8 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
password.txt

View file

@ -124,7 +124,7 @@ func update(ctx context.Context) (string, error) {
var ( var (
flagMatrixHomeserver = "matrix.org" flagMatrixHomeserver = "matrix.org"
flagMatrixUsername = "@fafomo:matrix.org" flagMatrixUsername = "@fafomo:matrix.org"
flagMatrixPassword string flagMatrixPasswordFile = "password.txt"
flagMatrixRoom string flagMatrixRoom string
flagBackendURL string flagBackendURL string
) )
@ -132,7 +132,7 @@ var (
func main() { func main() {
flag.StringVar(&flagMatrixHomeserver, "matrix_homeserver", flagMatrixHomeserver, "Address of Matrix homeserver") flag.StringVar(&flagMatrixHomeserver, "matrix_homeserver", flagMatrixHomeserver, "Address of Matrix homeserver")
flag.StringVar(&flagMatrixUsername, "matrix_username", flagMatrixUsername, "Matrix login username") flag.StringVar(&flagMatrixUsername, "matrix_username", flagMatrixUsername, "Matrix login username")
flag.StringVar(&flagMatrixPassword, "matrix_password", flagMatrixPassword, "Matrix login password") flag.StringVar(&flagMatrixPasswordFile, "matrix_password_file", flagMatrixPasswordFile, "Path to file containing matrix login password")
flag.StringVar(&flagMatrixRoom, "matrix_room", flagMatrixRoom, "Matrix room MXID") flag.StringVar(&flagMatrixRoom, "matrix_room", flagMatrixRoom, "Matrix room MXID")
flag.StringVar(&flagBackendURL, "backend_url", flagBackendURL, "Checkinator (backend) addresss") flag.StringVar(&flagBackendURL, "backend_url", flagBackendURL, "Checkinator (backend) addresss")
flag.Parse() flag.Parse()
@ -143,7 +143,7 @@ func main() {
}{ }{
{flagMatrixHomeserver, "matrix_homeserver"}, {flagMatrixHomeserver, "matrix_homeserver"},
{flagMatrixUsername, "matrix_username"}, {flagMatrixUsername, "matrix_username"},
{flagMatrixPassword, "matrix_password"}, {flagMatrixPasswordFile, "matrix_password_file"},
{flagMatrixRoom, "matrix_room"}, {flagMatrixRoom, "matrix_room"},
{flagBackendURL, "backend_url"}, {flagBackendURL, "backend_url"},
} { } {
@ -164,12 +164,18 @@ func main() {
klog.Exitf("NewClient failed: %v", err) klog.Exitf("NewClient failed: %v", err)
} }
passwordBytes, err := os.ReadFile(flagMatrixPasswordFile)
if err != nil {
klog.Exitf("Could not read password file: %v", err)
}
password := strings.TrimSpace(string(passwordBytes))
klog.Infof("Logging in...") klog.Infof("Logging in...")
login, err := client.Login(startCtx, &mautrix.ReqLogin{ login, err := client.Login(startCtx, &mautrix.ReqLogin{
Type: mautrix.AuthTypePassword, Type: mautrix.AuthTypePassword,
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: flagMatrixUsername}, Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: flagMatrixUsername},
Password: flagMatrixPassword, Password: password,
}) })
if err != nil { if err != nil {
klog.Exitf("Failed to log in: %v", err) klog.Exitf("Failed to log in: %v", err)