Fix 'configure' request for custom stores (#21)
This commit is contained in:
@@ -10,79 +10,37 @@ type Code int
|
|||||||
// Error codes that are sent to the browser extension and used as exit codes in the app.
|
// Error codes that are sent to the browser extension and used as exit codes in the app.
|
||||||
// DO NOT MODIFY THE VALUES, always append new error codes to the bottom.
|
// DO NOT MODIFY THE VALUES, always append new error codes to the bottom.
|
||||||
const (
|
const (
|
||||||
// CodeParseRequestLength error parsing a request length
|
CodeParseRequestLength Code = 10
|
||||||
CodeParseRequestLength Code = 10
|
CodeParseRequest Code = 11
|
||||||
|
CodeInvalidRequestAction Code = 12
|
||||||
// CodeParseRequest error parsing a request
|
CodeInaccessiblePasswordStore Code = 13
|
||||||
CodeParseRequest Code = 11
|
CodeInaccessibleDefaultPasswordStore Code = 14
|
||||||
|
CodeUnknownDefaultPasswordStoreLocation Code = 15
|
||||||
// CodeInvalidRequestAction error parsing a request action
|
CodeUnreadablePasswordStoreDefaultSettings Code = 16
|
||||||
CodeInvalidRequestAction Code = 12
|
CodeUnreadableDefaultPasswordStoreDefaultSettings Code = 17
|
||||||
|
CodeUnableToListFilesInPasswordStore Code = 18
|
||||||
// CodeInaccessiblePasswordStore error accessing a user-configured password store
|
|
||||||
CodeInaccessiblePasswordStore Code = 13
|
|
||||||
|
|
||||||
// CodeInaccessibleDefaultPasswordStore error accessing the default password store
|
|
||||||
CodeInaccessibleDefaultPasswordStore Code = 14
|
|
||||||
|
|
||||||
// CodeUnknownDefaultPasswordStoreLocation error determining the location of the default password store
|
|
||||||
CodeUnknownDefaultPasswordStoreLocation Code = 15
|
|
||||||
|
|
||||||
// CodeUnreadablePasswordStoreDefaultSettings error reading the default settings of a user-configured password store
|
|
||||||
CodeUnreadablePasswordStoreDefaultSettings Code = 16
|
|
||||||
|
|
||||||
// CodeUnreadableDefaultPasswordStoreDefaultSettings error reading the default settings of the default password store
|
|
||||||
CodeUnreadableDefaultPasswordStoreDefaultSettings Code = 17
|
|
||||||
|
|
||||||
// CodeUnableToListFilesInPasswordStore error listing files in a password store
|
|
||||||
CodeUnableToListFilesInPasswordStore Code = 18
|
|
||||||
|
|
||||||
// CodeUnableToDetermineRelativeFilePathInPasswordStore error determining a relative path for a file in a password store
|
|
||||||
CodeUnableToDetermineRelativeFilePathInPasswordStore Code = 19
|
CodeUnableToDetermineRelativeFilePathInPasswordStore Code = 19
|
||||||
|
CodeInvalidPasswordStore Code = 20
|
||||||
// CodeInvalidPasswordStore error looking for a password store with the given ID
|
CodeInvalidGpgPath Code = 21
|
||||||
CodeInvalidPasswordStore Code = 20
|
CodeUnableToDetectGpgPath Code = 22
|
||||||
|
CodeInvalidPasswordFileExtension Code = 23
|
||||||
// CodeInvalidGpgPath error looking for a gpg binary at the given path
|
CodeUnableToDecryptPasswordFile Code = 24
|
||||||
CodeInvalidGpgPath Code = 21
|
|
||||||
|
|
||||||
// CodeUnableToDetectGpgPath error detecting the location of the gpg binary
|
|
||||||
CodeUnableToDetectGpgPath Code = 22
|
|
||||||
|
|
||||||
// CodeInvalidPasswordFileExtension error unexpected password file extension
|
|
||||||
CodeInvalidPasswordFileExtension Code = 23
|
|
||||||
|
|
||||||
// CodeUnableToDecryptPasswordFile error decrypting a password file
|
|
||||||
CodeUnableToDecryptPasswordFile Code = 24
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Field extra field in the error response params
|
// Field extra field in the error response params
|
||||||
type Field string
|
type Field string
|
||||||
|
|
||||||
|
// Extra fields that can be sent to the browser extension as part of an error response.
|
||||||
|
// FieldMessage is always present, others are optional.
|
||||||
const (
|
const (
|
||||||
// FieldMessage a user-friendly error message, always present
|
FieldMessage Field = "message"
|
||||||
FieldMessage Field = "message"
|
FieldAction Field = "action"
|
||||||
|
FieldError Field = "error"
|
||||||
// FieldAction a browser request action that resulted in a failure
|
FieldStoreID Field = "storeId"
|
||||||
FieldAction Field = "action"
|
|
||||||
|
|
||||||
// FieldError an error message returned from an external system
|
|
||||||
FieldError Field = "error"
|
|
||||||
|
|
||||||
// FieldStoreID a password store id
|
|
||||||
FieldStoreID Field = "storeId"
|
|
||||||
|
|
||||||
// FieldStoreName a password store name
|
|
||||||
FieldStoreName Field = "storeName"
|
FieldStoreName Field = "storeName"
|
||||||
|
|
||||||
// FieldStorePath a password store path
|
|
||||||
FieldStorePath Field = "storePath"
|
FieldStorePath Field = "storePath"
|
||||||
|
FieldFile Field = "file"
|
||||||
// FieldFile a password file
|
FieldGpgPath Field = "gpgPath"
|
||||||
FieldFile Field = "file"
|
|
||||||
|
|
||||||
// FieldGpgPath a path to the gpg binary
|
|
||||||
FieldGpgPath Field = "gpgPath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExitWithCode exit with error code
|
// ExitWithCode exit with error code
|
||||||
|
2
main.go
2
main.go
@@ -24,7 +24,7 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
openbsd.Pledge("stdio rpath proc exec")
|
openbsd.Pledge("stdio rpath proc exec getpw")
|
||||||
|
|
||||||
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
|
||||||
if isVerbose {
|
if isVerbose {
|
||||||
|
@@ -8,6 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func normalizePasswordStorePath(storePath string) (string, error) {
|
func normalizePasswordStorePath(storePath string) (string, error) {
|
||||||
|
if storePath == "" {
|
||||||
|
return "", errors.New("The store path cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(storePath, "~/") {
|
if strings.HasPrefix(storePath, "~/") {
|
||||||
storePath = filepath.Join("$HOME", storePath[2:])
|
storePath = filepath.Join("$HOME", storePath[2:])
|
||||||
}
|
}
|
||||||
|
@@ -138,7 +138,7 @@ func readDefaultSettings(storePath string) (string, error) {
|
|||||||
return string(content), nil
|
return string(content), nil
|
||||||
}
|
}
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return "", nil
|
return "{}", nil
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ package request
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
goerrors "errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -135,8 +134,7 @@ func detectGpgBinary() (string, error) {
|
|||||||
return binary, nil
|
return binary, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return "", fmt.Errorf("Unable to detect the location of the gpg binary to use")
|
||||||
return "", goerrors.New("Unable to detect the location of the gpg binary to use")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateGpgBinary(gpgPath string) error {
|
func validateGpgBinary(gpgPath string) error {
|
||||||
@@ -159,7 +157,7 @@ func decryptFile(store *store, file string, gpgPath string) (string, error) {
|
|||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return "", goerrors.New(fmt.Sprintf("Error: %s, Stderr: %s", err.Error(), stderr.String()))
|
return "", fmt.Errorf("Error: %s, Stderr: %s", err.Error(), stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return stdout.String(), nil
|
return stdout.String(), nil
|
||||||
|
Reference in New Issue
Block a user