#!/bin/bash # Drone Secrets Management Script # Usage: ./manage-secrets.sh set -e echo "🔐 Drone Secrets Management" echo "==========================" echo read -p "Enter your TOKEN: " DRONE_TOKEN # Configuration DRONE_SERVER="https://drone.aipice.local" REPO_OWNER="AIPICE" REPO_NAME="auth-service" REPO="${REPO_OWNER}/${REPO_NAME}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Check if drone CLI is available if ! command -v drone &> /dev/null; then echo -e "${YELLOW}📥 Installing Drone CLI...${NC}" curl -L https://github.com/harness/drone-cli/releases/latest/download/drone_linux_amd64.tar.gz | tar zx sudo install -t /usr/local/bin drone echo -e "${GREEN}✅ Drone CLI installed${NC}" fi # Check if DRONE_TOKEN is set if [ -z "$DRONE_TOKEN" ]; then echo -e "${RED}❌ DRONE_TOKEN environment variable not set${NC}" echo "Please get your Drone API token from: ${DRONE_SERVER}/account" echo "Then run: export DRONE_TOKEN=your-token-here" echo exit 1 fi # Configure drone CLI export DRONE_SERVER export DRONE_TOKEN echo "📋 Configuration:" echo " Server: $DRONE_SERVER" echo " Repository: $REPO" echo # Function to create a secret create_secret() { local secret_name=$1 local secret_value=$2 local description=$3 echo -e "${YELLOW}Creating secret: $secret_name${NC}" if drone secret add --repository "$REPO" --name "$secret_name" --data "$secret_value"; then echo -e "${GREEN}✅ Secret '$secret_name' created successfully${NC}" else echo -e "${RED}❌ Failed to create secret '$secret_name'${NC}" fi echo } # Function to list secrets list_secrets() { echo -e "${YELLOW}📋 Current secrets for $REPO:${NC}" drone secret ls --repository "$REPO" || echo -e "${RED}❌ Failed to list secrets${NC}" echo } # Main menu while true; do echo "🎯 What would you like to do?" echo "1) List existing secrets" echo "2) Add Gitea credentials" echo "3) Add Docker Hub credentials" echo "4) Add custom secret" echo "5) Test connection" echo "6) Exit" echo read -p "Choose an option (1-6): " choice echo case $choice in 1) list_secrets ;; 2) echo "🔑 Adding Gitea credentials..." read -p "Gitea Username: " gitea_username read -s -p "Gitea Password/Token: " gitea_password echo create_secret "gitea_username" "$gitea_username" "Gitea username for cloning" create_secret "gitea_password" "$gitea_password" "Gitea password/token for cloning" ;; 3) echo "🐳 Adding Docker Hub credentials..." read -p "Docker Hub Username: " docker_username read -s -p "Docker Hub Password/Token: " docker_password echo create_secret "docker_username" "$docker_username" "Docker Hub username" create_secret "docker_password" "$docker_password" "Docker Hub password/token" ;; 4) echo "🔐 Adding custom secret..." read -p "Secret name: " secret_name read -s -p "Secret value: " secret_value echo create_secret "$secret_name" "$secret_value" "Custom secret" ;; 5) echo "🔍 Testing connection..." drone info || echo -e "${RED}❌ Connection failed${NC}" echo ;; 6) echo "👋 Goodbye!" break ;; *) echo -e "${RED}❌ Invalid option${NC}" ;; esac done