mirror of
https://github.com/vwxyzjn/portwarden
synced 2026-01-05 16:43:13 +00:00
API-1 # Refactor finished.
Now the front-end `cmd` and `web` should be able to call common methods
This commit is contained in:
15
core.go
15
core.go
@@ -4,10 +4,13 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mholt/archiver"
|
||||
@@ -78,6 +81,18 @@ func DecryptBackup(fileName, passphrase string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExtractSessionKey(stdout string) (string, error) {
|
||||
r := regexp.MustCompile(`BW_SESSION=".+"`)
|
||||
matches := r.FindAllString(stdout, 1)
|
||||
if len(matches) == 0 {
|
||||
return "", errors.New(ErrSessionKeyExtractionFailed)
|
||||
}
|
||||
sessionKeyRawString := r.FindAllString(stdout, 1)[0]
|
||||
sessionKey := strings.TrimPrefix(sessionKeyRawString, `BW_SESSION="`)
|
||||
sessionKey = sessionKey[:len(sessionKey)-1]
|
||||
return sessionKey, nil
|
||||
}
|
||||
|
||||
func BWListItemsRawBytes(sessionKey string) []byte {
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd := exec.Command("bw", "list", "items", "--session", sessionKey)
|
||||
|
||||
Reference in New Issue
Block a user