generated from devcontainers/feature-starter
-
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.
Add bitwarden-cli-persistence feature
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"id": "bitwarden-cli-persistence", | ||
"version": "0.1.0", | ||
"name": "Bitwarden CLI Persistence", | ||
"description": "Avoid extra logins from the Bitwarden CLI by preserving the `~/.config/Bitwarden CLI` folder across container instances.", | ||
"documentationURL": "https://github.com/flokoe/devcontainer-features/tree/main/src/bitwarden-cli-persistence", | ||
"licenseURL": "https://github.com/flokoe/devcontainer-features/blob/main/LICENSE", | ||
"options": {}, | ||
"mounts": [ | ||
{ | ||
"source": "${devcontainerId}-bitwarden-cli", | ||
"target": "/dc/bitwarden-cli", | ||
"type": "volume" | ||
} | ||
], | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers-contrib/features/bitwarden-cli" | ||
] | ||
} |
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,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then | ||
echo "***********************************************************************************" | ||
echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" | ||
echo "***********************************************************************************" | ||
exit 1 | ||
fi | ||
|
||
# Ensure ~/.config exists to prevent tests failing if root user | ||
mkdir -p "$_REMOTE_USER_HOME/.config" | ||
|
||
# Create /dc/bitwarden-cli folder if doesn't exist. | ||
mkdir -p "/dc/bitwarden-cli" | ||
|
||
# As to why we move around the folder, check `github-cli-persistence/install.sh` @github.com/joshuanianji/devcontainer-features | ||
if [ -d "$_REMOTE_USER_HOME/.config/Bitwarden CLI" ]; then | ||
echo "Moving existing '~/.config/Bitwarden CLI' folder to '~/.config/Bitwarden CLI OLD'" | ||
mv "$_REMOTE_USER_HOME/.config/Bitwarden CLI" "$_REMOTE_USER_HOME/.config/Bitwarden CLI OLD" | ||
fi | ||
|
||
ln -s /dc/bitwarden-cli "$_REMOTE_USER_HOME/.config/Bitwarden CLI" | ||
|
||
# Change owner of folder. | ||
chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.config/Bitwarden CLI" | ||
|
||
# chown mount (only attached on startup) | ||
cat <<EOF >>"$_REMOTE_USER_HOME/.bashrc" | ||
sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/bitwarden-cli | ||
EOF | ||
chown -R "$_REMOTE_USER" "$_REMOTE_USER_HOME/.bashrc" | ||
|
||
echo "done!" |
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,9 @@ | ||
{ | ||
"with_vscode": { | ||
"image": "mcr.microsoft.com/devcontainers/base:bookworm", | ||
"features": { | ||
"bitwarden-cli-persistence": {}, | ||
"ghcr.io/devcontainers-contrib/features/bitwarden-cli": {} | ||
} | ||
} | ||
} |
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,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
# The 'check' command comes from the dev-container-features-test-lib. Syntax is... | ||
# check <LABEL> <cmd> [args...] | ||
|
||
# shellcheck disable=SC2016 | ||
check '`~/.config/Bitwarden CLI` existence' test -d "$HOME/.config/Bitwarden CLI" | ||
|
||
# shellcheck disable=SC2016 | ||
check '`/dc/bitwarden-cli` existence' test -d /dc/bitwarden-cli | ||
|
||
# shellcheck disable=SC2016 | ||
check '`~/.config/Bitwarden CLI` is a symlink' test -L "$HOME/.config/Bitwarden CLI" | ||
|
||
# shellcheck disable=SC2016 | ||
check '`~/.config/Bitwarden CLI` is writable' test -w "$HOME/.config/Bitwarden CLI" | ||
|
||
# Report results | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
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,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
# The 'check' command comes from the dev-container-features-test-lib. Syntax is... | ||
# check <LABEL> <cmd> [args...] | ||
|
||
# shellcheck disable=SC2016 | ||
check '`~/.config/Bitwarden CLI` existence' test -d "$HOME/.config/Bitwarden CLI" | ||
|
||
# shellcheck disable=SC2016 | ||
check '`/dc/bitwarden-cli` existence' test -d /dc/bitwarden-cli | ||
|
||
# shellcheck disable=SC2016 | ||
check '`~/.config/Bitwarden CLI` is a symlink' test -L "$HOME/.config/Bitwarden CLI" | ||
|
||
check 'Bitwarden CLI is working' bw --version | ||
|
||
check 'Bitwarden CLI data file exists' test -f /dc/bitwarden-cli/data.json | ||
|
||
# Report results | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |