|
| 1 | +#!/usr/bin/env bash |
| 2 | +# test.sh - Test script for the encrypted secrets example |
| 3 | +# |
| 4 | +# This script demonstrates running the disco agent with encrypted secrets enabled. |
| 5 | +# It will run in one-shot mode and output to a local file for inspection. |
| 6 | + |
| 7 | +set -euo pipefail |
| 8 | + |
| 9 | +# Colors for output |
| 10 | +RED='\033[0;31m' |
| 11 | +GREEN='\033[0;32m' |
| 12 | +YELLOW='\033[1;33m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +echo -e "${GREEN}=== Encrypted Secrets Example Test ===${NC}\n" |
| 16 | + |
| 17 | +echo -e "${GREEN}Testing agent with Kubernetes secrets${NC}" |
| 18 | +echo "" |
| 19 | + |
| 20 | +# Enable encrypted secrets |
| 21 | +export ARK_SEND_SECRETS="true" |
| 22 | + |
| 23 | +# Check Kubernetes connectivity |
| 24 | +if ! kubectl cluster-info &> /dev/null; then |
| 25 | + echo -e "${RED}Error: Unable to connect to Kubernetes cluster${NC}" |
| 26 | + echo "Please ensure your kubeconfig is configured correctly." |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +echo -e "${GREEN}✓ Connected to Kubernetes cluster${NC}" |
| 31 | +CONTEXT=$(kubectl config current-context) |
| 32 | +echo " Context: ${CONTEXT}" |
| 33 | +echo "" |
| 34 | + |
| 35 | +# Check for secrets |
| 36 | +SECRET_COUNT=$(kubectl get secrets --all-namespaces --no-headers 2>/dev/null | wc -l | tr -d ' ') |
| 37 | +echo "Found ${SECRET_COUNT} secrets in cluster" |
| 38 | +echo "" |
| 39 | + |
| 40 | +# Run the agent in one-shot mode with output to file |
| 41 | +OUTPUT_FILE="output.json" |
| 42 | +echo -e "${GREEN}Running disco agent with encrypted secrets enabled...${NC}" |
| 43 | +echo "Command: go run ../.. agent --agent-config-file config.yaml --one-shot --output-path ${OUTPUT_FILE}" |
| 44 | +echo "" |
| 45 | + |
| 46 | +if go run ../.. agent \ |
| 47 | + --agent-config-file config.yaml \ |
| 48 | + --one-shot \ |
| 49 | + --output-path "${OUTPUT_FILE}"; then |
| 50 | + |
| 51 | + echo "" |
| 52 | + echo -e "${GREEN}✓ Agent completed successfully${NC}" |
| 53 | + |
| 54 | + # Check if output file was created |
| 55 | + if [ -f "${OUTPUT_FILE}" ]; then |
| 56 | + echo -e "${GREEN}✓ Output file created: ${OUTPUT_FILE}${NC}" |
| 57 | + else |
| 58 | + echo -e "${RED}✗ Output file was not created${NC}" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +else |
| 62 | + echo "" |
| 63 | + echo -e "${RED}✗ Agent failed${NC}" |
| 64 | + exit 1 |
| 65 | +fi |
0 commit comments