mirror of
https://github.com/donuts-are-good/neosay.git
synced 2024-10-01 01:35:40 -04:00
add option to get access token from command
To allow adding neosays configuration to a dotfiles repo, it's beneficial to allow providing a command to retrieve the access token via a command (for example from a password manager). If an access token is set while a command is set as well, the token is overwritten in favour of the securely retrieved one. Fixes: https://github.com/donuts-are-good/neosay/issues/1 Signed-off-by: Moritz Poldrack <git@moritz.sh>
This commit is contained in:
parent
b966bcfb04
commit
07469b4aa7
@ -2,5 +2,6 @@
|
|||||||
"homeserverURL": "https://matrix.org",
|
"homeserverURL": "https://matrix.org",
|
||||||
"userID": "@example:matrix.org",
|
"userID": "@example:matrix.org",
|
||||||
"accessToken": "my_access_token",
|
"accessToken": "my_access_token",
|
||||||
|
"accessTokenCmd": "secret-tool lookup Title 'Neosay Matrix Access Token'",
|
||||||
"roomID": "!oJJwhvLOYfduLjDTjA:matrix.org"
|
"roomID": "!oJJwhvLOYfduLjDTjA:matrix.org"
|
||||||
}
|
}
|
||||||
|
19
main.go
19
main.go
@ -2,10 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -16,10 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HomeserverURL string `json:"homeserverURL"`
|
HomeserverURL string `json:"homeserverURL"`
|
||||||
UserID string `json:"userID"`
|
UserID string `json:"userID"`
|
||||||
AccessToken string `json:"accessToken"`
|
AccessToken string `json:"accessToken"`
|
||||||
RoomID string `json:"roomID"`
|
AccessTokenCmd string `json:"accessTokenCmd"`
|
||||||
|
RoomID string `json:"roomID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxMessageSize = 4000
|
const maxMessageSize = 4000
|
||||||
@ -76,6 +79,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the access token
|
// get the access token
|
||||||
|
if config.AccessTokenCmd != "" {
|
||||||
|
res := bytes.NewBuffer([]byte{})
|
||||||
|
cmd := exec.Command("/bin/sh", "-c", config.AccessTokenCmd)
|
||||||
|
cmd.Stdout = res
|
||||||
|
cmd.Run()
|
||||||
|
|
||||||
|
config.AccessToken = res.String()
|
||||||
|
}
|
||||||
accessToken := config.AccessToken
|
accessToken := config.AccessToken
|
||||||
if accessToken == "" {
|
if accessToken == "" {
|
||||||
accessToken = os.Getenv("MATRIX_ACCESS_TOKEN")
|
accessToken = os.Getenv("MATRIX_ACCESS_TOKEN")
|
||||||
|
Loading…
Reference in New Issue
Block a user