forked from twpayne/chezmoi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Dashlane password manager support
- Loading branch information
Showing
9 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
assets/chezmoi.io/docs/reference/templates/dashlane-functions/dashlanePassword.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# `dashlanePassword` *filter* | ||
|
||
`dashlanePassword` returns structured data from [Dashlane](https://dashlane.com) | ||
using the [Dashlane CLI](https://github.com/Dashlane/dashlane-cli) (`dcli`). | ||
*filter* is passed to `dcli password --output json`, and the output from `dcli | ||
password` is parsed as JSON. | ||
|
||
The output from `dcli password` cached so calling `dashlanePassword` multiple | ||
times with the same *filter* will only invoke `dcli password` once. | ||
|
||
!!! example | ||
|
||
``` | ||
{{ (index (dashlanePassword "filter") 0).password }} | ||
``` |
4 changes: 4 additions & 0 deletions
4
assets/chezmoi.io/docs/reference/templates/dashlane-functions/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Dashlane functions | ||
|
||
The `dashlane*` functions return data from [Dashlane](https://dashlane.com) | ||
using the [Dashlane CLI](https://github.com/Dashlane/dashlane-cli). |
10 changes: 10 additions & 0 deletions
10
assets/chezmoi.io/docs/user-guide/password-managers/dashlane.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Dashlane | ||
|
||
chezmoi includes support for [Dashlane](https://dashlane.com). | ||
|
||
Structured data can be retrieved with the `dashlanePassword` template function, | ||
for example: | ||
|
||
``` | ||
examplePassword = {{ (index (dashlanePassword "filter") 0).password }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/twpayne/chezmoi/v2/pkg/chezmoilog" | ||
) | ||
|
||
type dashlaneConfig struct { | ||
Command string `json:"command" mapstructure:"command" yaml:"command"` | ||
Args []string `json:"args" mapstructure:"args" yaml:"args"` | ||
cache map[string]any | ||
} | ||
|
||
func (c *Config) dashlanePasswordTemplateFunc(filter string) any { | ||
if data, ok := c.Dashlane.cache[filter]; ok { | ||
return data | ||
} | ||
|
||
if c.Dashlane.cache == nil { | ||
c.Dashlane.cache = make(map[string]any) | ||
} | ||
|
||
output, err := c.dashlaneOutput("password", "--output", "json", filter) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var data any | ||
if err := json.Unmarshal(output, &data); err != nil { | ||
panic(err) | ||
} | ||
|
||
c.Dashlane.cache[filter] = data | ||
return data | ||
} | ||
|
||
func (c *Config) dashlaneOutput(args ...string) ([]byte, error) { | ||
name := c.Dashlane.Command | ||
cmd := exec.Command(name, append(c.Dashlane.Args, args...)...) | ||
cmd.Stdin = os.Stdin | ||
cmd.Stderr = os.Stderr | ||
output, err := chezmoilog.LogCmdOutput(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return output, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[!windows] chmod 755 bin/dcli | ||
[windows] unix2dos bin/dcli.cmd | ||
|
||
# test dashlanePassword template function | ||
exec chezmoi execute-template '{{ (index (dashlanePassword "filter") 0).password }}' | ||
stdout ^<password>$ | ||
|
||
-- bin/dcli -- | ||
#!/bin/sh | ||
|
||
case "$*" in | ||
"password --output json filter") | ||
cat <<EOF | ||
[ | ||
{ | ||
"title": "<name of the entry>", | ||
"useFixedUrl": false, | ||
"login": "<login>", | ||
"status": "ACCOUNT_NOT_VERIFIED", | ||
"note": "<any note>", | ||
"autoLogin": false, | ||
"modificationDatetime": "<timestamp>", | ||
"checked": false, | ||
"id": "<id>", | ||
"anonId": "<anonymous id>", | ||
"localeFormat": "UNIVERSAL", | ||
"password": "<password>", | ||
"creationDatetime": "<timestamp>", | ||
"userModificationDatetime": "<timestamp>", | ||
"lastBackupTime": "<timestamp>", | ||
"autoProtected": false, | ||
"strength": 0, | ||
"subdomainOnly": false | ||
} | ||
] | ||
EOF | ||
;; | ||
*) | ||
echo "error: unknown command '$*'" | ||
exit 1 | ||
esac | ||
-- bin/dcli.cmd -- | ||
@echo off | ||
IF "%*" == "password --output json filter" ( | ||
echo.[ | ||
echo. { | ||
echo. "title": "<name of the entry>", | ||
echo. "useFixedUrl": false, | ||
echo. "login": "<login>", | ||
echo. "status": "ACCOUNT_NOT_VERIFIED", | ||
echo. "note": "<any note>", | ||
echo. "autoLogin": false, | ||
echo. "modificationDatetime": "<timestamp>", | ||
echo. "checked": false, | ||
echo. "id": "<id>", | ||
echo. "anonId": "<anonymous id>", | ||
echo. "localeFormat": "UNIVERSAL", | ||
echo. "password": "<password>", | ||
echo. "creationDatetime": "<timestamp>", | ||
echo. "userModificationDatetime": "<timestamp>", | ||
echo. "lastBackupTime": "<timestamp>", | ||
echo. "autoProtected": false, | ||
echo. "strength": 0, | ||
echo. "subdomainOnly": false | ||
echo. } | ||
echo.] | ||
) ELSE ( | ||
echo error: unknown command '$*' | ||
exit /b 1 | ||
) |