feat(cli): add credential management commands #73
Workflow file for this run
This file contains hidden or 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
| name: build_and_test_godon_cli | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v25 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-25.11 | |
| extra_nix_config: | | |
| sandbox = false | |
| sandbox-paths = /etc/ssl/certs/ca-bundle.crt | |
| experimental-features = nix-command flakes | |
| - name: Configure Nix daemon SSL certificates | |
| run: | | |
| # Find and symlink SSL certificates for Nix daemon | |
| sudo mkdir -p /etc/ssl/certs | |
| CERT_BUNDLE=$(find /nix/store -name "ca-bundle.crt" | head -1) | |
| echo "Found certificate bundle: $CERT_BUNDLE" | |
| sudo ln -sf "$CERT_BUNDLE" /etc/ssl/certs/ca-bundle.crt | |
| sudo ln -sf "$CERT_BUNDLE" /etc/ssl/certs/ca-certificates.crt | |
| # Set environment variables for this session | |
| export SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt" | |
| export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt" | |
| export CURL_CA_BUNDLE="/etc/ssl/certs/ca-bundle.crt" | |
| # Add to nix.conf for daemon | |
| echo "ssl-cert-file = /etc/ssl/certs/ca-bundle.crt" | sudo tee -a /etc/nix/nix.conf | |
| echo "SSL certificates configured for Nix daemon" | |
| - name: Build with Nix | |
| run: | | |
| export SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt" | |
| export NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-bundle.crt" | |
| export CURL_CA_BUNDLE="/etc/ssl/certs/ca-bundle.crt" | |
| nix --experimental-features "nix-command flakes" build --verbose | |
| - name: Test binary | |
| run: | | |
| echo "Checking build output..." | |
| echo "Result path:" | |
| nix path-info .#default | |
| echo "Contents of result directory:" | |
| ls -la $(nix path-info .#default)/ || echo "result directory contents" | |
| echo "Checking $out/bin directory:" | |
| ls -la $(nix path-info .#default)/bin/ || echo "$out/bin not found" | |
| # Verify static binary | |
| BINARY_PATH="$(nix path-info .#default)/bin/godon_cli" | |
| echo "=== Binary information ===" | |
| file "$BINARY_PATH" | |
| echo "=== Dynamic libraries check (should show 'not a dynamic executable' or similar) ===" | |
| ldd "$BINARY_PATH" || echo "✅ Binary appears to be statically linked (ldd failed as expected)" | |
| echo "Testing compiled binary with direct path..." | |
| "$BINARY_PATH" --help | |
| - name: Start Prism mock container | |
| run: | | |
| # Download the OpenAPI spec with retry | |
| echo "Downloading OpenAPI spec..." | |
| curl -L --retry 3 --retry-delay 5 -o openapi.yml \ | |
| https://raw.githubusercontent.com/godon-dev/godon-images/main/images/godon-api/openapi.yml | |
| # Verify the spec was downloaded | |
| if [ ! -f openapi.yml ]; then | |
| echo "Failed to download OpenAPI spec" | |
| exit 1 | |
| fi | |
| echo "OpenAPI spec downloaded successfully" | |
| echo "=== Spec file size ===" | |
| wc -l openapi.yml | |
| echo "=== First 20 lines of spec ===" | |
| head -20 openapi.yml | |
| echo "=== Paths section ===" | |
| grep -A 20 "^paths:" openapi.yml || echo "No paths section found" | |
| echo "=== All path definitions ===" | |
| grep -E "^\s*/" openapi.yml || echo "No path definitions found" | |
| # Start Prism container in background | |
| docker run -d --name prism -p 4010:4010 \ | |
| -v $(pwd)/openapi.yml:/tmp/openapi.yml \ | |
| stoplight/prism:4 \ | |
| mock --host 0.0.0.0 /tmp/openapi.yml | |
| # Check if container started | |
| echo "Checking container status..." | |
| docker ps | grep prism || echo "Container not found in docker ps" | |
| echo "=== Container logs ===" | |
| docker logs prism || echo "No logs available" | |
| echo "=== Container inspection ===" | |
| docker inspect prism | grep -A 10 -B 10 "State" || echo "Could not inspect container" | |
| echo "=== Network ports ===" | |
| docker port prism || echo "Could not get port mappings" | |
| # Wait for Prism to start | |
| echo "Waiting for Prism to start..." | |
| sleep 15 | |
| # Test basic connectivity | |
| echo "Testing basic connectivity to localhost:4010..." | |
| curl -v http://localhost:4010 || echo "Basic connection failed" | |
| # Verify Prism is running with retry | |
| for i in {1..5}; do | |
| echo "=== Attempt $i: Testing Prism health ===" | |
| if curl -v http://localhost:4010/health 2>&1 | head -10; then | |
| echo "✅ Prism container started successfully on port 4010" | |
| break | |
| else | |
| echo "❌ Attempt $i: Prism not ready yet, waiting..." | |
| echo "Container still running?" | |
| docker ps | grep prism || echo "Container stopped" | |
| echo "Recent logs:" | |
| docker logs --tail 5 prism | |
| sleep 5 | |
| fi | |
| done | |
| # Test available endpoints | |
| echo "=== Testing available Prism endpoints ===" | |
| echo "Testing root path:" | |
| curl -v http://localhost:4010/ 2>&1 | head -10 || echo "Root path failed" | |
| echo "Testing /v0 path:" | |
| curl -v http://localhost:4010/v0 2>&1 | head -10 || echo "/v0 path failed" | |
| echo "Testing /v0/breeders:" | |
| curl -v http://localhost:4010/v0/breeders 2>&1 | head -10 || echo "/v0/breeders failed" | |
| echo "Testing OpenAPI spec:" | |
| curl -v http://localhost:4010/openapi.json 2>&1 | head -5 || echo "OpenAPI spec failed" | |
| echo "=== Testing exact URLs that CLI will use ===" | |
| echo "Testing /breeders (what CLI should call):" | |
| curl -v http://localhost:4010/breeders 2>&1 | head -10 || echo "/breeders failed" | |
| echo "Testing POST /breeders:" | |
| curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' \ | |
| http://localhost:4010/breeders 2>&1 | head -10 || echo "POST /breeders failed" | |
| echo "Testing /credentials (new endpoints):" | |
| curl -v http://localhost:4010/credentials 2>&1 | head -10 || echo "/credentials failed" | |
| echo "Testing POST /credentials:" | |
| curl -X POST -H "Content-Type: application/json" \ | |
| -d '{"name":"test","credential_type":"ssh_private_key","content":"test_key_content"}' \ | |
| http://localhost:4010/credentials 2>&1 | head -10 || echo "POST /credentials failed" | |
| - name: Integration tests against Prism mock | |
| run: | | |
| # Get the binary path | |
| BINARY_PATH=$(nix path-info .#default)/bin/godon_cli | |
| echo "Running integration tests against Prism mock..." | |
| # Test breeder list with HTTP (default) | |
| echo "Testing: breeder list (HTTP default)" | |
| $BINARY_PATH --hostname=localhost --port=4010 breeder list | |
| # Test explicit HTTP prefix | |
| echo "Testing: breeder list (explicit http:// prefix)" | |
| $BINARY_PATH --hostname=http://localhost --port=4010 breeder list | |
| # Test HTTPS prefix with insecure flag (using HTTP port for testing) | |
| echo "Testing: breeder list (HTTPS prefix with --insecure flag)" | |
| $BINARY_PATH --hostname=https://localhost --port=4010 --insecure breeder list || echo "Expected: HTTPS on HTTP port may fail" | |
| # Test HTTPS prefix without insecure flag (should fail on missing certificates) | |
| echo "Testing: breeder list (HTTPS prefix without --insecure flag - should fail)" | |
| $BINARY_PATH --hostname=https://localhost --port=4010 breeder list && echo "❌ Unexpected success - should have failed without certificates" || echo "✅ Expected failure without SSL certificates" | |
| # Test help command shows new --insecure flag | |
| echo "Testing: help shows --insecure flag" | |
| $BINARY_PATH --help | grep -q "insecure" && echo "✅ --insecure flag documented in help" || echo "❌ --insecure flag missing from help" | |
| # Create test YAML files using echo | |
| echo 'name: "Test Breeder"' > test_breeder.yml | |
| echo 'config: >' >> test_breeder.yml | |
| echo ' {"setting1": "value1", "setting2": 42}' >> test_breeder.yml | |
| echo "Testing: breeder create" | |
| $BINARY_PATH --hostname=localhost --port=4010 breeder create --file=test_breeder.yml | |
| # Test breeder show with a mock UUID | |
| echo "Testing: breeder show" | |
| $BINARY_PATH --hostname=localhost --port=4010 breeder show --id=550e8400-e29b-41d4-a716-446655440000 | |
| # Create update test file | |
| echo 'uuid: "550e8400-e29b-41d4-a716-446655440000"' > test_breeder_update.yml | |
| echo 'name: "Updated Test Breeder"' >> test_breeder_update.yml | |
| echo 'description: "Updated integration test breeder"' >> test_breeder_update.yml | |
| echo 'config: >' >> test_breeder_update.yml | |
| echo ' {"setting1": "updated_value1", "setting2": 100, "new_setting": "new_value"}' >> test_breeder_update.yml | |
| echo "Testing: breeder update" | |
| $BINARY_PATH --hostname=localhost --port=4010 breeder update --file=test_breeder_update.yml | |
| # Test breeder purge | |
| echo "Testing: breeder purge" | |
| $BINARY_PATH --hostname=localhost --port=4010 breeder purge --id=550e8400-e29b-41d4-a716-446655440000 | |
| # Test help commands | |
| echo "Testing: help commands" | |
| $BINARY_PATH --help | |
| $BINARY_PATH breeder --help || true # May fail but tests argument parsing | |
| # === Credential Command Tests === | |
| echo "" | |
| echo "=== Testing Credential Commands ===" | |
| # Test credential list | |
| echo "Testing: credential list" | |
| $BINARY_PATH --hostname=localhost --port=4010 credential list | |
| # Create test credential YAML file | |
| echo 'name: "test_ssh_key"' > test_credential.yml | |
| echo 'credential_type: "ssh_private_key"' >> test_credential.yml | |
| echo 'description: "Test SSH key for CI"' >> test_credential.yml | |
| echo 'content: "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA2Z2H7V..."' >> test_credential.yml | |
| # Test credential create | |
| echo "Testing: credential create" | |
| $BINARY_PATH --hostname=localhost --port=4010 credential create --file=test_credential.yml | |
| # Test credential show with mock UUID | |
| echo "Testing: credential show (including content)" | |
| $BINARY_PATH --hostname=localhost --port=4010 credential show --id=550e8400-e29b-41d4-a716-446655440001 | |
| # Test credential delete | |
| echo "Testing: credential delete" | |
| $BINARY_PATH --hostname=localhost --port=4010 credential delete --id=550e8400-e29b-41d4-a716-446655440001 | |
| # Test help shows credential commands | |
| echo "Testing: help shows credential commands" | |
| $BINARY_PATH --help | grep -q "credential" && echo "✅ Credential commands documented in help" || echo "❌ Credential commands missing from help" | |
| - name: Cleanup Prism container | |
| if: always() | |
| run: | | |
| docker stop prism || true | |
| docker rm prism || true |