#!/usr/bin/env bash set -euo pipefail # Create a Bitwarden item for a FetchML API user. # # Usage: # ./scripts/create_bitwarden_fetchml_item.sh # # Requirements: # - Bitwarden CLI (bw) installed # - You are logged in and unlocked (bw login; bw unlock) # - jq installed # # This script does NOT run on the homelab server. Run it from your # own machine where you manage Bitwarden. if [[ $# -ne 3 ]]; then echo "Usage: $0 " >&2 exit 1 fi USER_NAME="$1" API_KEY="$2" API_KEY_HASH="$3" ITEM_NAME="FetchML API  $USER_NAME" # Get base item template TEMPLATE_JSON=$(bw get template item) # Build item JSON with jq ITEM_JSON=$(echo "$TEMPLATE_JSON" | jq \ --arg name "$ITEM_NAME" \ --arg username "$USER_NAME" \ --arg password "$API_KEY" \ --arg hash "$API_KEY_HASH" \ '.name = $name | .login.username = $username | .login.password = $password | .notes = "FetchML API key for user " + $username | .fields = [{"name":"api_key_hash","value":$hash,"type":1}]') # Create item in Bitwarden # If you ever want to edit instead, you can capture the ID from this call # and use: bw edit item echo "$ITEM_JSON" | bw encode | bw create item echo "Created Bitwarden item: $ITEM_NAME"