Browse Source

add secretes

pull/48/head
Rasmus Lindroth 5 years ago
parent
commit
b9de37eccc
  1. 20
      account.go
  2. 8
      util.go

20
account.go

@ -3,12 +3,25 @@ package main
import (
"context"
"io/ioutil"
"log"
"os"
"strings"
"github.com/mattn/go-mastodon"
"github.com/pelletier/go-toml/v2"
)
func GetSecret(s string) string {
var err error
if strings.HasPrefix(s, "!CMD!") {
s, err = CmdToString(s)
if err != nil {
log.Fatalf("Couldn't run CMD on auth-file. Error; %v", err)
}
}
return s
}
func GetAccounts(filepath string) (*AccountData, error) {
f, err := os.Open(filepath)
if err != nil {
@ -21,6 +34,13 @@ func GetAccounts(filepath string) (*AccountData, error) {
}
accounts := &AccountData{}
err = toml.Unmarshal(data, accounts)
for i, acc := range accounts.Accounts {
accounts.Accounts[i].ClientID = GetSecret(acc.ClientID)
accounts.Accounts[i].ClientSecret = GetSecret(acc.ClientSecret)
accounts.Accounts[i].AccessToken = GetSecret(acc.AccessToken)
}
return accounts, err
}

8
util.go

@ -29,6 +29,14 @@ type URL struct {
Classes []string
}
//Runs commands prefixed !CMD!
func CmdToString(cmd string) (string, error) {
cmd = strings.TrimPrefix(cmd, "!CMD!")
parts := strings.Split(cmd, " ")
s, err := exec.Command(parts[0], parts[1:]...).CombinedOutput()
return string(s), err
}
func getURLs(text string) []URL {
urlReg := regexp.MustCompile(`<a\s+?(.+?)>(.+?)<\/a>`)
attrReg := regexp.MustCompile(`(\w+?)="(.+?)"`)

Loading…
Cancel
Save