twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.63k stars 475 forks source link

bitwarden and bitwardenFields template functions seems not working #3827

Closed sobi3ch closed 2 months ago

sobi3ch commented 2 months ago

What exactly are you trying to do?

Grab secret from my bitwarden vault via template function (bitwarden ...)

What have you tried so far?

I've setup in BitWarden my item gitconfig Login to my bitwarden with bw cli command line Export my BW_SESSION and confirm bw command works (bw get item gitconfig returned json with my values) Tried to use both example from manual

echo "test {{ (bitwarden "item" "gitconfig").username.value }}" | chezmoi execute-template
echo "test {{ (bitwardenFields "item" "gitconfig").username.value }}" | chezmoi execute-template

with the same result:

chezmoi: template: stdin:1: function "item" not defined

When I use "get" instead of "item" there is the following msg:

$ echo "ala {{ (bitwarden "get" "gitconfig").token.value }}" | chezmoi execute-template 
chezmoi: template: stdin:1: function "gitconfig" not defined

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose $COMMAND

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.49.0, commit 2e0573779db0c42717585ac8abc4ad1ab814dfb2, built at 2024-06-10T20:04:26Z, built by goreleaser ok latest-version v2.49.0 ok os-arch linux/amd64 (Fedora Linux 40 (Workstation Edition)) ok uname Linux fedora 6.9.5-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jun 16 15:47:09 UTC 2024 x86_64 GNU/Linux ok go-version go1.22.4 (gc) ok executable ~/bin/chezmoi ok upgrade-method replace-executable ok config-file no config file found warning source-dir ~/.local/share/chezmoi is a git working tree (dirty) ok suspicious-entries no suspicious entries warning working-tree ~/.local/share/chezmoi is a git working tree (dirty) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set ok edit-command found /usr/bin/vim ok edit-args /usr/bin/vim ok git-command found /usr/bin/git, version 2.45.2 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.4.4 info pinentry-command not set info 1password-command op not found in $PATH ok bitwarden-command found /usr/local/bin/bw, version 2024.6.0 info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info vlt-command vlt not found in $PATH info secret-command not set ```
twpayne commented 2 months ago

Your shell quoting is not correct:

$ echo "test {{ (bitwarden "item" "gitconfig").username.value }}" | cat
test {{ (bitwarden item gitconfig).username.value }}

Use single quotes to preserve the double quotes:

$ echo 'test {{ (bitwarden "item" "gitconfig").username.value }}' | cat
test {{ (bitwarden "item" "gitconfig").username.value }}
sobi3ch commented 2 months ago

Can't believe it, I was probably too tired to pick this up. Works, obviously. Thank you!