Better default path handling (#7)

* Better handling of default store
* Add store name as a settings param
This commit is contained in:
Erayd
2018-04-13 12:16:42 +12:00
committed by GitHub
parent eafa71cc9b
commit ca706e7699
2 changed files with 17 additions and 7 deletions

View File

@@ -63,16 +63,18 @@ Settings are applied using the following priority, highest first:
### Global Settings
| Setting | Description | Default |
| ------- | ---------------------------------------------------- | ------- |
| gpgPath | Optional path to gpg binary | `null` |
| stores | List of password stores with store-specific settings | `null` |
| Setting | Description | Default |
| ------------ | ---------------------------------------------------- | ------- |
| gpgPath | Optional path to gpg binary | `null` |
| defaultStore | Store-specific settings for default store | `{}` |
| stores | List of password stores with store-specific settings | `{}` |
### Store-specific Settings
| Setting | Description | Default |
| ------- | ---------------------------------------------------- | ------- |
| | | |
| Setting | Description | Default |
| ------------ | ---------------------------------------------------- | ------- |
| name | Store name (same as the store key) | <key> |
| path | Path to the password store directory | `""` |
## Actions
@@ -99,6 +101,7 @@ is alive, determine the version at startup, and provide per-store defaults.
   “version”: <int>
   “response”: {
"defaultPath": "/path/to/default/store",
"defaultSettings": <raw contents of $defaultPath/.browserpass.json>,
       “storeSettings”: {
           “storeName”: <raw contents of storePath/.browserpass.json>
       }

View File

@@ -96,6 +96,13 @@ function configure()
[ -n "$PASSWORD_STORE_DIR" ] || PASSWORD_STORE_DIR="~/.password-store"
OUTPUT="$(jq -n --arg defaultPath "$PASSWORD_STORE_DIR" '.defaultPath = $defaultPath')"
STOREPATH=$(echo "$PASSWORD_STORE_DIR" | sed 's/^~/$HOME/' | envsubst)
if [ -f "$STOREPATH/.browserpass.json" ]; then
OUTPUT=$(jq --arg settings "$(cat "$STOREPATH/.browserpass.json")" '.defaultSettings = $settings' <<< "$OUTPUT")
else
OUTPUT=$(jq '.defaultSettings = ""' <<< "$OUTPUT")
fi
for STORE in "${!STORES[@]}"; do
OUTPUT=$(jq --arg store "$STORE" --arg settings "${STORES[$STORE]}" '.storeSettings[$store] = $settings' <<< "$OUTPUT")
done