Skip to content

Commit a848611

Browse files
authored
Merge pull request #2 from RouL/feature_bitwarden-secrets-manager
Feature bitwarden secrets manager
2 parents 0429ba3 + f831f57 commit a848611

File tree

8 files changed

+188
-0
lines changed

8 files changed

+188
-0
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
matrix:
1616
features:
1717
- bitwarden-cli
18+
- bitwarden-secrets-manager
1819
baseImage:
1920
- debian:latest
2021
- ubuntu:latest
@@ -35,6 +36,7 @@ jobs:
3536
matrix:
3637
features:
3738
- bitwarden-cli
39+
- bitwarden-secrets-manager
3840
steps:
3941
- uses: actions/checkout@v4
4042

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Bitwarden Secrets Manager CLI (bws) (bitwarden-secrets-manager)
3+
4+
Installs the bitwarden secrets manager CLI (bws) and optionally configures it to use a self-hosted server.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/RouL/devcontainer-features/bitwarden-secrets-manager:1": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| server_base | Provides the base URL of your Bitwarden server, if you host your own server. | string | - |
19+
| server_api | Provides an API URL that differs from the default (if in doubt, leave it empty!). | string | - |
20+
| server_identity | Provides an identity URL that differs from the default (if in doubt, leave it empty!). | string | - |
21+
22+
23+
24+
---
25+
26+
_Note: This file was auto-generated from the [devcontainer-feature.json](devcontainer-feature.json). Add additional notes to a `NOTES.md`._
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "bitwarden-secrets-manager",
3+
"version": "1.0.0",
4+
"name": "Bitwarden Secrets Manager CLI (bws)",
5+
"description": "Installs the bitwarden secrets manager CLI (bws) and optionally configures it to use a self-hosted server.",
6+
"options": {
7+
"server_base":{
8+
"description": "Provides the base URL of your Bitwarden server, if you host your own server.",
9+
"type": "string",
10+
"default": ""
11+
},
12+
"server_api":{
13+
"description": "Provides an API URL that differs from the default (if in doubt, leave it empty!).",
14+
"type": "string",
15+
"default": ""
16+
},
17+
"server_identity":{
18+
"description": "Provides an identity URL that differs from the default (if in doubt, leave it empty!).",
19+
"type": "string",
20+
"default": ""
21+
}
22+
}
23+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
set -e
3+
4+
SERVER_BASE="${SERVER_BASE}"
5+
SERVER_API="${SERVER_API}"
6+
SERVER_IDENTITY="${SERVER_IDENTITY}"
7+
8+
REQUIRED_PACKAGES="curl unzip sudo ca-certificates jq"
9+
TARGET_PATH=/usr/local/bin/bws
10+
11+
error() {
12+
echo "$1" >&2
13+
echo "Exiting..." >&2
14+
exit 1
15+
}
16+
17+
apt_get_update()
18+
{
19+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
20+
echo "Running apt-get update..."
21+
apt-get update -y
22+
fi
23+
}
24+
25+
check_packages() {
26+
if ! dpkg -s "$@" > /dev/null 2>&1; then
27+
apt_get_update
28+
apt-get -y install --no-install-recommends "$@"
29+
fi
30+
}
31+
32+
platform_detect() {
33+
if [ "$(uname -s)" = "Linux" ]; then
34+
PLATFORM="unknown-linux-gnu"
35+
elif [ "$(uname -s)" = "Darwin" ]; then
36+
PLATFORM="apple-darwin"
37+
else
38+
error "Unsupported platform: $(uname -s)"
39+
fi
40+
}
41+
42+
arch_detect() {
43+
if [ "$(uname -m)" = "x86_64" ]; then
44+
ARCH="x86_64"
45+
elif [ "$(uname -m)" = "aarch64" ]; then # Linux
46+
ARCH="aarch64"
47+
elif [ "$(uname -m)" = "arm64" ]; then # Darwin/macOS
48+
ARCH="aarch64"
49+
else
50+
error "Unsupported architecture: $(uname -m)"
51+
fi
52+
}
53+
54+
export DEBIAN_FRONTEND=noninteractive
55+
56+
check_packages $REQUIRED_PACKAGES
57+
58+
CURRENT_TAG="$(curl --request GET https://api.github.com/repos/bitwarden/sdk-sm/releases?per_page=100 | jq --raw-output '[.[] | select(.draft == false) | select(.prerelease == false) | select(.tag_name | startswith("bws-")) | .tag_name][0]')"
59+
CURRENT_VERSION="${CURRENT_TAG#bws-v}"
60+
VERSION="${VERSION:-$CURRENT_VERSION}"
61+
62+
platform_detect
63+
arch_detect
64+
65+
install() {
66+
curl -L "https://github.com/bitwarden/sdk-sm/releases/download/bws-v${VERSION}/bws-${ARCH}-${PLATFORM}-${VERSION}.zip" -o bws.zip
67+
68+
unzip bws.zip
69+
rm bws.zip
70+
71+
chmod a+x bws
72+
mv bws $TARGET_PATH
73+
}
74+
75+
configure() {
76+
configCmd="sudo -u ${_REMOTE_USER} -i ${TARGET_PATH} config"
77+
78+
[ "${SERVER_BASE}" != "" ] && $configCmd server-base $SERVER_BASE
79+
[ "${SERVER_API}" != "" ] && $configCmd server-api $SERVER_API
80+
[ "${SERVER_IDENTITY}" != "" ] && $configCmd server-identity $SERVER_IDENTITY
81+
82+
return 0
83+
}
84+
85+
echo "(*) Installing Bitwarden Secrets Manager CLI..."
86+
87+
install
88+
89+
if [ "${SERVER_BASE}" != "" ] || [ "${SERVER_API}" != "" ] || [ "${SERVER_IDENTITY}" != "" ]; then
90+
echo "(*) Configure custom Bitwarden server URLs..."
91+
configure
92+
fi
93+
94+
# Clean up
95+
rm -rf /var/lib/apt/lists/*
96+
97+
echo "Done!"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"server_example": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
4+
"features": {
5+
"bitwarden-secrets-manager": {
6+
"server_base": "https://example.com"
7+
}
8+
}
9+
},
10+
"server_example_full": {
11+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
12+
"features": {
13+
"bitwarden-secrets-manager": {
14+
"server_base": "https://example.com",
15+
"server_api": "https://example.com/api",
16+
"server_identity": "https://example.com/identity"
17+
}
18+
}
19+
}
20+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "server config server-base => https://example.com" bash -c "grep -E '^server_base = \"https://example.com\"\$' ~/.config/bws/config"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "server config server-base => https://example.com" bash -c "grep -E '^server_base = \"https://example.com\"\$' ~/.config/bws/config"
7+
check "server config server-api => https://example.com/api" bash -c "grep -E '^server_api = \"https://example.com/api\"\$' ~/.config/bws/config"
8+
check "server config server-identity => https://example.com/identity" bash -c "grep -E '^server_identity = \"https://example.com/identity\"\$' ~/.config/bws/config"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "bws --version" bash -c "bws --version | grep -E '^bws [1-9][0-9]*\\.[0-9]+\\.[0-9]+\$'"

0 commit comments

Comments
 (0)