Compare commits

..

1 Commits

Author SHA1 Message Date
anonpenguin
ade6241357
Merge pull request #78 from DeBrosOfficial/nightly
Nightly version 0.9
2026-01-20 10:19:01 +02:00
529 changed files with 9299 additions and 85999 deletions

View File

@ -57,9 +57,9 @@ jobs:
mkdir -p build/usr/local/bin
go build -ldflags "$LDFLAGS" -o build/usr/local/bin/orama cmd/cli/main.go
go build -ldflags "$LDFLAGS" -o build/usr/local/bin/orama-node cmd/node/main.go
go build -ldflags "$LDFLAGS" -o build/usr/local/bin/debros-node cmd/node/main.go
# Build the entire gateway package so helper files (e.g., config parsing) are included
go build -ldflags "$LDFLAGS" -o build/usr/local/bin/orama-gateway ./cmd/gateway
go build -ldflags "$LDFLAGS" -o build/usr/local/bin/debros-gateway ./cmd/gateway
- name: Create Debian package structure
run: |
@ -82,7 +82,7 @@ jobs:
Priority: optional
Architecture: ${ARCH}
Depends: libc6
Maintainer: DeBros Team <team@orama.network>
Maintainer: DeBros Team <team@debros.network>
Description: Orama Network - Distributed P2P Database System
Orama is a distributed peer-to-peer network that combines
RQLite for distributed SQL, IPFS for content-addressed storage,

View File

@ -34,7 +34,6 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
@ -43,26 +42,32 @@ jobs:
path: dist/
retention-days: 5
# Verify release artifacts
verify-release:
# Optional: Publish to GitHub Packages (requires additional setup)
publish-packages:
runs-on: ubuntu-latest
needs: build-release
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: release-artifacts
path: dist/
- name: List release artifacts
- name: Publish to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "=== Release Artifacts ==="
ls -la dist/
echo ""
echo "=== .deb packages ==="
ls -la dist/*.deb 2>/dev/null || echo "No .deb files found"
echo ""
echo "=== Archives ==="
ls -la dist/*.tar.gz 2>/dev/null || echo "No .tar.gz files found"
echo "Publishing Debian packages to GitHub Packages..."
for deb in dist/*.deb; do
if [ -f "$deb" ]; then
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$deb" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/upload?name=$(basename "$deb")"
fi
done

33
.gitignore vendored
View File

@ -30,8 +30,6 @@ dist/
# OS generated files
.DS_Store
.codex/
redeploy-6.sh
.DS_Store?
._*
.Spotlight-V100
@ -47,9 +45,6 @@ Thumbs.db
.env.local
.env.*.local
# E2E test config (contains production credentials)
e2e/config.yaml
# Temporary files
tmp/
temp/
@ -85,30 +80,4 @@ configs/
.claude/
.mcp.json
.cursor/
# Remote node credentials
scripts/remote-nodes.conf
orama-cli-linux
rnd/
keys_backup/
vps.txt
bin-linux/
website/
terms-agreement
./cli
./inspector
results/
phantom-auth/
*.db
.cursor/

View File

@ -1,21 +1,17 @@
# GoReleaser Configuration for DeBros Network
# Builds and releases orama (CLI) and orama-node binaries
# Publishes to: GitHub Releases, Homebrew, and apt (.deb packages)
# Builds and releases the dbn binary for multiple platforms
# Other binaries (node, gateway, identity) are installed via: dbn setup
project_name: orama-network
project_name: debros-network
env:
- GO111MODULE=on
before:
hooks:
- go mod tidy
builds:
# orama CLI binary
- id: orama
# dbn binary - only build the CLI
- id: dbn
main: ./cmd/cli
binary: orama
binary: dbn
goos:
- linux
- darwin
@ -29,106 +25,18 @@ builds:
- -X main.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
# orama-node binary (Linux only for apt)
- id: orama-node
main: ./cmd/node
binary: orama-node
goos:
- linux
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.ShortCommit}}
- -X main.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
archives:
# Tar.gz archives for orama CLI
- id: orama-archives
builds:
- orama
# Tar.gz archives for dbn
- id: binaries
format: tar.gz
name_template: "orama_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
- LICENSE
# Tar.gz archives for orama-node
- id: orama-node-archives
builds:
- orama-node
format: tar.gz
name_template: "orama-node_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
- LICENSE
# Debian packages for apt
nfpms:
# orama CLI .deb package
- id: orama-deb
package_name: orama
builds:
- orama
vendor: DeBros
homepage: https://github.com/DeBrosOfficial/network
maintainer: DeBros <dev@debros.io>
description: CLI tool for the Orama decentralized network
license: MIT
formats:
- deb
bindir: /usr/bin
section: utils
priority: optional
contents:
- src: ./README.md
dst: /usr/share/doc/orama/README.md
deb:
lintian_overrides:
- statically-linked-binary
# orama-node .deb package
- id: orama-node-deb
package_name: orama-node
builds:
- orama-node
vendor: DeBros
homepage: https://github.com/DeBrosOfficial/network
maintainer: DeBros <dev@debros.io>
description: Node daemon for the Orama decentralized network
license: MIT
formats:
- deb
bindir: /usr/bin
section: net
priority: optional
contents:
- src: ./README.md
dst: /usr/share/doc/orama-node/README.md
deb:
lintian_overrides:
- statically-linked-binary
# Homebrew tap for macOS (orama CLI only)
brews:
- name: orama
ids:
- orama-archives
repository:
owner: DeBrosOfficial
name: homebrew-tap
token: "{{ .Env.HOMEBREW_TAP_TOKEN }}"
folder: Formula
homepage: https://github.com/DeBrosOfficial/network
description: CLI tool for the Orama decentralized network
license: MIT
install: |
bin.install "orama"
test: |
system "#{bin}/orama", "--version"
- CHANGELOG.md
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"

View File

@ -32,7 +32,7 @@ This Code applies within all project spaces and when an individual is officially
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the maintainers at: security@orama.io
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the maintainers at: security@debros.io
All complaints will be reviewed and investigated promptly and fairly.

164
Makefile
View File

@ -8,66 +8,21 @@ test:
# Gateway-focused E2E tests assume gateway and nodes are already running
# Auto-discovers configuration from ~/.orama and queries database for API key
# No environment variables required
.PHONY: test-e2e test-e2e-deployments test-e2e-fullstack test-e2e-https test-e2e-quick test-e2e-prod test-e2e-shared test-e2e-cluster test-e2e-integration test-e2e-production
# Production E2E tests - includes production-only tests
test-e2e-prod:
@if [ -z "$$ORAMA_GATEWAY_URL" ]; then \
echo "❌ ORAMA_GATEWAY_URL not set"; \
echo "Usage: ORAMA_GATEWAY_URL=https://dbrs.space make test-e2e-prod"; \
exit 1; \
fi
@echo "Running E2E tests (including production-only) against $$ORAMA_GATEWAY_URL..."
go test -v -tags "e2e production" -timeout 30m ./e2e/...
# Generic e2e target
.PHONY: test-e2e
test-e2e:
@echo "Running comprehensive E2E tests..."
@echo "Auto-discovering configuration from ~/.orama..."
go test -v -tags e2e -timeout 30m ./e2e/...
test-e2e-deployments:
@echo "Running deployment E2E tests..."
go test -v -tags e2e -timeout 15m ./e2e/deployments/...
test-e2e-fullstack:
@echo "Running fullstack E2E tests..."
go test -v -tags e2e -timeout 20m -run "TestFullStack" ./e2e/...
test-e2e-https:
@echo "Running HTTPS/external access E2E tests..."
go test -v -tags e2e -timeout 10m -run "TestHTTPS" ./e2e/...
test-e2e-shared:
@echo "Running shared E2E tests..."
go test -v -tags e2e -timeout 10m ./e2e/shared/...
test-e2e-cluster:
@echo "Running cluster E2E tests..."
go test -v -tags e2e -timeout 15m ./e2e/cluster/...
test-e2e-integration:
@echo "Running integration E2E tests..."
go test -v -tags e2e -timeout 20m ./e2e/integration/...
test-e2e-production:
@echo "Running production-only E2E tests..."
go test -v -tags "e2e production" -timeout 15m ./e2e/production/...
test-e2e-quick:
@echo "Running quick E2E smoke tests..."
go test -v -tags e2e -timeout 5m -run "TestStatic|TestHealth" ./e2e/...
go test -v -tags e2e ./e2e
# Network - Distributed P2P Database System
# Makefile for development and build tasks
.PHONY: build clean test deps tidy fmt vet lint install-hooks redeploy-devnet redeploy-testnet release health
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports install-hooks kill
VERSION := 0.111.0
VERSION := 0.90.0
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
LDFLAGS_LINUX := -s -w $(LDFLAGS)
# Build targets
build: deps
@ -75,22 +30,12 @@ build: deps
@mkdir -p bin
go build -ldflags "$(LDFLAGS)" -o bin/identity ./cmd/identity
go build -ldflags "$(LDFLAGS)" -o bin/orama-node ./cmd/node
go build -ldflags "$(LDFLAGS)" -o bin/orama ./cmd/cli/
go build -ldflags "$(LDFLAGS)" -o bin/orama cmd/cli/main.go
go build -ldflags "$(LDFLAGS)" -o bin/rqlite-mcp ./cmd/rqlite-mcp
# Inject gateway build metadata via pkg path variables
go build -ldflags "$(LDFLAGS) -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=$(VERSION)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=$(COMMIT)' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=$(DATE)'" -o bin/gateway ./cmd/gateway
@echo "Build complete! Run ./bin/orama version"
# Cross-compile CLI for Linux (only binary needed locally; VPS builds everything else from source)
build-linux: deps
@echo "Cross-compiling CLI for linux/amd64 (version=$(VERSION))..."
@mkdir -p bin-linux
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS_LINUX)" -trimpath -o bin-linux/orama ./cmd/cli/
@echo "✓ CLI built at bin-linux/orama"
@echo ""
@echo "Next steps:"
@echo " ./scripts/generate-source-archive.sh"
@echo " ./bin/orama install --vps-ip <ip> --nameserver --domain ..."
# Install git hooks
install-hooks:
@echo "Installing git hooks..."
@ -103,69 +48,70 @@ clean:
rm -rf data/
@echo "Clean complete!"
# Deploy to devnet (build + rolling upgrade all nodes)
redeploy-devnet:
@bash scripts/redeploy.sh --devnet
# Run bootstrap node (auto-selects identity and data dir)
run-node:
@echo "Starting node..."
@echo "Config: ~/.orama/node.yaml"
go run ./cmd/orama-node --config node.yaml
# Deploy to devnet without rebuilding
redeploy-devnet-quick:
@bash scripts/redeploy.sh --devnet --no-build
# Run second node - requires join address
run-node2:
@echo "Starting second node..."
@echo "Config: ~/.orama/node2.yaml"
go run ./cmd/orama-node --config node2.yaml
# Deploy to testnet (build + rolling upgrade all nodes)
redeploy-testnet:
@bash scripts/redeploy.sh --testnet
# Run third node - requires join address
run-node3:
@echo "Starting third node..."
@echo "Config: ~/.orama/node3.yaml"
go run ./cmd/orama-node --config node3.yaml
# Deploy to testnet without rebuilding
redeploy-testnet-quick:
@bash scripts/redeploy.sh --testnet --no-build
# Run gateway HTTP server
run-gateway:
@echo "Starting gateway HTTP server..."
@echo "Note: Config must be in ~/.orama/data/gateway.yaml"
go run ./cmd/orama-gateway
# Interactive release workflow (tag + push)
release:
@bash scripts/release.sh
# Development environment target
# Uses orama dev up to start full stack with dependency and port checking
dev: build
@./bin/orama dev up
# Check health of all nodes in an environment
# Usage: make health ENV=devnet
health:
@if [ -z "$(ENV)" ]; then \
echo "Usage: make health ENV=devnet|testnet"; \
exit 1; \
# Graceful shutdown of all dev services
stop:
@if [ -f ./bin/orama ]; then \
./bin/orama dev down || true; \
fi
@while IFS='|' read -r env host pass role key; do \
[ -z "$$env" ] && continue; \
case "$$env" in \#*) continue;; esac; \
env="$$(echo "$$env" | xargs)"; \
[ "$$env" != "$(ENV)" ] && continue; \
role="$$(echo "$$role" | xargs)"; \
bash scripts/check-node-health.sh "$$host" "$$pass" "$$host ($$role)"; \
done < scripts/remote-nodes.conf
@bash scripts/dev-kill-all.sh
# Force kill all processes (immediate termination)
kill:
@bash scripts/dev-kill-all.sh
# Help
help:
@echo "Available targets:"
@echo " build - Build all executables"
@echo " clean - Clean build artifacts"
@echo " test - Run unit tests"
@echo " test - Run tests"
@echo ""
@echo "E2E Testing:"
@echo " make test-e2e-prod - Run all E2E tests incl. production-only (needs ORAMA_GATEWAY_URL)"
@echo " make test-e2e-shared - Run shared E2E tests (cache, storage, pubsub, auth)"
@echo " make test-e2e-cluster - Run cluster E2E tests (libp2p, olric, rqlite, namespace)"
@echo " make test-e2e-integration - Run integration E2E tests (fullstack, persistence, concurrency)"
@echo " make test-e2e-deployments - Run deployment E2E tests"
@echo " make test-e2e-production - Run production-only E2E tests (DNS, HTTPS, cross-node)"
@echo " make test-e2e-quick - Quick smoke tests (static deploys, health checks)"
@echo " make test-e2e - Generic E2E tests (auto-discovers config)"
@echo "Local Development (Recommended):"
@echo " make dev - Start full development stack with one command"
@echo " - Checks dependencies and available ports"
@echo " - Generates configs and starts all services"
@echo " - Validates cluster health"
@echo " make stop - Gracefully stop all development services"
@echo " make kill - Force kill all development services (use if stop fails)"
@echo ""
@echo " Example:"
@echo " ORAMA_GATEWAY_URL=https://orama-devnet.network make test-e2e-prod"
@echo "Development Management (via orama):"
@echo " ./bin/orama dev status - Show status of all dev services"
@echo " ./bin/orama dev logs <component> [--follow]"
@echo ""
@echo "Deployment:"
@echo " make redeploy-devnet - Build + rolling deploy to all devnet nodes"
@echo " make redeploy-devnet-quick - Deploy to devnet without rebuilding"
@echo " make redeploy-testnet - Build + rolling deploy to all testnet nodes"
@echo " make redeploy-testnet-quick- Deploy to testnet without rebuilding"
@echo " make health ENV=devnet - Check health of all nodes in an environment"
@echo " make release - Interactive release workflow (tag + push)"
@echo "Individual Node Targets (advanced):"
@echo " run-node - Start first node directly"
@echo " run-node2 - Start second node directly"
@echo " run-node3 - Start third node directly"
@echo " run-gateway - Start HTTP gateway directly"
@echo ""
@echo "Maintenance:"
@echo " deps - Download dependencies"

354
README.md
View File

@ -9,150 +9,135 @@ A high-performance API Gateway and distributed platform built in Go. Provides a
- **🔐 Authentication** - Wallet signatures, API keys, JWT tokens
- **💾 Storage** - IPFS-based decentralized file storage with encryption
- **⚡ Cache** - Distributed cache with Olric (in-memory key-value)
- **🗄️ Database** - RQLite distributed SQL with Raft consensus + Per-namespace SQLite databases
- **🗄️ Database** - RQLite distributed SQL with Raft consensus
- **📡 Pub/Sub** - Real-time messaging via LibP2P and WebSocket
- **⚙️ Serverless** - WebAssembly function execution with host functions
- **🌐 HTTP Gateway** - Unified REST API with automatic HTTPS (Let's Encrypt)
- **📦 Client SDK** - Type-safe Go SDK for all services
- **🚀 App Deployments** - Deploy React, Next.js, Go, Node.js apps with automatic domains
- **🗄️ SQLite Databases** - Per-namespace isolated databases with IPFS backups
## Application Deployments
Deploy full-stack applications with automatic domain assignment and namespace isolation.
### Deploy a React App
```bash
# Build your app
cd my-react-app
npm run build
# Deploy to Orama Network
orama deploy static ./dist --name my-app
# Your app is now live at: https://my-app.orama.network
```
### Deploy Next.js with SSR
```bash
cd my-nextjs-app
# Ensure next.config.js has: output: 'standalone'
npm run build
orama deploy nextjs . --name my-nextjs --ssr
# Live at: https://my-nextjs.orama.network
```
### Deploy Go Backend
```bash
# Build for Linux (name binary 'app' for auto-detection)
GOOS=linux GOARCH=amd64 go build -o app main.go
# Deploy (must implement /health endpoint)
orama deploy go ./app --name my-api
# API live at: https://my-api.orama.network
```
### Create SQLite Database
```bash
# Create database
orama db create my-database
# Create schema
orama db query my-database "CREATE TABLE users (id INT, name TEXT)"
# Insert data
orama db query my-database "INSERT INTO users VALUES (1, 'Alice')"
# Query data
orama db query my-database "SELECT * FROM users"
# Backup to IPFS
orama db backup my-database
```
### Full-Stack Example
Deploy a complete app with React frontend, Go backend, and SQLite database:
```bash
# 1. Create database
orama db create myapp-db
orama db query myapp-db "CREATE TABLE users (id INT PRIMARY KEY, name TEXT)"
# 2. Deploy Go backend (connects to database)
GOOS=linux GOARCH=amd64 go build -o api main.go
orama deploy go ./api --name myapp-api
# 3. Deploy React frontend (calls backend API)
cd frontend && npm run build
orama deploy static ./dist --name myapp
# Access:
# Frontend: https://myapp.orama.network
# Backend: https://myapp-api.orama.network
```
**📖 Full Guide**: See [Deployment Guide](docs/DEPLOYMENT_GUIDE.md) for complete documentation, examples, and best practices.
## Quick Start
### Building
### Local Development
```bash
# Build all binaries
# Build the project
make build
# Start 5-node development cluster
make dev
```
The cluster automatically performs health checks before declaring success.
### Stop Development Environment
```bash
make stop
```
## Testing Services
After running `make dev`, test service health using these curl requests:
### Node Unified Gateways
Each node is accessible via a single unified gateway port:
```bash
# Node-1 (port 6001)
curl http://localhost:6001/health
# Node-2 (port 6002)
curl http://localhost:6002/health
# Node-3 (port 6003)
curl http://localhost:6003/health
# Node-4 (port 6004)
curl http://localhost:6004/health
# Node-5 (port 6005)
curl http://localhost:6005/health
```
## Network Architecture
### Unified Gateway Ports
```
Node-1: localhost:6001 → /rqlite/http, /rqlite/raft, /cluster, /ipfs/api
Node-2: localhost:6002 → Same routes
Node-3: localhost:6003 → Same routes
Node-4: localhost:6004 → Same routes
Node-5: localhost:6005 → Same routes
```
### Direct Service Ports (for debugging)
```
RQLite HTTP: 5001, 5002, 5003, 5004, 5005 (one per node)
RQLite Raft: 7001, 7002, 7003, 7004, 7005
IPFS API: 4501, 4502, 4503, 4504, 4505
IPFS Swarm: 4101, 4102, 4103, 4104, 4105
Cluster API: 9094, 9104, 9114, 9124, 9134
Internal Gateway: 6000
Olric Cache: 3320
Anon SOCKS: 9050
```
## Development Commands
```bash
# Start full cluster (5 nodes + gateway)
make dev
# Check service status
orama dev status
# View logs
orama dev logs node-1 # Node-1 logs
orama dev logs node-1 --follow # Follow logs in real-time
orama dev logs gateway --follow # Gateway logs
# Stop all services
orama stop
# Build binaries
make build
```
## CLI Commands
### Network Status
```bash
./bin/orama health # Cluster health check
./bin/orama peers # List connected peers
./bin/orama status # Network status
```
### Database Operations
```bash
./bin/orama query "SELECT * FROM users"
./bin/orama query "CREATE TABLE users (id INTEGER PRIMARY KEY)"
./bin/orama transaction --file ops.json
```
### Pub/Sub
```bash
./bin/orama pubsub publish <topic> <message>
./bin/orama pubsub subscribe <topic> 30s
./bin/orama pubsub topics
```
### Authentication
```bash
orama auth login # Authenticate with wallet
orama auth status # Check authentication
orama auth logout # Clear credentials
```
### Application Deployments
```bash
# Deploy applications
orama deploy static <path> --name myapp # React, Vue, static sites
orama deploy nextjs <path> --name myapp --ssr # Next.js with SSR (requires output: 'standalone')
orama deploy go <path> --name myapp # Go binaries (must have /health endpoint)
orama deploy nodejs <path> --name myapp # Node.js apps (must have /health endpoint)
# Manage deployments
orama app list # List all deployments
orama app get <name> # Get deployment details
orama app logs <name> --follow # View logs
orama app delete <name> # Delete deployment
orama app rollback <name> --version 1 # Rollback to version
```
### SQLite Databases
```bash
orama db create <name> # Create database
orama db query <name> "SELECT * FROM t" # Execute SQL query
orama db list # List all databases
orama db backup <name> # Backup to IPFS
orama db backups <name> # List backups
```
### Environment Management
```bash
orama env list # List available environments
orama env current # Show active environment
orama env use <name> # Switch environment
./bin/orama auth login
./bin/orama auth status
./bin/orama auth logout
```
## Serverless Functions (WASM)
@ -174,7 +159,7 @@ Deploy your compiled `.wasm` file to the network via the Gateway.
```bash
# Deploy a function
curl -X POST https://your-node.example.com/v1/functions \
curl -X POST http://localhost:6001/v1/functions \
-H "Authorization: Bearer <your_api_key>" \
-F "name=hello-world" \
-F "namespace=default" \
@ -187,7 +172,7 @@ Trigger your function with a JSON payload. The function receives the payload via
```bash
# Invoke via HTTP
curl -X POST https://your-node.example.com/v1/functions/hello-world/invoke \
curl -X POST http://localhost:6001/v1/functions/hello-world/invoke \
-H "Authorization: Bearer <your_api_key>" \
-H "Content-Type: application/json" \
-d '{"name": "Developer"}'
@ -197,10 +182,10 @@ curl -X POST https://your-node.example.com/v1/functions/hello-world/invoke \
```bash
# List all functions in a namespace
curl https://your-node.example.com/v1/functions?namespace=default
curl http://localhost:6001/v1/functions?namespace=default
# Delete a function
curl -X DELETE https://your-node.example.com/v1/functions/hello-world?namespace=default
curl -X DELETE http://localhost:6001/v1/functions/hello-world?namespace=default
```
## Production Deployment
@ -226,109 +211,43 @@ curl -X DELETE https://your-node.example.com/v1/functions/hello-world?namespace=
- 5001 - RQLite HTTP API
- 6001 - Unified Gateway
- 8080 - IPFS Gateway
- 9050 - Anyone SOCKS5 proxy
- 9050 - Anyone Client SOCKS5 proxy
- 9094 - IPFS Cluster API
- 3320/3322 - Olric Cache
**Anyone Relay Mode (optional, for earning rewards):**
- 9001 - Anyone ORPort (relay traffic, must be open externally)
### Anyone Network Integration
Orama Network integrates with the [Anyone Protocol](https://anyone.io) for anonymous routing. By default, nodes run as **clients** (consuming the network). Optionally, you can run as a **relay operator** to earn rewards.
**Client Mode (Default):**
- Routes traffic through Anyone network for anonymity
- SOCKS5 proxy on localhost:9050
- No rewards, just consumes network
**Relay Mode (Earn Rewards):**
- Provide bandwidth to the Anyone network
- Earn $ANYONE tokens as a relay operator
- Requires 100 $ANYONE tokens in your wallet
- Requires ORPort (9001) open to the internet
```bash
# Install as relay operator (earn rewards)
sudo orama node install --vps-ip <IP> --domain <domain> \
--anyone-relay \
--anyone-nickname "MyRelay" \
--anyone-contact "operator@email.com" \
--anyone-wallet "0x1234...abcd"
# With exit relay (legal implications apply)
sudo orama node install --vps-ip <IP> --domain <domain> \
--anyone-relay \
--anyone-exit \
--anyone-nickname "MyExitRelay" \
--anyone-contact "operator@email.com" \
--anyone-wallet "0x1234...abcd"
# Migrate existing Anyone installation
sudo orama node install --vps-ip <IP> --domain <domain> \
--anyone-relay \
--anyone-migrate \
--anyone-nickname "MyRelay" \
--anyone-contact "operator@email.com" \
--anyone-wallet "0x1234...abcd"
```
**Important:** After installation, register your relay at [dashboard.anyone.io](https://dashboard.anyone.io) to start earning rewards.
### Installation
**macOS (Homebrew):**
```bash
brew install DeBrosOfficial/tap/orama
```
# Install via APT
echo "deb https://debrosficial.github.io/network/apt stable main" | sudo tee /etc/apt/sources.list.d/debros.list
**Linux (Debian/Ubuntu):**
sudo apt update && sudo apt install orama
```bash
# Download and install the latest .deb package
curl -sL https://github.com/DeBrosOfficial/network/releases/latest/download/orama_$(curl -s https://api.github.com/repos/DeBrosOfficial/network/releases/latest | grep tag_name | cut -d '"' -f 4 | tr -d 'v')_linux_amd64.deb -o orama.deb
sudo dpkg -i orama.deb
```
**From Source:**
```bash
go install github.com/DeBrosOfficial/network/cmd/cli@latest
```
**Setup (after installation):**
```bash
sudo orama node install --interactive
sudo orama install --interactive
```
### Service Management
```bash
# Status
sudo orama node status
orama status
# Control services
sudo orama node start
sudo orama node stop
sudo orama node restart
# Diagnose issues
sudo orama node doctor
sudo orama start
sudo orama stop
sudo orama restart
# View logs
orama node logs node --follow
orama node logs gateway --follow
orama node logs ipfs --follow
orama logs node --follow
orama logs gateway --follow
orama logs ipfs --follow
```
### Upgrade
```bash
# Upgrade to latest version
sudo orama node upgrade --restart
sudo orama upgrade --interactive
```
## Configuration
@ -347,13 +266,13 @@ All configuration lives in `~/.orama/`:
```bash
# Check status
systemctl status orama-node
systemctl status debros-node
# View logs
journalctl -u orama-node -f
journalctl -u debros-node -f
# Check log files
tail -f /opt/orama/.orama/logs/node.log
tail -f /home/debros/.orama/logs/node.log
```
### Port Conflicts
@ -384,9 +303,9 @@ rqlite -H localhost -p 5001
```bash
# Production reset (⚠️ DESTROYS DATA)
sudo orama node uninstall
sudo rm -rf /opt/orama/.orama
sudo orama node install
sudo orama uninstall
sudo rm -rf /home/debros/.orama
sudo orama install
```
## HTTP Gateway API
@ -412,12 +331,10 @@ See `openapi/gateway.yaml` for complete API specification.
## Documentation
- **[Deployment Guide](docs/DEPLOYMENT_GUIDE.md)** - Deploy React, Next.js, Go apps and manage databases
- **[Architecture Guide](docs/ARCHITECTURE.md)** - System architecture and design patterns
- **[Client SDK](docs/CLIENT_SDK.md)** - Go SDK documentation and examples
- **[Gateway API](docs/GATEWAY_API.md)** - Complete HTTP API reference
- **[Security Deployment](docs/SECURITY_DEPLOYMENT_GUIDE.md)** - Production security hardening
- **[Testing Plan](docs/TESTING_PLAN.md)** - Comprehensive testing strategy and implementation
## Resources
@ -436,6 +353,7 @@ network/
│ ├── cli/ # CLI tool
│ ├── gateway/ # HTTP Gateway
│ ├── node/ # P2P Node
│ └── rqlite-mcp/ # RQLite MCP server
├── pkg/ # Core packages
│ ├── gateway/ # Gateway implementation
│ │ └── handlers/ # HTTP handlers by domain

View File

@ -1,5 +1,151 @@
package main
import (
"fmt"
"os"
"time"
"github.com/DeBrosOfficial/network/pkg/cli"
)
var (
timeout = 30 * time.Second
format = "table"
)
// version metadata populated via -ldflags at build time
var (
version = "dev"
commit = ""
date = ""
)
func main() {
runCLI()
if len(os.Args) < 2 {
showHelp()
return
}
command := os.Args[1]
args := os.Args[2:]
// Parse global flags
parseGlobalFlags(args)
switch command {
case "version":
fmt.Printf("orama %s", version)
if commit != "" {
fmt.Printf(" (commit %s)", commit)
}
if date != "" {
fmt.Printf(" built %s", date)
}
fmt.Println()
return
// Development environment commands
case "dev":
cli.HandleDevCommand(args)
// Production environment commands (legacy with 'prod' prefix)
case "prod":
cli.HandleProdCommand(args)
// Direct production commands (new simplified interface)
case "install":
cli.HandleProdCommand(append([]string{"install"}, args...))
case "upgrade":
cli.HandleProdCommand(append([]string{"upgrade"}, args...))
case "migrate":
cli.HandleProdCommand(append([]string{"migrate"}, args...))
case "status":
cli.HandleProdCommand(append([]string{"status"}, args...))
case "start":
cli.HandleProdCommand(append([]string{"start"}, args...))
case "stop":
cli.HandleProdCommand(append([]string{"stop"}, args...))
case "restart":
cli.HandleProdCommand(append([]string{"restart"}, args...))
case "logs":
cli.HandleProdCommand(append([]string{"logs"}, args...))
case "uninstall":
cli.HandleProdCommand(append([]string{"uninstall"}, args...))
// Authentication commands
case "auth":
cli.HandleAuthCommand(args)
// Help
case "help", "--help", "-h":
showHelp()
default:
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", command)
showHelp()
os.Exit(1)
}
}
func parseGlobalFlags(args []string) {
for i, arg := range args {
switch arg {
case "-f", "--format":
if i+1 < len(args) {
format = args[i+1]
}
case "-t", "--timeout":
if i+1 < len(args) {
if d, err := time.ParseDuration(args[i+1]); err == nil {
timeout = d
}
}
}
}
}
func showHelp() {
fmt.Printf("Orama CLI - Distributed P2P Network Management Tool\n\n")
fmt.Printf("Usage: orama <command> [args...]\n\n")
fmt.Printf("💻 Local Development:\n")
fmt.Printf(" dev up - Start full local dev environment\n")
fmt.Printf(" dev down - Stop all dev services\n")
fmt.Printf(" dev status - Show status of dev services\n")
fmt.Printf(" dev logs <component> - View dev component logs\n")
fmt.Printf(" dev help - Show dev command help\n\n")
fmt.Printf("🚀 Production Deployment:\n")
fmt.Printf(" install - Install production node (requires root/sudo)\n")
fmt.Printf(" upgrade - Upgrade existing installation\n")
fmt.Printf(" status - Show production service status\n")
fmt.Printf(" start - Start all production services (requires root/sudo)\n")
fmt.Printf(" stop - Stop all production services (requires root/sudo)\n")
fmt.Printf(" restart - Restart all production services (requires root/sudo)\n")
fmt.Printf(" logs <service> - View production service logs\n")
fmt.Printf(" uninstall - Remove production services (requires root/sudo)\n\n")
fmt.Printf("🔐 Authentication:\n")
fmt.Printf(" auth login - Authenticate with wallet\n")
fmt.Printf(" auth logout - Clear stored credentials\n")
fmt.Printf(" auth whoami - Show current authentication\n")
fmt.Printf(" auth status - Show detailed auth info\n")
fmt.Printf(" auth help - Show auth command help\n\n")
fmt.Printf("Global Flags:\n")
fmt.Printf(" -f, --format <format> - Output format: table, json (default: table)\n")
fmt.Printf(" -t, --timeout <duration> - Operation timeout (default: 30s)\n")
fmt.Printf(" --help, -h - Show this help message\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" # First node (creates new cluster)\n")
fmt.Printf(" sudo orama install --vps-ip 203.0.113.1 --domain node-1.orama.network\n\n")
fmt.Printf(" # Join existing cluster\n")
fmt.Printf(" sudo orama install --vps-ip 203.0.113.2 --domain node-2.orama.network \\\n")
fmt.Printf(" --peers /ip4/203.0.113.1/tcp/4001/p2p/12D3KooW... --cluster-secret <hex>\n\n")
fmt.Printf(" # Service management\n")
fmt.Printf(" orama status\n")
fmt.Printf(" orama logs node --follow\n")
}

View File

@ -1,95 +0,0 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
// Command groups
"github.com/DeBrosOfficial/network/pkg/cli/cmd/app"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/authcmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/dbcmd"
deploycmd "github.com/DeBrosOfficial/network/pkg/cli/cmd/deploy"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/envcmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/functioncmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/inspectcmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/monitorcmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/namespacecmd"
"github.com/DeBrosOfficial/network/pkg/cli/cmd/node"
)
// version metadata populated via -ldflags at build time
// Must match Makefile: -X 'main.version=...' -X 'main.commit=...' -X 'main.date=...'
var (
version = "dev"
commit = ""
date = ""
)
func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "orama",
Short: "Orama CLI - Distributed P2P Network Management Tool",
Long: `Orama CLI is a tool for managing nodes, deploying applications,
and interacting with the Orama distributed network.`,
SilenceUsage: true,
SilenceErrors: true,
}
// Version command
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Show version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("orama %s", version)
if commit != "" {
fmt.Printf(" (commit %s)", commit)
}
if date != "" {
fmt.Printf(" built %s", date)
}
fmt.Println()
},
})
// Node operator commands (was "prod")
rootCmd.AddCommand(node.Cmd)
// Deploy command (top-level, upsert)
rootCmd.AddCommand(deploycmd.Cmd)
// App management (was "deployments")
rootCmd.AddCommand(app.Cmd)
// Database commands
rootCmd.AddCommand(dbcmd.Cmd)
// Namespace commands
rootCmd.AddCommand(namespacecmd.Cmd)
// Environment commands
rootCmd.AddCommand(envcmd.Cmd)
// Auth commands
rootCmd.AddCommand(authcmd.Cmd)
// Inspect command
rootCmd.AddCommand(inspectcmd.Cmd)
// Monitor command
rootCmd.AddCommand(monitorcmd.Cmd)
// Serverless function commands
rootCmd.AddCommand(functioncmd.Cmd)
return rootCmd
}
func runCLI() {
rootCmd := newRootCmd()
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

View File

@ -14,6 +14,10 @@ import (
"go.uber.org/zap"
)
// For transition, alias main.GatewayConfig to pkg/gateway.Config
// server.go will be removed; this keeps compatibility until then.
type GatewayConfig = gateway.Config
func getEnvDefault(key, def string) string {
if v := os.Getenv(key); strings.TrimSpace(v) != "" {
return v
@ -73,7 +77,6 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config {
ListenAddr string `yaml:"listen_addr"`
ClientNamespace string `yaml:"client_namespace"`
RQLiteDSN string `yaml:"rqlite_dsn"`
GlobalRQLiteDSN string `yaml:"global_rqlite_dsn"`
Peers []string `yaml:"bootstrap_peers"`
EnableHTTPS bool `yaml:"enable_https"`
DomainName string `yaml:"domain_name"`
@ -92,7 +95,7 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config {
zap.String("path", configPath),
zap.Error(err))
fmt.Fprintf(os.Stderr, "\nConfig file not found at %s\n", configPath)
fmt.Fprintf(os.Stderr, "Generate it using: orama config init --type gateway\n")
fmt.Fprintf(os.Stderr, "Generate it using: dbn config init --type gateway\n")
os.Exit(1)
}
@ -110,7 +113,6 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config {
ClientNamespace: "default",
BootstrapPeers: nil,
RQLiteDSN: "",
GlobalRQLiteDSN: "",
EnableHTTPS: false,
DomainName: "",
TLSCacheDir: "",
@ -131,9 +133,6 @@ func parseGatewayConfig(logger *logging.ColoredLogger) *gateway.Config {
if v := strings.TrimSpace(y.RQLiteDSN); v != "" {
cfg.RQLiteDSN = v
}
if v := strings.TrimSpace(y.GlobalRQLiteDSN); v != "" {
cfg.GlobalRQLiteDSN = v
}
if len(y.Peers) > 0 {
var peers []string
for _, p := range y.Peers {

View File

@ -66,25 +66,15 @@ func main() {
// Create HTTP server for ACME challenge (port 80)
httpServer := &http.Server{
Addr: ":80",
Handler: manager.HTTPHandler(nil), // Redirects all HTTP traffic to HTTPS except ACME challenge
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 60 * time.Second,
WriteTimeout: 120 * time.Second,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20, // 1MB
Addr: ":80",
Handler: manager.HTTPHandler(nil), // Redirects all HTTP traffic to HTTPS except ACME challenge
}
// Create HTTPS server (port 443)
httpsServer := &http.Server{
Addr: ":443",
Handler: gw.Routes(),
TLSConfig: manager.TLSConfig(),
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 60 * time.Second,
WriteTimeout: 120 * time.Second,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20, // 1MB
Addr: ":443",
Handler: gw.Routes(),
TLSConfig: manager.TLSConfig(),
}
// Start HTTP server for ACME challenge
@ -171,13 +161,8 @@ func main() {
// Standard HTTP server (no HTTPS)
server := &http.Server{
Addr: cfg.ListenAddr,
Handler: gw.Routes(),
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 60 * time.Second,
WriteTimeout: 120 * time.Second,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20, // 1MB
Addr: cfg.ListenAddr,
Handler: gw.Routes(),
}
// Try to bind listener explicitly so binding failures are visible immediately.

View File

@ -1,11 +0,0 @@
package main
import (
"os"
"github.com/DeBrosOfficial/network/pkg/cli"
)
func main() {
cli.HandleInspectCommand(os.Args[1:])
}

320
cmd/rqlite-mcp/main.go Normal file
View File

@ -0,0 +1,320 @@
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"strings"
"time"
"github.com/rqlite/gorqlite"
)
// MCP JSON-RPC types
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id"`
Result any `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
type ResponseError struct {
Code int `json:"code"`
Message string `json:"message"`
}
// Tool definition
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema any `json:"inputSchema"`
}
// Tool call types
type CallToolRequest struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
type TextContent struct {
Type string `json:"type"`
Text string `json:"text"`
}
type CallToolResult struct {
Content []TextContent `json:"content"`
IsError bool `json:"isError,omitempty"`
}
type MCPServer struct {
conn *gorqlite.Connection
}
func NewMCPServer(rqliteURL string) (*MCPServer, error) {
conn, err := gorqlite.Open(rqliteURL)
if err != nil {
return nil, err
}
return &MCPServer{
conn: conn,
}, nil
}
func (s *MCPServer) handleRequest(req JSONRPCRequest) JSONRPCResponse {
var resp JSONRPCResponse
resp.JSONRPC = "2.0"
resp.ID = req.ID
// Debug logging disabled to prevent excessive disk writes
// log.Printf("Received method: %s", req.Method)
switch req.Method {
case "initialize":
resp.Result = map[string]any{
"protocolVersion": "2024-11-05",
"capabilities": map[string]any{
"tools": map[string]any{},
},
"serverInfo": map[string]any{
"name": "rqlite-mcp",
"version": "0.1.0",
},
}
case "notifications/initialized":
// This is a notification, no response needed
return JSONRPCResponse{}
case "tools/list":
// Debug logging disabled to prevent excessive disk writes
tools := []Tool{
{
Name: "list_tables",
Description: "List all tables in the Rqlite database",
InputSchema: map[string]any{
"type": "object",
"properties": map[string]any{},
},
},
{
Name: "query",
Description: "Run a SELECT query on the Rqlite database",
InputSchema: map[string]any{
"type": "object",
"properties": map[string]any{
"sql": map[string]any{
"type": "string",
"description": "The SQL SELECT query to run",
},
},
"required": []string{"sql"},
},
},
{
Name: "execute",
Description: "Run an INSERT, UPDATE, or DELETE statement on the Rqlite database",
InputSchema: map[string]any{
"type": "object",
"properties": map[string]any{
"sql": map[string]any{
"type": "string",
"description": "The SQL statement (INSERT, UPDATE, DELETE) to run",
},
},
"required": []string{"sql"},
},
},
}
resp.Result = map[string]any{"tools": tools}
case "tools/call":
var callReq CallToolRequest
if err := json.Unmarshal(req.Params, &callReq); err != nil {
resp.Error = &ResponseError{Code: -32700, Message: "Parse error"}
return resp
}
resp.Result = s.handleToolCall(callReq)
default:
// Debug logging disabled to prevent excessive disk writes
resp.Error = &ResponseError{Code: -32601, Message: "Method not found"}
}
return resp
}
func (s *MCPServer) handleToolCall(req CallToolRequest) CallToolResult {
// Debug logging disabled to prevent excessive disk writes
// log.Printf("Tool call: %s", req.Name)
switch req.Name {
case "list_tables":
rows, err := s.conn.QueryOne("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
if err != nil {
return errorResult(fmt.Sprintf("Error listing tables: %v", err))
}
var tables []string
for rows.Next() {
slice, err := rows.Slice()
if err == nil && len(slice) > 0 {
tables = append(tables, fmt.Sprint(slice[0]))
}
}
if len(tables) == 0 {
return textResult("No tables found")
}
return textResult(strings.Join(tables, "\n"))
case "query":
var args struct {
SQL string `json:"sql"`
}
if err := json.Unmarshal(req.Arguments, &args); err != nil {
return errorResult(fmt.Sprintf("Invalid arguments: %v", err))
}
// Debug logging disabled to prevent excessive disk writes
rows, err := s.conn.QueryOne(args.SQL)
if err != nil {
return errorResult(fmt.Sprintf("Query error: %v", err))
}
var result strings.Builder
cols := rows.Columns()
result.WriteString(strings.Join(cols, " | ") + "\n")
result.WriteString(strings.Repeat("-", len(cols)*10) + "\n")
rowCount := 0
for rows.Next() {
vals, err := rows.Slice()
if err != nil {
continue
}
rowCount++
for i, v := range vals {
if i > 0 {
result.WriteString(" | ")
}
result.WriteString(fmt.Sprint(v))
}
result.WriteString("\n")
}
result.WriteString(fmt.Sprintf("\n(%d rows)", rowCount))
return textResult(result.String())
case "execute":
var args struct {
SQL string `json:"sql"`
}
if err := json.Unmarshal(req.Arguments, &args); err != nil {
return errorResult(fmt.Sprintf("Invalid arguments: %v", err))
}
// Debug logging disabled to prevent excessive disk writes
res, err := s.conn.WriteOne(args.SQL)
if err != nil {
return errorResult(fmt.Sprintf("Execution error: %v", err))
}
return textResult(fmt.Sprintf("Rows affected: %d", res.RowsAffected))
default:
return errorResult(fmt.Sprintf("Unknown tool: %s", req.Name))
}
}
func textResult(text string) CallToolResult {
return CallToolResult{
Content: []TextContent{
{
Type: "text",
Text: text,
},
},
}
}
func errorResult(text string) CallToolResult {
return CallToolResult{
Content: []TextContent{
{
Type: "text",
Text: text,
},
},
IsError: true,
}
}
func main() {
// Log to stderr so stdout is clean for JSON-RPC
log.SetOutput(os.Stderr)
rqliteURL := "http://localhost:5001"
if u := os.Getenv("RQLITE_URL"); u != "" {
rqliteURL = u
}
var server *MCPServer
var err error
// Retry connecting to rqlite
maxRetries := 30
for i := 0; i < maxRetries; i++ {
server, err = NewMCPServer(rqliteURL)
if err == nil {
break
}
if i%5 == 0 {
log.Printf("Waiting for Rqlite at %s... (%d/%d)", rqliteURL, i+1, maxRetries)
}
time.Sleep(1 * time.Second)
}
if err != nil {
log.Fatalf("Failed to connect to Rqlite after %d retries: %v", maxRetries, err)
}
log.Printf("MCP Rqlite server started (stdio transport)")
log.Printf("Connected to Rqlite at %s", rqliteURL)
// Read JSON-RPC requests from stdin, write responses to stdout
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
var req JSONRPCRequest
if err := json.Unmarshal([]byte(line), &req); err != nil {
// Debug logging disabled to prevent excessive disk writes
continue
}
resp := server.handleRequest(req)
// Don't send response for notifications (no ID)
if req.ID == nil && strings.HasPrefix(req.Method, "notifications/") {
continue
}
respData, err := json.Marshal(resp)
if err != nil {
// Debug logging disabled to prevent excessive disk writes
continue
}
fmt.Println(string(respData))
}
if err := scanner.Err(); err != nil {
// Debug logging disabled to prevent excessive disk writes
}
}

2
debian/control vendored
View File

@ -4,7 +4,7 @@ Section: net
Priority: optional
Architecture: amd64
Depends: libc6
Maintainer: DeBros Team <dev@orama.io>
Maintainer: DeBros Team <dev@debros.io>
Description: Orama Network - Distributed P2P Database System
Orama is a distributed peer-to-peer network that combines
RQLite for distributed SQL, IPFS for content-addressed storage,

View File

@ -52,13 +52,6 @@ The system follows a clean, layered architecture with clear separation of concer
│ │ │ │
│ Port 9094 │ │ In-Process │
└─────────────────┘ └──────────────┘
┌─────────────────┐
│ Anyone │
│ (Anonymity) │
│ │
│ Port 9050 │
└─────────────────┘
```
## Core Components
@ -233,38 +226,7 @@ pkg/config/
└── gateway.go
```
### 6. Anyone Integration (`pkg/anyoneproxy/`)
Integration with the Anyone Protocol for anonymous routing.
**Modes:**
| Mode | Purpose | Port | Rewards |
|------|---------|------|---------|
| Client | Route traffic anonymously | 9050 (SOCKS5) | No |
| Relay | Provide bandwidth to network | 9001 (ORPort) + 9050 | Yes ($ANYONE) |
**Key Files:**
- `pkg/anyoneproxy/socks.go` - SOCKS5 proxy client interface
- `pkg/gateway/anon_proxy_handler.go` - Anonymous proxy API endpoint
- `pkg/environments/production/installers/anyone_relay.go` - Relay installation
**Features:**
- Smart routing (bypasses proxy for local/private addresses)
- Automatic detection of existing Anyone installations
- Migration support for existing relay operators
- Exit relay mode with legal warnings
**API Endpoint:**
- `POST /v1/proxy/anon` - Route HTTP requests through Anyone network
**Relay Requirements:**
- Linux OS (Debian/Ubuntu)
- 100 $ANYONE tokens in wallet
- ORPort accessible from internet
- Registration at dashboard.anyone.io
### 7. Shared Utilities
### 6. Shared Utilities
**HTTP Utilities (`pkg/httputil/`):**
- Request parsing and validation
@ -353,22 +315,12 @@ Function Invocation:
- Refresh token support
- Claims-based authorization
### Network Security (WireGuard Mesh)
All inter-node communication is encrypted via a WireGuard VPN mesh:
- **WireGuard IPs:** Each node gets a private IP (10.0.0.x) used for all cluster traffic
- **UFW Firewall:** Only public ports are exposed: 22 (SSH), 53 (DNS, nameservers only), 80/443 (HTTP/HTTPS), 51820 (WireGuard UDP)
- **Internal services** (RQLite 5001/7001, IPFS 4001/4501, Olric 3320/3322, Gateway 6001) are only accessible via WireGuard or localhost
- **Invite tokens:** Single-use, time-limited tokens for secure node joining. No shared secrets on the CLI
- **Join flow:** New nodes authenticate via HTTPS (443), establish WireGuard tunnel, then join all services over the encrypted mesh
### TLS/HTTPS
- Automatic ACME (Let's Encrypt) certificate management via Caddy
- Automatic ACME (Let's Encrypt) certificate management
- TLS 1.3 support
- HTTP/2 enabled
- On-demand TLS for deployment custom domains
- Certificate caching
### Middleware Stack
@ -439,10 +391,11 @@ All inter-node communication is encrypted via a WireGuard VPN mesh:
## Deployment
### Building & Testing
### Development
```bash
make build # Build all binaries
make dev # Start 5-node cluster
make stop # Stop all services
make test # Run unit tests
make test-e2e # Run E2E tests
```
@ -450,26 +403,17 @@ make test-e2e # Run E2E tests
### Production
```bash
# First node (genesis — creates cluster)
# Nameserver nodes use the base domain as --domain
sudo orama install --vps-ip <IP> --domain example.com --base-domain example.com --nameserver
# First node (creates cluster)
sudo orama install --vps-ip <IP> --domain node1.example.com
# On the genesis node, generate an invite for a new node
orama invite
# Outputs: sudo orama install --join https://example.com --token <TOKEN> --vps-ip <NEW_IP>
# Additional nameserver nodes (join via invite token over HTTPS)
sudo orama install --join https://example.com --token <TOKEN> \
--vps-ip <IP> --domain example.com --base-domain example.com --nameserver
# Additional nodes (join cluster)
sudo orama install --vps-ip <IP> --domain node2.example.com \
--peers /dns4/node1.example.com/tcp/4001/p2p/<PEER_ID> \
--join <node1-ip>:7002 \
--cluster-secret <secret> \
--swarm-key <key>
```
**Security:** Nodes join via single-use invite tokens over HTTPS. A WireGuard VPN tunnel
is established before any cluster services start. All inter-node traffic (RQLite, IPFS,
Olric, LibP2P) flows over the encrypted WireGuard mesh — no cluster ports are exposed
publicly. **Never use `http://<ip>:6001`** for joining — port 6001 is internal-only and
blocked by UFW. Use the domain (`https://node1.example.com`) or, if DNS is not yet
configured, use the IP over HTTP port 80 (`http://<ip>`) which goes through Caddy.
### Docker (Future)
Planned containerization with Docker Compose and Kubernetes support.

View File

@ -1,149 +0,0 @@
# Clean Node — Full Reset Guide
How to completely remove all Orama Network state from a VPS so it can be reinstalled fresh.
## Quick Clean (Copy-Paste)
Run this as root or with sudo on the target VPS:
```bash
# 1. Stop and disable all services
sudo systemctl stop orama-node orama-ipfs orama-ipfs-cluster orama-olric orama-anyone-relay orama-anyone-client coredns caddy 2>/dev/null
sudo systemctl disable orama-node orama-ipfs orama-ipfs-cluster orama-olric orama-anyone-relay orama-anyone-client coredns caddy 2>/dev/null
# 1b. Kill leftover processes (binaries may run outside systemd)
sudo pkill -f orama-node 2>/dev/null; sudo pkill -f ipfs-cluster-service 2>/dev/null
sudo pkill -f "ipfs daemon" 2>/dev/null; sudo pkill -f olric-server 2>/dev/null
sudo pkill -f rqlited 2>/dev/null; sudo pkill -f coredns 2>/dev/null
sleep 1
# 2. Remove systemd service files
sudo rm -f /etc/systemd/system/orama-*.service
sudo rm -f /etc/systemd/system/coredns.service
sudo rm -f /etc/systemd/system/caddy.service
sudo systemctl daemon-reload
# 3. Tear down WireGuard
# Must stop the systemd unit first — wg-quick@wg0 is a oneshot with
# RemainAfterExit=yes, so it stays "active (exited)" even after the
# interface is removed. Without "stop", a future "systemctl start" is a no-op.
sudo systemctl stop wg-quick@wg0 2>/dev/null
sudo wg-quick down wg0 2>/dev/null
sudo systemctl disable wg-quick@wg0 2>/dev/null
sudo rm -f /etc/wireguard/wg0.conf
# 4. Reset UFW firewall
sudo ufw --force reset
sudo ufw allow 22/tcp
sudo ufw --force enable
# 5. Remove orama data directory
sudo rm -rf /opt/orama
# 6. Remove legacy orama user (if exists from old installs)
sudo userdel -r orama 2>/dev/null
sudo rm -rf /home/orama
sudo rm -f /etc/sudoers.d/orama-access
sudo rm -f /etc/sudoers.d/orama-deployments
sudo rm -f /etc/sudoers.d/orama-wireguard
# 7. Remove CoreDNS config
sudo rm -rf /etc/coredns
# 8. Remove Caddy config and data
sudo rm -rf /etc/caddy
sudo rm -rf /var/lib/caddy
# 9. Remove deployment systemd services (dynamic)
sudo rm -f /etc/systemd/system/orama-deploy-*.service
sudo systemctl daemon-reload
# 10. Clean temp files
sudo rm -f /tmp/orama /tmp/network-source.tar.gz /tmp/network-source.zip
sudo rm -rf /tmp/network-extract /tmp/coredns-build /tmp/caddy-build
echo "Node cleaned. Ready for fresh install."
```
## What This Removes
| Category | Paths |
|----------|-------|
| **App data** | `/opt/orama/.orama/` (configs, secrets, logs, IPFS, RQLite, Olric) |
| **Source code** | `/opt/orama/src/` |
| **Binaries** | `/opt/orama/bin/orama-node`, `/opt/orama/bin/gateway` |
| **Systemd** | `orama-*.service`, `coredns.service`, `caddy.service`, `orama-deploy-*.service` |
| **WireGuard** | `/etc/wireguard/wg0.conf`, `wg-quick@wg0` systemd unit |
| **Firewall** | All UFW rules (reset to default + SSH only) |
| **Legacy** | `orama` user, `/etc/sudoers.d/orama-*` (old installs only) |
| **CoreDNS** | `/etc/coredns/Corefile` |
| **Caddy** | `/etc/caddy/Caddyfile`, `/var/lib/caddy/` (TLS certs) |
| **Anyone Relay** | `orama-anyone-relay.service`, `orama-anyone-client.service` |
| **Temp files** | `/tmp/orama`, `/tmp/network-source.*`, build dirs |
## What This Does NOT Remove
These are shared system tools that may be used by other software. Remove manually if desired:
| Binary | Path | Remove Command |
|--------|------|----------------|
| RQLite | `/usr/local/bin/rqlited` | `sudo rm /usr/local/bin/rqlited` |
| IPFS | `/usr/local/bin/ipfs` | `sudo rm /usr/local/bin/ipfs` |
| IPFS Cluster | `/usr/local/bin/ipfs-cluster-service` | `sudo rm /usr/local/bin/ipfs-cluster-service` |
| Olric | `/usr/local/bin/olric-server` | `sudo rm /usr/local/bin/olric-server` |
| CoreDNS | `/usr/local/bin/coredns` | `sudo rm /usr/local/bin/coredns` |
| Caddy | `/usr/bin/caddy` | `sudo rm /usr/bin/caddy` |
| xcaddy | `/usr/local/bin/xcaddy` | `sudo rm /usr/local/bin/xcaddy` |
| Go | `/usr/local/go/` | `sudo rm -rf /usr/local/go` |
| Orama CLI | `/usr/local/bin/orama` | `sudo rm /usr/local/bin/orama` |
## Nuclear Clean (Remove Everything Including Binaries)
```bash
# Run quick clean above first, then:
sudo rm -f /usr/local/bin/rqlited
sudo rm -f /usr/local/bin/ipfs
sudo rm -f /usr/local/bin/ipfs-cluster-service
sudo rm -f /usr/local/bin/olric-server
sudo rm -f /usr/local/bin/coredns
sudo rm -f /usr/local/bin/xcaddy
sudo rm -f /usr/bin/caddy
sudo rm -f /usr/local/bin/orama
```
## Multi-Node Clean
To clean all nodes at once from your local machine:
```bash
# Define your nodes
NODES=(
"ubuntu@141.227.165.168:password1"
"ubuntu@141.227.165.154:password2"
"ubuntu@141.227.156.51:password3"
)
for entry in "${NODES[@]}"; do
IFS=: read -r userhost pass <<< "$entry"
echo "Cleaning $userhost..."
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no "$userhost" 'bash -s' << 'CLEAN'
sudo systemctl stop orama-node orama-ipfs orama-ipfs-cluster orama-olric orama-anyone-relay orama-anyone-client coredns caddy 2>/dev/null
sudo systemctl disable orama-node orama-ipfs orama-ipfs-cluster orama-olric orama-anyone-relay orama-anyone-client coredns caddy 2>/dev/null
sudo rm -f /etc/systemd/system/orama-*.service /etc/systemd/system/coredns.service /etc/systemd/system/caddy.service /etc/systemd/system/orama-deploy-*.service
sudo systemctl daemon-reload
sudo systemctl stop wg-quick@wg0 2>/dev/null
sudo wg-quick down wg0 2>/dev/null
sudo systemctl disable wg-quick@wg0 2>/dev/null
sudo rm -f /etc/wireguard/wg0.conf
sudo ufw --force reset && sudo ufw allow 22/tcp && sudo ufw --force enable
sudo rm -rf /opt/orama
sudo userdel -r orama 2>/dev/null
sudo rm -rf /home/orama
sudo rm -f /etc/sudoers.d/orama-access /etc/sudoers.d/orama-deployments /etc/sudoers.d/orama-wireguard
sudo rm -rf /etc/coredns /etc/caddy /var/lib/caddy
sudo rm -f /tmp/orama /tmp/network-source.tar.gz
sudo rm -rf /tmp/network-extract /tmp/coredns-build /tmp/caddy-build
echo "Done"
CLEAN
done
```

View File

@ -1,160 +0,0 @@
# Common Problems & Solutions
Troubleshooting guide for known issues in the Orama Network.
---
## 1. Namespace Gateway: "Olric unavailable"
**Symptom:** `ns-<name>.orama-devnet.network/v1/health` returns `"olric": {"status": "unavailable"}`.
**Cause:** The Olric memberlist gossip between namespace nodes is broken. Olric uses UDP pings for health checks — if those fail, the cluster can't bootstrap and the gateway reports Olric as unavailable.
### Check 1: WireGuard packet loss between nodes
SSH into each node and ping the other namespace nodes over WireGuard:
```bash
ping -c 10 -W 2 10.0.0.X # replace with the WG IP of each peer
```
If you see packet loss over WireGuard but **not** over the public IP (`ping <public-ip>`), the WireGuard peer session is corrupted.
**Fix — Reset the WireGuard peer on both sides:**
```bash
# On Node A — replace <pubkey> and <endpoint> with Node B's values
wg set wg0 peer <NodeB-pubkey> remove
wg set wg0 peer <NodeB-pubkey> endpoint <NodeB-public-ip>:51820 allowed-ips <NodeB-wg-ip>/32 persistent-keepalive 25
# On Node B — same but with Node A's values
wg set wg0 peer <NodeA-pubkey> remove
wg set wg0 peer <NodeA-pubkey> endpoint <NodeA-public-ip>:51820 allowed-ips <NodeA-wg-ip>/32 persistent-keepalive 25
```
Then restart services: `sudo orama prod restart`
You can find peer public keys with `wg show wg0`.
### Check 2: Olric bound to 0.0.0.0 instead of WireGuard IP
Check the Olric config on each node:
```bash
cat /opt/orama/.orama/data/namespaces/<name>/configs/olric-*.yaml
```
If `bindAddr` is `0.0.0.0`, the node will try to bind to IPv6 on dual-stack hosts, breaking memberlist gossip.
**Fix:** Edit the YAML to use the node's WireGuard IP (run `ip addr show wg0` to find it), then restart: `sudo orama prod restart`
This was fixed in code (BindAddr validation in `SpawnOlric`), so new namespaces won't have this issue.
### Check 3: Olric logs show "Failed UDP ping" constantly
```bash
journalctl -u orama-namespace-olric@<name>.service --no-pager -n 30
```
If every UDP ping fails but TCP stream connections succeed, it's the WireGuard packet loss issue (see Check 1).
---
## 2. Namespace Gateway: Missing config fields
**Symptom:** Gateway config YAML is missing `global_rqlite_dsn`, has `olric_timeout: 0s`, or `olric_servers` only lists `localhost`.
**Cause:** Before the spawn handler fix, `spawnGatewayRemote()` didn't send `global_rqlite_dsn` or `olric_timeout` to remote nodes.
**Fix:** Edit the gateway config manually:
```bash
vim /opt/orama/.orama/data/namespaces/<name>/configs/gateway-*.yaml
```
Add/fix:
```yaml
global_rqlite_dsn: "http://10.0.0.X:10001"
olric_timeout: 30s
olric_servers:
- "10.0.0.X:10002"
- "10.0.0.Y:10002"
- "10.0.0.Z:10002"
```
Then: `sudo orama prod restart`
This was fixed in code, so new namespaces get the correct config.
---
## 3. Namespace not restoring after restart (missing cluster-state.json)
**Symptom:** After `orama prod restart`, the namespace services don't come back because `RestoreLocalClustersFromDisk` has no state file.
**Check:**
```bash
ls /opt/orama/.orama/data/namespaces/<name>/cluster-state.json
```
If the file doesn't exist, the node can't restore the namespace.
**Fix:** Create the file manually from another node that has it, or reconstruct it. The format is:
```json
{
"namespace": "<name>",
"rqlite": { "http_port": 10001, "raft_port": 10000, ... },
"olric": { "http_port": 10002, "memberlist_port": 10003, ... },
"gateway": { "http_port": 10004, ... }
}
```
This was fixed in code — `ProvisionCluster` now saves state to all nodes (including remote ones via the `save-cluster-state` spawn action).
---
## 4. Namespace gateway processes not restarting after upgrade
**Symptom:** After `orama upgrade --restart` or `orama prod restart`, namespace gateway/olric/rqlite services don't start.
**Cause:** `orama prod stop` disables systemd template services (`orama-namespace-gateway@<name>.service`). They have `PartOf=orama-node.service`, but that only propagates restart to **enabled** services.
**Fix:** Re-enable the services before restarting:
```bash
systemctl enable orama-namespace-rqlite@<name>.service
systemctl enable orama-namespace-olric@<name>.service
systemctl enable orama-namespace-gateway@<name>.service
sudo orama prod restart
```
This was fixed in code — the upgrade orchestrator now re-enables `@` services before restarting.
---
## 5. SSH commands eating stdin inside heredocs
**Symptom:** When running a script that SSHes into multiple nodes inside a heredoc (`<<'EOS'`), only the first SSH command runs — the rest are silently skipped.
**Cause:** `ssh` reads from stdin, consuming the rest of the heredoc.
**Fix:** Add `-n` flag to all `ssh` calls inside heredocs:
```bash
ssh -n user@host 'command'
```
`scp` is not affected (doesn't read stdin).
---
## General Debugging Tips
- **Always use `sudo orama prod restart`** instead of raw `systemctl` commands
- **Namespace data lives at:** `/opt/orama/.orama/data/namespaces/<name>/`
- **Check service logs:** `journalctl -u orama-namespace-olric@<name>.service --no-pager -n 50`
- **Check WireGuard:** `wg show wg0` — look for recent handshakes and transfer bytes
- **Check gateway health:** `curl http://localhost:<port>/v1/health` from the node itself
- **Node IPs:** Check `scripts/remote-nodes.conf` for credentials, `wg show wg0` for WG IPs

View File

@ -1,990 +0,0 @@
# Orama Network Deployment Guide
Complete guide for deploying applications and managing databases on Orama Network.
## Table of Contents
- [Overview](#overview)
- [Authentication](#authentication)
- [Deploying Static Sites (React, Vue, etc.)](#deploying-static-sites)
- [Deploying Next.js Applications](#deploying-nextjs-applications)
- [Deploying Go Backends](#deploying-go-backends)
- [Deploying Node.js Backends](#deploying-nodejs-backends)
- [Managing SQLite Databases](#managing-sqlite-databases)
- [How Domains Work](#how-domains-work)
- [Full-Stack Application Example](#full-stack-application-example)
- [Managing Deployments](#managing-deployments)
- [Troubleshooting](#troubleshooting)
---
## Overview
Orama Network provides a decentralized platform for deploying web applications and managing databases. Each deployment:
- **Gets a unique domain** automatically (e.g., `myapp.orama.network`)
- **Isolated per namespace** - your data and apps are completely separate from others
- **Served from IPFS** (static) or **runs as a process** (dynamic apps)
- **Fully managed** - automatic health checks, restarts, and logging
### Supported Deployment Types
| Type | Description | Use Case | Domain Example |
|------|-------------|----------|----------------|
| **Static** | HTML/CSS/JS files served from IPFS | React, Vue, Angular, plain HTML | `myapp.orama.network` |
| **Next.js** | Next.js with SSR support | Full-stack Next.js apps | `myapp.orama.network` |
| **Go** | Compiled Go binaries | REST APIs, microservices | `api.orama.network` |
| **Node.js** | Node.js applications | Express APIs, TypeScript backends | `backend.orama.network` |
---
## Authentication
Before deploying, authenticate with your wallet:
```bash
# Authenticate
orama auth login
# Check authentication status
orama auth whoami
```
Your API key is stored securely and used for all deployment operations.
---
## Deploying Static Sites
Deploy static sites built with React, Vue, Angular, or any static site generator.
### React/Vite Example
```bash
# 1. Build your React app
cd my-react-app
npm run build
# 2. Deploy the build directory
orama deploy static ./dist --name my-react-app --domain repoanalyzer.ai
# Output:
# 📦 Creating tarball from ./dist...
# ☁️ Uploading to Orama Network...
#
# ✅ Deployment successful!
#
# Name: my-react-app
# Type: static
# Status: active
# Version: 1
# Content CID: QmXxxx...
#
# URLs:
# • https://my-react-app.orama.network
```
### What Happens Behind the Scenes
1. **Tarball Creation**: CLI automatically creates a `.tar.gz` from your directory
2. **IPFS Upload**: Files are uploaded to IPFS and pinned across the network
3. **DNS Record**: A DNS record is created pointing `my-react-app.orama.network` to the gateway
4. **Instant Serving**: Your app is immediately accessible via the URL
### Features
- ✅ **SPA Routing**: Unknown routes automatically serve `/index.html` (perfect for React Router)
- ✅ **Correct Content-Types**: Automatically detects and serves `.html`, `.css`, `.js`, `.json`, `.png`, etc.
- ✅ **Caching**: `Cache-Control: public, max-age=3600` headers for optimal performance
- ✅ **Zero Downtime Updates**: Use `--update` flag to update without downtime
### Updating a Deployment
```bash
# Make changes to your app
# Rebuild
npm run build
# Update deployment
orama deploy static ./dist --name my-react-app --update
# Version increments automatically (1 → 2)
```
---
## Deploying Next.js Applications
Deploy Next.js apps with full SSR (Server-Side Rendering) support.
### Prerequisites
> ⚠️ **IMPORTANT**: Your `next.config.js` MUST have `output: 'standalone'` for SSR deployments.
```js
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone', // REQUIRED for SSR deployments
}
module.exports = nextConfig
```
This setting makes Next.js create a standalone build in `.next/standalone/` that can run without `node_modules`.
### Next.js with SSR
```bash
# 1. Ensure next.config.js has output: 'standalone'
# 2. Build your Next.js app
cd my-nextjs-app
npm run build
# 3. Create tarball (must include .next and public directories)
tar -czvf nextjs.tar.gz .next public package.json next.config.js
# 4. Deploy with SSR enabled
orama deploy nextjs ./nextjs.tar.gz --name my-nextjs --ssr
# Output:
# 📦 Creating tarball from .
# ☁️ Uploading to Orama Network...
#
# ✅ Deployment successful!
#
# Name: my-nextjs
# Type: nextjs
# Status: active
# Version: 1
# Port: 10100
#
# URLs:
# • https://my-nextjs.orama.network
#
# ⚠️ Note: SSR deployment may take a minute to start. Check status with: orama app get my-nextjs
```
### What Happens Behind the Scenes
1. **Tarball Upload**: Your `.next` build directory, `package.json`, and `public` are uploaded
2. **Home Node Assignment**: A node is chosen to host your app based on capacity
3. **Port Allocation**: A unique port (10100-19999) is assigned
4. **Systemd Service**: A systemd service is created to run `node server.js`
5. **Health Checks**: Gateway monitors your app every 30 seconds
6. **Reverse Proxy**: Gateway proxies requests from your domain to the local port
### Static Next.js Export (No SSR)
If you export Next.js to static HTML:
```bash
# next.config.js
module.exports = {
output: 'export'
}
# Build and deploy as static
npm run build
orama deploy static ./out --name my-nextjs-static
```
---
## Deploying Go Backends
Deploy compiled Go binaries for high-performance APIs.
### Prerequisites
> ⚠️ **IMPORTANT**: Your Go application MUST:
> 1. Be compiled for Linux: `GOOS=linux GOARCH=amd64`
> 2. Listen on the port from `PORT` environment variable
> 3. Implement a `/health` endpoint that returns HTTP 200 when ready
### Go REST API Example
```bash
# 1. Build your Go binary for Linux (if on Mac/Windows)
cd my-go-api
GOOS=linux GOARCH=amd64 go build -o app main.go # Name it 'app' for auto-detection
# 2. Create tarball
tar -czvf api.tar.gz app
# 3. Deploy the binary
orama deploy go ./api.tar.gz --name my-api
# Output:
# 📦 Creating tarball from ./api...
# ☁️ Uploading to Orama Network...
#
# ✅ Deployment successful!
#
# Name: my-api
# Type: go
# Status: active
# Version: 1
# Port: 10101
#
# URLs:
# • https://my-api.orama.network
```
### Example Go API Code
```go
// main.go
package main
import (
"encoding/json"
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]string{"status": "healthy"})
})
http.HandleFunc("/api/users", func(w http.ResponseWriter, r *http.Request) {
users := []map[string]interface{}{
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
}
json.NewEncoder(w).Encode(users)
})
log.Printf("Starting server on port %s", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
```
### Important Notes
- **Environment Variables**: The `PORT` environment variable is automatically set to your allocated port
- **Health Endpoint**: **REQUIRED** - Must implement `/health` that returns HTTP 200 when ready
- **Binary Requirements**: Must be Linux amd64 (`GOOS=linux GOARCH=amd64`)
- **Binary Naming**: Name your binary `app` for automatic detection, or any ELF executable will work
- **Systemd Managed**: Runs as a systemd service with auto-restart on failure
- **Port Range**: Allocated ports are in the range 10100-19999
---
## Deploying Node.js Backends
Deploy Node.js/Express/TypeScript backends.
### Prerequisites
> ⚠️ **IMPORTANT**: Your Node.js application MUST:
> 1. Listen on the port from `PORT` environment variable
> 2. Implement a `/health` endpoint that returns HTTP 200 when ready
> 3. Have a valid `package.json` with either:
> - A `start` script (runs via `npm start`), OR
> - A `main` field pointing to entry file (runs via `node {main}`), OR
> - An `index.js` file (default fallback)
### Express API Example
```bash
# 1. Build your Node.js app (if using TypeScript)
cd my-node-api
npm run build
# 2. Create tarball (include package.json, your code, and optionally node_modules)
tar -czvf api.tar.gz dist package.json package-lock.json
# 3. Deploy
orama deploy nodejs ./api.tar.gz --name my-node-api
# Output:
# 📦 Creating tarball from ./dist...
# ☁️ Uploading to Orama Network...
#
# ✅ Deployment successful!
#
# Name: my-node-api
# Type: nodejs
# Status: active
# Version: 1
# Port: 10102
#
# URLs:
# • https://my-node-api.orama.network
```
### Example Node.js API
```javascript
// server.js
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
app.get('/health', (req, res) => {
res.json({ status: 'healthy' });
});
app.get('/api/data', (req, res) => {
res.json({ message: 'Hello from Orama Network!' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
```
### Important Notes
- **Environment Variables**: The `PORT` environment variable is automatically set to your allocated port
- **Health Endpoint**: **REQUIRED** - Must implement `/health` that returns HTTP 200 when ready
- **Dependencies**: If `node_modules` is not included, `npm install --production` runs automatically
- **Start Command Detection**:
1. If `package.json` has `scripts.start` → runs `npm start`
2. Else if `package.json` has `main` field → runs `node {main}`
3. Else → runs `node index.js`
- **Systemd Managed**: Runs as a systemd service with auto-restart on failure
---
## Managing SQLite Databases
Each namespace gets its own isolated SQLite databases.
### Creating a Database
```bash
# Create a new database
orama db create my-database
# Output:
# ✅ Database created: my-database
# Home Node: node-abc123
# File Path: /opt/orama/.orama/data/sqlite/your-namespace/my-database.db
```
### Executing Queries
```bash
# Create a table
orama db query my-database "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)"
# Insert data
orama db query my-database "INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')"
# Query data
orama db query my-database "SELECT * FROM users"
# Output:
# 📊 Query Result
# Rows: 1
#
# id | name | email
# ----------------+-----------------+-------------------------
# 1 | Alice | alice@example.com
```
### Listing Databases
```bash
orama db list
# Output:
# NAME SIZE HOME NODE CREATED
# my-database 12.3 KB node-abc123 2024-01-22 10:30
# prod-database 1.2 MB node-abc123 2024-01-20 09:15
#
# Total: 2
```
### Backing Up to IPFS
```bash
# Create a backup
orama db backup my-database
# Output:
# ✅ Backup created
# CID: QmYxxx...
# Size: 12.3 KB
# List backups
orama db backups my-database
# Output:
# VERSION CID SIZE DATE
# 1 QmYxxx... 12.3 KB 2024-01-22 10:45
# 2 QmZxxx... 15.1 KB 2024-01-22 14:20
```
### Database Features
- ✅ **WAL Mode**: Write-Ahead Logging for better concurrency
- ✅ **Namespace Isolation**: Complete separation between namespaces
- ✅ **Automatic Backups**: Scheduled backups to IPFS every 6 hours
- ✅ **ACID Transactions**: Full SQLite transactional support
- ✅ **Concurrent Reads**: Multiple readers can query simultaneously
---
## How Domains Work
### Domain Assignment
When you deploy an application, it automatically gets a domain:
```
Format: {deployment-name}.orama.network
Example: my-react-app.orama.network
```
### Node-Specific Domains (Optional)
For direct access to a specific node:
```
Format: {deployment-name}.node-{shortID}.orama.network
Example: my-react-app.node-LL1Qvu.orama.network
```
The `shortID` is derived from the node's peer ID (characters 9-14 of the full peer ID).
For example: `12D3KooWLL1QvumH...``LL1Qvu`
### DNS Resolution Flow
1. **Client**: Browser requests `my-react-app.orama.network`
2. **DNS**: CoreDNS server queries RQLite for DNS record
3. **Record**: Returns IP address of a gateway node (round-robin across all nodes)
4. **Gateway**: Receives request with `Host: my-react-app.orama.network` header
5. **Routing**: Domain routing middleware looks up deployment by domain
6. **Cross-Node Proxy**: If deployment is on a different node, request is forwarded
7. **Response**:
- **Static**: Serves content from IPFS
- **Dynamic**: Reverse proxies to the app's local port
### Cross-Node Routing
DNS uses round-robin, so requests may hit any node in the cluster. If a deployment is hosted on a different node than the one receiving the request, the gateway automatically proxies the request to the correct home node.
```
┌─────────────────────────────────────────────────────────────────┐
│ Request Flow Example │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Client │
│ │ │
│ ▼ │
│ DNS (round-robin) ───► Node-2 (141.227.165.154) │
│ │ │
│ ▼ │
│ Check: Is deployment here? │
│ │ │
│ No ─────┴───► Cross-node proxy │
│ │ │
│ ▼ │
│ Node-1 (141.227.165.168) │
│ (Home node for deployment) │
│ │ │
│ ▼ │
│ localhost:10100 │
│ (Deployment process) │
│ │
└─────────────────────────────────────────────────────────────────┘
```
This is **transparent to users** - your app works regardless of which node handles the initial request.
### Custom Domains (Future Feature)
Support for custom domains (e.g., `www.myapp.com`) with TXT record verification.
---
## Full-Stack Application Example
Deploy a complete full-stack application with React frontend, Go backend, and SQLite database.
### Architecture
```
┌─────────────────────────────────────────────┐
│ React Frontend (Static) │
│ Domain: myapp.orama.network │
│ Deployed to IPFS │
└─────────────────┬───────────────────────────┘
│ API Calls
┌─────────────────────────────────────────────┐
│ Go Backend (Dynamic) │
│ Domain: myapp-api.orama.network │
│ Port: 10100 │
│ Systemd Service │
└─────────────────┬───────────────────────────┘
│ SQL Queries
┌─────────────────────────────────────────────┐
│ SQLite Database │
│ Name: myapp-db │
│ File: ~/.orama/data/sqlite/ns/myapp-db.db│
└─────────────────────────────────────────────┘
```
### Step 1: Create the Database
```bash
# Create database
orama db create myapp-db
# Create schema
orama db query myapp-db "CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)"
# Insert test data
orama db query myapp-db "INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')"
```
### Step 2: Deploy Go Backend
**Backend Code** (`main.go`):
```go
package main
import (
"database/sql"
"encoding/json"
"log"
"net/http"
"os"
_ "github.com/mattn/go-sqlite3"
)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
CreatedAt string `json:"created_at"`
}
var db *sql.DB
func main() {
// DATABASE_NAME env var is automatically set by Orama
dbPath := os.Getenv("DATABASE_PATH")
if dbPath == "" {
dbPath = "/opt/orama/.orama/data/sqlite/" + os.Getenv("NAMESPACE") + "/myapp-db.db"
}
var err error
db, err = sql.Open("sqlite3", dbPath)
if err != nil {
log.Fatal(err)
}
defer db.Close()
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
// CORS middleware
http.HandleFunc("/", corsMiddleware(routes))
log.Printf("Starting server on port %s", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
func routes(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/health":
json.NewEncoder(w).Encode(map[string]string{"status": "healthy"})
case "/api/users":
if r.Method == "GET" {
getUsers(w, r)
} else if r.Method == "POST" {
createUser(w, r)
}
default:
http.NotFound(w, r)
}
}
func getUsers(w http.ResponseWriter, r *http.Request) {
rows, err := db.Query("SELECT id, name, email, created_at FROM users ORDER BY id")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
var users []User
for rows.Next() {
var u User
rows.Scan(&u.ID, &u.Name, &u.Email, &u.CreatedAt)
users = append(users, u)
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(users)
}
func createUser(w http.ResponseWriter, r *http.Request) {
var u User
if err := json.NewDecoder(r.Body).Decode(&u); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
result, err := db.Exec("INSERT INTO users (name, email) VALUES (?, ?)", u.Name, u.Email)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
id, _ := result.LastInsertId()
u.ID = int(id)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(u)
}
func corsMiddleware(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next(w, r)
}
}
```
**Deploy Backend**:
```bash
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o api main.go
# Deploy
orama deploy go ./api --name myapp-api
```
### Step 3: Deploy React Frontend
**Frontend Code** (`src/App.jsx`):
```jsx
import { useEffect, useState } from 'react';
function App() {
const [users, setUsers] = useState([]);
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const API_URL = 'https://myapp-api.orama.network';
useEffect(() => {
fetchUsers();
}, []);
const fetchUsers = async () => {
const response = await fetch(`${API_URL}/api/users`);
const data = await response.json();
setUsers(data);
};
const addUser = async (e) => {
e.preventDefault();
await fetch(`${API_URL}/api/users`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, email }),
});
setName('');
setEmail('');
fetchUsers();
};
return (
<div>
<h1>Orama Network Full-Stack App</h1>
<h2>Add User</h2>
<form onSubmit={addUser}>
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Name"
required
/>
<input
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
type="email"
required
/>
<button type="submit">Add User</button>
</form>
<h2>Users</h2>
<ul>
{users.map((user) => (
<li key={user.id}>
{user.name} - {user.email}
</li>
))}
</ul>
</div>
);
}
export default App;
```
**Deploy Frontend**:
```bash
# Build
npm run build
# Deploy
orama deploy static ./dist --name myapp
```
### Step 4: Access Your App
Open your browser to:
- **Frontend**: `https://myapp.orama.network`
- **Backend API**: `https://myapp-api.orama.network/api/users`
### Full-Stack Summary
**Frontend**: React app served from IPFS
**Backend**: Go API running on allocated port
**Database**: SQLite database with ACID transactions
**Domains**: Automatic DNS for both services
**Isolated**: All resources namespaced and secure
---
## Managing Deployments
### List All Deployments
```bash
orama app list
# Output:
# NAME TYPE STATUS VERSION CREATED
# my-react-app static active 1 2024-01-22 10:30
# myapp-api go active 1 2024-01-22 10:45
# my-nextjs nextjs active 2 2024-01-22 11:00
#
# Total: 3
```
### Get Deployment Details
```bash
orama app get my-react-app
# Output:
# Deployment: my-react-app
#
# ID: dep-abc123
# Type: static
# Status: active
# Version: 1
# Namespace: your-namespace
# Content CID: QmXxxx...
# Memory Limit: 256 MB
# CPU Limit: 50%
# Restart Policy: always
#
# URLs:
# • https://my-react-app.orama.network
#
# Created: 2024-01-22T10:30:00Z
# Updated: 2024-01-22T10:30:00Z
```
### View Logs
```bash
# View last 100 lines
orama app logs my-nextjs
# Follow logs in real-time
orama app logs my-nextjs --follow
```
### Rollback to Previous Version
```bash
# Rollback to version 1
orama app rollback my-nextjs --version 1
# Output:
# ⚠️ Rolling back 'my-nextjs' to version 1. Continue? (y/N): y
#
# ✅ Rollback successful!
#
# Deployment: my-nextjs
# Current Version: 1
# Rolled Back From: 2
# Rolled Back To: 1
# Status: active
```
### Delete Deployment
```bash
orama app delete my-old-app
# Output:
# ⚠️ Are you sure you want to delete deployment 'my-old-app'? (y/N): y
#
# ✅ Deployment 'my-old-app' deleted successfully
```
---
## Troubleshooting
### Deployment Issues
**Problem**: Deployment status is "failed"
```bash
# Check deployment details
orama app get my-app
# View logs for errors
orama app logs my-app
# Common issues:
# - Binary not compiled for Linux (GOOS=linux GOARCH=amd64)
# - Missing dependencies (node_modules not included)
# - Port already in use (shouldn't happen, but check logs)
# - Health check failing (ensure /health endpoint exists)
```
**Problem**: Can't access deployment URL
```bash
# 1. Check deployment status
orama app get my-app
# 2. Verify DNS (may take up to 10 seconds to propagate)
dig my-app.orama.network
# 3. For local development, add to /etc/hosts
echo "127.0.0.1 my-app.orama.network" | sudo tee -a /etc/hosts
# 4. Test with Host header
curl -H "Host: my-app.orama.network" http://localhost:6001/
```
### Database Issues
**Problem**: Database not found
```bash
# List all databases
orama db list
# Ensure database name matches exactly (case-sensitive)
# Databases are namespace-isolated
```
**Problem**: SQL query fails
```bash
# Check table exists
orama db query my-db "SELECT name FROM sqlite_master WHERE type='table'"
# Check syntax
orama db query my-db ".schema users"
```
### Authentication Issues
```bash
# Re-authenticate
orama auth logout
orama auth login
# Check token validity
orama auth status
```
### Need Help?
- **Documentation**: Check `/docs` directory
- **Logs**: Gateway logs at `~/.orama/logs/gateway.log`
- **Issues**: Report bugs at GitHub repository
- **Community**: Join our Discord/Telegram
---
## Best Practices
### Security
1. **Never commit sensitive data**: Use environment variables for secrets
2. **Validate inputs**: Always sanitize user input in your backend
3. **HTTPS only**: All deployments automatically use HTTPS in production
4. **CORS**: Configure CORS appropriately for your API
### Performance
1. **Optimize builds**: Minimize bundle sizes (React, Next.js)
2. **Use caching**: Leverage browser caching for static assets
3. **Database indexes**: Add indexes to frequently queried columns
4. **Health checks**: Implement `/health` endpoint for monitoring
### Deployment Workflow
1. **Test locally first**: Ensure your app works before deploying
2. **Use version control**: Track changes in Git
3. **Incremental updates**: Use `--update` flag instead of delete + redeploy
4. **Backup databases**: Regular backups via `orama db backup`
5. **Monitor logs**: Check logs after deployment for errors
---
## Next Steps
- **Explore the API**: See `/docs/GATEWAY_API.md` for HTTP API details
- **Advanced Features**: Custom domains, load balancing, autoscaling (coming soon)
- **Production Deployment**: Install nodes with `orama node install` for production clusters
- **Client SDK**: Use the Go/JS SDK for programmatic deployments
---
**Orama Network** - Decentralized Application Platform
Deploy anywhere. Access everywhere. Own everything.

View File

@ -1,152 +0,0 @@
# Devnet Installation Commands
This document contains example installation commands for a multi-node devnet cluster.
**Wallet:** `<YOUR_WALLET_ADDRESS>`
**Contact:** `@anon: <YOUR_WALLET_ADDRESS>`
## Node Configuration
| Node | Role | Nameserver | Anyone Relay |
|------|------|------------|--------------|
| ns1 | Genesis | Yes | No |
| ns2 | Nameserver | Yes | Yes (relay-1) |
| ns3 | Nameserver | Yes | Yes (relay-2) |
| node4 | Worker | No | Yes (relay-3) |
| node5 | Worker | No | Yes (relay-4) |
| node6 | Worker | No | No |
**Note:** Store credentials securely (not in version control).
## MyFamily Fingerprints
If running multiple Anyone relays, configure MyFamily with all your relay fingerprints:
```
<FINGERPRINT_1>,<FINGERPRINT_2>,<FINGERPRINT_3>,...
```
## Installation Order
Install nodes **one at a time**, waiting for each to complete before starting the next:
1. ns1 (genesis, no Anyone relay)
2. ns2 (nameserver + relay)
3. ns3 (nameserver + relay)
4. node4 (non-nameserver + relay)
5. node5 (non-nameserver + relay)
6. node6 (non-nameserver, no relay)
## ns1 - Genesis Node (No Anyone Relay)
```bash
# SSH: <user>@<ns1-ip>
sudo orama node install \
--vps-ip <ns1-ip> \
--domain <your-domain.com> \
--base-domain <your-domain.com> \
--nameserver
```
After ns1 is installed, generate invite tokens:
```bash
sudo orama node invite --expiry 24h
```
## ns2 - Nameserver + Relay
```bash
# SSH: <user>@<ns2-ip>
sudo orama node install \
--join http://<ns1-ip> --token <TOKEN> \
--vps-ip <ns2-ip> \
--domain <your-domain.com> \
--base-domain <your-domain.com> \
--nameserver \
--anyone-relay --anyone-migrate \
--anyone-nickname <relay-name> \
--anyone-wallet <wallet-address> \
--anyone-contact "<contact-info>" \
--anyone-family "<fingerprint1>,<fingerprint2>,..."
```
## ns3 - Nameserver + Relay
```bash
# SSH: <user>@<ns3-ip>
sudo orama node install \
--join http://<ns1-ip> --token <TOKEN> \
--vps-ip <ns3-ip> \
--domain <your-domain.com> \
--base-domain <your-domain.com> \
--nameserver \
--anyone-relay --anyone-migrate \
--anyone-nickname <relay-name> \
--anyone-wallet <wallet-address> \
--anyone-contact "<contact-info>" \
--anyone-family "<fingerprint1>,<fingerprint2>,..."
```
## node4 - Non-Nameserver + Relay
Domain is auto-generated (e.g., `node-a3f8k2.<your-domain.com>`). No `--domain` flag needed.
```bash
# SSH: <user>@<node4-ip>
sudo orama node install \
--join http://<ns1-ip> --token <TOKEN> \
--vps-ip <node4-ip> \
--base-domain <your-domain.com> \
--anyone-relay --anyone-migrate \
--anyone-nickname <relay-name> \
--anyone-wallet <wallet-address> \
--anyone-contact "<contact-info>" \
--anyone-family "<fingerprint1>,<fingerprint2>,..."
```
## node5 - Non-Nameserver + Relay
```bash
# SSH: <user>@<node5-ip>
sudo orama node install \
--join http://<ns1-ip> --token <TOKEN> \
--vps-ip <node5-ip> \
--base-domain <your-domain.com> \
--anyone-relay --anyone-migrate \
--anyone-nickname <relay-name> \
--anyone-wallet <wallet-address> \
--anyone-contact "<contact-info>" \
--anyone-family "<fingerprint1>,<fingerprint2>,..."
```
## node6 - Non-Nameserver (No Anyone Relay)
```bash
# SSH: <user>@<node6-ip>
sudo orama node install \
--join http://<ns1-ip> --token <TOKEN> \
--vps-ip <node6-ip> \
--base-domain <your-domain.com>
```
## Verification
After all nodes are installed, verify cluster health:
```bash
# Full cluster report (from local machine)
./bin/orama monitor report --env devnet
# Single node health
./bin/orama monitor report --env devnet --node <ip>
# Or manually from any VPS:
curl -s http://localhost:5001/status | jq -r '.store.raft.state, .store.raft.num_peers'
curl -s http://localhost:6001/health
systemctl status orama-anyone-relay
```

View File

@ -1,412 +0,0 @@
# Development Guide
## Prerequisites
- Go 1.21+
- Node.js 18+ (for anyone-client in dev mode)
- macOS or Linux
## Building
```bash
# Build all binaries
make build
# Outputs:
# bin/orama-node — the node binary
# bin/orama — the CLI
# bin/gateway — standalone gateway (optional)
# bin/identity — identity tool
```
## Running Tests
```bash
make test
```
## Deploying to VPS
Source is always deployed via SCP (no git on VPS). The CLI is the only binary cross-compiled locally; everything else is built from source on the VPS.
### Deploy Workflow
```bash
# 1. Cross-compile the CLI for Linux
make build-linux
# 2. Generate a source archive (includes CLI binary + full source)
./scripts/generate-source-archive.sh
# Creates: /tmp/network-source.tar.gz
# 3. Install on a new VPS (handles SCP, extract, and remote install automatically)
./bin/orama node install --vps-ip <ip> --nameserver --domain <domain> --base-domain <domain>
# Or upgrade an existing VPS
./bin/orama node upgrade --restart
```
The `orama node install` command automatically:
1. Uploads the source archive via SCP
2. Extracts source to `/opt/orama/src` and installs the CLI to `/usr/local/bin/orama`
3. Runs `orama node install` on the VPS which builds all binaries from source (Go, CoreDNS, Caddy, Olric, etc.)
### Upgrading a Multi-Node Cluster (CRITICAL)
**NEVER restart all nodes simultaneously.** RQLite uses Raft consensus and requires a majority (quorum) to function. Restarting all nodes at once can cause cluster splits where nodes elect different leaders or form isolated clusters.
#### Safe Upgrade Procedure (Rolling Restart)
Always upgrade nodes **one at a time**, waiting for each to rejoin before proceeding:
```bash
# 1. Build CLI + generate archive
make build-linux
./scripts/generate-source-archive.sh
# Creates: /tmp/network-source.tar.gz
# 2. Upload to ONE node first (the "hub" node)
sshpass -p '<password>' scp /tmp/network-source.tar.gz ubuntu@<hub-ip>:/tmp/
# 3. Fan out from hub to all other nodes (server-to-server is faster)
ssh ubuntu@<hub-ip>
for ip in <ip2> <ip3> <ip4> <ip5> <ip6>; do
scp /tmp/network-source.tar.gz ubuntu@$ip:/tmp/
done
exit
# 4. Extract on ALL nodes (can be done in parallel, no restart yet)
for ip in <ip1> <ip2> <ip3> <ip4> <ip5> <ip6>; do
ssh ubuntu@$ip 'sudo bash -s' < scripts/extract-deploy.sh
done
# 5. Find the RQLite leader (upgrade this one LAST)
orama monitor report --env <env>
# Check "rqlite_leader" in summary output
# 6. Upgrade FOLLOWER nodes one at a time
ssh ubuntu@<follower-ip> 'sudo orama node stop && sudo orama node upgrade --restart'
# IMPORTANT: Verify FULL health before proceeding to next node:
orama monitor report --env <env> --node <follower-ip>
# Check:
# - All services active, 0 restart loops
# - RQLite: Follower state, applied_index matches cluster
# - All RQLite peers reachable (no partition alerts)
# - WireGuard peers connected with recent handshakes
# Only proceed to next node after ALL checks pass.
#
# NOTE: After restarting a node, other nodes may briefly report it as
# "unreachable" with "broken pipe" errors. This is normal — Raft TCP
# connections need ~1-2 minutes to re-establish. Wait and re-check
# before escalating.
# Repeat for each follower...
# 7. Upgrade the LEADER node last
ssh ubuntu@<leader-ip> 'sudo orama node stop && sudo orama node upgrade --restart'
# Verify the new leader was elected and cluster is fully healthy:
orama monitor report --env <env>
```
#### What NOT to Do
- **DON'T** stop all nodes, replace binaries, then start all nodes
- **DON'T** run `orama node upgrade --restart` on multiple nodes in parallel
- **DON'T** clear RQLite data directories unless doing a full cluster rebuild
- **DON'T** use `systemctl stop orama-node` on multiple nodes simultaneously
#### Recovery from Cluster Split
If nodes get stuck in "Candidate" state or show "leader not found" errors:
1. Identify which node has the most recent data (usually the old leader)
2. Keep that node running as the new leader
3. On each other node, clear RQLite data and restart:
```bash
sudo orama node stop
sudo rm -rf /opt/orama/.orama/data/rqlite
sudo systemctl start orama-node
```
4. The node should automatically rejoin using its configured `rqlite_join_address`
If automatic rejoin fails, the node may have started without the `-join` flag. Check:
```bash
ps aux | grep rqlited
# Should include: -join 10.0.0.1:7001 (or similar)
```
If `-join` is missing, the node bootstrapped standalone. You'll need to either:
- Restart orama-node (it should detect empty data and use join)
- Or do a full cluster rebuild from CLEAN_NODE.md
### Deploying to Multiple Nodes
To deploy to all nodes, repeat steps 3-5 (dev) or 3-4 (production) for each VPS IP.
**Important:** When using `--restart`, do nodes one at a time (see "Upgrading a Multi-Node Cluster" above).
### CLI Flags Reference
#### `orama node install`
| Flag | Description |
|------|-------------|
| `--vps-ip <ip>` | VPS public IP address (required) |
| `--domain <domain>` | Domain for HTTPS certificates. Required for nameserver nodes (use the base domain, e.g., `example.com`). Auto-generated for non-nameserver nodes if omitted (e.g., `node-a3f8k2.example.com`) |
| `--base-domain <domain>` | Base domain for deployment routing (e.g., example.com) |
| `--nameserver` | Configure this node as a nameserver (CoreDNS + Caddy) |
| `--join <url>` | Join existing cluster via HTTPS URL (e.g., `https://node1.example.com`) |
| `--token <token>` | Invite token for joining (from `orama node invite` on existing node) |
| `--force` | Force reconfiguration even if already installed |
| `--skip-firewall` | Skip UFW firewall setup |
| `--skip-checks` | Skip minimum resource checks (RAM/CPU) |
| `--anyone-relay` | Install and configure an Anyone relay on this node |
| `--anyone-migrate` | Migrate existing Anyone relay installation (preserves keys/fingerprint) |
| `--anyone-nickname <name>` | Relay nickname (required for relay mode) |
| `--anyone-wallet <addr>` | Ethereum wallet for relay rewards (required for relay mode) |
| `--anyone-contact <info>` | Contact info for relay (required for relay mode) |
| `--anyone-family <fps>` | Comma-separated fingerprints of related relays (MyFamily) |
| `--anyone-orport <port>` | ORPort for relay (default: 9001) |
| `--anyone-exit` | Configure as an exit relay (default: non-exit) |
| `--anyone-bandwidth <pct>` | Limit relay to N% of VPS bandwidth (default: 30, 0=unlimited). Runs a speedtest during install to measure available bandwidth |
| `--anyone-accounting <GB>` | Monthly data cap for relay in GB (0=unlimited) |
#### `orama node invite`
| Flag | Description |
|------|-------------|
| `--expiry <duration>` | Token expiry duration (default: 1h, e.g. `--expiry 24h`) |
**Important notes about invite tokens:**
- **Tokens are single-use.** Once a node consumes a token during the join handshake, it cannot be reused. Generate a separate token for each node you want to join.
- **Expiry is checked in UTC.** RQLite uses `datetime('now')` which is always UTC. If your local timezone differs, account for the offset when choosing expiry durations.
- **Use longer expiry for multi-node deployments.** When deploying multiple nodes, use `--expiry 24h` to avoid tokens expiring mid-deployment.
#### `orama node upgrade`
| Flag | Description |
|------|-------------|
| `--restart` | Restart all services after upgrade |
| `--anyone-relay` | Enable Anyone relay (same flags as install) |
| `--anyone-bandwidth <pct>` | Limit relay to N% of VPS bandwidth (default: 30, 0=unlimited) |
| `--anyone-accounting <GB>` | Monthly data cap for relay in GB (0=unlimited) |
#### `orama node` (Service Management)
Use these commands to manage services on production nodes:
```bash
# Stop all services (orama-node, coredns, caddy)
sudo orama node stop
# Start all services
sudo orama node start
# Restart all services
sudo orama node restart
# Check service status
sudo orama node status
# Diagnose common issues
sudo orama node doctor
```
**Note:** Always use `orama node stop` instead of manually running `systemctl stop`. The CLI ensures all related services (including CoreDNS and Caddy on nameserver nodes) are handled correctly.
#### `orama node report`
Outputs comprehensive health data as JSON. Used by `orama monitor` over SSH:
```bash
sudo orama node report --json
```
See [MONITORING.md](MONITORING.md) for full details.
#### `orama monitor`
Real-time cluster monitoring from your local machine:
```bash
# Interactive TUI
orama monitor --env testnet
# Cluster overview
orama monitor cluster --env testnet
# Alerts only
orama monitor alerts --env testnet
# Full JSON for LLM analysis
orama monitor report --env testnet
```
See [MONITORING.md](MONITORING.md) for all subcommands and flags.
### Node Join Flow
```bash
# 1. Genesis node (first node, creates cluster)
# Nameserver nodes use the base domain as --domain
sudo orama node install --vps-ip 1.2.3.4 --domain example.com \
--base-domain example.com --nameserver
# 2. On genesis node, generate an invite
orama node invite --expiry 24h
# Output: sudo orama node install --join https://example.com --token <TOKEN> --vps-ip <IP>
# 3a. Join as nameserver (requires --domain set to base domain)
sudo orama node install --join http://1.2.3.4 --token abc123... \
--vps-ip 5.6.7.8 --domain example.com --base-domain example.com --nameserver
# 3b. Join as regular node (domain auto-generated, no --domain needed)
sudo orama node install --join http://1.2.3.4 --token abc123... \
--vps-ip 5.6.7.8 --base-domain example.com
```
The join flow establishes a WireGuard VPN tunnel before starting cluster services.
All inter-node communication (RQLite, IPFS, Olric) uses WireGuard IPs (10.0.0.x).
No cluster ports are ever exposed publicly.
#### DNS Prerequisite
The `--join` URL should use the HTTPS domain of the genesis node (e.g., `https://node1.example.com`).
For this to work, the domain registrar for `example.com` must have NS records pointing to the genesis
node's IP so that `node1.example.com` resolves publicly.
**If DNS is not yet configured**, you can use the genesis node's public IP with HTTP as a fallback:
```bash
sudo orama node install --join http://1.2.3.4 --vps-ip 5.6.7.8 --token abc123... --nameserver
```
This works because Caddy's `:80` block proxies all HTTP traffic to the gateway. However, once DNS
is properly configured, always use the HTTPS domain URL.
**Important:** Never use `http://<ip>:6001` — port 6001 is the internal gateway and is blocked by
UFW from external access. The join request goes through Caddy on port 80 (HTTP) or 443 (HTTPS),
which proxies to the gateway internally.
## Pre-Install Checklist
Before running `orama node install` on a VPS, ensure:
1. **Stop Docker if running.** Docker commonly binds ports 4001 and 8080 which conflict with IPFS. The installer checks for port conflicts and shows which process is using each port, but it's easier to stop Docker first:
```bash
sudo systemctl stop docker docker.socket
sudo systemctl disable docker docker.socket
```
2. **Stop any existing IPFS instance.**
```bash
sudo systemctl stop ipfs
```
3. **Stop any service on port 53** (for nameserver nodes). The installer handles `systemd-resolved` automatically, but other DNS services (like `bind9` or `dnsmasq`) must be stopped manually.
## Recovering from Failed Joins
If a node partially joins the cluster (registers in RQLite's Raft but then fails or gets cleaned), the remaining cluster can lose quorum permanently. This happens because RQLite thinks there are N voters but only N-1 are reachable.
**Symptoms:** RQLite stuck in "Candidate" state, no leader elected, all writes fail.
**Solution:** Do a full clean reinstall of all affected nodes. Use [CLEAN_NODE.md](CLEAN_NODE.md) to reset each node, then reinstall starting from the genesis node.
**Prevention:** Always ensure a joining node can complete the full installation before it joins. The installer validates port availability upfront to catch conflicts early.
## Debugging Production Issues
Always follow the local-first approach:
1. **Reproduce locally** — set up the same conditions on your machine
2. **Find the root cause** — understand why it's happening
3. **Fix in the codebase** — make changes to the source code
4. **Test locally** — run `make test` and verify
5. **Deploy** — only then deploy the fix to production
Never fix issues directly on the server — those fixes are lost on next deployment.
## Trusting the Self-Signed TLS Certificate
When Let's Encrypt is rate-limited, Caddy falls back to its internal CA (self-signed certificates). Browsers will show security warnings unless you install the root CA certificate.
### Downloading the Root CA Certificate
From VPS 1 (or any node), copy the certificate:
```bash
# Copy the cert to an accessible location on the VPS
ssh ubuntu@<VPS_IP> "sudo cp /var/lib/caddy/.local/share/caddy/pki/authorities/local/root.crt /tmp/caddy-root-ca.crt && sudo chmod 644 /tmp/caddy-root-ca.crt"
# Download to your local machine
scp ubuntu@<VPS_IP>:/tmp/caddy-root-ca.crt ~/Downloads/caddy-root-ca.crt
```
### macOS
```bash
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/Downloads/caddy-root-ca.crt
```
This adds the cert system-wide. All browsers (Safari, Chrome, Arc, etc.) will trust it immediately. Firefox uses its own certificate store — go to **Settings > Privacy & Security > Certificates > View Certificates > Import** and import the `.crt` file there.
To remove it later:
```bash
sudo security remove-trusted-cert -d ~/Downloads/caddy-root-ca.crt
```
### iOS (iPhone/iPad)
1. Transfer `caddy-root-ca.crt` to your device (AirDrop, email attachment, or host it on a URL)
2. Open the file — iOS will show "Profile Downloaded"
3. Go to **Settings > General > VPN & Device Management** (or "Profiles" on older iOS)
4. Tap the "Caddy Local Authority" profile and tap **Install**
5. Go to **Settings > General > About > Certificate Trust Settings**
6. Enable **full trust** for "Caddy Local Authority - 2026 ECC Root"
### Android
1. Transfer `caddy-root-ca.crt` to your device
2. Go to **Settings > Security > Encryption & Credentials > Install a certificate > CA certificate**
3. Select the `caddy-root-ca.crt` file
4. Confirm the installation
Note: On Android 7+, user-installed CA certificates are only trusted by apps that explicitly opt in. Chrome will trust it, but some apps may not.
### Windows
```powershell
certutil -addstore -f "ROOT" caddy-root-ca.crt
```
Or double-click the `.crt` file > **Install Certificate** > **Local Machine** > **Place in "Trusted Root Certification Authorities"**.
### Linux
```bash
sudo cp caddy-root-ca.crt /usr/local/share/ca-certificates/caddy-root-ca.crt
sudo update-ca-certificates
```
## Project Structure
See [ARCHITECTURE.md](ARCHITECTURE.md) for the full architecture overview.
Key directories:
```
cmd/
cli/ — CLI entry point (orama command)
node/ — Node entry point (orama-node)
gateway/ — Standalone gateway entry point
pkg/
cli/ — CLI command implementations
gateway/ — HTTP gateway, routes, middleware
deployments/ — Deployment types, service, storage
environments/ — Production (systemd) and development (direct) modes
rqlite/ — Distributed SQLite via RQLite
```

734
docs/GATEWAY_API.md Normal file
View File

@ -0,0 +1,734 @@
# Gateway API Documentation
## Overview
The Orama Network Gateway provides a unified HTTP/HTTPS API for all network services. It handles authentication, routing, and service coordination.
**Base URL:** `https://api.orama.network` (production) or `http://localhost:6001` (development)
## Authentication
All API requests (except `/health` and `/v1/auth/*`) require authentication.
### Authentication Methods
1. **API Key** (Recommended for server-to-server)
2. **JWT Token** (Recommended for user sessions)
3. **Wallet Signature** (For blockchain integration)
### Using API Keys
Include your API key in the `Authorization` header:
```bash
curl -H "Authorization: Bearer your-api-key-here" \
https://api.orama.network/v1/status
```
Or in the `X-API-Key` header:
```bash
curl -H "X-API-Key: your-api-key-here" \
https://api.orama.network/v1/status
```
### Using JWT Tokens
```bash
curl -H "Authorization: Bearer your-jwt-token-here" \
https://api.orama.network/v1/status
```
## Base Endpoints
### Health Check
```http
GET /health
```
**Response:**
```json
{
"status": "ok",
"timestamp": "2024-01-20T10:30:00Z"
}
```
### Status
```http
GET /v1/status
```
**Response:**
```json
{
"version": "0.80.0",
"uptime": "24h30m15s",
"services": {
"rqlite": "healthy",
"ipfs": "healthy",
"olric": "healthy"
}
}
```
### Version
```http
GET /v1/version
```
**Response:**
```json
{
"version": "0.80.0",
"commit": "abc123...",
"built": "2024-01-20T00:00:00Z"
}
```
## Authentication API
### Get Challenge (Wallet Auth)
Generate a nonce for wallet signature.
```http
POST /v1/auth/challenge
Content-Type: application/json
{
"wallet": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"purpose": "login",
"namespace": "default"
}
```
**Response:**
```json
{
"wallet": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"namespace": "default",
"nonce": "a1b2c3d4e5f6...",
"purpose": "login",
"expires_at": "2024-01-20T10:35:00Z"
}
```
### Verify Signature
Verify wallet signature and issue JWT + API key.
```http
POST /v1/auth/verify
Content-Type: application/json
{
"wallet": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"signature": "0x...",
"nonce": "a1b2c3d4e5f6...",
"namespace": "default"
}
```
**Response:**
```json
{
"jwt_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "refresh_abc123...",
"api_key": "api_xyz789...",
"expires_in": 900,
"namespace": "default"
}
```
### Refresh Token
Refresh an expired JWT token.
```http
POST /v1/auth/refresh
Content-Type: application/json
{
"refresh_token": "refresh_abc123..."
}
```
**Response:**
```json
{
"jwt_token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 900
}
```
### Logout
Revoke refresh tokens.
```http
POST /v1/auth/logout
Authorization: Bearer your-jwt-token
{
"all": false
}
```
**Response:**
```json
{
"message": "logged out successfully"
}
```
### Whoami
Get current authentication info.
```http
GET /v1/auth/whoami
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"authenticated": true,
"method": "api_key",
"api_key": "api_xyz789...",
"namespace": "default"
}
```
## Storage API (IPFS)
### Upload File
```http
POST /v1/storage/upload
Authorization: Bearer your-api-key
Content-Type: multipart/form-data
file: <binary data>
```
Or with JSON:
```http
POST /v1/storage/upload
Authorization: Bearer your-api-key
Content-Type: application/json
{
"data": "base64-encoded-data",
"filename": "document.pdf",
"pin": true,
"encrypt": false
}
```
**Response:**
```json
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"size": 1024,
"filename": "document.pdf"
}
```
### Get File
```http
GET /v1/storage/get/:cid
Authorization: Bearer your-api-key
```
**Response:** Binary file data or JSON (if `Accept: application/json`)
### Pin File
```http
POST /v1/storage/pin
Authorization: Bearer your-api-key
Content-Type: application/json
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"replication_factor": 3
}
```
**Response:**
```json
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"status": "pinned"
}
```
### Unpin File
```http
DELETE /v1/storage/unpin/:cid
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"message": "unpinned successfully"
}
```
### Get Pin Status
```http
GET /v1/storage/status/:cid
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"status": "pinned",
"replicas": 3,
"peers": ["12D3KooW...", "12D3KooW..."]
}
```
## Cache API (Olric)
### Set Value
```http
PUT /v1/cache/put
Authorization: Bearer your-api-key
Content-Type: application/json
{
"key": "user:123",
"value": {"name": "Alice", "email": "alice@example.com"},
"ttl": 300
}
```
**Response:**
```json
{
"message": "value set successfully"
}
```
### Get Value
```http
GET /v1/cache/get?key=user:123
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"key": "user:123",
"value": {"name": "Alice", "email": "alice@example.com"}
}
```
### Get Multiple Values
```http
POST /v1/cache/mget
Authorization: Bearer your-api-key
Content-Type: application/json
{
"keys": ["user:1", "user:2", "user:3"]
}
```
**Response:**
```json
{
"results": {
"user:1": {"name": "Alice"},
"user:2": {"name": "Bob"},
"user:3": null
}
}
```
### Delete Value
```http
DELETE /v1/cache/delete?key=user:123
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"message": "deleted successfully"
}
```
### Scan Keys
```http
GET /v1/cache/scan?pattern=user:*&limit=100
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"keys": ["user:1", "user:2", "user:3"],
"count": 3
}
```
## Database API (RQLite)
### Execute SQL
```http
POST /v1/rqlite/exec
Authorization: Bearer your-api-key
Content-Type: application/json
{
"sql": "INSERT INTO users (name, email) VALUES (?, ?)",
"args": ["Alice", "alice@example.com"]
}
```
**Response:**
```json
{
"last_insert_id": 123,
"rows_affected": 1
}
```
### Query SQL
```http
POST /v1/rqlite/query
Authorization: Bearer your-api-key
Content-Type: application/json
{
"sql": "SELECT * FROM users WHERE id = ?",
"args": [123]
}
```
**Response:**
```json
{
"columns": ["id", "name", "email"],
"rows": [
[123, "Alice", "alice@example.com"]
]
}
```
### Get Schema
```http
GET /v1/rqlite/schema
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"tables": [
{
"name": "users",
"schema": "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)"
}
]
}
```
## Pub/Sub API
### Publish Message
```http
POST /v1/pubsub/publish
Authorization: Bearer your-api-key
Content-Type: application/json
{
"topic": "chat",
"data": "SGVsbG8sIFdvcmxkIQ==",
"namespace": "default"
}
```
**Response:**
```json
{
"message": "published successfully"
}
```
### List Topics
```http
GET /v1/pubsub/topics
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"topics": ["chat", "notifications", "events"]
}
```
### Subscribe (WebSocket)
```http
GET /v1/pubsub/ws?topic=chat
Authorization: Bearer your-api-key
Upgrade: websocket
```
**WebSocket Messages:**
Incoming (from server):
```json
{
"type": "message",
"topic": "chat",
"data": "SGVsbG8sIFdvcmxkIQ==",
"timestamp": "2024-01-20T10:30:00Z"
}
```
Outgoing (to server):
```json
{
"type": "publish",
"topic": "chat",
"data": "SGVsbG8sIFdvcmxkIQ=="
}
```
### Presence
```http
GET /v1/pubsub/presence?topic=chat
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"topic": "chat",
"members": [
{"id": "user-123", "joined_at": "2024-01-20T10:00:00Z"},
{"id": "user-456", "joined_at": "2024-01-20T10:15:00Z"}
]
}
```
## Serverless API (WASM)
### Deploy Function
```http
POST /v1/functions
Authorization: Bearer your-api-key
Content-Type: multipart/form-data
name: hello-world
namespace: default
description: Hello world function
wasm: <binary WASM file>
memory_limit: 64
timeout: 30
```
**Response:**
```json
{
"id": "fn_abc123",
"name": "hello-world",
"namespace": "default",
"wasm_cid": "QmXxx...",
"version": 1,
"created_at": "2024-01-20T10:30:00Z"
}
```
### Invoke Function
```http
POST /v1/functions/hello-world/invoke
Authorization: Bearer your-api-key
Content-Type: application/json
{
"name": "Alice"
}
```
**Response:**
```json
{
"result": "Hello, Alice!",
"execution_time_ms": 15,
"memory_used_mb": 2.5
}
```
### List Functions
```http
GET /v1/functions?namespace=default
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"functions": [
{
"name": "hello-world",
"description": "Hello world function",
"version": 1,
"created_at": "2024-01-20T10:30:00Z"
}
]
}
```
### Delete Function
```http
DELETE /v1/functions/hello-world?namespace=default
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"message": "function deleted successfully"
}
```
### Get Function Logs
```http
GET /v1/functions/hello-world/logs?limit=100
Authorization: Bearer your-api-key
```
**Response:**
```json
{
"logs": [
{
"timestamp": "2024-01-20T10:30:00Z",
"level": "info",
"message": "Function invoked",
"invocation_id": "inv_xyz789"
}
]
}
```
## Error Responses
All errors follow a consistent format:
```json
{
"code": "NOT_FOUND",
"message": "user with ID '123' not found",
"details": {
"resource": "user",
"id": "123"
},
"trace_id": "trace-abc123"
}
```
### Common Error Codes
| Code | HTTP Status | Description |
|------|-------------|-------------|
| `VALIDATION_ERROR` | 400 | Invalid input |
| `UNAUTHORIZED` | 401 | Authentication required |
| `FORBIDDEN` | 403 | Permission denied |
| `NOT_FOUND` | 404 | Resource not found |
| `CONFLICT` | 409 | Resource already exists |
| `TIMEOUT` | 408 | Operation timeout |
| `RATE_LIMIT_EXCEEDED` | 429 | Too many requests |
| `SERVICE_UNAVAILABLE` | 503 | Service unavailable |
| `INTERNAL` | 500 | Internal server error |
## Rate Limiting
The API implements rate limiting per API key:
- **Default:** 100 requests per minute
- **Burst:** 200 requests
Rate limit headers:
```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1611144000
```
When rate limited:
```json
{
"code": "RATE_LIMIT_EXCEEDED",
"message": "rate limit exceeded",
"details": {
"limit": 100,
"retry_after": 60
}
}
```
## Pagination
List endpoints support pagination:
```http
GET /v1/functions?limit=10&offset=20
```
Response includes pagination metadata:
```json
{
"data": [...],
"pagination": {
"total": 100,
"limit": 10,
"offset": 20,
"has_more": true
}
}
```
## Webhooks (Future)
Coming soon: webhook support for event notifications.
## Support
- API Issues: https://github.com/DeBrosOfficial/network/issues
- OpenAPI Spec: `openapi/gateway.yaml`
- SDK Documentation: `docs/CLIENT_SDK.md`

View File

@ -1,213 +0,0 @@
# Inspector
The inspector is a cluster health check tool that SSHs into every node, collects subsystem data in parallel, runs deterministic checks, and optionally sends failures to an AI model for root-cause analysis.
## Pipeline
```
Collect (parallel SSH) → Check (deterministic Go) → Report (table/JSON) → Analyze (optional AI)
```
1. **Collect** — SSH into every node in parallel, run diagnostic commands, parse results into structured data.
2. **Check** — Run pure Go check functions against the collected data. Each check produces a pass/fail/warn/skip result with a severity level.
3. **Report** — Print results as a table (default) or JSON. Failures sort first, grouped by subsystem.
4. **Analyze** — If `--ai` is enabled and there are failures or warnings, send them to an LLM via OpenRouter for root-cause analysis.
## Quick Start
```bash
# Inspect all subsystems on devnet
orama inspect --env devnet
# Inspect only RQLite
orama inspect --env devnet --subsystem rqlite
# JSON output
orama inspect --env devnet --format json
# With AI analysis
orama inspect --env devnet --ai
```
## Usage
```
orama inspect [flags]
```
| Flag | Default | Description |
|------|---------|-------------|
| `--config` | `scripts/remote-nodes.conf` | Path to node configuration file |
| `--env` | *(required)* | Environment to inspect (`devnet`, `testnet`) |
| `--subsystem` | `all` | Comma-separated subsystems to inspect |
| `--format` | `table` | Output format: `table` or `json` |
| `--timeout` | `30s` | SSH command timeout per node |
| `--verbose` | `false` | Print collection progress |
| `--ai` | `false` | Enable AI analysis of failures |
| `--model` | `moonshotai/kimi-k2.5` | OpenRouter model for AI analysis |
| `--api-key` | `$OPENROUTER_API_KEY` | OpenRouter API key |
### Subsystem Names
`rqlite`, `olric`, `ipfs`, `dns`, `wireguard` (alias: `wg`), `system`, `network`, `namespace`
Multiple subsystems can be combined: `--subsystem rqlite,olric,dns`
## Subsystems
| Subsystem | What It Checks |
|-----------|---------------|
| **rqlite** | Raft state, leader election, readyz, commit/applied gap, FSM pending, strong reads, debug vars (query errors, leader_not_found, snapshots), cross-node leader agreement, term consistency, applied index convergence, quorum, version match |
| **olric** | Service active, memberlist up, restart count, memory usage, log analysis (suspects, flapping, errors), cross-node memberlist consistency |
| **ipfs** | Daemon active, cluster active, swarm peer count, cluster peer count, cluster errors, repo usage %, swarm key present, bootstrap list empty, cross-node version consistency |
| **dns** | CoreDNS active, Caddy active, ports (53/80/443), memory, restart count, log errors, Corefile exists, SOA/NS/wildcard/base-A resolution, TLS cert expiry, cross-node nameserver availability |
| **wireguard** | Interface up, service active, correct 10.0.0.x IP, listen port 51820, peer count vs expected, MTU 1420, config exists + permissions 600, peer handshakes (fresh/stale/never), peer traffic, catch-all route detection, cross-node peer count + MTU consistency |
| **system** | Core services (orama-node, rqlite, olric, ipfs, ipfs-cluster, wg-quick), nameserver services (coredns, caddy), failed systemd units, memory/disk/inode usage, load average, OOM kills, swap, UFW active, process user (orama), panic count, expected ports |
| **network** | Internet reachability, default route, WireGuard route, TCP connection count, TIME_WAIT count, TCP retransmission rate, WireGuard mesh ping (all peers) |
| **namespace** | Per-namespace: RQLite up + raft state + readyz, Olric memberlist, Gateway HTTP health. Cross-namespace: all-healthy check, RQLite quorum per namespace |
## Severity Levels
| Level | When Used |
|-------|-----------|
| **CRITICAL** | Service completely down. Raft quorum lost, RQLite unresponsive, no leader. |
| **HIGH** | Service degraded. Olric down, gateway not responding, IPFS swarm key missing. |
| **MEDIUM** | Non-ideal but functional. Stale handshakes, elevated memory, log suspects. |
| **LOW** | Informational. Non-standard MTU, port mismatch, version skew. |
## Check Statuses
| Status | Meaning |
|--------|---------|
| **pass** | Check passed. |
| **fail** | Check failed — action needed. |
| **warn** | Degraded — monitor or investigate. |
| **skip** | Check could not run (insufficient data). |
## Output Formats
### Table (default)
```
Inspecting 14 devnet nodes...
## RQLITE
----------------------------------------------------------------------
OK [CRITICAL] RQLite responding (ubuntu@10.0.0.1)
responsive=true version=v8.36.16
FAIL [CRITICAL] Cluster has exactly one leader
leaders=0 (NO LEADER)
...
======================================================================
Summary: 800 passed, 12 failed, 31 warnings, 0 skipped (4.2s)
```
Failures sort first, then warnings, then passes. Within each group, higher severity checks appear first.
### JSON (`--format json`)
```json
{
"summary": {
"passed": 800,
"failed": 12,
"warned": 31,
"skipped": 0,
"total": 843,
"duration_seconds": 4.2
},
"checks": [
{
"id": "rqlite.responsive",
"name": "RQLite responding",
"subsystem": "rqlite",
"severity": 3,
"status": "pass",
"message": "responsive=true version=v8.36.16",
"node": "ubuntu@10.0.0.1"
}
]
}
```
## AI Analysis
When `--ai` is enabled, failures and warnings are sent to an LLM via OpenRouter for root-cause analysis.
```bash
# Use default model (kimi-k2.5)
orama inspect --env devnet --ai
# Use a different model
orama inspect --env devnet --ai --model openai/gpt-4o
# Pass API key directly
orama inspect --env devnet --ai --api-key sk-or-...
```
The API key can be set via:
1. `--api-key` flag
2. `OPENROUTER_API_KEY` environment variable
3. `.env` file in the current directory
The AI receives the full check results plus cluster metadata and returns a structured analysis with likely root causes and suggested fixes.
## Exit Codes
| Code | Meaning |
|------|---------|
| `0` | All checks passed (or only warnings). |
| `1` | At least one check failed. |
## Configuration
The inspector reads node definitions from a pipe-delimited config file (default: `scripts/remote-nodes.conf`).
### Format
```
# environment|user@host|password|role|ssh_key
devnet|ubuntu@1.2.3.4|mypassword|node|
devnet|ubuntu@5.6.7.8|mypassword|nameserver-ns1|/path/to/key
```
| Field | Description |
|-------|-------------|
| `environment` | Cluster name (`devnet`, `testnet`) |
| `user@host` | SSH credentials |
| `password` | SSH password |
| `role` | `node` or `nameserver-ns1`, `nameserver-ns2`, etc. |
| `ssh_key` | Optional path to SSH private key |
Blank lines and lines starting with `#` are ignored.
### Node Roles
- **`node`** — Regular cluster node. Runs RQLite, Olric, IPFS, WireGuard, namespaces.
- **`nameserver-*`** — DNS nameserver. Runs CoreDNS + Caddy in addition to base services. System checks verify nameserver-specific services.
## Examples
```bash
# Full cluster inspection
orama inspect --env devnet
# Check only networking
orama inspect --env devnet --subsystem wireguard,network
# Quick RQLite health check
orama inspect --env devnet --subsystem rqlite
# Verbose mode (shows collection progress)
orama inspect --env devnet --verbose
# JSON for scripting / piping
orama inspect --env devnet --format json | jq '.checks[] | select(.status == "fail")'
# AI-assisted debugging
orama inspect --env devnet --ai --model anthropic/claude-sonnet-4
# Custom config file
orama inspect --config /path/to/nodes.conf --env testnet
```

View File

@ -1,275 +0,0 @@
# Monitoring
Real-time cluster health monitoring via SSH. The system has two parts:
1. **`orama node report`** — Runs on each VPS node, collects all local health data, outputs JSON
2. **`orama monitor`** — Runs on your local machine, SSHes into nodes, aggregates results, displays via TUI or tables
## Architecture
```
Developer Machine VPS Nodes (via SSH)
┌──────────────────┐ ┌────────────────────┐
│ orama monitor │ ──SSH──────────>│ orama node report │
│ (TUI / tables) │ <──JSON─────── │ (local collector) │
│ │ └────────────────────┘
│ CollectOnce() │ ──SSH──────────>│ orama node report │
│ DeriveAlerts() │ <──JSON─────── │ (local collector) │
│ Render() │ └────────────────────┘
└──────────────────┘
```
Each node runs `orama node report --json` locally (no SSH to other nodes), collecting data via `os/exec` and `net/http` to localhost services. The monitor SSHes into all nodes in parallel, collects reports, then runs cross-node analysis to detect cluster-wide issues.
## Quick Start
```bash
# Interactive TUI (auto-refreshes every 30s)
orama monitor --env testnet
# Cluster overview table
orama monitor cluster --env testnet
# Alerts only
orama monitor alerts --env testnet
# Full JSON report (pipe to jq or feed to LLM)
orama monitor report --env testnet
```
## `orama monitor` — Local Orchestrator
### Usage
```
orama monitor [subcommand] --env <environment> [flags]
```
Without a subcommand, launches the interactive TUI.
### Global Flags
| Flag | Default | Description |
|------|---------|-------------|
| `--env` | *(required)* | Environment: `devnet`, `testnet`, `mainnet` |
| `--json` | `false` | Machine-readable JSON output (for one-shot subcommands) |
| `--node` | | Filter to a specific node host/IP |
| `--config` | `scripts/remote-nodes.conf` | Path to node configuration file |
### Subcommands
| Subcommand | Description |
|------------|-------------|
| `live` | Interactive TUI monitor (default when no subcommand) |
| `cluster` | Cluster overview: all nodes, roles, RQLite state, WG peers |
| `node` | Per-node health details (system, services, WG, DNS) |
| `service` | Service status matrix across all nodes |
| `mesh` | WireGuard mesh connectivity and peer details |
| `dns` | DNS health: CoreDNS, Caddy, TLS cert expiry, resolution |
| `namespaces` | Namespace health across nodes |
| `alerts` | Active alerts and warnings sorted by severity |
| `report` | Full JSON dump optimized for LLM consumption |
### Examples
```bash
# Cluster overview
orama monitor cluster --env testnet
# Cluster overview as JSON
orama monitor cluster --env testnet --json
# Alerts for all nodes
orama monitor alerts --env testnet
# Single-node deep dive
orama monitor node --env testnet --node 51.195.109.238
# Services for one node
orama monitor service --env testnet --node 51.195.109.238
# WireGuard mesh details
orama monitor mesh --env testnet
# DNS health
orama monitor dns --env testnet
# Namespace health
orama monitor namespaces --env testnet
# Full report for LLM analysis
orama monitor report --env testnet | jq .
# Single-node report
orama monitor report --env testnet --node 51.195.109.238
# Custom config file
orama monitor cluster --config /path/to/nodes.conf --env devnet
```
### Interactive TUI
The `live` subcommand (default) launches a full-screen terminal UI:
**Tabs:** Overview | Nodes | Services | WG Mesh | DNS | Namespaces | Alerts
**Key Bindings:**
| Key | Action |
|-----|--------|
| `Tab` / `Shift+Tab` | Switch tabs |
| `j` / `k` or `↑` / `↓` | Scroll content |
| `r` | Force refresh |
| `q` / `Ctrl+C` | Quit |
The TUI auto-refreshes every 30 seconds. A spinner shows during data collection. Colors indicate health: green = healthy, red = critical, yellow = warning.
### LLM Report Format
`orama monitor report` outputs structured JSON designed for AI consumption:
```json
{
"meta": {
"environment": "testnet",
"collected_at": "2026-02-16T12:00:00Z",
"duration_seconds": 3.2,
"node_count": 3,
"healthy_count": 3
},
"summary": {
"rqlite_leader": "10.0.0.1",
"rqlite_voters": "3/3",
"rqlite_raft_term": 42,
"wg_mesh_status": "all connected",
"service_health": "all nominal",
"critical_alerts": 0,
"warning_alerts": 1,
"info_alerts": 0
},
"alerts": [...],
"nodes": [
{
"host": "51.195.109.238",
"status": "healthy",
"collection_ms": 526,
"report": { ... }
}
]
}
```
## `orama node report` — VPS-Side Collector
Runs locally on a VPS node. Collects all system and service data in parallel and outputs a single JSON blob. Requires root privileges.
### Usage
```bash
# On a VPS node
sudo orama node report --json
```
### What It Collects
| Section | Data |
|---------|------|
| **system** | CPU count, load average, memory/disk/swap usage, OOM kills, kernel version, uptime, clock time |
| **services** | Systemd service states (active, restarts, memory, CPU, restart loop detection) for 10 core services |
| **rqlite** | Raft state, leader, term, applied/commit index, peers, strong read test, readyz, debug vars |
| **olric** | Service state, memberlist, member count, restarts, memory, log analysis |
| **ipfs** | Daemon/cluster state, swarm/cluster peers, repo size, versions, swarm key |
| **gateway** | HTTP health check, subsystem status |
| **wireguard** | Interface state, WG IP, peers, handshake ages, MTU, config permissions |
| **dns** | CoreDNS/Caddy state, port bindings, resolution tests, TLS cert expiry |
| **anyone** | Relay/client state, bootstrap progress, fingerprint |
| **network** | Internet reachability, TCP stats, retransmission rate, listening ports, UFW rules |
| **processes** | Zombie count, orphan orama processes, panic/fatal count in logs |
| **namespaces** | Per-namespace service probes (RQLite, Olric, Gateway) |
### Performance
All 12 collectors run in parallel with goroutines. Typical collection time is **< 1 second** per node. HTTP timeouts are 3 seconds, command timeouts are 4 seconds.
### Output Schema
```json
{
"timestamp": "2026-02-16T12:00:00Z",
"hostname": "ns1",
"version": "0.107.0",
"collect_ms": 526,
"errors": [],
"system": { "cpu_count": 4, "load_avg_1": 0.1, "mem_total_mb": 7937, ... },
"services": { "services": [...], "failed_units": [] },
"rqlite": { "responsive": true, "raft_state": "Leader", "term": 42, ... },
"olric": { "service_active": true, "memberlist_up": true, ... },
"ipfs": { "daemon_active": true, "swarm_peers": 2, ... },
"gateway": { "responsive": true, "http_status": 200, ... },
"wireguard": { "interface_up": true, "wg_ip": "10.0.0.1", "peers": [...], ... },
"dns": { "coredns_active": true, "caddy_active": true, "base_tls_days_left": 88, ... },
"anyone": { "relay_active": true, "bootstrapped": true, ... },
"network": { "internet_reachable": true, "ufw_active": true, ... },
"processes": { "zombie_count": 0, "orphan_count": 0, "panic_count": 0, ... },
"namespaces": []
}
```
## Alert Detection
Alerts are derived from cross-node analysis of all collected reports. Each alert has a severity level and identifies the affected subsystem and node.
### Alert Severities
| Severity | Examples |
|----------|----------|
| **critical** | SSH collection failed (node unreachable), no RQLite leader, split brain, RQLite unresponsive, WireGuard interface down, WG peer never handshaked, OOM kills, service failed, UFW inactive |
| **warning** | Strong read failed, memory > 90%, disk > 85%, stale WG handshake (> 3min), Raft term inconsistency, applied index lag > 100, restart loop detected, TLS cert < 14 days, DNS down, namespace gateway down, Anyone not bootstrapped, clock skew > 5s, binary version mismatch, internet unreachable, high TCP retransmission |
| **info** | Zombie processes, orphan orama processes, swap usage > 30% |
### Cross-Node Checks
These checks compare data across all nodes:
- **RQLite Leader**: Exactly one leader exists (no split brain)
- **Leader Agreement**: All nodes agree on the same leader address
- **Raft Term Consistency**: Term values within 1 of each other
- **Applied Index Lag**: Followers within 100 entries of the leader
- **WireGuard Peer Symmetry**: Each node has N-1 peers
- **Clock Skew**: Node clocks within 5 seconds of each other
- **Binary Version**: All nodes running the same version
### Per-Node Checks
- **RQLite**: Responsive, ready, strong read
- **WireGuard**: Interface up, handshake freshness
- **System**: Memory, disk, load, OOM kills, swap
- **Services**: Systemd state, restart loops
- **DNS**: CoreDNS/Caddy up, TLS cert expiry, SOA resolution
- **Anyone**: Bootstrap progress
- **Processes**: Zombies, orphans, panics in logs
- **Namespaces**: Gateway and RQLite per namespace
- **Network**: UFW, internet reachability, TCP retransmission
## Monitor vs Inspector
Both tools check cluster health, but they serve different purposes:
| | `orama monitor` | `orama inspect` |
|---|---|---|
| **Data source** | `orama node report --json` (single SSH call per node) | 15+ SSH commands per node per subsystem |
| **Speed** | ~3-5s for full cluster | ~4-10s for full cluster |
| **Output** | TUI, tables, JSON | Tables, JSON |
| **Focus** | Real-time monitoring, alert detection | Deep diagnostic checks with pass/fail/warn |
| **AI support** | `report` subcommand for LLM input | `--ai` flag for inline analysis |
| **Use case** | "Is anything wrong right now?" | "What exactly is wrong and why?" |
Use `monitor` for day-to-day health checks and the interactive TUI. Use `inspect` for deep diagnostics when something is already known to be broken.
## Configuration
Uses the same `scripts/remote-nodes.conf` as the inspector. See [INSPECTOR.md](INSPECTOR.md#configuration) for format details.
## Prerequisites
Nodes must have the `orama` CLI installed (via `orama node install` or `upload-source.sh`). The monitor runs `sudo orama node report --json` over SSH, so the binary must be at `/usr/local/bin/orama` on each node.

View File

@ -1,248 +0,0 @@
# Nameserver Setup Guide
This guide explains how to configure your domain registrar to use Orama Network nodes as authoritative nameservers.
## Overview
When you install Orama with the `--nameserver` flag, the node runs CoreDNS to serve DNS records for your domain. This enables:
- Dynamic DNS for deployments (e.g., `myapp.node-abc123.dbrs.space`)
- Wildcard DNS support for all subdomains
- ACME DNS-01 challenges for automatic SSL certificates
## Prerequisites
Before setting up nameservers, you need:
1. **Domain ownership** - A domain you control (e.g., `dbrs.space`)
2. **3+ VPS nodes** - Recommended for redundancy
3. **Static IP addresses** - Each VPS must have a static public IP
4. **Access to registrar DNS settings** - Admin access to your domain registrar
## Understanding DNS Records
### NS Records (Nameserver Records)
NS records tell the internet which servers are authoritative for your domain:
```
dbrs.space. IN NS ns1.dbrs.space.
dbrs.space. IN NS ns2.dbrs.space.
dbrs.space. IN NS ns3.dbrs.space.
```
### Glue Records
Glue records are A records that provide IP addresses for nameservers that are under the same domain. They're required because:
- `ns1.dbrs.space` is under `dbrs.space`
- To resolve `ns1.dbrs.space`, you need to query `dbrs.space` nameservers
- But those nameservers ARE `ns1.dbrs.space` - circular dependency!
- Glue records break this cycle by providing IPs at the registry level
```
ns1.dbrs.space. IN A 141.227.165.168
ns2.dbrs.space. IN A 141.227.165.154
ns3.dbrs.space. IN A 141.227.156.51
```
## Installation
### Step 1: Install Orama on Each VPS
Install Orama with the `--nameserver` flag on each VPS that will serve as a nameserver:
```bash
# On VPS 1 (ns1)
sudo orama install \
--nameserver \
--domain dbrs.space \
--vps-ip 141.227.165.168
# On VPS 2 (ns2)
sudo orama install \
--nameserver \
--domain dbrs.space \
--vps-ip 141.227.165.154
# On VPS 3 (ns3)
sudo orama install \
--nameserver \
--domain dbrs.space \
--vps-ip 141.227.156.51
```
### Step 2: Configure Your Registrar
#### For Namecheap
1. **Log into Namecheap Dashboard**
- Go to https://www.namecheap.com
- Navigate to **Domain List****Manage** (next to your domain)
2. **Add Glue Records (Personal DNS Servers)**
- Go to **Advanced DNS** tab
- Scroll down to **Personal DNS Servers** section
- Click **Add Nameserver**
- Add each nameserver with its IP:
| Nameserver | IP Address |
|------------|------------|
| ns1.yourdomain.com | 141.227.165.168 |
| ns2.yourdomain.com | 141.227.165.154 |
| ns3.yourdomain.com | 141.227.156.51 |
3. **Set Custom Nameservers**
- Go back to the **Domain** tab
- Under **Nameservers**, select **Custom DNS**
- Add your nameserver hostnames:
- ns1.yourdomain.com
- ns2.yourdomain.com
- ns3.yourdomain.com
- Click the green checkmark to save
4. **Wait for Propagation**
- DNS changes can take 24-48 hours to propagate globally
- Most changes are visible within 1-4 hours
#### For GoDaddy
1. Log into GoDaddy account
2. Go to **My Products****DNS** for your domain
3. Under **Nameservers**, click **Change**
4. Select **Enter my own nameservers**
5. Add your nameserver hostnames
6. For glue records, go to **DNS Management** → **Host Names**
7. Add A records for ns1, ns2, ns3
#### For Cloudflare (as Registrar)
1. Log into Cloudflare Dashboard
2. Go to **Domain Registration** → your domain
3. Under **Nameservers**, change to custom
4. Note: Cloudflare Registrar may require contacting support for glue records
#### For Google Domains
1. Log into Google Domains
2. Select your domain → **DNS**
3. Under **Name servers**, select **Use custom name servers**
4. Add your nameserver hostnames
5. For glue records, click **Add** under **Glue records**
## Verification
### Step 1: Verify NS Records
After propagation, check that NS records are visible:
```bash
# Check NS records from Google DNS
dig NS yourdomain.com @8.8.8.8
# Expected output should show:
# yourdomain.com. IN NS ns1.yourdomain.com.
# yourdomain.com. IN NS ns2.yourdomain.com.
# yourdomain.com. IN NS ns3.yourdomain.com.
```
### Step 2: Verify Glue Records
Check that glue records resolve:
```bash
# Check glue records
dig A ns1.yourdomain.com @8.8.8.8
dig A ns2.yourdomain.com @8.8.8.8
dig A ns3.yourdomain.com @8.8.8.8
# Each should return the correct IP address
```
### Step 3: Test CoreDNS
Query your nameservers directly:
```bash
# Test a query against ns1
dig @ns1.yourdomain.com test.yourdomain.com
# Test wildcard resolution
dig @ns1.yourdomain.com myapp.node-abc123.yourdomain.com
```
### Step 4: Verify from Multiple Locations
Use online tools to verify global propagation:
- https://dnschecker.org
- https://www.whatsmydns.net
## Troubleshooting
### DNS Not Resolving
1. **Check CoreDNS is running:**
```bash
sudo systemctl status coredns
```
2. **Check CoreDNS logs:**
```bash
sudo journalctl -u coredns -f
```
3. **Verify port 53 is open:**
```bash
sudo ufw status
# Port 53 (TCP/UDP) should be allowed
```
4. **Test locally:**
```bash
dig @localhost yourdomain.com
```
### Glue Records Not Propagating
- Glue records are stored at the registry level, not DNS level
- They can take longer to propagate (up to 48 hours)
- Verify at your registrar that they were saved correctly
- Some registrars require the domain to be using their nameservers first
### SERVFAIL Errors
Usually indicates CoreDNS configuration issues:
1. Check Corefile syntax
2. Verify RQLite connectivity
3. Check firewall rules
## Security Considerations
### Firewall Rules
Only expose necessary ports:
```bash
# Allow DNS from anywhere
sudo ufw allow 53/tcp
sudo ufw allow 53/udp
# Restrict admin ports to internal network
sudo ufw allow from 10.0.0.0/8 to any port 8080 # Health
sudo ufw allow from 10.0.0.0/8 to any port 9153 # Metrics
```
### Rate Limiting
Consider adding rate limiting to prevent DNS amplification attacks.
This can be configured in the CoreDNS Corefile.
## Multi-Node Coordination
When running multiple nameservers:
1. **All nodes share the same RQLite cluster** - DNS records are automatically synchronized
2. **Install in order** - First node bootstraps, others join
3. **Same domain configuration** - All nodes must use the same `--domain` value
## Related Documentation
- [CoreDNS RQLite Plugin](../pkg/coredns/README.md) - Technical details
- [Deployment Guide](./DEPLOYMENT_GUIDE.md) - Full deployment instructions
- [Architecture](./ARCHITECTURE.md) - System architecture overview

View File

@ -0,0 +1,476 @@
# Orama Network - Security Deployment Guide
**Date:** January 18, 2026
**Status:** Production-Ready
**Audit Completed By:** Claude Code Security Audit
---
## Executive Summary
This document outlines the security hardening measures applied to the 4-node Orama Network production cluster. All critical vulnerabilities identified in the security audit have been addressed.
**Security Status:** ✅ SECURED FOR PRODUCTION
---
## Server Inventory
| Server ID | IP Address | Domain | OS | Role |
|-----------|------------|--------|-----|------|
| VPS 1 | 51.83.128.181 | node-kv4la8.debros.network | Ubuntu 22.04 | Gateway + Cluster Node |
| VPS 2 | 194.61.28.7 | node-7prvNa.debros.network | Ubuntu 24.04 | Gateway + Cluster Node |
| VPS 3 | 83.171.248.66 | node-xn23dq.debros.network | Ubuntu 24.04 | Gateway + Cluster Node |
| VPS 4 | 62.72.44.87 | node-nns4n5.debros.network | Ubuntu 24.04 | Gateway + Cluster Node |
---
## Services Running on Each Server
| Service | Port(s) | Purpose | Public Access |
|---------|---------|---------|---------------|
| **orama-node** | 80, 443, 7001 | API Gateway | Yes (80, 443 only) |
| **rqlited** | 5001, 7002 | Distributed SQLite DB | Cluster only |
| **ipfs** | 4101, 4501, 8080 | Content-addressed storage | Cluster only |
| **ipfs-cluster** | 9094, 9098 | IPFS cluster management | Cluster only |
| **olric-server** | 3320, 3322 | Distributed cache | Cluster only |
| **anon** (Anyone proxy) | 9001, 9050, 9051 | Anonymity proxy | Cluster only |
| **libp2p** | 4001 | P2P networking | Yes (public P2P) |
| **SSH** | 22 | Remote access | Yes |
---
## Security Measures Implemented
### 1. Firewall Configuration (UFW)
**Status:** ✅ Enabled on all 4 servers
#### Public Ports (Open to Internet)
- **22/tcp** - SSH (with hardening)
- **80/tcp** - HTTP (redirects to HTTPS)
- **443/tcp** - HTTPS (Let's Encrypt production certificates)
- **4001/tcp** - libp2p swarm (P2P networking)
#### Cluster-Only Ports (Restricted to 4 Server IPs)
All the following ports are ONLY accessible from the 4 cluster IPs:
- **5001/tcp** - rqlite HTTP API
- **7001/tcp** - SNI Gateway
- **7002/tcp** - rqlite Raft consensus
- **9094/tcp** - IPFS Cluster API
- **9098/tcp** - IPFS Cluster communication
- **3322/tcp** - Olric distributed cache
- **4101/tcp** - IPFS swarm (cluster internal)
#### Firewall Rules Example
```bash
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment "SSH"
sudo ufw allow 80/tcp comment "HTTP"
sudo ufw allow 443/tcp comment "HTTPS"
sudo ufw allow 4001/tcp comment "libp2p swarm"
# Cluster-only access for sensitive services
sudo ufw allow from 51.83.128.181 to any port 5001 proto tcp
sudo ufw allow from 194.61.28.7 to any port 5001 proto tcp
sudo ufw allow from 83.171.248.66 to any port 5001 proto tcp
sudo ufw allow from 62.72.44.87 to any port 5001 proto tcp
# (repeat for ports 7001, 7002, 9094, 9098, 3322, 4101)
sudo ufw enable
```
### 2. SSH Hardening
**Location:** `/etc/ssh/sshd_config.d/99-hardening.conf`
**Configuration:**
```bash
PermitRootLogin yes # Root login allowed with SSH keys
PasswordAuthentication yes # Password auth enabled (you have keys configured)
PubkeyAuthentication yes # SSH key authentication enabled
PermitEmptyPasswords no # No empty passwords
X11Forwarding no # X11 disabled for security
MaxAuthTries 3 # Max 3 login attempts
ClientAliveInterval 300 # Keep-alive every 5 minutes
ClientAliveCountMax 2 # Disconnect after 2 failed keep-alives
```
**Your SSH Keys Added:**
- ✅ `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPcGZPX2iHXWO8tuyyDkHPS5eByPOktkw3+ugcw79yQO`
- ✅ `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDgCWmycaBN3aAZJcM2w4+Xi2zrTwN78W8oAiQywvMEkubqNNWHF6I3...`
Both keys are installed on all 4 servers in:
- VPS 1: `/home/ubuntu/.ssh/authorized_keys`
- VPS 2, 3, 4: `/root/.ssh/authorized_keys`
### 3. Fail2ban Protection
**Status:** ✅ Installed and running on all 4 servers
**Purpose:** Automatically bans IPs after failed SSH login attempts
**Check Status:**
```bash
sudo systemctl status fail2ban
```
### 4. Security Updates
**Status:** ✅ All security updates applied (as of Jan 18, 2026)
**Update Command:**
```bash
sudo apt update && sudo apt upgrade -y
```
### 5. Let's Encrypt TLS Certificates
**Status:** ✅ Production certificates (NOT staging)
**Configuration:**
- **Provider:** Let's Encrypt (ACME v2 Production)
- **Auto-renewal:** Enabled via autocert
- **Cache Directory:** `/home/debros/.orama/tls-cache/`
- **Domains:**
- node-kv4la8.debros.network (VPS 1)
- node-7prvNa.debros.network (VPS 2)
- node-xn23dq.debros.network (VPS 3)
- node-nns4n5.debros.network (VPS 4)
**Certificate Files:**
- Account key: `/home/debros/.orama/tls-cache/acme_account+key`
- Certificates auto-managed by autocert
**Verification:**
```bash
curl -I https://node-kv4la8.debros.network
# Should return valid SSL certificate
```
---
## Cluster Configuration
### RQLite Cluster
**Nodes:**
- 51.83.128.181:7002 (Leader)
- 194.61.28.7:7002
- 83.171.248.66:7002
- 62.72.44.87:7002
**Test Cluster Health:**
```bash
ssh ubuntu@51.83.128.181
curl -s http://localhost:5001/status | jq '.store.nodes'
```
**Expected Output:**
```json
[
{"id":"194.61.28.7:7002","addr":"194.61.28.7:7002","suffrage":"Voter"},
{"id":"51.83.128.181:7002","addr":"51.83.128.181:7002","suffrage":"Voter"},
{"id":"62.72.44.87:7002","addr":"62.72.44.87:7002","suffrage":"Voter"},
{"id":"83.171.248.66:7002","addr":"83.171.248.66:7002","suffrage":"Voter"}
]
```
### IPFS Cluster
**Test Cluster Health:**
```bash
ssh ubuntu@51.83.128.181
curl -s http://localhost:9094/id | jq '.cluster_peers'
```
**Expected:** All 4 peer IDs listed
### Olric Cache Cluster
**Port:** 3320 (localhost), 3322 (cluster communication)
**Test:**
```bash
ssh ubuntu@51.83.128.181
ss -tulpn | grep olric
```
---
## Access Credentials
### SSH Access
**VPS 1:**
```bash
ssh ubuntu@51.83.128.181
# OR using your SSH key:
ssh -i ~/.ssh/ssh-sotiris/id_ed25519 ubuntu@51.83.128.181
```
**VPS 2, 3, 4:**
```bash
ssh root@194.61.28.7
ssh root@83.171.248.66
ssh root@62.72.44.87
```
**Important:** Password authentication is still enabled, but your SSH keys are configured for passwordless access.
---
## Testing & Verification
### 1. Test External Port Access (From Your Machine)
```bash
# These should be BLOCKED (timeout or connection refused):
nc -zv 51.83.128.181 5001 # rqlite API - should be blocked
nc -zv 51.83.128.181 7002 # rqlite Raft - should be blocked
nc -zv 51.83.128.181 9094 # IPFS cluster - should be blocked
# These should be OPEN:
nc -zv 51.83.128.181 22 # SSH - should succeed
nc -zv 51.83.128.181 80 # HTTP - should succeed
nc -zv 51.83.128.181 443 # HTTPS - should succeed
nc -zv 51.83.128.181 4001 # libp2p - should succeed
```
### 2. Test Domain Access
```bash
curl -I https://node-kv4la8.debros.network
curl -I https://node-7prvNa.debros.network
curl -I https://node-xn23dq.debros.network
curl -I https://node-nns4n5.debros.network
```
All should return `HTTP/1.1 200 OK` or similar with valid SSL certificates.
### 3. Test Cluster Communication (From VPS 1)
```bash
ssh ubuntu@51.83.128.181
# Test rqlite cluster
curl -s http://localhost:5001/status | jq -r '.store.nodes[].id'
# Test IPFS cluster
curl -s http://localhost:9094/id | jq -r '.cluster_peers[]'
# Check all services running
ps aux | grep -E "(orama-node|rqlited|ipfs|olric)" | grep -v grep
```
---
## Maintenance & Operations
### Firewall Management
**View current rules:**
```bash
sudo ufw status numbered
```
**Add a new allowed IP for cluster services:**
```bash
sudo ufw allow from NEW_IP_ADDRESS to any port 5001 proto tcp
sudo ufw allow from NEW_IP_ADDRESS to any port 7002 proto tcp
# etc.
```
**Delete a rule:**
```bash
sudo ufw status numbered # Get rule number
sudo ufw delete [NUMBER]
```
### SSH Management
**Test SSH config without applying:**
```bash
sudo sshd -t
```
**Reload SSH after config changes:**
```bash
sudo systemctl reload ssh
```
**View SSH login attempts:**
```bash
sudo journalctl -u ssh | tail -50
```
### Fail2ban Management
**Check banned IPs:**
```bash
sudo fail2ban-client status sshd
```
**Unban an IP:**
```bash
sudo fail2ban-client set sshd unbanip IP_ADDRESS
```
### Security Updates
**Check for updates:**
```bash
apt list --upgradable
```
**Apply updates:**
```bash
sudo apt update && sudo apt upgrade -y
```
**Reboot if kernel updated:**
```bash
sudo reboot
```
---
## Security Improvements Completed
### Before Security Audit:
- ❌ No firewall enabled
- ❌ rqlite database exposed to internet (port 5001, 7002)
- ❌ IPFS cluster management exposed (port 9094, 9098)
- ❌ Olric cache exposed (port 3322)
- ❌ Root login enabled without restrictions (VPS 2, 3, 4)
- ❌ No fail2ban on 3 out of 4 servers
- ❌ 19-39 security updates pending
### After Security Hardening:
- ✅ UFW firewall enabled on all servers
- ✅ Sensitive ports restricted to cluster IPs only
- ✅ SSH hardened with key authentication
- ✅ Fail2ban protecting all servers
- ✅ All security updates applied
- ✅ Let's Encrypt production certificates verified
- ✅ Cluster communication tested and working
- ✅ External access verified (HTTP/HTTPS only)
---
## Recommended Next Steps (Optional)
These were not implemented per your request but are recommended for future consideration:
1. **VPN/Private Networking** - Use WireGuard or Tailscale for encrypted cluster communication instead of firewall rules
2. **Automated Security Updates** - Enable unattended-upgrades for automatic security patches
3. **Monitoring & Alerting** - Set up Prometheus/Grafana for service monitoring
4. **Regular Security Audits** - Run `lynis` or `rkhunter` monthly for security checks
---
## Important Notes
### Let's Encrypt Configuration
The Orama Network gateway uses **autocert** from Go's `golang.org/x/crypto/acme/autocert` package. The configuration is in:
**File:** `/home/debros/.orama/configs/node.yaml`
**Relevant settings:**
```yaml
http_gateway:
https:
enabled: true
domain: "node-kv4la8.debros.network"
auto_cert: true
cache_dir: "/home/debros/.orama/tls-cache"
http_port: 80
https_port: 443
email: "admin@node-kv4la8.debros.network"
```
**Important:** There is NO `letsencrypt_staging` flag set, which means it defaults to **production Let's Encrypt**. This is correct for production deployment.
### Firewall Persistence
UFW rules are persistent across reboots. The firewall will automatically start on boot.
### SSH Key Access
Both of your SSH keys are configured on all servers. You can access:
- VPS 1: `ssh -i ~/.ssh/ssh-sotiris/id_ed25519 ubuntu@51.83.128.181`
- VPS 2-4: `ssh -i ~/.ssh/ssh-sotiris/id_ed25519 root@IP_ADDRESS`
Password authentication is still enabled as a fallback, but keys are recommended.
---
## Emergency Access
If you get locked out:
1. **VPS Provider Console:** All major VPS providers offer web-based console access
2. **Password Access:** Password auth is still enabled on all servers
3. **SSH Keys:** Two keys configured for redundancy
**Disable firewall temporarily (emergency only):**
```bash
sudo ufw disable
# Fix the issue
sudo ufw enable
```
---
## Verification Checklist
Use this checklist to verify the security hardening:
- [ ] All 4 servers have UFW firewall enabled
- [ ] SSH is hardened (MaxAuthTries 3, X11Forwarding no)
- [ ] Your SSH keys work on all servers
- [ ] Fail2ban is running on all servers
- [ ] Security updates are current
- [ ] rqlite port 5001 is NOT accessible from internet
- [ ] rqlite port 7002 is NOT accessible from internet
- [ ] IPFS cluster ports 9094, 9098 are NOT accessible from internet
- [ ] Domains are accessible via HTTPS with valid certificates
- [ ] RQLite cluster shows all 4 nodes
- [ ] IPFS cluster shows all 4 peers
- [ ] All services are running (5 processes per server)
---
## Contact & Support
For issues or questions about this deployment:
- **Security Audit Date:** January 18, 2026
- **Configuration Files:** `/home/debros/.orama/configs/`
- **Firewall Rules:** `/etc/ufw/`
- **SSH Config:** `/etc/ssh/sshd_config.d/99-hardening.conf`
- **TLS Certs:** `/home/debros/.orama/tls-cache/`
---
## Changelog
### January 18, 2026 - Production Security Hardening
**Changes:**
1. Added UFW firewall rules on all 4 VPS servers
2. Restricted sensitive ports (5001, 7002, 9094, 9098, 3322, 4101) to cluster IPs only
3. Hardened SSH configuration
4. Added your 2 SSH keys to all servers
5. Installed fail2ban on VPS 1, 2, 3 (VPS 4 already had it)
6. Applied all pending security updates (23-39 packages per server)
7. Verified Let's Encrypt is using production (not staging)
8. Tested all services: rqlite, IPFS, libp2p, Olric clusters
9. Verified all 4 domains are accessible via HTTPS
**Result:** Production-ready secure deployment ✅
---
**END OF DEPLOYMENT GUIDE**

294
e2e/auth_negative_test.go Normal file
View File

@ -0,0 +1,294 @@
//go:build e2e
package e2e
import (
"context"
"net/http"
"testing"
"time"
"unicode"
)
func TestAuth_MissingAPIKey(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request without auth headers
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/network/status", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should be unauthorized
if resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusForbidden {
t.Logf("warning: expected 401/403 for missing auth, got %d (auth may not be enforced on this endpoint)", resp.StatusCode)
}
}
func TestAuth_InvalidAPIKey(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with invalid API key
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/cache/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Authorization", "Bearer invalid-key-xyz")
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should be unauthorized
if resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusForbidden {
t.Logf("warning: expected 401/403 for invalid key, got %d", resp.StatusCode)
}
}
func TestAuth_CacheWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request cache endpoint without auth
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/cache/health",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("request failed: %v", err)
}
// Should fail with 401 or 403
if status != http.StatusUnauthorized && status != http.StatusForbidden {
t.Logf("warning: expected 401/403 for cache without auth, got %d", status)
}
}
func TestAuth_StorageWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request storage endpoint without auth
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/storage/status/QmTest",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("request failed: %v", err)
}
// Should fail with 401 or 403
if status != http.StatusUnauthorized && status != http.StatusForbidden {
t.Logf("warning: expected 401/403 for storage without auth, got %d", status)
}
}
func TestAuth_RQLiteWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request rqlite endpoint without auth
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/rqlite/schema",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("request failed: %v", err)
}
// Should fail with 401 or 403
if status != http.StatusUnauthorized && status != http.StatusForbidden {
t.Logf("warning: expected 401/403 for rqlite without auth, got %d", status)
}
}
func TestAuth_MalformedBearerToken(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with malformed bearer token
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/cache/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
// Missing "Bearer " prefix
req.Header.Set("Authorization", "invalid-token-format")
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should be unauthorized
if resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusForbidden {
t.Logf("warning: expected 401/403 for malformed token, got %d", resp.StatusCode)
}
}
func TestAuth_ExpiredJWT(t *testing.T) {
// Skip if JWT is not being used
if GetJWT() == "" && GetAPIKey() == "" {
t.Skip("No JWT or API key configured")
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// This test would require an expired JWT token
// For now, test with a clearly invalid JWT structure
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/cache/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Authorization", "Bearer expired.jwt.token")
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should be unauthorized
if resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusForbidden {
t.Logf("warning: expected 401/403 for expired JWT, got %d", resp.StatusCode)
}
}
func TestAuth_EmptyBearerToken(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with empty bearer token
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/cache/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Authorization", "Bearer ")
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should be unauthorized
if resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusForbidden {
t.Logf("warning: expected 401/403 for empty token, got %d", resp.StatusCode)
}
}
func TestAuth_DuplicateAuthHeaders(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with both API key and invalid JWT
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/cache/health",
Headers: map[string]string{
"Authorization": "Bearer " + GetAPIKey(),
"X-API-Key": GetAPIKey(),
},
}
_, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("request failed: %v", err)
}
// Should succeed if API key is valid
if status != http.StatusOK {
t.Logf("request with both headers returned %d", status)
}
}
func TestAuth_CaseSensitiveAPIKey(t *testing.T) {
if GetAPIKey() == "" {
t.Skip("No API key configured")
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with incorrectly cased API key
apiKey := GetAPIKey()
incorrectKey := ""
for i, ch := range apiKey {
if i%2 == 0 && unicode.IsLetter(ch) {
incorrectKey += string(unicode.ToUpper(ch)) // Convert to uppercase
} else {
incorrectKey += string(ch)
}
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/cache/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Authorization", "Bearer "+incorrectKey)
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// API keys should be case-sensitive
if resp.StatusCode == http.StatusOK {
t.Logf("warning: API key check may not be case-sensitive (got 200)")
}
}
func TestAuth_HealthEndpointNoAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Health endpoint at /health should not require auth
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/health", nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
client := NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("request failed: %v", err)
}
defer resp.Body.Close()
// Should succeed without auth
if resp.StatusCode != http.StatusOK {
t.Fatalf("expected 200 for /health without auth, got %d", resp.StatusCode)
}
}

View File

@ -1,6 +1,6 @@
//go:build e2e
package shared_test
package e2e
import (
"context"
@ -8,19 +8,17 @@ import (
"net/http"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
func TestCache_Health(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/cache/health",
URL: GetGatewayURL() + "/v1/cache/health",
}
body, status, err := req.Do(ctx)
@ -33,7 +31,7 @@ func TestCache_Health(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -47,19 +45,19 @@ func TestCache_Health(t *testing.T) {
}
func TestCache_PutGet(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "test-key"
value := "test-value"
// Put value
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -77,9 +75,9 @@ func TestCache_PutGet(t *testing.T) {
}
// Get value
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -96,7 +94,7 @@ func TestCache_PutGet(t *testing.T) {
}
var getResp map[string]interface{}
if err := e2e.DecodeJSON(body, &getResp); err != nil {
if err := DecodeJSON(body, &getResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -106,12 +104,12 @@ func TestCache_PutGet(t *testing.T) {
}
func TestCache_PutGetJSON(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "json-key"
jsonValue := map[string]interface{}{
"name": "John",
@ -120,9 +118,9 @@ func TestCache_PutGetJSON(t *testing.T) {
}
// Put JSON value
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -140,9 +138,9 @@ func TestCache_PutGetJSON(t *testing.T) {
}
// Get JSON value
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -159,7 +157,7 @@ func TestCache_PutGetJSON(t *testing.T) {
}
var getResp map[string]interface{}
if err := e2e.DecodeJSON(body, &getResp); err != nil {
if err := DecodeJSON(body, &getResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -173,19 +171,19 @@ func TestCache_PutGetJSON(t *testing.T) {
}
func TestCache_Delete(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "delete-key"
value := "delete-value"
// Put value
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -199,9 +197,9 @@ func TestCache_Delete(t *testing.T) {
}
// Delete value
deleteReq := &e2e.HTTPRequest{
deleteReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/delete",
URL: GetGatewayURL() + "/v1/cache/delete",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -218,9 +216,9 @@ func TestCache_Delete(t *testing.T) {
}
// Verify deletion
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -235,19 +233,19 @@ func TestCache_Delete(t *testing.T) {
}
func TestCache_TTL(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "ttl-key"
value := "ttl-value"
// Put value with TTL
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -266,9 +264,9 @@ func TestCache_TTL(t *testing.T) {
}
// Verify value exists
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -281,7 +279,7 @@ func TestCache_TTL(t *testing.T) {
}
// Wait for TTL expiry (2 seconds + buffer)
e2e.Delay(2500)
Delay(2500)
// Verify value is expired
_, status, err = getReq.Do(ctx)
@ -291,19 +289,19 @@ func TestCache_TTL(t *testing.T) {
}
func TestCache_Scan(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
// Put multiple keys
keys := []string{"user-1", "user-2", "session-1", "session-2"}
for _, key := range keys {
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -318,9 +316,9 @@ func TestCache_Scan(t *testing.T) {
}
// Scan all keys
scanReq := &e2e.HTTPRequest{
scanReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/scan",
URL: GetGatewayURL() + "/v1/cache/scan",
Body: map[string]interface{}{
"dmap": dmap,
},
@ -336,7 +334,7 @@ func TestCache_Scan(t *testing.T) {
}
var scanResp map[string]interface{}
if err := e2e.DecodeJSON(body, &scanResp); err != nil {
if err := DecodeJSON(body, &scanResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -347,19 +345,19 @@ func TestCache_Scan(t *testing.T) {
}
func TestCache_ScanWithRegex(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
// Put keys with different patterns
keys := []string{"user-1", "user-2", "session-1", "session-2"}
for _, key := range keys {
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -374,9 +372,9 @@ func TestCache_ScanWithRegex(t *testing.T) {
}
// Scan with regex pattern
scanReq := &e2e.HTTPRequest{
scanReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/scan",
URL: GetGatewayURL() + "/v1/cache/scan",
Body: map[string]interface{}{
"dmap": dmap,
"pattern": "^user-",
@ -393,7 +391,7 @@ func TestCache_ScanWithRegex(t *testing.T) {
}
var scanResp map[string]interface{}
if err := e2e.DecodeJSON(body, &scanResp); err != nil {
if err := DecodeJSON(body, &scanResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -404,19 +402,19 @@ func TestCache_ScanWithRegex(t *testing.T) {
}
func TestCache_MultiGet(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
keys := []string{"key-1", "key-2", "key-3"}
// Put values
for i, key := range keys {
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -431,9 +429,9 @@ func TestCache_MultiGet(t *testing.T) {
}
// Multi-get
multiGetReq := &e2e.HTTPRequest{
multiGetReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/mget",
URL: GetGatewayURL() + "/v1/cache/mget",
Body: map[string]interface{}{
"dmap": dmap,
"keys": keys,
@ -450,7 +448,7 @@ func TestCache_MultiGet(t *testing.T) {
}
var mgetResp map[string]interface{}
if err := e2e.DecodeJSON(body, &mgetResp); err != nil {
if err := DecodeJSON(body, &mgetResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -461,14 +459,14 @@ func TestCache_MultiGet(t *testing.T) {
}
func TestCache_MissingDMap(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": "",
"key": "any-key",
@ -486,16 +484,16 @@ func TestCache_MissingDMap(t *testing.T) {
}
func TestCache_MissingKey(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": "non-existent-key",

View File

@ -1,556 +0,0 @@
//go:build e2e
package cluster_test
import (
"context"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"sort"
"strings"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/require"
)
// =============================================================================
// STRICT NAMESPACE CLUSTER TESTS
// These tests FAIL if things don't work. No t.Skip() for expected functionality.
// =============================================================================
// TestNamespaceCluster_FullProvisioning is a STRICT test that verifies the complete
// namespace cluster provisioning flow. This test FAILS if any component doesn't work.
func TestNamespaceCluster_FullProvisioning(t *testing.T) {
// Generate unique namespace name
newNamespace := fmt.Sprintf("e2e-cluster-%d", time.Now().UnixNano())
env, err := e2e.LoadTestEnvWithNamespace(newNamespace)
require.NoError(t, err, "FATAL: Failed to create test environment for namespace %s", newNamespace)
require.NotEmpty(t, env.APIKey, "FATAL: No API key received - namespace provisioning failed")
t.Logf("Created namespace: %s", newNamespace)
t.Logf("API Key: %s...", env.APIKey[:min(20, len(env.APIKey))])
// Get cluster status to verify provisioning
t.Run("Cluster status shows ready", func(t *testing.T) {
// Query the namespace cluster status
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/namespace/status?name="+newNamespace, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to query cluster status")
defer resp.Body.Close()
bodyBytes, _ := io.ReadAll(resp.Body)
t.Logf("Cluster status response: %s", string(bodyBytes))
// If status endpoint exists and returns cluster info, verify it
if resp.StatusCode == http.StatusOK {
var result map[string]interface{}
if err := json.Unmarshal(bodyBytes, &result); err == nil {
status, _ := result["status"].(string)
if status != "" && status != "ready" && status != "default" {
t.Errorf("FAIL: Cluster status is '%s', expected 'ready'", status)
}
}
}
})
// Verify we can use the namespace for deployments
t.Run("Deployments work on namespace", func(t *testing.T) {
tarballPath := filepath.Join("../../testdata/apps/react-app")
if _, err := os.Stat(tarballPath); os.IsNotExist(err) {
t.Skip("Test tarball not found - skipping deployment test")
}
deploymentName := fmt.Sprintf("cluster-test-%d", time.Now().Unix())
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID, "FAIL: Deployment creation failed on namespace cluster")
t.Logf("Created deployment %s (ID: %s) on namespace %s", deploymentName, deploymentID, newNamespace)
// Cleanup
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Verify deployment is accessible
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/get?id="+deploymentID, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to get deployment")
defer resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode, "FAIL: Cannot retrieve deployment from namespace cluster")
})
}
// TestNamespaceCluster_RQLiteHealth verifies that namespace RQLite cluster is running
// and accepting connections. This test FAILS if RQLite is not accessible.
func TestNamespaceCluster_RQLiteHealth(t *testing.T) {
t.Run("Check namespace port range for RQLite", func(t *testing.T) {
foundRQLite := false
var healthyPorts []int
var unhealthyPorts []int
// Check first few port blocks
for portStart := 10000; portStart <= 10015; portStart += 5 {
rqlitePort := portStart // RQLite HTTP is first port in block
if isPortListening("localhost", rqlitePort) {
t.Logf("Found RQLite instance on port %d", rqlitePort)
foundRQLite = true
// Verify it responds to health check
healthURL := fmt.Sprintf("http://localhost:%d/status", rqlitePort)
healthResp, err := http.Get(healthURL)
if err == nil {
defer healthResp.Body.Close()
if healthResp.StatusCode == http.StatusOK {
healthyPorts = append(healthyPorts, rqlitePort)
t.Logf(" ✓ RQLite on port %d is healthy", rqlitePort)
} else {
unhealthyPorts = append(unhealthyPorts, rqlitePort)
t.Errorf("FAIL: RQLite on port %d returned status %d", rqlitePort, healthResp.StatusCode)
}
} else {
unhealthyPorts = append(unhealthyPorts, rqlitePort)
t.Errorf("FAIL: RQLite on port %d health check failed: %v", rqlitePort, err)
}
}
}
if !foundRQLite {
t.Log("No namespace RQLite instances found in port range 10000-10015")
t.Log("This is expected if no namespaces have been provisioned yet")
} else {
t.Logf("Summary: %d healthy, %d unhealthy RQLite instances", len(healthyPorts), len(unhealthyPorts))
require.Empty(t, unhealthyPorts, "FAIL: Some RQLite instances are unhealthy")
}
})
}
// TestNamespaceCluster_OlricHealth verifies that namespace Olric cluster is running
// and accepting connections.
func TestNamespaceCluster_OlricHealth(t *testing.T) {
t.Run("Check namespace port range for Olric", func(t *testing.T) {
foundOlric := false
foundCount := 0
// Check first few port blocks - Olric memberlist is port_start + 3
for portStart := 10000; portStart <= 10015; portStart += 5 {
olricMemberlistPort := portStart + 3
if isPortListening("localhost", olricMemberlistPort) {
t.Logf("Found Olric memberlist on port %d", olricMemberlistPort)
foundOlric = true
foundCount++
}
}
if !foundOlric {
t.Log("No namespace Olric instances found in port range 10003-10018")
t.Log("This is expected if no namespaces have been provisioned yet")
} else {
t.Logf("Found %d Olric memberlist ports accepting connections", foundCount)
}
})
}
// TestNamespaceCluster_GatewayHealth verifies that namespace Gateway instances are running.
// This test FAILS if gateway binary exists but gateways don't spawn.
func TestNamespaceCluster_GatewayHealth(t *testing.T) {
// Check if gateway binary exists
gatewayBinaryPaths := []string{
"./bin/orama",
"../bin/orama",
"/usr/local/bin/orama",
}
var gatewayBinaryExists bool
var foundPath string
for _, path := range gatewayBinaryPaths {
if _, err := os.Stat(path); err == nil {
gatewayBinaryExists = true
foundPath = path
break
}
}
if !gatewayBinaryExists {
t.Log("Gateway binary not found - namespace gateways will not spawn")
t.Log("Run 'make build' to build the gateway binary")
t.Log("Checked paths:", gatewayBinaryPaths)
// This is a FAILURE if we expect gateway to work
t.Error("FAIL: Gateway binary not found. Run 'make build' first.")
return
}
t.Logf("Gateway binary found at: %s", foundPath)
t.Run("Check namespace port range for Gateway", func(t *testing.T) {
foundGateway := false
var healthyPorts []int
var unhealthyPorts []int
// Check first few port blocks - Gateway HTTP is port_start + 4
for portStart := 10000; portStart <= 10015; portStart += 5 {
gatewayPort := portStart + 4
if isPortListening("localhost", gatewayPort) {
t.Logf("Found Gateway instance on port %d", gatewayPort)
foundGateway = true
// Verify it responds to health check
healthURL := fmt.Sprintf("http://localhost:%d/v1/health", gatewayPort)
healthResp, err := http.Get(healthURL)
if err == nil {
defer healthResp.Body.Close()
if healthResp.StatusCode == http.StatusOK {
healthyPorts = append(healthyPorts, gatewayPort)
t.Logf(" ✓ Gateway on port %d is healthy", gatewayPort)
} else {
unhealthyPorts = append(unhealthyPorts, gatewayPort)
t.Errorf("FAIL: Gateway on port %d returned status %d", gatewayPort, healthResp.StatusCode)
}
} else {
unhealthyPorts = append(unhealthyPorts, gatewayPort)
t.Errorf("FAIL: Gateway on port %d health check failed: %v", gatewayPort, err)
}
}
}
if !foundGateway {
t.Log("No namespace Gateway instances found in port range 10004-10019")
t.Log("This is expected if no namespaces have been provisioned yet")
} else {
t.Logf("Summary: %d healthy, %d unhealthy Gateway instances", len(healthyPorts), len(unhealthyPorts))
require.Empty(t, unhealthyPorts, "FAIL: Some Gateway instances are unhealthy")
}
})
}
// TestNamespaceCluster_ProvisioningCreatesProcesses creates a new namespace and
// verifies that actual processes are spawned. This is the STRICTEST test.
func TestNamespaceCluster_ProvisioningCreatesProcesses(t *testing.T) {
newNamespace := fmt.Sprintf("e2e-strict-%d", time.Now().UnixNano())
// Record ports before provisioning
portsBefore := getListeningPortsInRange(10000, 10099)
t.Logf("Ports in use before provisioning: %v", portsBefore)
// Create namespace
env, err := e2e.LoadTestEnvWithNamespace(newNamespace)
require.NoError(t, err, "FATAL: Failed to create namespace")
require.NotEmpty(t, env.APIKey, "FATAL: No API key - provisioning failed")
t.Logf("Namespace '%s' created successfully", newNamespace)
// Wait a moment for processes to fully start
time.Sleep(3 * time.Second)
// Record ports after provisioning
portsAfter := getListeningPortsInRange(10000, 10099)
t.Logf("Ports in use after provisioning: %v", portsAfter)
// Check if new ports were opened
newPorts := diffPorts(portsBefore, portsAfter)
sort.Ints(newPorts)
t.Logf("New ports opened: %v", newPorts)
t.Run("New ports allocated for namespace cluster", func(t *testing.T) {
if len(newPorts) == 0 {
// This might be OK for default namespace or if using global cluster
t.Log("No new ports detected")
t.Log("Possible reasons:")
t.Log(" - Namespace uses default cluster (expected for 'default')")
t.Log(" - Cluster already existed from previous test")
t.Log(" - Provisioning is handled differently in this environment")
} else {
t.Logf("SUCCESS: %d new ports opened for namespace cluster", len(newPorts))
// Verify the ports follow expected pattern
for _, port := range newPorts {
offset := (port - 10000) % 5
switch offset {
case 0:
t.Logf(" Port %d: RQLite HTTP", port)
case 1:
t.Logf(" Port %d: RQLite Raft", port)
case 2:
t.Logf(" Port %d: Olric HTTP", port)
case 3:
t.Logf(" Port %d: Olric Memberlist", port)
case 4:
t.Logf(" Port %d: Gateway HTTP", port)
}
}
}
})
t.Run("RQLite is accessible on allocated ports", func(t *testing.T) {
rqlitePorts := filterPortsByOffset(newPorts, 0) // RQLite HTTP is offset 0
if len(rqlitePorts) == 0 {
t.Log("No new RQLite ports detected")
return
}
for _, port := range rqlitePorts {
healthURL := fmt.Sprintf("http://localhost:%d/status", port)
resp, err := http.Get(healthURL)
require.NoError(t, err, "FAIL: RQLite on port %d is not responding", port)
resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode,
"FAIL: RQLite on port %d returned status %d", port, resp.StatusCode)
t.Logf("✓ RQLite on port %d is healthy", port)
}
})
t.Run("Olric is accessible on allocated ports", func(t *testing.T) {
olricPorts := filterPortsByOffset(newPorts, 3) // Olric Memberlist is offset 3
if len(olricPorts) == 0 {
t.Log("No new Olric ports detected")
return
}
for _, port := range olricPorts {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("localhost:%d", port), 2*time.Second)
require.NoError(t, err, "FAIL: Olric memberlist on port %d is not responding", port)
conn.Close()
t.Logf("✓ Olric memberlist on port %d is accepting connections", port)
}
})
}
// TestNamespaceCluster_StatusEndpoint tests the /v1/namespace/status endpoint
func TestNamespaceCluster_StatusEndpoint(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
t.Run("Status endpoint returns 404 for non-existent cluster", func(t *testing.T) {
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/namespace/status?id=non-existent-id", nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Request should not fail")
defer resp.Body.Close()
require.Equal(t, http.StatusNotFound, resp.StatusCode,
"FAIL: Should return 404 for non-existent cluster, got %d", resp.StatusCode)
})
}
// TestNamespaceCluster_CrossNamespaceAccess verifies namespace isolation
func TestNamespaceCluster_CrossNamespaceAccess(t *testing.T) {
nsA := fmt.Sprintf("ns-a-%d", time.Now().Unix())
nsB := fmt.Sprintf("ns-b-%d", time.Now().Unix())
envA, err := e2e.LoadTestEnvWithNamespace(nsA)
require.NoError(t, err, "FAIL: Cannot create namespace A")
envB, err := e2e.LoadTestEnvWithNamespace(nsB)
require.NoError(t, err, "FAIL: Cannot create namespace B")
// Verify both namespaces have different API keys
require.NotEqual(t, envA.APIKey, envB.APIKey, "FAIL: Namespaces should have different API keys")
t.Logf("Namespace A API key: %s...", envA.APIKey[:min(10, len(envA.APIKey))])
t.Logf("Namespace B API key: %s...", envB.APIKey[:min(10, len(envB.APIKey))])
t.Run("API keys are namespace-scoped", func(t *testing.T) {
// Namespace A should not see namespace B's resources
req, _ := http.NewRequest("GET", envA.GatewayURL+"/v1/deployments/list", nil)
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Request failed")
defer resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode, "Should list deployments")
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
json.Unmarshal(bodyBytes, &result)
deployments, _ := result["deployments"].([]interface{})
for _, d := range deployments {
dep, ok := d.(map[string]interface{})
if !ok {
continue
}
ns, _ := dep["namespace"].(string)
require.NotEqual(t, nsB, ns,
"FAIL: Namespace A sees Namespace B deployments - isolation broken!")
}
})
}
// TestDeployment_SubdomainFormat tests deployment subdomain format
func TestDeployment_SubdomainFormat(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
tarballPath := filepath.Join("../../testdata/apps/react-app")
if _, err := os.Stat(tarballPath); os.IsNotExist(err) {
t.Skip("Test tarball not found")
}
deploymentName := fmt.Sprintf("subdomain-test-%d", time.Now().UnixNano())
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID, "FAIL: Deployment creation failed")
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deployment has subdomain with random suffix", func(t *testing.T) {
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/get?id="+deploymentID, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to get deployment")
defer resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode, "Should get deployment")
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
json.Unmarshal(bodyBytes, &result)
deployment, ok := result["deployment"].(map[string]interface{})
if !ok {
deployment = result
}
subdomain, _ := deployment["subdomain"].(string)
if subdomain != "" {
require.True(t, strings.HasPrefix(subdomain, deploymentName),
"FAIL: Subdomain '%s' should start with deployment name '%s'", subdomain, deploymentName)
suffix := strings.TrimPrefix(subdomain, deploymentName+"-")
if suffix != subdomain { // There was a dash separator
require.Equal(t, 6, len(suffix),
"FAIL: Random suffix should be 6 characters, got %d (%s)", len(suffix), suffix)
}
t.Logf("Deployment subdomain: %s", subdomain)
}
})
}
// TestNamespaceCluster_PortAllocation tests port allocation correctness
func TestNamespaceCluster_PortAllocation(t *testing.T) {
t.Run("Port range is 10000-10099", func(t *testing.T) {
const portRangeStart = 10000
const portRangeEnd = 10099
const portsPerNamespace = 5
const maxNamespacesPerNode = 20
totalPorts := portRangeEnd - portRangeStart + 1
require.Equal(t, 100, totalPorts, "Port range should be 100 ports")
expectedMax := totalPorts / portsPerNamespace
require.Equal(t, maxNamespacesPerNode, expectedMax,
"Max namespaces per node calculation mismatch")
})
t.Run("Port assignments are sequential within block", func(t *testing.T) {
portStart := 10000
ports := map[string]int{
"rqlite_http": portStart + 0,
"rqlite_raft": portStart + 1,
"olric_http": portStart + 2,
"olric_memberlist": portStart + 3,
"gateway_http": portStart + 4,
}
seen := make(map[int]bool)
for name, port := range ports {
require.False(t, seen[port], "FAIL: Port %d for %s is duplicate", port, name)
seen[port] = true
}
})
}
// =============================================================================
// HELPER FUNCTIONS
// =============================================================================
func isPortListening(host string, port int) bool {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", host, port), 1*time.Second)
if err != nil {
return false
}
conn.Close()
return true
}
func getListeningPortsInRange(start, end int) []int {
var ports []int
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Check ports concurrently for speed
results := make(chan int, end-start+1)
for port := start; port <= end; port++ {
go func(p int) {
select {
case <-ctx.Done():
results <- 0
return
default:
if isPortListening("localhost", p) {
results <- p
} else {
results <- 0
}
}
}(port)
}
for i := 0; i <= end-start; i++ {
if port := <-results; port > 0 {
ports = append(ports, port)
}
}
return ports
}
func diffPorts(before, after []int) []int {
beforeMap := make(map[int]bool)
for _, p := range before {
beforeMap[p] = true
}
var newPorts []int
for _, p := range after {
if !beforeMap[p] {
newPorts = append(newPorts, p)
}
}
return newPorts
}
func filterPortsByOffset(ports []int, offset int) []int {
var filtered []int
for _, p := range ports {
if (p-10000)%5 == offset {
filtered = append(filtered, p)
}
}
return filtered
}
func min(a, b int) int {
if a < b {
return a
}
return b
}

View File

@ -1,447 +0,0 @@
//go:build e2e
package cluster_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestNamespaceIsolation creates two namespaces once and runs all isolation
// subtests against them. This keeps namespace usage to 2 regardless of how
// many isolation scenarios we test.
func TestNamespaceIsolation(t *testing.T) {
envA, err := e2e.LoadTestEnvWithNamespace("namespace-a-" + fmt.Sprintf("%d", time.Now().Unix()))
require.NoError(t, err, "Failed to create namespace A environment")
envB, err := e2e.LoadTestEnvWithNamespace("namespace-b-" + fmt.Sprintf("%d", time.Now().Unix()))
require.NoError(t, err, "Failed to create namespace B environment")
t.Run("Deployments", func(t *testing.T) {
testNamespaceIsolationDeployments(t, envA, envB)
})
t.Run("SQLiteDatabases", func(t *testing.T) {
testNamespaceIsolationSQLiteDatabases(t, envA, envB)
})
t.Run("IPFSContent", func(t *testing.T) {
testNamespaceIsolationIPFSContent(t, envA, envB)
})
t.Run("OlricCache", func(t *testing.T) {
testNamespaceIsolationOlricCache(t, envA, envB)
})
}
func testNamespaceIsolationDeployments(t *testing.T, envA, envB *e2e.E2ETestEnv) {
tarballPath := filepath.Join("../../testdata/apps/react-app")
// Create deployment in namespace-a
deploymentNameA := "test-app-ns-a"
deploymentIDA := e2e.CreateTestDeployment(t, envA, deploymentNameA, tarballPath)
defer func() {
if !envA.SkipCleanup {
e2e.DeleteDeployment(t, envA, deploymentIDA)
}
}()
// Create deployment in namespace-b
deploymentNameB := "test-app-ns-b"
deploymentIDB := e2e.CreateTestDeployment(t, envB, deploymentNameB, tarballPath)
defer func() {
if !envB.SkipCleanup {
e2e.DeleteDeployment(t, envB, deploymentIDB)
}
}()
t.Run("Namespace-A cannot list Namespace-B deployments", func(t *testing.T) {
req, _ := http.NewRequest("GET", envA.GatewayURL+"/v1/deployments/list", nil)
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
require.NoError(t, json.Unmarshal(bodyBytes, &result), "Should decode JSON")
deployments, ok := result["deployments"].([]interface{})
require.True(t, ok, "Deployments should be an array")
// Should only see namespace-a deployments
for _, d := range deployments {
dep, ok := d.(map[string]interface{})
if !ok {
continue
}
assert.NotEqual(t, deploymentNameB, dep["name"], "Should not see namespace-b deployment")
}
t.Logf("✓ Namespace A cannot see Namespace B deployments")
})
t.Run("Namespace-A cannot access Namespace-B deployment by ID", func(t *testing.T) {
req, _ := http.NewRequest("GET", envA.GatewayURL+"/v1/deployments/get?id="+deploymentIDB, nil)
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
// Should return 404 or 403
assert.Contains(t, []int{http.StatusNotFound, http.StatusForbidden}, resp.StatusCode,
"Should block cross-namespace access")
t.Logf("✓ Namespace A cannot access Namespace B deployment (status: %d)", resp.StatusCode)
})
t.Run("Namespace-A cannot delete Namespace-B deployment", func(t *testing.T) {
req, _ := http.NewRequest("DELETE", envA.GatewayURL+"/v1/deployments/delete?id="+deploymentIDB, nil)
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Contains(t, []int{http.StatusNotFound, http.StatusForbidden}, resp.StatusCode,
"Should block cross-namespace deletion")
// Verify deployment still exists for namespace-b
req2, _ := http.NewRequest("GET", envB.GatewayURL+"/v1/deployments/get?id="+deploymentIDB, nil)
req2.Header.Set("Authorization", "Bearer "+envB.APIKey)
resp2, err := envB.HTTPClient.Do(req2)
require.NoError(t, err, "Should execute request")
defer resp2.Body.Close()
assert.Equal(t, http.StatusOK, resp2.StatusCode, "Deployment should still exist in namespace B")
t.Logf("✓ Namespace A cannot delete Namespace B deployment")
})
}
func testNamespaceIsolationSQLiteDatabases(t *testing.T, envA, envB *e2e.E2ETestEnv) {
// Create database in namespace-a
dbNameA := "users-db-a"
e2e.CreateSQLiteDB(t, envA, dbNameA)
defer func() {
if !envA.SkipCleanup {
e2e.DeleteSQLiteDB(t, envA, dbNameA)
}
}()
// Create database in namespace-b
dbNameB := "users-db-b"
e2e.CreateSQLiteDB(t, envB, dbNameB)
defer func() {
if !envB.SkipCleanup {
e2e.DeleteSQLiteDB(t, envB, dbNameB)
}
}()
t.Run("Namespace-A cannot list Namespace-B databases", func(t *testing.T) {
req, _ := http.NewRequest("GET", envA.GatewayURL+"/v1/db/sqlite/list", nil)
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
require.NoError(t, json.Unmarshal(bodyBytes, &result), "Should decode JSON")
databases, ok := result["databases"].([]interface{})
require.True(t, ok, "Databases should be an array")
for _, db := range databases {
database, ok := db.(map[string]interface{})
if !ok {
continue
}
assert.NotEqual(t, dbNameB, database["database_name"], "Should not see namespace-b database")
}
t.Logf("✓ Namespace A cannot see Namespace B databases")
})
t.Run("Namespace-A cannot query Namespace-B database", func(t *testing.T) {
reqBody := map[string]interface{}{
"database_name": dbNameB,
"query": "SELECT * FROM users",
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envA.GatewayURL+"/v1/db/sqlite/query", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should block cross-namespace query")
t.Logf("✓ Namespace A cannot query Namespace B database")
})
t.Run("Namespace-A cannot backup Namespace-B database", func(t *testing.T) {
reqBody := map[string]string{"database_name": dbNameB}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envA.GatewayURL+"/v1/db/sqlite/backup", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should block cross-namespace backup")
t.Logf("✓ Namespace A cannot backup Namespace B database")
})
}
func testNamespaceIsolationIPFSContent(t *testing.T, envA, envB *e2e.E2ETestEnv) {
// Upload file in namespace-a
cidA := e2e.UploadTestFile(t, envA, "test-file-a.txt", "Content from namespace A")
defer func() {
if !envA.SkipCleanup {
e2e.UnpinFile(t, envA, cidA)
}
}()
t.Run("Namespace-B cannot GET Namespace-A IPFS content", func(t *testing.T) {
req, _ := http.NewRequest("GET", envB.GatewayURL+"/v1/storage/get/"+cidA, nil)
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Contains(t, []int{http.StatusNotFound, http.StatusForbidden}, resp.StatusCode,
"Should block cross-namespace IPFS GET")
t.Logf("✓ Namespace B cannot GET Namespace A IPFS content (status: %d)", resp.StatusCode)
})
t.Run("Namespace-B cannot PIN Namespace-A IPFS content", func(t *testing.T) {
reqBody := map[string]string{
"cid": cidA,
"name": "stolen-content",
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envB.GatewayURL+"/v1/storage/pin", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Contains(t, []int{http.StatusNotFound, http.StatusForbidden}, resp.StatusCode,
"Should block cross-namespace PIN")
t.Logf("✓ Namespace B cannot PIN Namespace A IPFS content (status: %d)", resp.StatusCode)
})
t.Run("Namespace-B cannot UNPIN Namespace-A IPFS content", func(t *testing.T) {
req, _ := http.NewRequest("DELETE", envB.GatewayURL+"/v1/storage/unpin/"+cidA, nil)
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Contains(t, []int{http.StatusNotFound, http.StatusForbidden}, resp.StatusCode,
"Should block cross-namespace UNPIN")
t.Logf("✓ Namespace B cannot UNPIN Namespace A IPFS content (status: %d)", resp.StatusCode)
})
t.Run("Namespace-A can list only their own IPFS pins", func(t *testing.T) {
t.Skip("List pins endpoint not implemented yet - namespace isolation enforced at GET/PIN/UNPIN levels")
})
}
func testNamespaceIsolationOlricCache(t *testing.T, envA, envB *e2e.E2ETestEnv) {
dmap := "test-cache"
keyA := "user-session-123"
valueA := `{"user_id": "alice", "token": "secret-token-a"}`
t.Run("Namespace-A sets cache key", func(t *testing.T) {
reqBody := map[string]interface{}{
"dmap": dmap,
"key": keyA,
"value": valueA,
"ttl": "300s",
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envA.GatewayURL+"/v1/cache/put", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envA.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envA.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Should set cache key successfully")
t.Logf("✓ Namespace A set cache key")
})
t.Run("Namespace-B cannot GET Namespace-A cache key", func(t *testing.T) {
reqBody := map[string]interface{}{
"dmap": dmap,
"key": keyA,
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envB.GatewayURL+"/v1/cache/get", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
// Should return 404 (key doesn't exist in namespace-b)
assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should not find key in different namespace")
t.Logf("✓ Namespace B cannot GET Namespace A cache key")
})
t.Run("Namespace-B cannot DELETE Namespace-A cache key", func(t *testing.T) {
reqBody := map[string]string{
"dmap": dmap,
"key": keyA,
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envB.GatewayURL+"/v1/cache/delete", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Contains(t, []int{http.StatusOK, http.StatusNotFound}, resp.StatusCode)
// Verify key still exists for namespace-a
reqBody2 := map[string]interface{}{
"dmap": dmap,
"key": keyA,
}
bodyBytes2, _ := json.Marshal(reqBody2)
req2, _ := http.NewRequest("POST", envA.GatewayURL+"/v1/cache/get", bytes.NewReader(bodyBytes2))
req2.Header.Set("Authorization", "Bearer "+envA.APIKey)
req2.Header.Set("Content-Type", "application/json")
resp2, err := envA.HTTPClient.Do(req2)
require.NoError(t, err, "Should execute request")
defer resp2.Body.Close()
assert.Equal(t, http.StatusOK, resp2.StatusCode, "Key should still exist in namespace A")
var result map[string]interface{}
bodyBytes3, _ := io.ReadAll(resp2.Body)
require.NoError(t, json.Unmarshal(bodyBytes3, &result), "Should decode result")
// Parse expected JSON string for comparison
var expectedValue map[string]interface{}
json.Unmarshal([]byte(valueA), &expectedValue)
assert.Equal(t, expectedValue, result["value"], "Value should match")
t.Logf("✓ Namespace B cannot DELETE Namespace A cache key")
})
t.Run("Namespace-B can set same key name in their namespace", func(t *testing.T) {
// Same key name, different namespace should be allowed
valueB := `{"user_id": "bob", "token": "secret-token-b"}`
reqBody := map[string]interface{}{
"dmap": dmap,
"key": keyA, // Same key name as namespace-a
"value": valueB,
"ttl": "300s",
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", envB.GatewayURL+"/v1/cache/put", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+envB.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := envB.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Should set key in namespace B")
// Verify namespace-a still has their value
reqBody2 := map[string]interface{}{
"dmap": dmap,
"key": keyA,
}
bodyBytes2, _ := json.Marshal(reqBody2)
req2, _ := http.NewRequest("POST", envA.GatewayURL+"/v1/cache/get", bytes.NewReader(bodyBytes2))
req2.Header.Set("Authorization", "Bearer "+envA.APIKey)
req2.Header.Set("Content-Type", "application/json")
resp2, _ := envA.HTTPClient.Do(req2)
defer resp2.Body.Close()
var resultA map[string]interface{}
bodyBytesA, _ := io.ReadAll(resp2.Body)
require.NoError(t, json.Unmarshal(bodyBytesA, &resultA), "Should decode result A")
// Parse expected JSON string for comparison
var expectedValueA map[string]interface{}
json.Unmarshal([]byte(valueA), &expectedValueA)
assert.Equal(t, expectedValueA, resultA["value"], "Namespace A value should be unchanged")
// Verify namespace-b has their different value
reqBody3 := map[string]interface{}{
"dmap": dmap,
"key": keyA,
}
bodyBytes3, _ := json.Marshal(reqBody3)
req3, _ := http.NewRequest("POST", envB.GatewayURL+"/v1/cache/get", bytes.NewReader(bodyBytes3))
req3.Header.Set("Authorization", "Bearer "+envB.APIKey)
req3.Header.Set("Content-Type", "application/json")
resp3, _ := envB.HTTPClient.Do(req3)
defer resp3.Body.Close()
var resultB map[string]interface{}
bodyBytesB, _ := io.ReadAll(resp3.Body)
require.NoError(t, json.Unmarshal(bodyBytesB, &resultB), "Should decode result B")
// Parse expected JSON string for comparison
var expectedValueB map[string]interface{}
json.Unmarshal([]byte(valueB), &expectedValueB)
assert.Equal(t, expectedValueB, resultB["value"], "Namespace B value should be different")
t.Logf("✓ Namespace B can set same key name independently")
t.Logf(" - Namespace A value: %s", valueA)
t.Logf(" - Namespace B value: %s", valueB)
})
}

View File

@ -1,177 +0,0 @@
//go:build e2e
package cluster
import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestRQLite_ReadConsistencyLevels tests that different consistency levels work.
func TestRQLite_ReadConsistencyLevels(t *testing.T) {
e2e.SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
gatewayURL := e2e.GetGatewayURL()
table := e2e.GenerateTableName()
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
// Create table
createReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, val TEXT)", table),
},
}
_, status, err := createReq.Do(ctx)
require.NoError(t, err)
require.True(t, status == http.StatusOK || status == http.StatusCreated, "create table got %d", status)
// Insert data
insertReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s(val) VALUES ('consistency-test')", table),
},
},
}
_, status, err = insertReq.Do(ctx)
require.NoError(t, err)
require.Equal(t, http.StatusOK, status)
t.Run("Default consistency read", func(t *testing.T) {
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT * FROM %s", table),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, status)
t.Logf("Default read: %s", string(body))
})
t.Run("Strong consistency read", func(t *testing.T) {
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/query?level=strong",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT * FROM %s", table),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, status)
t.Logf("Strong read: %s", string(body))
})
t.Run("Weak consistency read", func(t *testing.T) {
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/query?level=weak",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT * FROM %s", table),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, status)
t.Logf("Weak read: %s", string(body))
})
}
// TestRQLite_WriteAfterMultipleReads verifies write-read cycles stay consistent.
func TestRQLite_WriteAfterMultipleReads(t *testing.T) {
e2e.SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
gatewayURL := e2e.GetGatewayURL()
table := e2e.GenerateTableName()
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
createReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, counter INTEGER DEFAULT 0)", table),
},
}
_, status, err := createReq.Do(ctx)
require.NoError(t, err)
require.True(t, status == http.StatusOK || status == http.StatusCreated)
// Write-read cycle 10 times
for i := 1; i <= 10; i++ {
insertReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s(counter) VALUES (%d)", table, i),
},
},
}
_, status, err := insertReq.Do(ctx)
require.NoError(t, err, "insert %d failed", i)
require.Equal(t, http.StatusOK, status, "insert %d got status %d", i, status)
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) as cnt FROM %s", table),
},
}
body, _, _ := queryReq.Do(ctx)
t.Logf("Iteration %d: %s", i, string(body))
}
// Final verification
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: gatewayURL + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) as cnt FROM %s", table),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err)
require.Equal(t, http.StatusOK, status)
var result map[string]interface{}
json.Unmarshal(body, &result)
t.Logf("Final count result: %s", string(body))
}

View File

@ -1,6 +1,6 @@
//go:build e2e
package integration_test
package e2e
import (
"context"
@ -10,18 +10,16 @@ import (
"sync/atomic"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
)
// TestCache_ConcurrentWrites tests concurrent cache writes
func TestCache_ConcurrentWrites(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
numGoroutines := 10
var wg sync.WaitGroup
var errorCount int32
@ -34,9 +32,9 @@ func TestCache_ConcurrentWrites(t *testing.T) {
key := fmt.Sprintf("key-%d", idx)
value := fmt.Sprintf("value-%d", idx)
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -58,9 +56,9 @@ func TestCache_ConcurrentWrites(t *testing.T) {
}
// Verify all values exist
scanReq := &e2e.HTTPRequest{
scanReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/scan",
URL: GetGatewayURL() + "/v1/cache/scan",
Body: map[string]interface{}{
"dmap": dmap,
},
@ -72,7 +70,7 @@ func TestCache_ConcurrentWrites(t *testing.T) {
}
var scanResp map[string]interface{}
if err := e2e.DecodeJSON(body, &scanResp); err != nil {
if err := DecodeJSON(body, &scanResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -84,19 +82,19 @@ func TestCache_ConcurrentWrites(t *testing.T) {
// TestCache_ConcurrentReads tests concurrent cache reads
func TestCache_ConcurrentReads(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "shared-key"
value := "shared-value"
// Put value first
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -119,9 +117,9 @@ func TestCache_ConcurrentReads(t *testing.T) {
go func() {
defer wg.Done()
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -135,7 +133,7 @@ func TestCache_ConcurrentReads(t *testing.T) {
}
var getResp map[string]interface{}
if err := e2e.DecodeJSON(body, &getResp); err != nil {
if err := DecodeJSON(body, &getResp); err != nil {
atomic.AddInt32(&errorCount, 1)
return
}
@ -155,12 +153,12 @@ func TestCache_ConcurrentReads(t *testing.T) {
// TestCache_ConcurrentDeleteAndWrite tests concurrent delete and write
func TestCache_ConcurrentDeleteAndWrite(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
var wg sync.WaitGroup
var errorCount int32
@ -176,9 +174,9 @@ func TestCache_ConcurrentDeleteAndWrite(t *testing.T) {
key := fmt.Sprintf("key-%d", idx)
value := fmt.Sprintf("value-%d", idx)
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -203,9 +201,9 @@ func TestCache_ConcurrentDeleteAndWrite(t *testing.T) {
key := fmt.Sprintf("key-%d", idx)
deleteReq := &e2e.HTTPRequest{
deleteReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/delete",
URL: GetGatewayURL() + "/v1/cache/delete",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -228,32 +226,21 @@ func TestCache_ConcurrentDeleteAndWrite(t *testing.T) {
// TestRQLite_ConcurrentInserts tests concurrent database inserts
func TestRQLite_ConcurrentInserts(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
table := e2e.GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER)",
table,
)
// Create table
createReq := &e2e.HTTPRequest{
createReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -274,9 +261,9 @@ func TestRQLite_ConcurrentInserts(t *testing.T) {
go func(idx int) {
defer wg.Done()
txReq := &e2e.HTTPRequest{
txReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s(value) VALUES (%d)", table, idx),
@ -298,9 +285,9 @@ func TestRQLite_ConcurrentInserts(t *testing.T) {
}
// Verify count
queryReq := &e2e.HTTPRequest{
queryReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) as count FROM %s", table),
},
@ -312,7 +299,7 @@ func TestRQLite_ConcurrentInserts(t *testing.T) {
}
var countResp map[string]interface{}
if err := e2e.DecodeJSON(body, &countResp); err != nil {
if err := DecodeJSON(body, &countResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -327,32 +314,21 @@ func TestRQLite_ConcurrentInserts(t *testing.T) {
// TestRQLite_LargeBatchTransaction tests a large transaction with many statements
func TestRQLite_LargeBatchTransaction(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
table := e2e.GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value TEXT)",
table,
)
// Create table
createReq := &e2e.HTTPRequest{
createReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -372,9 +348,9 @@ func TestRQLite_LargeBatchTransaction(t *testing.T) {
})
}
txReq := &e2e.HTTPRequest{
txReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"ops": ops,
},
@ -386,9 +362,9 @@ func TestRQLite_LargeBatchTransaction(t *testing.T) {
}
// Verify count
queryReq := &e2e.HTTPRequest{
queryReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) as count FROM %s", table),
},
@ -400,7 +376,7 @@ func TestRQLite_LargeBatchTransaction(t *testing.T) {
}
var countResp map[string]interface{}
if err := e2e.DecodeJSON(body, &countResp); err != nil {
if err := DecodeJSON(body, &countResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -414,19 +390,19 @@ func TestRQLite_LargeBatchTransaction(t *testing.T) {
// TestCache_TTLExpiryWithSleep tests TTL expiry with a controlled sleep
func TestCache_TTLExpiryWithSleep(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "ttl-expiry-key"
value := "ttl-expiry-value"
// Put value with 2 second TTL
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -441,9 +417,9 @@ func TestCache_TTLExpiryWithSleep(t *testing.T) {
}
// Verify exists immediately
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -456,7 +432,7 @@ func TestCache_TTLExpiryWithSleep(t *testing.T) {
}
// Sleep for TTL duration + buffer
e2e.Delay(2500)
Delay(2500)
// Try to get after TTL expires
_, status, err = getReq.Do(ctx)
@ -467,21 +443,21 @@ func TestCache_TTLExpiryWithSleep(t *testing.T) {
// TestCache_ConcurrentWriteAndDelete tests concurrent writes and deletes on same key
func TestCache_ConcurrentWriteAndDelete(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
dmap := e2e.GenerateDMapName()
dmap := GenerateDMapName()
key := "contested-key"
// Alternate between writes and deletes
numIterations := 5
for i := 0; i < numIterations; i++ {
// Write
putReq := &e2e.HTTPRequest{
putReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/put",
URL: GetGatewayURL() + "/v1/cache/put",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -495,9 +471,9 @@ func TestCache_ConcurrentWriteAndDelete(t *testing.T) {
}
// Read
getReq := &e2e.HTTPRequest{
getReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/get",
URL: GetGatewayURL() + "/v1/cache/get",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,
@ -510,9 +486,9 @@ func TestCache_ConcurrentWriteAndDelete(t *testing.T) {
}
// Delete
deleteReq := &e2e.HTTPRequest{
deleteReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/cache/delete",
URL: GetGatewayURL() + "/v1/cache/delete",
Body: map[string]interface{}{
"dmap": dmap,
"key": key,

View File

@ -1,147 +0,0 @@
//go:build e2e
package e2e
import (
"os"
"path/filepath"
"gopkg.in/yaml.v2"
)
// E2EConfig holds the configuration for E2E tests
type E2EConfig struct {
// Mode can be "local" or "production"
Mode string `yaml:"mode"`
// BaseDomain is the domain used for deployment routing (e.g., "dbrs.space" or "orama.network")
BaseDomain string `yaml:"base_domain"`
// Servers is a list of production servers (only used when mode=production)
Servers []ServerConfig `yaml:"servers"`
// Nameservers is a list of nameserver hostnames (e.g., ["ns1.dbrs.space", "ns2.dbrs.space"])
Nameservers []string `yaml:"nameservers"`
// APIKey is the API key for production testing (auto-discovered if empty)
APIKey string `yaml:"api_key"`
}
// ServerConfig holds configuration for a single production server
type ServerConfig struct {
Name string `yaml:"name"`
IP string `yaml:"ip"`
User string `yaml:"user"`
Password string `yaml:"password"`
IsNameserver bool `yaml:"is_nameserver"`
}
// DefaultConfig returns the default configuration
func DefaultConfig() *E2EConfig {
return &E2EConfig{
Mode: "production",
BaseDomain: "orama.network",
Servers: []ServerConfig{},
Nameservers: []string{},
APIKey: "",
}
}
// LoadE2EConfig loads the E2E test configuration from e2e/config.yaml
// Falls back to defaults if the file doesn't exist
func LoadE2EConfig() (*E2EConfig, error) {
// Try multiple locations for the config file
configPaths := []string{
"config.yaml", // Relative to e2e directory (when running from e2e/)
"e2e/config.yaml", // Relative to project root
"../e2e/config.yaml", // From subdirectory within e2e/
}
// Also try absolute path based on working directory
if cwd, err := os.Getwd(); err == nil {
configPaths = append(configPaths, filepath.Join(cwd, "config.yaml"))
configPaths = append(configPaths, filepath.Join(cwd, "e2e", "config.yaml"))
// Go up one level if we're in a subdirectory
configPaths = append(configPaths, filepath.Join(cwd, "..", "config.yaml"))
}
var configData []byte
var readErr error
for _, path := range configPaths {
data, err := os.ReadFile(path)
if err == nil {
configData = data
break
}
readErr = err
}
// If no config file found, return defaults
if configData == nil {
// Check if running in production mode via environment variable
if os.Getenv("E2E_MODE") == "production" {
return nil, readErr // Config file required for production mode
}
return DefaultConfig(), nil
}
var cfg E2EConfig
if err := yaml.Unmarshal(configData, &cfg); err != nil {
return nil, err
}
// Apply defaults for empty values
if cfg.Mode == "" {
cfg.Mode = "production"
}
if cfg.BaseDomain == "" {
cfg.BaseDomain = "orama.network"
}
return &cfg, nil
}
// IsProductionMode returns true if running in production mode
func IsProductionMode() bool {
// Check environment variable first
if os.Getenv("E2E_MODE") == "production" {
return true
}
cfg, err := LoadE2EConfig()
if err != nil {
return false
}
return cfg.Mode == "production"
}
// GetServerIPs returns a list of all server IP addresses from config
func GetServerIPs(cfg *E2EConfig) []string {
if cfg == nil {
return nil
}
ips := make([]string, 0, len(cfg.Servers))
for _, server := range cfg.Servers {
if server.IP != "" {
ips = append(ips, server.IP)
}
}
return ips
}
// GetNameserverServers returns servers configured as nameservers
func GetNameserverServers(cfg *E2EConfig) []ServerConfig {
if cfg == nil {
return nil
}
var nameservers []ServerConfig
for _, server := range cfg.Servers {
if server.IsNameserver {
nameservers = append(nameservers, server)
}
}
return nameservers
}

View File

@ -1,45 +0,0 @@
# E2E Test Configuration
#
# Copy this file to config.yaml and fill in your values.
# config.yaml is git-ignored and should contain your actual credentials.
#
# Usage:
# cp config.yaml.example config.yaml
# # Edit config.yaml with your server credentials
# go test -v -tags e2e ./e2e/...
# Test mode: "local" or "production"
# - local: Tests run against `make dev` cluster on localhost
# - production: Tests run against real VPS servers
mode: local
# Base domain for deployment routing
# - Local: orama.network (default)
# - Production: dbrs.space (or your custom domain)
base_domain: orama.network
# Production servers (only used when mode=production)
# Add your VPS servers here with their credentials
servers:
# Example:
# - name: vps-1
# ip: 1.2.3.4
# user: ubuntu
# password: "your-password-here"
# is_nameserver: true
# - name: vps-2
# ip: 5.6.7.8
# user: ubuntu
# password: "another-password"
# is_nameserver: false
# Nameserver hostnames (for DNS tests in production)
# These should match your NS records
nameservers:
# Example:
# - ns1.yourdomain.com
# - ns2.yourdomain.com
# API key for production testing
# Leave empty to auto-discover from RQLite or create fresh key
api_key: ""

View File

@ -1,223 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"sync"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestDeploy_InvalidTarball verifies that uploading an invalid/corrupt tarball
// returns a clean error (not a 500 or panic).
func TestDeploy_InvalidTarball(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
deploymentName := fmt.Sprintf("invalid-tar-%d", time.Now().Unix())
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(deploymentName + "\r\n")
// Write invalid tarball data (random bytes, not a real gzip)
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.WriteString("this is not a valid tarball content at all!!!")
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/upload", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
t.Logf("Status: %d, Body: %s", resp.StatusCode, string(respBody))
// Should return an error, not 2xx (ideally 400, but server currently returns 500)
assert.True(t, resp.StatusCode >= 400,
"Invalid tarball should return error (got %d)", resp.StatusCode)
}
// TestDeploy_EmptyTarball verifies that uploading an empty file returns an error.
func TestDeploy_EmptyTarball(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
deploymentName := fmt.Sprintf("empty-tar-%d", time.Now().Unix())
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(deploymentName + "\r\n")
// Empty tarball
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/upload", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
t.Logf("Status: %d, Body: %s", resp.StatusCode, string(respBody))
assert.True(t, resp.StatusCode >= 400,
"Empty tarball should return error (got %d)", resp.StatusCode)
}
// TestDeploy_MissingName verifies that deploying without a name returns an error.
func TestDeploy_MissingName(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
tarballPath := filepath.Join("../../testdata/apps/react-app")
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
// No name field
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
// Create tarball from directory for the "no name" test
tarData, err := exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
if err != nil {
t.Skip("Failed to create tarball from test app")
}
body.Write(tarData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/upload", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.True(t, resp.StatusCode >= 400,
"Missing name should return error (got %d)", resp.StatusCode)
}
// TestDeploy_ConcurrentSameName verifies that deploying two apps with the same
// name concurrently doesn't cause data corruption.
func TestDeploy_ConcurrentSameName(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
deploymentName := fmt.Sprintf("concurrent-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var wg sync.WaitGroup
results := make([]int, 2)
ids := make([]string, 2)
// Pre-create tarball once for both goroutines
tarData, err := exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
if err != nil {
t.Skip("Failed to create tarball from test app")
}
for i := 0; i < 2; i++ {
wg.Add(1)
go func(idx int) {
defer wg.Done()
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(deploymentName + "\r\n")
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(tarData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/upload", body)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
results[idx] = resp.StatusCode
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
if id, ok := result["deployment_id"].(string); ok {
ids[idx] = id
} else if id, ok := result["id"].(string); ok {
ids[idx] = id
}
}(i)
}
wg.Wait()
t.Logf("Concurrent deploy results: status1=%d status2=%d id1=%s id2=%s",
results[0], results[1], ids[0], ids[1])
// At least one should succeed
successCount := 0
for _, status := range results {
if status == http.StatusCreated {
successCount++
}
}
assert.GreaterOrEqual(t, successCount, 1,
"At least one concurrent deploy should succeed")
// Cleanup
for _, id := range ids {
if id != "" {
e2e.DeleteDeployment(t, env, id)
}
}
}
func readFileBytes(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}

View File

@ -1,308 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestGoBackendWithSQLite tests Go backend deployment with hosted SQLite connectivity
// 1. Create hosted SQLite database
// 2. Deploy Go backend with DATABASE_NAME env var
// 3. POST /api/users → verify insert
// 4. GET /api/users → verify read
// 5. Cleanup
func TestGoBackendWithSQLite(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("go-sqlite-test-%d", time.Now().Unix())
dbName := fmt.Sprintf("test-db-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/go-api")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup {
if deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
// Delete the test database
deleteSQLiteDB(t, env, dbName)
}
}()
t.Run("Create SQLite database", func(t *testing.T) {
e2e.CreateSQLiteDB(t, env, dbName)
t.Logf("Created database: %s", dbName)
})
t.Run("Deploy Go backend with DATABASE_NAME", func(t *testing.T) {
deploymentID = createGoDeployment(t, env, deploymentName, tarballPath, map[string]string{
"DATABASE_NAME": dbName,
"GATEWAY_URL": env.GatewayURL,
"API_KEY": env.APIKey,
})
require.NotEmpty(t, deploymentID, "Deployment ID should not be empty")
t.Logf("Created Go deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Wait for deployment to become healthy", func(t *testing.T) {
healthy := e2e.WaitForHealthy(t, env, deploymentID, 90*time.Second)
require.True(t, healthy, "Deployment should become healthy")
t.Logf("Deployment is healthy")
})
t.Run("Test health endpoint", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/health")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Health check should return 200")
body, _ := io.ReadAll(resp.Body)
var health map[string]interface{}
require.NoError(t, json.Unmarshal(body, &health))
assert.Contains(t, []string{"healthy", "ok"}, health["status"])
t.Logf("Health response: %+v", health)
})
t.Run("POST /api/notes - create note", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
noteData := map[string]string{
"title": "Test Note",
"content": "This is a test note",
}
body, _ := json.Marshal(noteData)
req, err := http.NewRequest("POST", env.GatewayURL+"/api/notes", bytes.NewBuffer(body))
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
req.Host = domain
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusCreated, resp.StatusCode, "Should create note successfully")
var note map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&note))
assert.Equal(t, "Test Note", note["title"])
assert.Equal(t, "This is a test note", note["content"])
t.Logf("Created note: %+v", note)
})
t.Run("GET /api/notes - list notes", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/notes")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
var notes []map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&notes))
assert.GreaterOrEqual(t, len(notes), 1, "Should have at least one note")
found := false
for _, note := range notes {
if note["title"] == "Test Note" {
found = true
break
}
}
assert.True(t, found, "Test note should be in the list")
t.Logf("Notes count: %d", len(notes))
})
t.Run("DELETE /api/notes - delete note", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
// First get the note ID
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/notes")
defer resp.Body.Close()
var notes []map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&notes))
var noteID int
for _, note := range notes {
if note["title"] == "Test Note" {
noteID = int(note["id"].(float64))
break
}
}
require.NotZero(t, noteID, "Should find test note ID")
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/api/notes/%d", env.GatewayURL, noteID), nil)
require.NoError(t, err)
req.Host = domain
deleteResp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer deleteResp.Body.Close()
assert.Equal(t, http.StatusOK, deleteResp.StatusCode, "Should delete note successfully")
t.Logf("Deleted note ID: %d", noteID)
})
}
// createGoDeployment creates a Go backend deployment with environment variables
func createGoDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string, envVars map[string]string) string {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
if err != nil {
t.Fatalf("failed to stat tarball path: %v", err)
}
if info.IsDir() {
// Build Go binary for linux/amd64, then tar it
tmpDir, err := os.MkdirTemp("", "go-deploy-*")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
binaryPath := filepath.Join(tmpDir, "app")
buildCmd := exec.Command("go", "build", "-o", binaryPath, ".")
buildCmd.Dir = tarballPath
buildCmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
if out, err := buildCmd.CombinedOutput(); err != nil {
t.Fatalf("failed to build Go app: %v\n%s", err, string(out))
}
fileData, err = exec.Command("tar", "-czf", "-", "-C", tmpDir, ".").Output()
if err != nil {
t.Fatalf("failed to create tarball: %v", err)
}
} else {
file, err := os.Open(tarballPath)
if err != nil {
t.Fatalf("failed to open tarball: %v", err)
}
defer file.Close()
fileData, _ = io.ReadAll(file)
}
// Create multipart form
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
// Write name field
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
// Write environment variables
for key, value := range envVars {
body.WriteString("--" + boundary + "\r\n")
body.WriteString(fmt.Sprintf("Content-Disposition: form-data; name=\"env_%s\"\r\n\r\n", key))
body.WriteString(value + "\r\n")
}
// Write tarball file
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/go/upload", body)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to execute request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Deployment upload failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
if id, ok := result["deployment_id"].(string); ok {
return id
}
if id, ok := result["id"].(string); ok {
return id
}
t.Fatalf("Deployment response missing id field: %+v", result)
return ""
}
// deleteSQLiteDB deletes a SQLite database
func deleteSQLiteDB(t *testing.T, env *e2e.E2ETestEnv, dbName string) {
t.Helper()
req, err := http.NewRequest("DELETE", env.GatewayURL+"/v1/db/"+dbName, nil)
if err != nil {
t.Logf("warning: failed to create delete request: %v", err)
return
}
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Logf("warning: failed to delete database: %v", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Logf("warning: delete database returned status %d", resp.StatusCode)
}
}

View File

@ -1,264 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestNextJSDeployment_SSR tests Next.js deployment with SSR and API routes
// 1. Deploy Next.js app
// 2. Test SSR page (verify server-rendered HTML)
// 3. Test API routes (/api/hello, /api/data)
// 4. Test static assets
// 5. Cleanup
func TestNextJSDeployment_SSR(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("nextjs-ssr-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/nextjs-ssr.tar.gz")
var deploymentID string
// Check if tarball exists
if _, err := os.Stat(tarballPath); os.IsNotExist(err) {
t.Skip("Next.js SSR tarball not found at " + tarballPath)
}
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy Next.js SSR app", func(t *testing.T) {
deploymentID = createNextJSDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID, "Deployment ID should not be empty")
t.Logf("Created Next.js deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Wait for deployment to become healthy", func(t *testing.T) {
healthy := e2e.WaitForHealthy(t, env, deploymentID, 120*time.Second)
require.True(t, healthy, "Deployment should become healthy")
t.Logf("Deployment is healthy")
})
t.Run("Verify deployment in database", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
assert.Equal(t, deploymentName, deployment["name"], "Deployment name should match")
deploymentType, ok := deployment["type"].(string)
require.True(t, ok, "Type should be a string")
assert.Contains(t, deploymentType, "nextjs", "Type should be nextjs")
t.Logf("Deployment type: %s", deploymentType)
})
t.Run("Test SSR page - verify server-rendered HTML", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "SSR page should return 200")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "Should read response body")
bodyStr := string(body)
// Verify HTML is server-rendered (contains actual content, not just loading state)
assert.Contains(t, bodyStr, "Orama Network Next.js Test", "Should contain app title")
assert.Contains(t, bodyStr, "Server-Side Rendering Test", "Should contain SSR test marker")
assert.Contains(t, resp.Header.Get("Content-Type"), "text/html", "Should be HTML content")
t.Logf("SSR page loaded successfully")
t.Logf("Content-Type: %s", resp.Header.Get("Content-Type"))
})
t.Run("Test API route - /api/hello", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/hello")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "API route should return 200")
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result), "Should decode JSON response")
assert.Contains(t, result["message"], "Hello", "Should contain hello message")
assert.NotEmpty(t, result["timestamp"], "Should have timestamp")
t.Logf("API /hello response: %+v", result)
})
t.Run("Test API route - /api/data", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/api/data")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "API data route should return 200")
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result), "Should decode JSON response")
// Just verify it returns valid JSON
t.Logf("API /data response: %+v", result)
})
t.Run("Test static asset - _next directory", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
// First, get the main page to find the actual static asset path
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
bodyStr := string(body)
// Look for _next/static references in the HTML
if strings.Contains(bodyStr, "_next/static") {
t.Logf("Found _next/static references in HTML")
// Try to fetch a common static chunk
// The exact path depends on Next.js build output
// We'll just verify the _next directory structure is accessible
chunkResp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/_next/static/chunks/main.js")
defer chunkResp.Body.Close()
// It's OK if specific files don't exist (they have hashed names)
// Just verify we don't get a 500 error
assert.NotEqual(t, http.StatusInternalServerError, chunkResp.StatusCode,
"Static asset request should not cause server error")
t.Logf("Static asset request status: %d", chunkResp.StatusCode)
} else {
t.Logf("No _next/static references found (may be using different bundling)")
}
})
t.Run("Test 404 handling", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/nonexistent-page-xyz")
defer resp.Body.Close()
// Next.js should handle 404 gracefully
// Could be 404 or 200 depending on catch-all routes
assert.Contains(t, []int{200, 404}, resp.StatusCode,
"Should return either 200 (catch-all) or 404")
t.Logf("404 handling: status=%d", resp.StatusCode)
})
}
// createNextJSDeployment creates a Next.js deployment
func createNextJSDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) string {
t.Helper()
file, err := os.Open(tarballPath)
if err != nil {
t.Fatalf("failed to open tarball: %v", err)
}
defer file.Close()
// Create multipart form
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
// Write name field
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
// Write ssr field (enable SSR mode)
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"ssr\"\r\n\r\n")
body.WriteString("true\r\n")
// Write tarball file
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
fileData, _ := io.ReadAll(file)
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/nextjs/upload", body)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
// Use a longer timeout for large Next.js uploads (can be 50MB+)
uploadClient := e2e.NewHTTPClient(5 * time.Minute)
resp, err := uploadClient.Do(req)
if err != nil {
t.Fatalf("failed to execute request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Deployment upload failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
if id, ok := result["deployment_id"].(string); ok {
return id
}
if id, ok := result["id"].(string); ok {
return id
}
t.Fatalf("Deployment response missing id field: %+v", result)
return ""
}

View File

@ -1,203 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNodeJSDeployment_FullFlow(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("test-nodejs-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/node-api")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Upload Node.js backend", func(t *testing.T) {
deploymentID = createNodeJSDeployment(t, env, deploymentName, tarballPath)
assert.NotEmpty(t, deploymentID, "Deployment ID should not be empty")
t.Logf("Created deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Wait for deployment to become healthy", func(t *testing.T) {
healthy := e2e.WaitForHealthy(t, env, deploymentID, 90*time.Second)
assert.True(t, healthy, "Deployment should become healthy within timeout")
t.Logf("Deployment is healthy")
})
t.Run("Test health endpoint", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
// Get the deployment URLs (can be array of strings or map)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
// Test via Host header (localhost testing)
resp := e2e.TestDeploymentWithHostHeader(t, env, extractDomain(nodeURL), "/health")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Health check should return 200")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var health map[string]interface{}
require.NoError(t, json.Unmarshal(body, &health))
assert.Contains(t, []string{"healthy", "ok"}, health["status"],
"Health status should be 'healthy' or 'ok'")
t.Logf("Health check passed: %v", health)
})
t.Run("Test API endpoint", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
// Test health endpoint (node-api app serves /health)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/health")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var result map[string]interface{}
require.NoError(t, json.Unmarshal(body, &result))
assert.NotEmpty(t, result["service"])
t.Logf("API endpoint response: %v", result)
})
}
func createNodeJSDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) string {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
if err != nil {
t.Fatalf("Failed to stat tarball path: %v", err)
}
if info.IsDir() {
// Create tarball from directory
tarData, err := exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
require.NoError(t, err, "Failed to create tarball from %s", tarballPath)
fileData = tarData
} else {
file, err := os.Open(tarballPath)
require.NoError(t, err, "Failed to open tarball: %s", tarballPath)
defer file.Close()
fileData, _ = io.ReadAll(file)
}
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/nodejs/upload", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Deployment upload failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
if id, ok := result["deployment_id"].(string); ok {
return id
}
if id, ok := result["id"].(string); ok {
return id
}
t.Fatalf("Deployment response missing id field: %+v", result)
return ""
}
// extractNodeURL gets the node URL from deployment response
// Handles both array of strings and map formats
func extractNodeURL(t *testing.T, deployment map[string]interface{}) string {
t.Helper()
// Try as array of strings first (new format)
if urls, ok := deployment["urls"].([]interface{}); ok && len(urls) > 0 {
if url, ok := urls[0].(string); ok {
return url
}
}
// Try as map (legacy format)
if urls, ok := deployment["urls"].(map[string]interface{}); ok {
if url, ok := urls["node"].(string); ok {
return url
}
}
return ""
}
func extractDomain(url string) string {
// Extract domain from URL like "https://myapp.node-xyz.dbrs.space"
// Remove protocol
domain := url
if len(url) > 8 && url[:8] == "https://" {
domain = url[8:]
} else if len(url) > 7 && url[:7] == "http://" {
domain = url[7:]
}
// Remove trailing slash
if len(domain) > 0 && domain[len(domain)-1] == '/' {
domain = domain[:len(domain)-1]
}
return domain
}

View File

@ -1,352 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestStaticReplica_CreatedOnDeploy verifies that deploying a static app
// creates replica records on a second node.
func TestStaticReplica_CreatedOnDeploy(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("replica-static-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy static app", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
t.Logf("Created deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Wait for replica setup", func(t *testing.T) {
// Static replicas should set up quickly (IPFS content)
time.Sleep(10 * time.Second)
})
t.Run("Deployment has replica records", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
// Check that replicas field exists and has entries
replicas, ok := deployment["replicas"].([]interface{})
if !ok {
// Replicas might be in a nested structure or separate endpoint
t.Logf("Deployment response: %+v", deployment)
// Try querying replicas via the deployment details
homeNodeID, _ := deployment["home_node_id"].(string)
require.NotEmpty(t, homeNodeID, "Deployment should have a home_node_id")
t.Logf("Home node: %s", homeNodeID)
// If replicas aren't in the response, that's still okay — we verify
// via DNS and cross-node serving below
t.Log("Replica records not in deployment response; will verify via DNS/serving")
return
}
assert.GreaterOrEqual(t, len(replicas), 1, "Should have at least 1 replica")
t.Logf("Found %d replica records", len(replicas))
for i, r := range replicas {
if replica, ok := r.(map[string]interface{}); ok {
t.Logf(" Replica %d: node=%s status=%s", i, replica["node_id"], replica["status"])
}
}
})
t.Run("Static content served via gateway", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Static content should be served (got %d: %s)", resp.StatusCode, string(body))
t.Logf("Served via gateway: status=%d", resp.StatusCode)
})
}
// TestDynamicReplica_CreatedOnDeploy verifies that deploying a dynamic (Node.js) app
// creates a replica process on a second node.
func TestDynamicReplica_CreatedOnDeploy(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("replica-nodejs-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/node-api")
var deploymentID string
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy Node.js backend", func(t *testing.T) {
deploymentID = createNodeJSDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
t.Logf("Created deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Wait for deployment and replica", func(t *testing.T) {
healthy := e2e.WaitForHealthy(t, env, deploymentID, 90*time.Second)
assert.True(t, healthy, "Deployment should become healthy")
// Extra wait for async replica setup
time.Sleep(15 * time.Second)
})
t.Run("Dynamic app served from both nodes", func(t *testing.T) {
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
if nodeURL == "" {
t.Skip("No node URL in deployment")
}
domain := extractDomain(nodeURL)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/health")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Dynamic app should be served via gateway (got %d: %s)", resp.StatusCode, string(body))
t.Logf("Served via gateway: status=%d body=%s", resp.StatusCode, string(body))
})
}
// TestReplica_UpdatePropagation verifies that updating a deployment propagates to replicas.
func TestReplica_UpdatePropagation(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
deploymentName := fmt.Sprintf("replica-update-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy v1", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
time.Sleep(10 * time.Second) // Wait for replica
})
var v1CID string
t.Run("Record v1 CID", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
v1CID, _ = deployment["content_cid"].(string)
require.NotEmpty(t, v1CID)
t.Logf("v1 CID: %s", v1CID)
})
t.Run("Update to v2", func(t *testing.T) {
updateStaticDeployment(t, env, deploymentName, tarballPath)
time.Sleep(10 * time.Second) // Wait for update + replica propagation
})
t.Run("All nodes serve updated version", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
v2CID, _ := deployment["content_cid"].(string)
// v2 CID might be same (same tarball) but version should increment
version, _ := deployment["version"].(float64)
assert.Equal(t, float64(2), version, "Should be version 2")
t.Logf("v2 CID: %s, version: %v", v2CID, version)
// Verify via gateway
dep := e2e.GetDeployment(t, env, deploymentID)
depCID, _ := dep["content_cid"].(string)
assert.Equal(t, v2CID, depCID, "CID should match after update")
})
}
// TestReplica_RollbackPropagation verifies rollback propagates to replica nodes.
func TestReplica_RollbackPropagation(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
deploymentName := fmt.Sprintf("replica-rollback-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy v1 and update to v2", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
time.Sleep(10 * time.Second)
updateStaticDeployment(t, env, deploymentName, tarballPath)
time.Sleep(10 * time.Second)
})
var v1CID string
t.Run("Get v1 CID from versions", func(t *testing.T) {
versions := listVersions(t, env, deploymentName)
if len(versions) > 0 {
v1CID, _ = versions[0]["content_cid"].(string)
}
if v1CID == "" {
// Fall back: v1 CID from current deployment
deployment := e2e.GetDeployment(t, env, deploymentID)
v1CID, _ = deployment["content_cid"].(string)
}
t.Logf("v1 CID for rollback comparison: %s", v1CID)
})
t.Run("Rollback to v1", func(t *testing.T) {
rollbackDeployment(t, env, deploymentName, 1)
time.Sleep(10 * time.Second) // Wait for rollback + replica propagation
})
t.Run("All nodes have rolled-back CID", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
currentCID, _ := deployment["content_cid"].(string)
t.Logf("Post-rollback CID: %s", currentCID)
assert.Equal(t, v1CID, currentCID, "CID should match v1 after rollback")
})
}
// TestReplica_TeardownOnDelete verifies that deleting a deployment removes replicas.
func TestReplica_TeardownOnDelete(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
deploymentName := fmt.Sprintf("replica-delete-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
time.Sleep(10 * time.Second) // Wait for replica
// Get the domain before deletion
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
domain := ""
if nodeURL != "" {
domain = extractDomain(nodeURL)
}
t.Run("Delete deployment", func(t *testing.T) {
e2e.DeleteDeployment(t, env, deploymentID)
time.Sleep(10 * time.Second) // Wait for teardown propagation
})
t.Run("Deployment no longer served on any node", func(t *testing.T) {
if domain == "" {
t.Skip("No domain to test")
}
req, err := http.NewRequest("GET", env.GatewayURL+"/", nil)
require.NoError(t, err)
req.Host = domain
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Logf("Connection failed (expected after deletion)")
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode == http.StatusOK {
assert.NotContains(t, string(body), "<div id=\"root\">",
"Deleted deployment should not be served")
}
t.Logf("status=%d (expected non-200)", resp.StatusCode)
})
}
// updateStaticDeployment updates an existing static deployment.
func updateStaticDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
require.NoError(t, err)
if info.IsDir() {
fileData, err = exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
require.NoError(t, err)
} else {
file, err := os.Open(tarballPath)
require.NoError(t, err)
defer file.Close()
fileData, _ = io.ReadAll(file)
}
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/update", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Update failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
}

View File

@ -1,232 +0,0 @@
//go:build e2e
package deployments_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestDeploymentRollback_FullFlow tests the complete rollback workflow:
// 1. Deploy v1
// 2. Update to v2
// 3. Verify v2 content
// 4. Rollback to v1
// 5. Verify v1 content is restored
func TestDeploymentRollback_FullFlow(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("rollback-test-%d", time.Now().Unix())
tarballPathV1 := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy v1", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPathV1)
require.NotEmpty(t, deploymentID, "Deployment ID should not be empty")
t.Logf("Created deployment v1: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Verify v1 deployment", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
version, ok := deployment["version"].(float64)
require.True(t, ok, "Version should be a number")
assert.Equal(t, float64(1), version, "Initial version should be 1")
contentCID, ok := deployment["content_cid"].(string)
require.True(t, ok, "Content CID should be a string")
assert.NotEmpty(t, contentCID, "Content CID should not be empty")
t.Logf("v1 version: %v, CID: %s", version, contentCID)
})
var v1CID string
t.Run("Save v1 CID", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
v1CID = deployment["content_cid"].(string)
t.Logf("Saved v1 CID: %s", v1CID)
})
t.Run("Update to v2", func(t *testing.T) {
// Update the deployment with the same tarball (simulates a new version)
updateDeployment(t, env, deploymentName, tarballPathV1)
// Wait for update to complete
time.Sleep(2 * time.Second)
})
t.Run("Verify v2 deployment", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
version, ok := deployment["version"].(float64)
require.True(t, ok, "Version should be a number")
assert.Equal(t, float64(2), version, "Version should be 2 after update")
t.Logf("v2 version: %v", version)
})
t.Run("List deployment versions", func(t *testing.T) {
versions := listVersions(t, env, deploymentName)
t.Logf("Available versions: %+v", versions)
// Should have at least 2 versions in history
assert.GreaterOrEqual(t, len(versions), 1, "Should have version history")
})
t.Run("Rollback to v1", func(t *testing.T) {
rollbackDeployment(t, env, deploymentName, 1)
// Wait for rollback to complete
time.Sleep(2 * time.Second)
})
t.Run("Verify rollback succeeded", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
version, ok := deployment["version"].(float64)
require.True(t, ok, "Version should be a number")
// Note: Version number increases even on rollback (it's a new deployment version)
// But the content_cid should be the same as v1
t.Logf("Post-rollback version: %v", version)
contentCID, ok := deployment["content_cid"].(string)
require.True(t, ok, "Content CID should be a string")
assert.Equal(t, v1CID, contentCID, "Content CID should match v1 after rollback")
t.Logf("Rollback verified - content CID matches v1: %s", contentCID)
})
}
// updateDeployment updates an existing static deployment
func updateDeployment(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
require.NoError(t, err)
if info.IsDir() {
fileData, err = exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
require.NoError(t, err)
} else {
file, err := os.Open(tarballPath)
require.NoError(t, err, "Failed to open tarball")
defer file.Close()
fileData, _ = io.ReadAll(file)
}
// Create multipart form
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
// Write name field
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
// Write tarball file
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/update", body)
require.NoError(t, err, "Failed to create request")
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to execute request")
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Update failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result), "Failed to decode response")
t.Logf("Update response: %+v", result)
}
// listVersions lists available versions for a deployment
func listVersions(t *testing.T, env *e2e.E2ETestEnv, name string) []map[string]interface{} {
t.Helper()
req, err := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/versions?name="+name, nil)
require.NoError(t, err, "Failed to create request")
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to execute request")
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Logf("List versions returned status %d: %s", resp.StatusCode, string(bodyBytes))
return nil
}
var result struct {
Versions []map[string]interface{} `json:"versions"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Logf("Failed to decode versions: %v", err)
return nil
}
return result.Versions
}
// rollbackDeployment triggers a rollback to a specific version
func rollbackDeployment(t *testing.T, env *e2e.E2ETestEnv, name string, targetVersion int) {
t.Helper()
reqBody := map[string]interface{}{
"name": name,
"version": targetVersion,
}
bodyBytes, _ := json.Marshal(reqBody)
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/rollback", bytes.NewBuffer(bodyBytes))
require.NoError(t, err, "Failed to create request")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Failed to execute request")
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Rollback failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result), "Failed to decode response")
t.Logf("Rollback response: %+v", result)
}

View File

@ -1,210 +0,0 @@
//go:build e2e
package deployments_test
import (
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStaticDeployment_FullFlow(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("test-static-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Upload static tarball", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
assert.NotEmpty(t, deploymentID, "Deployment ID should not be empty")
t.Logf("✓ Created deployment: %s (ID: %s)", deploymentName, deploymentID)
})
t.Run("Verify deployment in database", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
assert.Equal(t, deploymentName, deployment["name"], "Deployment name should match")
assert.NotEmpty(t, deployment["content_cid"], "Content CID should not be empty")
// Status might be "deploying" or "active" depending on timing
status, ok := deployment["status"].(string)
require.True(t, ok, "Status should be a string")
assert.Contains(t, []string{"deploying", "active"}, status, "Status should be deploying or active")
t.Logf("✓ Deployment verified in database")
t.Logf(" - Name: %s", deployment["name"])
t.Logf(" - Status: %s", status)
t.Logf(" - CID: %s", deployment["content_cid"])
})
t.Run("Verify DNS record creation", func(t *testing.T) {
// Wait for deployment to become active
time.Sleep(2 * time.Second)
// Get the actual domain from deployment response
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
require.NotEmpty(t, nodeURL, "Deployment should have a URL")
expectedDomain := extractDomain(nodeURL)
// Make request with Host header (localhost testing)
resp := e2e.TestDeploymentWithHostHeader(t, env, expectedDomain, "/")
defer resp.Body.Close()
// Should return 200 with React app HTML
assert.Equal(t, http.StatusOK, resp.StatusCode, "Should return 200 OK")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "Should read response body")
bodyStr := string(body)
// Verify React app content
assert.Contains(t, bodyStr, "<div id=\"root\">", "Should contain React root div")
assert.Contains(t, resp.Header.Get("Content-Type"), "text/html", "Content-Type should be text/html")
t.Logf("✓ Domain routing works")
t.Logf(" - Domain: %s", expectedDomain)
t.Logf(" - Status: %d", resp.StatusCode)
t.Logf(" - Content-Type: %s", resp.Header.Get("Content-Type"))
})
t.Run("Verify static assets serve correctly", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
require.NotEmpty(t, nodeURL, "Deployment should have a URL")
expectedDomain := extractDomain(nodeURL)
// Test CSS file (exact path depends on Vite build output)
// We'll just test a few common asset paths
assetPaths := []struct {
path string
contentType string
}{
{"/index.html", "text/html"},
// Note: Asset paths with hashes change on each build
// We'll test what we can
}
for _, asset := range assetPaths {
resp := e2e.TestDeploymentWithHostHeader(t, env, expectedDomain, asset.path)
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
assert.Contains(t, resp.Header.Get("Content-Type"), asset.contentType,
"Content-Type should be %s for %s", asset.contentType, asset.path)
t.Logf("✓ Asset served correctly: %s (%s)", asset.path, asset.contentType)
}
}
})
t.Run("Verify SPA fallback routing", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
require.NotEmpty(t, nodeURL, "Deployment should have a URL")
expectedDomain := extractDomain(nodeURL)
// Request unknown route (should return index.html for SPA)
resp := e2e.TestDeploymentWithHostHeader(t, env, expectedDomain, "/about/team")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "SPA fallback should return 200")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "Should read response body")
assert.Contains(t, string(body), "<div id=\"root\">", "Should return index.html for unknown paths")
t.Logf("✓ SPA fallback routing works")
})
t.Run("List deployments", func(t *testing.T) {
req, err := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/list", nil)
require.NoError(t, err, "Should create request")
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "List deployments should return 200")
var result map[string]interface{}
require.NoError(t, e2e.DecodeJSON(mustReadAll(t, resp.Body), &result), "Should decode JSON")
deployments, ok := result["deployments"].([]interface{})
require.True(t, ok, "Deployments should be an array")
assert.GreaterOrEqual(t, len(deployments), 1, "Should have at least one deployment")
// Find our deployment
found := false
for _, d := range deployments {
dep, ok := d.(map[string]interface{})
if !ok {
continue
}
if dep["name"] == deploymentName {
found = true
t.Logf("✓ Found deployment in list: %s", deploymentName)
break
}
}
assert.True(t, found, "Deployment should be in list")
})
t.Run("Delete deployment", func(t *testing.T) {
e2e.DeleteDeployment(t, env, deploymentID)
// Verify deletion - allow time for replication
time.Sleep(3 * time.Second)
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/get?id="+deploymentID, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
t.Logf("Delete verification response: status=%d body=%s", resp.StatusCode, string(body))
// After deletion, either 404 (not found) or 200 with empty/error response is acceptable
if resp.StatusCode == http.StatusOK {
// If 200, check if the deployment is actually gone
t.Logf("Got 200 - this may indicate soft delete or eventual consistency")
}
t.Logf("✓ Deployment deleted successfully")
// Clear deploymentID so cleanup doesn't try to delete again
deploymentID = ""
})
}
func mustReadAll(t *testing.T, r io.Reader) []byte {
t.Helper()
data, err := io.ReadAll(r)
require.NoError(t, err, "Should read all data")
return data
}

View File

@ -15,7 +15,6 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
@ -41,73 +40,6 @@ var (
cacheMutex sync.RWMutex
)
// createAPIKeyWithProvisioning creates an API key for a namespace, handling async provisioning
// For non-default namespaces, this may trigger cluster provisioning and wait for it to complete.
func createAPIKeyWithProvisioning(gatewayURL, wallet, namespace string, timeout time.Duration) (string, error) {
httpClient := NewHTTPClient(10 * time.Second)
makeRequest := func() (*http.Response, []byte, error) {
reqBody := map[string]string{
"wallet": wallet,
"namespace": namespace,
}
bodyBytes, _ := json.Marshal(reqBody)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "POST", gatewayURL+"/v1/auth/simple-key", bytes.NewReader(bodyBytes))
if err != nil {
return nil, nil, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := httpClient.Do(req)
if err != nil {
return nil, nil, fmt.Errorf("request failed: %w", err)
}
respBody, _ := io.ReadAll(resp.Body)
resp.Body.Close()
return resp, respBody, nil
}
startTime := time.Now()
for {
if time.Since(startTime) > timeout {
return "", fmt.Errorf("timeout waiting for namespace provisioning")
}
resp, respBody, err := makeRequest()
if err != nil {
return "", err
}
// If we got 200, extract the API key
if resp.StatusCode == http.StatusOK {
var apiKeyResp map[string]interface{}
if err := json.Unmarshal(respBody, &apiKeyResp); err != nil {
return "", fmt.Errorf("failed to decode API key response: %w", err)
}
apiKey, ok := apiKeyResp["api_key"].(string)
if !ok || apiKey == "" {
return "", fmt.Errorf("API key not found in response")
}
return apiKey, nil
}
// If we got 202 Accepted, provisioning is in progress
if resp.StatusCode == http.StatusAccepted {
// Wait and retry - the cluster is being provisioned
time.Sleep(5 * time.Second)
continue
}
// Any other status is an error
return "", fmt.Errorf("API key creation failed with status %d: %s", resp.StatusCode, string(respBody))
}
}
// loadGatewayConfig loads gateway configuration from ~/.orama/gateway.yaml
func loadGatewayConfig() (map[string]interface{}, error) {
configPath, err := config.DefaultPath("gateway.yaml")
@ -148,90 +80,6 @@ func loadNodeConfig(filename string) (map[string]interface{}, error) {
return cfg, nil
}
// loadActiveEnvironment reads ~/.orama/environments.json and returns the active environment's gateway URL.
func loadActiveEnvironment() (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
data, err := os.ReadFile(filepath.Join(homeDir, ".orama", "environments.json"))
if err != nil {
return "", err
}
var envConfig struct {
Environments []struct {
Name string `json:"name"`
GatewayURL string `json:"gateway_url"`
} `json:"environments"`
ActiveEnvironment string `json:"active_environment"`
}
if err := json.Unmarshal(data, &envConfig); err != nil {
return "", err
}
for _, env := range envConfig.Environments {
if env.Name == envConfig.ActiveEnvironment {
return env.GatewayURL, nil
}
}
return "", fmt.Errorf("active environment %q not found", envConfig.ActiveEnvironment)
}
// loadCredentialAPIKey reads ~/.orama/credentials.json and returns the API key for the given gateway URL.
func loadCredentialAPIKey(gatewayURL string) (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
data, err := os.ReadFile(filepath.Join(homeDir, ".orama", "credentials.json"))
if err != nil {
return "", err
}
// credentials.json v2 format: gateways -> url -> credentials[] array
var store struct {
Gateways map[string]json.RawMessage `json:"gateways"`
}
if err := json.Unmarshal(data, &store); err != nil {
return "", err
}
raw, ok := store.Gateways[gatewayURL]
if !ok {
return "", fmt.Errorf("no credentials for gateway %s", gatewayURL)
}
// Try v2 format: { "credentials": [...], "default_index": 0 }
var v2 struct {
Credentials []struct {
APIKey string `json:"api_key"`
Namespace string `json:"namespace"`
} `json:"credentials"`
DefaultIndex int `json:"default_index"`
}
if err := json.Unmarshal(raw, &v2); err == nil && len(v2.Credentials) > 0 {
idx := v2.DefaultIndex
if idx >= len(v2.Credentials) {
idx = 0
}
return v2.Credentials[idx].APIKey, nil
}
// Try v1 format: direct Credentials object { "api_key": "..." }
var v1 struct {
APIKey string `json:"api_key"`
}
if err := json.Unmarshal(raw, &v1); err == nil && v1.APIKey != "" {
return v1.APIKey, nil
}
return "", fmt.Errorf("no API key found in credentials for %s", gatewayURL)
}
// GetGatewayURL returns the gateway base URL from config
func GetGatewayURL() string {
cacheMutex.RLock()
@ -241,13 +89,7 @@ func GetGatewayURL() string {
}
cacheMutex.RUnlock()
// Check environment variables first (ORAMA_GATEWAY_URL takes precedence)
if envURL := os.Getenv("ORAMA_GATEWAY_URL"); envURL != "" {
cacheMutex.Lock()
gatewayURLCache = envURL
cacheMutex.Unlock()
return envURL
}
// Check environment variable first
if envURL := os.Getenv("GATEWAY_URL"); envURL != "" {
cacheMutex.Lock()
gatewayURLCache = envURL
@ -255,14 +97,6 @@ func GetGatewayURL() string {
return envURL
}
// Try to load from orama active environment (~/.orama/environments.json)
if envURL, err := loadActiveEnvironment(); err == nil && envURL != "" {
cacheMutex.Lock()
gatewayURLCache = envURL
cacheMutex.Unlock()
return envURL
}
// Try to load from gateway config
gwCfg, err := loadGatewayConfig()
if err == nil {
@ -277,8 +111,8 @@ func GetGatewayURL() string {
}
}
// Fallback to devnet
return "https://orama-devnet.network"
// Default fallback
return "http://localhost:6001"
}
// GetRQLiteNodes returns rqlite endpoint addresses from config
@ -290,34 +124,50 @@ func GetRQLiteNodes() []string {
}
cacheMutex.RUnlock()
// No fallback — require explicit configuration via RQLITE_NODES env var
return nil
// Try all node config files
for _, cfgFile := range []string{"node-1.yaml", "node-2.yaml", "node-3.yaml", "node-4.yaml", "node-5.yaml"} {
nodeCfg, err := loadNodeConfig(cfgFile)
if err != nil {
continue
}
if db, ok := nodeCfg["database"].(map[interface{}]interface{}); ok {
if rqlitePort, ok := db["rqlite_port"].(int); ok {
nodes := []string{fmt.Sprintf("http://localhost:%d", rqlitePort)}
cacheMutex.Lock()
rqliteCache = nodes
cacheMutex.Unlock()
return nodes
}
}
}
// Default fallback
return []string{"http://localhost:5001"}
}
// queryAPIKeyFromRQLite queries the SQLite database directly for an API key
func queryAPIKeyFromRQLite() (string, error) {
// 1. Check environment variable first
if envKey := os.Getenv("ORAMA_API_KEY"); envKey != "" {
if envKey := os.Getenv("DEBROS_API_KEY"); envKey != "" {
return envKey, nil
}
// 2. If ORAMA_GATEWAY_URL is set (production mode), query the remote RQLite HTTP API
if gatewayURL := os.Getenv("ORAMA_GATEWAY_URL"); gatewayURL != "" {
apiKey, err := queryAPIKeyFromRemoteRQLite(gatewayURL)
if err == nil && apiKey != "" {
return apiKey, nil
}
// Fall through to local database check if remote fails
}
// 3. Build database path from node config
// 2. Build database path from bootstrap/node config
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("failed to get home directory: %w", err)
}
// Production paths (~/.orama/data/node-x/...)
// Try all node data directories (both production and development paths)
dbPaths := []string{
// Development paths (~/.orama/node-x/...)
filepath.Join(homeDir, ".orama", "node-1", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "node-2", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "node-3", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "node-4", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "node-5", "rqlite", "db.sqlite"),
// Production paths (~/.orama/data/node-x/...)
filepath.Join(homeDir, ".orama", "data", "node-1", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "data", "node-2", "rqlite", "db.sqlite"),
filepath.Join(homeDir, ".orama", "data", "node-3", "rqlite", "db.sqlite"),
@ -360,61 +210,7 @@ func queryAPIKeyFromRQLite() (string, error) {
return "", fmt.Errorf("failed to retrieve API key from any SQLite database")
}
// queryAPIKeyFromRemoteRQLite queries the remote RQLite HTTP API for an API key
func queryAPIKeyFromRemoteRQLite(gatewayURL string) (string, error) {
// Parse the gateway URL to extract the host
parsed, err := url.Parse(gatewayURL)
if err != nil {
return "", fmt.Errorf("failed to parse gateway URL: %w", err)
}
// RQLite HTTP API runs on port 5001 (not the gateway port 6001)
rqliteURL := fmt.Sprintf("http://%s:5001/db/query", parsed.Hostname())
// Create request body
reqBody := `["SELECT key FROM api_keys LIMIT 1"]`
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, rqliteURL, strings.NewReader(reqBody))
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to query rqlite: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("rqlite returned status %d", resp.StatusCode)
}
// Parse response
var result struct {
Results []struct {
Columns []string `json:"columns"`
Values [][]interface{} `json:"values"`
} `json:"results"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("failed to decode response: %w", err)
}
if len(result.Results) > 0 && len(result.Results[0].Values) > 0 && len(result.Results[0].Values[0]) > 0 {
if apiKey, ok := result.Results[0].Values[0][0].(string); ok && apiKey != "" {
return apiKey, nil
}
}
return "", fmt.Errorf("no API key found in rqlite")
}
// GetAPIKey returns the gateway API key from credentials.json, env vars, or rqlite
// GetAPIKey returns the gateway API key from rqlite or cache
func GetAPIKey() string {
cacheMutex.RLock()
if apiKeyCache != "" {
@ -423,24 +219,7 @@ func GetAPIKey() string {
}
cacheMutex.RUnlock()
// 1. Check env var
if envKey := os.Getenv("ORAMA_API_KEY"); envKey != "" {
cacheMutex.Lock()
apiKeyCache = envKey
cacheMutex.Unlock()
return envKey
}
// 2. Try credentials.json for the active gateway
gatewayURL := GetGatewayURL()
if apiKey, err := loadCredentialAPIKey(gatewayURL); err == nil && apiKey != "" {
cacheMutex.Lock()
apiKeyCache = apiKey
cacheMutex.Unlock()
return apiKey
}
// 3. Fall back to querying rqlite directly
// Query rqlite for API key
apiKey, err := queryAPIKeyFromRQLite()
if err != nil {
return ""
@ -453,6 +232,11 @@ func GetAPIKey() string {
return apiKey
}
// GetJWT returns the gateway JWT token (currently not auto-discovered)
func GetJWT() string {
return ""
}
// GetBootstrapPeers returns bootstrap peer addresses from config
func GetBootstrapPeers() []string {
cacheMutex.RLock()
@ -531,8 +315,8 @@ func GetIPFSClusterURL() string {
}
}
// No fallback — require explicit configuration
return ""
// Default fallback
return "http://localhost:9094"
}
// GetIPFSAPIURL returns the IPFS API URL from config
@ -563,8 +347,8 @@ func GetIPFSAPIURL() string {
}
}
// No fallback — require explicit configuration
return ""
// Default fallback
return "http://localhost:5001"
}
// GetClientNamespace returns the test client namespace from config
@ -718,6 +502,10 @@ func NewNetworkClient(t *testing.T) client.NetworkClient {
cfg.APIKey = GetAPIKey()
cfg.QuietMode = true // Suppress debug logs in tests
if jwt := GetJWT(); jwt != "" {
cfg.JWT = jwt
}
if peers := GetBootstrapPeers(); len(peers) > 0 {
cfg.BootstrapPeers = peers
}
@ -1178,554 +966,3 @@ func (p *WSPubSubClientPair) Close() {
p.Subscriber.Close()
}
}
// ============================================================================
// Deployment Testing Helpers
// ============================================================================
// E2ETestEnv holds the environment configuration for deployment E2E tests
type E2ETestEnv struct {
GatewayURL string
APIKey string
Namespace string
BaseDomain string // Domain for deployment routing (e.g., "dbrs.space")
Config *E2EConfig // Full E2E configuration (for production tests)
HTTPClient *http.Client
SkipCleanup bool
}
// BuildDeploymentDomain returns the full domain for a deployment name
// Format: {name}.{baseDomain} (e.g., "myapp.dbrs.space")
func (env *E2ETestEnv) BuildDeploymentDomain(deploymentName string) string {
return fmt.Sprintf("%s.%s", deploymentName, env.BaseDomain)
}
// LoadTestEnv loads the test environment from environment variables and config file
// If ORAMA_API_KEY is not set, it creates a fresh API key for the default test namespace
func LoadTestEnv() (*E2ETestEnv, error) {
// Load E2E config (for base_domain and production settings)
cfg, err := LoadE2EConfig()
if err != nil {
cfg = DefaultConfig()
}
gatewayURL := os.Getenv("ORAMA_GATEWAY_URL")
if gatewayURL == "" {
gatewayURL = GetGatewayURL()
}
// Check if API key is provided via environment variable, config, or credentials.json
apiKey := os.Getenv("ORAMA_API_KEY")
if apiKey == "" && cfg.APIKey != "" {
apiKey = cfg.APIKey
}
if apiKey == "" {
apiKey = GetAPIKey() // Reads from credentials.json or rqlite
}
namespace := os.Getenv("ORAMA_NAMESPACE")
// If still no API key, create a fresh one for a default test namespace
if apiKey == "" {
if namespace == "" {
namespace = "default-test-ns"
}
// Generate a unique wallet address for this namespace
wallet := fmt.Sprintf("0x%x", []byte(namespace+fmt.Sprintf("%d", time.Now().UnixNano())))
if len(wallet) < 42 {
wallet = wallet + strings.Repeat("0", 42-len(wallet))
}
if len(wallet) > 42 {
wallet = wallet[:42]
}
// Create an API key for this namespace (handles async provisioning for non-default namespaces)
var err error
apiKey, err = createAPIKeyWithProvisioning(gatewayURL, wallet, namespace, 2*time.Minute)
if err != nil {
return nil, fmt.Errorf("failed to create API key for namespace %s: %w", namespace, err)
}
} else if namespace == "" {
namespace = GetClientNamespace()
}
skipCleanup := os.Getenv("ORAMA_SKIP_CLEANUP") == "true"
return &E2ETestEnv{
GatewayURL: gatewayURL,
APIKey: apiKey,
Namespace: namespace,
BaseDomain: cfg.BaseDomain,
Config: cfg,
HTTPClient: NewHTTPClient(30 * time.Second),
SkipCleanup: skipCleanup,
}, nil
}
// LoadTestEnvWithNamespace loads test environment with a specific namespace
// It creates a new API key for the specified namespace to ensure proper isolation
func LoadTestEnvWithNamespace(namespace string) (*E2ETestEnv, error) {
// Load E2E config (for base_domain and production settings)
cfg, err := LoadE2EConfig()
if err != nil {
cfg = DefaultConfig()
}
gatewayURL := os.Getenv("ORAMA_GATEWAY_URL")
if gatewayURL == "" {
gatewayURL = GetGatewayURL()
}
skipCleanup := os.Getenv("ORAMA_SKIP_CLEANUP") == "true"
// Generate a unique wallet address for this namespace
// Using namespace as part of the wallet address for uniqueness
wallet := fmt.Sprintf("0x%x", []byte(namespace+fmt.Sprintf("%d", time.Now().UnixNano())))
if len(wallet) < 42 {
wallet = wallet + strings.Repeat("0", 42-len(wallet))
}
if len(wallet) > 42 {
wallet = wallet[:42]
}
// Create an API key for this namespace (handles async provisioning for non-default namespaces)
apiKey, err := createAPIKeyWithProvisioning(gatewayURL, wallet, namespace, 2*time.Minute)
if err != nil {
return nil, fmt.Errorf("failed to create API key for namespace %s: %w", namespace, err)
}
return &E2ETestEnv{
GatewayURL: gatewayURL,
APIKey: apiKey,
Namespace: namespace,
BaseDomain: cfg.BaseDomain,
Config: cfg,
HTTPClient: NewHTTPClient(30 * time.Second),
SkipCleanup: skipCleanup,
}, nil
}
// tarballFromDir creates a .tar.gz in memory from a directory.
func tarballFromDir(dirPath string) ([]byte, error) {
var buf bytes.Buffer
cmd := exec.Command("tar", "-czf", "-", "-C", dirPath, ".")
cmd.Stdout = &buf
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("tar failed: %w", err)
}
return buf.Bytes(), nil
}
// CreateTestDeployment creates a test deployment and returns its ID.
// tarballPath can be a .tar.gz file or a directory (which will be tarred automatically).
func CreateTestDeployment(t *testing.T, env *E2ETestEnv, name, tarballPath string) string {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
if err != nil {
t.Fatalf("failed to stat tarball path: %v", err)
}
if info.IsDir() {
// Create tarball from directory
fileData, err = tarballFromDir(tarballPath)
if err != nil {
t.Fatalf("failed to create tarball from dir: %v", err)
}
} else {
fileData, err = os.ReadFile(tarballPath)
if err != nil {
t.Fatalf("failed to read tarball: %v", err)
}
}
// Create multipart form
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
// Write name field
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
// NOTE: We intentionally do NOT send subdomain field
// This ensures only node-specific domains are created: {name}.node-{id}.domain
// Subdomain should only be sent if explicitly requested for custom domains
// Write tarball file
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/static/upload", body)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to upload deployment: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("deployment upload failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
// Try both "id" and "deployment_id" field names
if id, ok := result["deployment_id"].(string); ok {
return id
}
if id, ok := result["id"].(string); ok {
return id
}
t.Fatalf("deployment response missing id field: %+v", result)
return ""
}
// DeleteDeployment deletes a deployment by ID
func DeleteDeployment(t *testing.T, env *E2ETestEnv, deploymentID string) {
t.Helper()
req, _ := http.NewRequest("DELETE", env.GatewayURL+"/v1/deployments/delete?id="+deploymentID, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Logf("warning: failed to delete deployment: %v", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Logf("warning: delete deployment returned status %d", resp.StatusCode)
}
}
// GetDeployment retrieves deployment metadata by ID
func GetDeployment(t *testing.T, env *E2ETestEnv, deploymentID string) map[string]interface{} {
t.Helper()
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/get?id="+deploymentID, nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to get deployment: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("get deployment failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var deployment map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&deployment); err != nil {
t.Fatalf("failed to decode deployment: %v", err)
}
return deployment
}
// CreateSQLiteDB creates a SQLite database for a namespace
func CreateSQLiteDB(t *testing.T, env *E2ETestEnv, dbName string) {
t.Helper()
reqBody := map[string]string{"database_name": dbName}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/db/sqlite/create", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+env.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to create database: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("create database failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
}
// DeleteSQLiteDB deletes a SQLite database
func DeleteSQLiteDB(t *testing.T, env *E2ETestEnv, dbName string) {
t.Helper()
reqBody := map[string]string{"database_name": dbName}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("DELETE", env.GatewayURL+"/v1/db/sqlite/delete", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+env.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Logf("warning: failed to delete database: %v", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Logf("warning: delete database returned status %d", resp.StatusCode)
}
}
// ExecuteSQLQuery executes a SQL query on a database
func ExecuteSQLQuery(t *testing.T, env *E2ETestEnv, dbName, query string) map[string]interface{} {
t.Helper()
reqBody := map[string]interface{}{
"database_name": dbName,
"query": query,
}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/db/sqlite/query", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+env.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to execute query: %v", err)
}
defer resp.Body.Close()
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatalf("failed to decode query response: %v", err)
}
if errMsg, ok := result["error"].(string); ok && errMsg != "" {
t.Fatalf("SQL query failed: %s", errMsg)
}
return result
}
// QuerySQLite executes a SELECT query and returns rows
func QuerySQLite(t *testing.T, env *E2ETestEnv, dbName, query string) []map[string]interface{} {
t.Helper()
result := ExecuteSQLQuery(t, env, dbName, query)
rows, ok := result["rows"].([]interface{})
if !ok {
return []map[string]interface{}{}
}
columns, _ := result["columns"].([]interface{})
var results []map[string]interface{}
for _, row := range rows {
rowData, ok := row.([]interface{})
if !ok {
continue
}
rowMap := make(map[string]interface{})
for i, col := range columns {
if i < len(rowData) {
rowMap[col.(string)] = rowData[i]
}
}
results = append(results, rowMap)
}
return results
}
// UploadTestFile uploads a file to IPFS and returns the CID
func UploadTestFile(t *testing.T, env *E2ETestEnv, filename, content string) string {
t.Helper()
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString(fmt.Sprintf("Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n", filename))
body.WriteString("Content-Type: text/plain\r\n\r\n")
body.WriteString(content)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/storage/upload", body)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to upload file: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("upload file failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
t.Fatalf("failed to decode upload response: %v", err)
}
cid, ok := result["cid"].(string)
if !ok {
t.Fatalf("CID not found in response")
}
return cid
}
// UnpinFile unpins a file from IPFS
func UnpinFile(t *testing.T, env *E2ETestEnv, cid string) {
t.Helper()
reqBody := map[string]string{"cid": cid}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/storage/unpin", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+env.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Logf("warning: failed to unpin file: %v", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Logf("warning: unpin file returned status %d", resp.StatusCode)
}
}
// TestDeploymentWithHostHeader tests a deployment by setting the Host header
func TestDeploymentWithHostHeader(t *testing.T, env *E2ETestEnv, host, path string) *http.Response {
t.Helper()
req, err := http.NewRequest("GET", env.GatewayURL+path, nil)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Host = host
resp, err := env.HTTPClient.Do(req)
if err != nil {
t.Fatalf("failed to test deployment: %v", err)
}
return resp
}
// PutToOlric stores a key-value pair in Olric via the gateway HTTP API
func PutToOlric(gatewayURL, apiKey, dmap, key, value string) error {
reqBody := map[string]interface{}{
"dmap": dmap,
"key": key,
"value": value,
}
bodyBytes, _ := json.Marshal(reqBody)
req, err := http.NewRequest("POST", gatewayURL+"/v1/cache/put", strings.NewReader(string(bodyBytes)))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
body, _ := io.ReadAll(resp.Body)
return fmt.Errorf("put failed with status %d: %s", resp.StatusCode, string(body))
}
return nil
}
// GetFromOlric retrieves a value from Olric via the gateway HTTP API
func GetFromOlric(gatewayURL, apiKey, dmap, key string) (string, error) {
reqBody := map[string]interface{}{
"dmap": dmap,
"key": key,
}
bodyBytes, _ := json.Marshal(reqBody)
req, err := http.NewRequest("POST", gatewayURL+"/v1/cache/get", strings.NewReader(string(bodyBytes)))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
return "", fmt.Errorf("key not found")
}
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("get failed with status %d: %s", resp.StatusCode, string(body))
}
body, _ := io.ReadAll(resp.Body)
var result map[string]interface{}
if err := json.Unmarshal(body, &result); err != nil {
return "", err
}
if value, ok := result["value"].(string); ok {
return value, nil
}
if value, ok := result["value"]; ok {
return fmt.Sprintf("%v", value), nil
}
return "", fmt.Errorf("value not found in response")
}
// WaitForHealthy waits for a deployment to become healthy
func WaitForHealthy(t *testing.T, env *E2ETestEnv, deploymentID string, timeout time.Duration) bool {
t.Helper()
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
deployment := GetDeployment(t, env, deploymentID)
if status, ok := deployment["status"].(string); ok && status == "active" {
return true
}
time.Sleep(1 * time.Second)
}
return false
}

View File

@ -1,462 +0,0 @@
//go:build e2e
package integration_test
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/require"
)
// =============================================================================
// STRICT DATA PERSISTENCE TESTS
// These tests verify that data is properly persisted and survives operations.
// Tests FAIL if data is lost or corrupted.
// =============================================================================
// TestRQLite_DataPersistence verifies that RQLite data is persisted through the gateway.
func TestRQLite_DataPersistence(t *testing.T) {
e2e.SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
tableName := fmt.Sprintf("persist_test_%d", time.Now().UnixNano())
// Cleanup
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": tableName},
}
dropReq.Do(context.Background())
}()
// Create table
createReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY, value TEXT, version INTEGER)",
tableName,
),
},
}
_, status, err := createReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not create table")
require.True(t, status == http.StatusCreated || status == http.StatusOK,
"FAIL: Create table returned status %d", status)
t.Run("Data_survives_multiple_writes", func(t *testing.T) {
// Insert initial data
var statements []string
for i := 1; i <= 10; i++ {
statements = append(statements,
fmt.Sprintf("INSERT INTO %s (value, version) VALUES ('item_%d', %d)", tableName, i, i))
}
insertReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{"statements": statements},
}
_, status, err := insertReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not insert rows")
require.Equal(t, http.StatusOK, status, "FAIL: Insert returned status %d", status)
// Verify all data exists
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not count rows")
require.Equal(t, http.StatusOK, status, "FAIL: Count query returned status %d", status)
var queryResp map[string]interface{}
e2e.DecodeJSON(body, &queryResp)
if rows, ok := queryResp["rows"].([]interface{}); ok && len(rows) > 0 {
row := rows[0].([]interface{})
count := int(row[0].(float64))
require.Equal(t, 10, count, "FAIL: Expected 10 rows, got %d", count)
}
// Update data
updateReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("UPDATE %s SET version = version + 100 WHERE version <= 5", tableName),
},
},
}
_, status, err = updateReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not update rows")
require.Equal(t, http.StatusOK, status, "FAIL: Update returned status %d", status)
// Verify updates persisted
queryUpdatedReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE version > 100", tableName),
},
}
body, status, err = queryUpdatedReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not count updated rows")
require.Equal(t, http.StatusOK, status, "FAIL: Count updated query returned status %d", status)
e2e.DecodeJSON(body, &queryResp)
if rows, ok := queryResp["rows"].([]interface{}); ok && len(rows) > 0 {
row := rows[0].([]interface{})
count := int(row[0].(float64))
require.Equal(t, 5, count, "FAIL: Expected 5 updated rows, got %d", count)
}
t.Logf(" ✓ Data persists through multiple write operations")
})
t.Run("Deletes_are_persisted", func(t *testing.T) {
// Delete some rows
deleteReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("DELETE FROM %s WHERE version > 100", tableName),
},
},
}
_, status, err := deleteReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not delete rows")
require.Equal(t, http.StatusOK, status, "FAIL: Delete returned status %d", status)
// Verify deletes persisted
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) FROM %s", tableName),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not count remaining rows")
require.Equal(t, http.StatusOK, status, "FAIL: Count query returned status %d", status)
var queryResp map[string]interface{}
e2e.DecodeJSON(body, &queryResp)
if rows, ok := queryResp["rows"].([]interface{}); ok && len(rows) > 0 {
row := rows[0].([]interface{})
count := int(row[0].(float64))
require.Equal(t, 5, count, "FAIL: Expected 5 rows after delete, got %d", count)
}
t.Logf(" ✓ Deletes are properly persisted")
})
}
// TestRQLite_DataFilesExist verifies RQLite data files are created on disk.
func TestRQLite_DataFilesExist(t *testing.T) {
homeDir, err := os.UserHomeDir()
require.NoError(t, err, "FAIL: Could not get home directory")
// Check for RQLite data directories
dataLocations := []string{
filepath.Join(homeDir, ".orama", "node-1", "rqlite"),
filepath.Join(homeDir, ".orama", "node-2", "rqlite"),
filepath.Join(homeDir, ".orama", "node-3", "rqlite"),
filepath.Join(homeDir, ".orama", "node-4", "rqlite"),
filepath.Join(homeDir, ".orama", "node-5", "rqlite"),
}
foundDataDirs := 0
for _, dataDir := range dataLocations {
if _, err := os.Stat(dataDir); err == nil {
foundDataDirs++
t.Logf(" ✓ Found RQLite data directory: %s", dataDir)
// Check for Raft log files
entries, _ := os.ReadDir(dataDir)
for _, entry := range entries {
t.Logf(" - %s", entry.Name())
}
}
}
require.Greater(t, foundDataDirs, 0,
"FAIL: No RQLite data directories found - data may not be persisted")
t.Logf(" Found %d RQLite data directories", foundDataDirs)
}
// TestOlric_DataPersistence verifies Olric cache data persistence.
// Note: Olric is an in-memory cache, so this tests data survival during runtime.
func TestOlric_DataPersistence(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "FAIL: Could not load test environment")
dmap := fmt.Sprintf("persist_cache_%d", time.Now().UnixNano())
t.Run("Cache_data_survives_multiple_operations", func(t *testing.T) {
// Put multiple keys
keys := make(map[string]string)
for i := 0; i < 10; i++ {
key := fmt.Sprintf("persist_key_%d", i)
value := fmt.Sprintf("persist_value_%d", i)
keys[key] = value
err := e2e.PutToOlric(env.GatewayURL, env.APIKey, dmap, key, value)
require.NoError(t, err, "FAIL: Could not put key %s", key)
}
// Perform other operations
err := e2e.PutToOlric(env.GatewayURL, env.APIKey, dmap, "other_key", "other_value")
require.NoError(t, err, "FAIL: Could not put other key")
// Verify original keys still exist
for key, expectedValue := range keys {
retrieved, err := e2e.GetFromOlric(env.GatewayURL, env.APIKey, dmap, key)
require.NoError(t, err, "FAIL: Key %s not found after other operations", key)
require.Equal(t, expectedValue, retrieved, "FAIL: Value mismatch for key %s", key)
}
t.Logf(" ✓ Cache data survives multiple operations")
})
}
// TestNamespaceCluster_DataPersistence verifies namespace-specific data is isolated and persisted.
func TestNamespaceCluster_DataPersistence(t *testing.T) {
// Create namespace
namespace := fmt.Sprintf("persist-ns-%d", time.Now().UnixNano())
env, err := e2e.LoadTestEnvWithNamespace(namespace)
require.NoError(t, err, "FAIL: Could not create namespace")
t.Logf("Created namespace: %s", namespace)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
t.Run("Namespace_data_is_isolated", func(t *testing.T) {
// Create data via gateway API
tableName := fmt.Sprintf("ns_data_%d", time.Now().UnixNano())
req := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/rqlite/create-table",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"schema": fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY, value TEXT)", tableName),
},
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Could not create table in namespace")
require.True(t, status == http.StatusOK || status == http.StatusCreated,
"FAIL: Create table returned status %d", status)
// Insert data
insertReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/rqlite/transaction",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s (value) VALUES ('ns_test_value')", tableName),
},
},
}
_, status, err = insertReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not insert into namespace table")
require.Equal(t, http.StatusOK, status, "FAIL: Insert returned status %d", status)
// Verify data exists
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/rqlite/query",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT value FROM %s", tableName),
},
}
body, status, err := queryReq.Do(ctx)
require.NoError(t, err, "FAIL: Could not query namespace table")
require.Equal(t, http.StatusOK, status, "FAIL: Query returned status %d", status)
var queryResp map[string]interface{}
json.Unmarshal(body, &queryResp)
count, _ := queryResp["count"].(float64)
require.Equal(t, float64(1), count, "FAIL: Expected 1 row in namespace table")
t.Logf(" ✓ Namespace data is isolated and persisted")
})
}
// TestIPFS_DataPersistence verifies IPFS content is persisted and pinned.
// Note: Detailed IPFS tests are in storage_http_test.go. This test uses the helper from env.go.
func TestIPFS_DataPersistence(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "FAIL: Could not load test environment")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
t.Run("Uploaded_content_persists", func(t *testing.T) {
// Use helper function to upload content via multipart form
content := fmt.Sprintf("persistent content %d", time.Now().UnixNano())
cid := e2e.UploadTestFile(t, env, "persist_test.txt", content)
require.NotEmpty(t, cid, "FAIL: No CID returned from upload")
t.Logf(" Uploaded content with CID: %s", cid)
// Verify content can be retrieved
getReq := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: env.GatewayURL + "/v1/storage/get/" + cid,
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
}
respBody, status, err := getReq.Do(ctx)
require.NoError(t, err, "FAIL: Get content failed")
require.Equal(t, http.StatusOK, status, "FAIL: Get returned status %d", status)
require.Contains(t, string(respBody), "persistent content",
"FAIL: Retrieved content doesn't match uploaded content")
t.Logf(" ✓ IPFS content persists and is retrievable")
})
}
// TestSQLite_DataPersistence verifies per-deployment SQLite databases persist.
func TestSQLite_DataPersistence(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "FAIL: Could not load test environment")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
dbName := fmt.Sprintf("persist_db_%d", time.Now().UnixNano())
t.Run("SQLite_database_persists", func(t *testing.T) {
// Create database
createReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/db/sqlite/create",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"database_name": dbName,
},
}
_, status, err := createReq.Do(ctx)
require.NoError(t, err, "FAIL: Create database failed")
require.True(t, status == http.StatusOK || status == http.StatusCreated,
"FAIL: Create returned status %d", status)
t.Logf(" Created SQLite database: %s", dbName)
// Create table and insert data
queryReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/db/sqlite/query",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"database_name": dbName,
"query": "CREATE TABLE IF NOT EXISTS test_table (id INTEGER PRIMARY KEY, data TEXT)",
},
}
_, status, err = queryReq.Do(ctx)
require.NoError(t, err, "FAIL: Create table failed")
require.Equal(t, http.StatusOK, status, "FAIL: Create table returned status %d", status)
// Insert data
insertReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/db/sqlite/query",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"database_name": dbName,
"query": "INSERT INTO test_table (data) VALUES ('persistent_data')",
},
}
_, status, err = insertReq.Do(ctx)
require.NoError(t, err, "FAIL: Insert failed")
require.Equal(t, http.StatusOK, status, "FAIL: Insert returned status %d", status)
// Verify data persists
selectReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: env.GatewayURL + "/v1/db/sqlite/query",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
Body: map[string]interface{}{
"database_name": dbName,
"query": "SELECT data FROM test_table",
},
}
body, status, err := selectReq.Do(ctx)
require.NoError(t, err, "FAIL: Select failed")
require.Equal(t, http.StatusOK, status, "FAIL: Select returned status %d", status)
require.Contains(t, string(body), "persistent_data",
"FAIL: Data not found in SQLite database")
t.Logf(" ✓ SQLite database data persists")
})
t.Run("SQLite_database_listed", func(t *testing.T) {
// List databases to verify it was persisted
listReq := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: env.GatewayURL + "/v1/db/sqlite/list",
Headers: map[string]string{
"Authorization": "Bearer " + env.APIKey,
},
}
body, status, err := listReq.Do(ctx)
require.NoError(t, err, "FAIL: List databases failed")
require.Equal(t, http.StatusOK, status, "FAIL: List returned status %d", status)
require.Contains(t, string(body), dbName,
"FAIL: Created database not found in list")
t.Logf(" ✓ SQLite database appears in list")
})
}

View File

@ -1,356 +0,0 @@
//go:build e2e
package integration_test
import (
"encoding/json"
"fmt"
"io"
"net/http"
"path/filepath"
"strings"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDomainRouting_BasicRouting(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("test-routing-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for deployment to be active
time.Sleep(2 * time.Second)
// Get deployment details for debugging
deployment := e2e.GetDeployment(t, env, deploymentID)
t.Logf("Deployment created: ID=%s, CID=%s, Name=%s, Status=%s",
deploymentID, deployment["content_cid"], deployment["name"], deployment["status"])
t.Run("Standard domain resolves", func(t *testing.T) {
// Domain format: {deploymentName}.{baseDomain}
domain := env.BuildDeploymentDomain(deploymentName)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Should return 200 OK")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "Should read response body")
assert.Contains(t, string(body), "<div id=\"root\">", "Should serve React app")
assert.Contains(t, resp.Header.Get("Content-Type"), "text/html", "Content-Type should be HTML")
t.Logf("✓ Standard domain routing works: %s", domain)
})
t.Run("Non-orama domain passes through", func(t *testing.T) {
// Request with non-orama domain should not route to deployment
resp := e2e.TestDeploymentWithHostHeader(t, env, "example.com", "/")
defer resp.Body.Close()
// Should either return 404 or pass to default handler
assert.NotEqual(t, http.StatusOK, resp.StatusCode,
"Non-orama domain should not route to deployment")
t.Logf("✓ Non-orama domains correctly pass through (status: %d)", resp.StatusCode)
})
t.Run("API paths bypass domain routing", func(t *testing.T) {
// /v1/* paths should bypass domain routing and use API key auth
domain := env.BuildDeploymentDomain(deploymentName)
req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/list", nil)
req.Host = domain
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Should execute request")
defer resp.Body.Close()
// Should return API response, not deployment content
assert.Equal(t, http.StatusOK, resp.StatusCode, "API endpoint should work")
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
err = json.Unmarshal(bodyBytes, &result)
// Should be JSON API response
assert.NoError(t, err, "Should decode JSON (API response)")
assert.NotNil(t, result["deployments"], "Should have deployments field")
t.Logf("✓ API paths correctly bypass domain routing")
})
t.Run("Well-known paths bypass domain routing", func(t *testing.T) {
domain := env.BuildDeploymentDomain(deploymentName)
// /.well-known/ paths should bypass (used for ACME challenges, etc.)
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/.well-known/acme-challenge/test")
defer resp.Body.Close()
// Should not serve deployment content
// Exact status depends on implementation, but shouldn't be deployment content
body, _ := io.ReadAll(resp.Body)
bodyStr := string(body)
// Shouldn't contain React app content
if resp.StatusCode == http.StatusOK {
assert.NotContains(t, bodyStr, "<div id=\"root\">",
"Well-known paths should not serve deployment content")
}
t.Logf("✓ Well-known paths bypass routing (status: %d)", resp.StatusCode)
})
}
func TestDomainRouting_MultipleDeployments(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
tarballPath := filepath.Join("../../testdata/apps/react-app")
// Create multiple deployments
deployment1Name := fmt.Sprintf("test-multi-1-%d", time.Now().Unix())
deployment2Name := fmt.Sprintf("test-multi-2-%d", time.Now().Unix())
deployment1ID := e2e.CreateTestDeployment(t, env, deployment1Name, tarballPath)
time.Sleep(1 * time.Second)
deployment2ID := e2e.CreateTestDeployment(t, env, deployment2Name, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deployment1ID)
e2e.DeleteDeployment(t, env, deployment2ID)
}
}()
time.Sleep(2 * time.Second)
t.Run("Each deployment routes independently", func(t *testing.T) {
domain1 := env.BuildDeploymentDomain(deployment1Name)
domain2 := env.BuildDeploymentDomain(deployment2Name)
// Test deployment 1
resp1 := e2e.TestDeploymentWithHostHeader(t, env, domain1, "/")
defer resp1.Body.Close()
assert.Equal(t, http.StatusOK, resp1.StatusCode, "Deployment 1 should serve")
// Test deployment 2
resp2 := e2e.TestDeploymentWithHostHeader(t, env, domain2, "/")
defer resp2.Body.Close()
assert.Equal(t, http.StatusOK, resp2.StatusCode, "Deployment 2 should serve")
t.Logf("✓ Multiple deployments route independently")
t.Logf(" - Domain 1: %s", domain1)
t.Logf(" - Domain 2: %s", domain2)
})
t.Run("Wrong domain returns 404", func(t *testing.T) {
// Request with non-existent deployment subdomain
fakeDeploymentDomain := env.BuildDeploymentDomain(fmt.Sprintf("nonexistent-deployment-%d", time.Now().Unix()))
resp := e2e.TestDeploymentWithHostHeader(t, env, fakeDeploymentDomain, "/")
defer resp.Body.Close()
assert.Equal(t, http.StatusNotFound, resp.StatusCode,
"Non-existent deployment should return 404")
t.Logf("✓ Non-existent deployment returns 404")
})
}
func TestDomainRouting_ContentTypes(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("test-content-types-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
time.Sleep(2 * time.Second)
domain := env.BuildDeploymentDomain(deploymentName)
contentTypeTests := []struct {
path string
shouldHave string
description string
}{
{"/", "text/html", "HTML root"},
{"/index.html", "text/html", "HTML file"},
}
for _, test := range contentTypeTests {
t.Run(test.description, func(t *testing.T) {
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, test.path)
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
contentType := resp.Header.Get("Content-Type")
assert.Contains(t, contentType, test.shouldHave,
"Content-Type for %s should contain %s", test.path, test.shouldHave)
t.Logf("✓ %s: %s", test.description, contentType)
} else {
t.Logf("⚠ %s returned status %d", test.path, resp.StatusCode)
}
})
}
}
func TestDomainRouting_SPAFallback(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("test-spa-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
time.Sleep(2 * time.Second)
domain := env.BuildDeploymentDomain(deploymentName)
t.Run("Unknown paths fall back to index.html", func(t *testing.T) {
unknownPaths := []string{
"/about",
"/users/123",
"/settings/profile",
"/some/deep/nested/path",
}
for _, path := range unknownPaths {
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, path)
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
// Should return index.html for SPA routing
assert.Equal(t, http.StatusOK, resp.StatusCode,
"SPA fallback should return 200 for %s", path)
assert.Contains(t, string(body), "<div id=\"root\">",
"SPA fallback should return index.html for %s", path)
}
t.Logf("✓ SPA fallback routing verified for %d paths", len(unknownPaths))
})
}
// TestDeployment_DomainFormat verifies that deployment URLs use the correct format:
// - CORRECT: {name}-{random}.{baseDomain} (e.g., "myapp-f3o4if.dbrs.space")
// - WRONG: {name}.node-{shortID}.{baseDomain} (should NOT exist)
func TestDeployment_DomainFormat(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("format-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for deployment
time.Sleep(2 * time.Second)
t.Run("Deployment URL has correct format", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
// Get the deployment URLs
urls, ok := deployment["urls"].([]interface{})
if !ok || len(urls) == 0 {
// Fall back to single url field
if url, ok := deployment["url"].(string); ok && url != "" {
urls = []interface{}{url}
}
}
// Get the subdomain from deployment response
subdomain, _ := deployment["subdomain"].(string)
t.Logf("Deployment subdomain: %s", subdomain)
t.Logf("Deployment URLs: %v", urls)
foundCorrectFormat := false
for _, u := range urls {
urlStr, ok := u.(string)
if !ok {
continue
}
// URL should start with https://{name}-
expectedPrefix := fmt.Sprintf("https://%s-", deploymentName)
if strings.HasPrefix(urlStr, expectedPrefix) {
foundCorrectFormat = true
}
// URL should contain base domain
assert.Contains(t, urlStr, env.BaseDomain,
"URL should contain base domain %s", env.BaseDomain)
// URL should NOT contain node identifier pattern
assert.NotContains(t, urlStr, ".node-",
"URL should NOT have node identifier (got: %s)", urlStr)
}
if len(urls) > 0 {
assert.True(t, foundCorrectFormat, "Should find URL with correct domain format (https://{name}-{random}.{baseDomain})")
}
t.Logf("✓ Domain format verification passed")
t.Logf(" - Format: {name}-{random}.{baseDomain}")
})
t.Run("Domain resolves via Host header", func(t *testing.T) {
// Get the actual subdomain from the deployment
deployment := e2e.GetDeployment(t, env, deploymentID)
subdomain, _ := deployment["subdomain"].(string)
if subdomain == "" {
t.Skip("No subdomain set, skipping host header test")
}
domain := subdomain + "." + env.BaseDomain
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Domain %s should resolve successfully", domain)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Contains(t, string(body), "<div id=\"root\">",
"Should serve deployment content")
t.Logf("✓ Domain %s resolves correctly", domain)
})
}

View File

@ -1,278 +0,0 @@
//go:build e2e
package integration_test
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFullStack_GoAPI_SQLite(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
appName := fmt.Sprintf("fullstack-app-%d", time.Now().Unix())
backendName := appName + "-backend"
dbName := appName + "-db"
var backendID string
defer func() {
if !env.SkipCleanup {
if backendID != "" {
e2e.DeleteDeployment(t, env, backendID)
}
e2e.DeleteSQLiteDB(t, env, dbName)
}
}()
// Step 1: Create SQLite database
t.Run("Create SQLite database", func(t *testing.T) {
e2e.CreateSQLiteDB(t, env, dbName)
// Create users table
query := `CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)`
e2e.ExecuteSQLQuery(t, env, dbName, query)
// Insert test data
insertQuery := `INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')`
result := e2e.ExecuteSQLQuery(t, env, dbName, insertQuery)
assert.NotNil(t, result, "Should execute INSERT successfully")
t.Logf("✓ Database created with users table")
})
// Step 2: Deploy Go backend (this would normally connect to SQLite)
// Note: For now we test the Go backend deployment without actual DB connection
// as that requires environment variable injection during deployment
t.Run("Deploy Go backend", func(t *testing.T) {
tarballPath := filepath.Join("../../testdata/apps/go-api")
// Note: In a real implementation, we would pass DATABASE_NAME env var
// For now, we just test the deployment mechanism
backendID = e2e.CreateTestDeployment(t, env, backendName, tarballPath)
assert.NotEmpty(t, backendID, "Backend deployment ID should not be empty")
t.Logf("✓ Go backend deployed: %s", backendName)
// Wait for deployment to become active
time.Sleep(3 * time.Second)
})
// Step 3: Test database operations
t.Run("Test database CRUD operations", func(t *testing.T) {
// INSERT
insertQuery := `INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com')`
e2e.ExecuteSQLQuery(t, env, dbName, insertQuery)
// SELECT
users := e2e.QuerySQLite(t, env, dbName, "SELECT * FROM users ORDER BY id")
require.GreaterOrEqual(t, len(users), 2, "Should have at least 2 users")
assert.Equal(t, "Alice", users[0]["name"], "First user should be Alice")
assert.Equal(t, "Bob", users[1]["name"], "Second user should be Bob")
t.Logf("✓ Database CRUD operations work")
t.Logf(" - Found %d users", len(users))
// UPDATE
updateQuery := `UPDATE users SET email = 'alice.new@example.com' WHERE name = 'Alice'`
result := e2e.ExecuteSQLQuery(t, env, dbName, updateQuery)
rowsAffected, ok := result["rows_affected"].(float64)
require.True(t, ok, "Should have rows_affected")
assert.Equal(t, float64(1), rowsAffected, "Should update 1 row")
// Verify update
updated := e2e.QuerySQLite(t, env, dbName, "SELECT email FROM users WHERE name = 'Alice'")
require.Len(t, updated, 1, "Should find Alice")
assert.Equal(t, "alice.new@example.com", updated[0]["email"], "Email should be updated")
t.Logf("✓ UPDATE operation verified")
// DELETE
deleteQuery := `DELETE FROM users WHERE name = 'Bob'`
result = e2e.ExecuteSQLQuery(t, env, dbName, deleteQuery)
rowsAffected, ok = result["rows_affected"].(float64)
require.True(t, ok, "Should have rows_affected")
assert.Equal(t, float64(1), rowsAffected, "Should delete 1 row")
// Verify deletion
remaining := e2e.QuerySQLite(t, env, dbName, "SELECT * FROM users")
assert.Equal(t, 1, len(remaining), "Should have 1 user remaining")
t.Logf("✓ DELETE operation verified")
})
// Step 4: Test backend API endpoints (if deployment is active)
t.Run("Test backend API endpoints", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, backendID)
status, ok := deployment["status"].(string)
if !ok || status != "active" {
t.Skip("Backend deployment not active, skipping API tests")
return
}
backendDomain := env.BuildDeploymentDomain(backendName)
// Test health endpoint
resp := e2e.TestDeploymentWithHostHeader(t, env, backendDomain, "/health")
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
var health map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
require.NoError(t, json.Unmarshal(bodyBytes, &health), "Should decode health response")
assert.Equal(t, "healthy", health["status"], "Status should be healthy")
assert.Equal(t, "go-backend-test", health["service"], "Service name should match")
t.Logf("✓ Backend health check passed")
} else {
t.Logf("⚠ Health check returned status %d (deployment may still be starting)", resp.StatusCode)
}
// Test users API endpoint
resp2 := e2e.TestDeploymentWithHostHeader(t, env, backendDomain, "/api/users")
defer resp2.Body.Close()
if resp2.StatusCode == http.StatusOK {
var usersResp map[string]interface{}
bodyBytes, _ := io.ReadAll(resp2.Body)
require.NoError(t, json.Unmarshal(bodyBytes, &usersResp), "Should decode users response")
users, ok := usersResp["users"].([]interface{})
require.True(t, ok, "Should have users array")
assert.GreaterOrEqual(t, len(users), 3, "Should have test users")
t.Logf("✓ Backend API endpoint works")
t.Logf(" - Users endpoint returned %d users", len(users))
} else {
t.Logf("⚠ Users API returned status %d (deployment may still be starting)", resp2.StatusCode)
}
})
// Step 5: Test database backup
t.Run("Test database backup", func(t *testing.T) {
reqBody := map[string]string{"database_name": dbName}
bodyBytes, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", env.GatewayURL+"/v1/db/sqlite/backup", bytes.NewReader(bodyBytes))
req.Header.Set("Authorization", "Bearer "+env.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err, "Should execute backup request")
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
var result map[string]interface{}
bodyBytes, _ := io.ReadAll(resp.Body)
require.NoError(t, json.Unmarshal(bodyBytes, &result), "Should decode backup response")
backupCID, ok := result["backup_cid"].(string)
require.True(t, ok, "Should have backup CID")
assert.NotEmpty(t, backupCID, "Backup CID should not be empty")
t.Logf("✓ Database backup created")
t.Logf(" - CID: %s", backupCID)
} else {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Logf("⚠ Backup returned status %d: %s", resp.StatusCode, string(bodyBytes))
}
})
// Step 6: Test concurrent database queries
t.Run("Test concurrent database reads", func(t *testing.T) {
// WAL mode should allow concurrent reads — run sequentially to avoid t.Fatal in goroutines
for i := 0; i < 5; i++ {
users := e2e.QuerySQLite(t, env, dbName, "SELECT * FROM users")
assert.GreaterOrEqual(t, len(users), 0, "Should query successfully")
}
t.Logf("✓ Sequential reads successful")
})
}
func TestFullStack_StaticSite_SQLite(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
appName := fmt.Sprintf("fullstack-static-%d", time.Now().Unix())
frontendName := appName + "-frontend"
dbName := appName + "-db"
var frontendID string
defer func() {
if !env.SkipCleanup {
if frontendID != "" {
e2e.DeleteDeployment(t, env, frontendID)
}
e2e.DeleteSQLiteDB(t, env, dbName)
}
}()
t.Run("Deploy static site and create database", func(t *testing.T) {
// Create database
e2e.CreateSQLiteDB(t, env, dbName)
e2e.ExecuteSQLQuery(t, env, dbName, "CREATE TABLE page_views (id INTEGER PRIMARY KEY, page TEXT, count INTEGER)")
e2e.ExecuteSQLQuery(t, env, dbName, "INSERT INTO page_views (page, count) VALUES ('home', 0)")
// Deploy frontend
tarballPath := filepath.Join("../../testdata/apps/react-app")
frontendID = e2e.CreateTestDeployment(t, env, frontendName, tarballPath)
assert.NotEmpty(t, frontendID, "Frontend deployment should succeed")
t.Logf("✓ Static site deployed with SQLite backend")
// Wait for deployment
time.Sleep(2 * time.Second)
})
t.Run("Test frontend serving and database interaction", func(t *testing.T) {
frontendDomain := env.BuildDeploymentDomain(frontendName)
// Test frontend
resp := e2e.TestDeploymentWithHostHeader(t, env, frontendDomain, "/")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Frontend should serve")
body, _ := io.ReadAll(resp.Body)
assert.Contains(t, string(body), "<div id=\"root\">", "Should contain React app")
// Simulate page view tracking
e2e.ExecuteSQLQuery(t, env, dbName, "UPDATE page_views SET count = count + 1 WHERE page = 'home'")
// Verify count
views := e2e.QuerySQLite(t, env, dbName, "SELECT count FROM page_views WHERE page = 'home'")
require.Len(t, views, 1, "Should have page view record")
count, ok := views[0]["count"].(float64)
require.True(t, ok, "Count should be a number")
assert.Equal(t, float64(1), count, "Page view count should be incremented")
t.Logf("✓ Full stack integration verified")
t.Logf(" - Frontend: %s", frontendDomain)
t.Logf(" - Database: %s", dbName)
t.Logf(" - Page views tracked: %.0f", count)
})
}

View File

@ -1,125 +0,0 @@
//go:build e2e
package integration
import (
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestIPFS_ContentPinnedOnMultipleNodes verifies that deploying a static app
// makes the IPFS content available across multiple nodes.
func TestIPFS_ContentPinnedOnMultipleNodes(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
deploymentName := fmt.Sprintf("ipfs-pin-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
time.Sleep(15 * time.Second) // Wait for IPFS content replication
deployment := e2e.GetDeployment(t, env, deploymentID)
contentCID, _ := deployment["content_cid"].(string)
require.NotEmpty(t, contentCID, "Deployment should have a content CID")
t.Run("Content served via gateway", func(t *testing.T) {
// Extract domain from deployment URLs
urls, _ := deployment["urls"].([]interface{})
require.NotEmpty(t, urls, "Deployment should have URLs")
urlStr, _ := urls[0].(string)
domain := urlStr
if len(urlStr) > 8 && urlStr[:8] == "https://" {
domain = urlStr[8:]
} else if len(urlStr) > 7 && urlStr[:7] == "http://" {
domain = urlStr[7:]
}
if len(domain) > 0 && domain[len(domain)-1] == '/' {
domain = domain[:len(domain)-1]
}
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
t.Logf("status=%d, body=%d bytes", resp.StatusCode, len(body))
assert.Equal(t, http.StatusOK, resp.StatusCode,
"IPFS content should be served via gateway (CID: %s)", contentCID)
})
}
// TestIPFS_LargeFileDeployment verifies that deploying an app with larger
// static assets works correctly.
func TestIPFS_LargeFileDeployment(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
deploymentName := fmt.Sprintf("ipfs-large-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
// The react-vite tarball is our largest test asset
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
time.Sleep(5 * time.Second)
t.Run("Deployment has valid CID", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
contentCID, _ := deployment["content_cid"].(string)
assert.NotEmpty(t, contentCID, "Should have a content CID")
assert.True(t, len(contentCID) > 10, "CID should be a valid IPFS hash")
t.Logf("Content CID: %s", contentCID)
})
t.Run("Static content serves correctly", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
urls, ok := deployment["urls"].([]interface{})
if !ok || len(urls) == 0 {
t.Skip("No URLs in deployment")
}
nodeURL, _ := urls[0].(string)
domain := nodeURL
if len(nodeURL) > 8 && nodeURL[:8] == "https://" {
domain = nodeURL[8:]
} else if len(nodeURL) > 7 && nodeURL[:7] == "http://" {
domain = nodeURL[7:]
}
if len(domain) > 0 && domain[len(domain)-1] == '/' {
domain = domain[:len(domain)-1]
}
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Greater(t, len(body), 100, "Response should have substantial content")
})
}

400
e2e/ipfs_cluster_test.go Normal file
View File

@ -0,0 +1,400 @@
//go:build e2e
package e2e
import (
"bytes"
"context"
"fmt"
"io"
"testing"
"time"
"github.com/DeBrosOfficial/network/pkg/ipfs"
)
func TestIPFSCluster_Health(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 10 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
err = client.Health(ctx)
if err != nil {
t.Fatalf("health check failed: %v", err)
}
}
func TestIPFSCluster_GetPeerCount(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 10 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
peerCount, err := client.GetPeerCount(ctx)
if err != nil {
t.Fatalf("get peer count failed: %v", err)
}
if peerCount < 0 {
t.Fatalf("expected non-negative peer count, got %d", peerCount)
}
t.Logf("IPFS cluster peers: %d", peerCount)
}
func TestIPFSCluster_AddFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
content := []byte("IPFS cluster test content")
result, err := client.Add(ctx, bytes.NewReader(content), "test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
if result.Cid == "" {
t.Fatalf("expected non-empty CID")
}
if result.Size != int64(len(content)) {
t.Fatalf("expected size %d, got %d", len(content), result.Size)
}
t.Logf("Added file with CID: %s", result.Cid)
}
func TestIPFSCluster_PinFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add file first
content := []byte("IPFS pin test content")
addResult, err := client.Add(ctx, bytes.NewReader(content), "pin-test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
cid := addResult.Cid
// Pin the file
pinResult, err := client.Pin(ctx, cid, "pinned-file", 1)
if err != nil {
t.Fatalf("pin file failed: %v", err)
}
if pinResult.Cid != cid {
t.Fatalf("expected cid %s, got %s", cid, pinResult.Cid)
}
t.Logf("Pinned file: %s", cid)
}
func TestIPFSCluster_PinStatus(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add and pin file
content := []byte("IPFS status test content")
addResult, err := client.Add(ctx, bytes.NewReader(content), "status-test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
cid := addResult.Cid
pinResult, err := client.Pin(ctx, cid, "status-test", 1)
if err != nil {
t.Fatalf("pin file failed: %v", err)
}
if pinResult.Cid != cid {
t.Fatalf("expected cid %s, got %s", cid, pinResult.Cid)
}
// Give pin time to propagate
Delay(1000)
// Get status
status, err := client.PinStatus(ctx, cid)
if err != nil {
t.Fatalf("get pin status failed: %v", err)
}
if status.Cid != cid {
t.Fatalf("expected cid %s, got %s", cid, status.Cid)
}
if status.Name != "status-test" {
t.Fatalf("expected name 'status-test', got %s", status.Name)
}
if status.ReplicationFactor < 1 {
t.Logf("warning: replication factor is %d, expected >= 1", status.ReplicationFactor)
}
t.Logf("Pin status: %s (replication: %d, peers: %d)", status.Status, status.ReplicationFactor, len(status.Peers))
}
func TestIPFSCluster_UnpinFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add and pin file
content := []byte("IPFS unpin test content")
addResult, err := client.Add(ctx, bytes.NewReader(content), "unpin-test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
cid := addResult.Cid
_, err = client.Pin(ctx, cid, "unpin-test", 1)
if err != nil {
t.Fatalf("pin file failed: %v", err)
}
// Unpin file
err = client.Unpin(ctx, cid)
if err != nil {
t.Fatalf("unpin file failed: %v", err)
}
t.Logf("Unpinned file: %s", cid)
}
func TestIPFSCluster_GetFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add file
content := []byte("IPFS get test content")
addResult, err := client.Add(ctx, bytes.NewReader(content), "get-test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
cid := addResult.Cid
// Give time for propagation
Delay(1000)
// Get file
rc, err := client.Get(ctx, cid, GetIPFSAPIURL())
if err != nil {
t.Fatalf("get file failed: %v", err)
}
defer rc.Close()
retrievedContent, err := io.ReadAll(rc)
if err != nil {
t.Fatalf("failed to read content: %v", err)
}
if !bytes.Equal(retrievedContent, content) {
t.Fatalf("content mismatch: expected %q, got %q", string(content), string(retrievedContent))
}
t.Logf("Retrieved file: %s (%d bytes)", cid, len(retrievedContent))
}
func TestIPFSCluster_LargeFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 60 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Create 5MB file
content := bytes.Repeat([]byte("x"), 5*1024*1024)
result, err := client.Add(ctx, bytes.NewReader(content), "large.bin")
if err != nil {
t.Fatalf("add large file failed: %v", err)
}
if result.Cid == "" {
t.Fatalf("expected non-empty CID")
}
if result.Size != int64(len(content)) {
t.Fatalf("expected size %d, got %d", len(content), result.Size)
}
t.Logf("Added large file with CID: %s (%d bytes)", result.Cid, result.Size)
}
func TestIPFSCluster_ReplicationFactor(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add file
content := []byte("IPFS replication test content")
addResult, err := client.Add(ctx, bytes.NewReader(content), "replication-test.txt")
if err != nil {
t.Fatalf("add file failed: %v", err)
}
cid := addResult.Cid
// Pin with specific replication factor
replicationFactor := 2
pinResult, err := client.Pin(ctx, cid, "replication-test", replicationFactor)
if err != nil {
t.Fatalf("pin file failed: %v", err)
}
if pinResult.Cid != cid {
t.Fatalf("expected cid %s, got %s", cid, pinResult.Cid)
}
// Give time for replication
Delay(2000)
// Check status
status, err := client.PinStatus(ctx, cid)
if err != nil {
t.Fatalf("get pin status failed: %v", err)
}
t.Logf("Replication factor: requested=%d, actual=%d, peers=%d", replicationFactor, status.ReplicationFactor, len(status.Peers))
}
func TestIPFSCluster_MultipleFiles(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
logger := NewTestLogger(t)
cfg := ipfs.Config{
ClusterAPIURL: GetIPFSClusterURL(),
Timeout: 30 * time.Second,
}
client, err := ipfs.NewClient(cfg, logger)
if err != nil {
t.Fatalf("failed to create IPFS client: %v", err)
}
// Add multiple files
numFiles := 5
var cids []string
for i := 0; i < numFiles; i++ {
content := []byte(fmt.Sprintf("File %d", i))
result, err := client.Add(ctx, bytes.NewReader(content), fmt.Sprintf("file%d.txt", i))
if err != nil {
t.Fatalf("add file %d failed: %v", i, err)
}
cids = append(cids, result.Cid)
}
if len(cids) != numFiles {
t.Fatalf("expected %d files added, got %d", numFiles, len(cids))
}
// Verify all files exist
for i, cid := range cids {
status, err := client.PinStatus(ctx, cid)
if err != nil {
t.Logf("warning: failed to get status for file %d: %v", i, err)
continue
}
if status.Cid != cid {
t.Fatalf("expected cid %s, got %s", cid, status.Cid)
}
}
t.Logf("Successfully added and verified %d files", numFiles)
}

View File

@ -0,0 +1,294 @@
//go:build e2e
package e2e
import (
"context"
"net/http"
"strings"
"testing"
"time"
)
func TestLibP2P_PeerConnectivity(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Create and connect client
c := NewNetworkClient(t)
if err := c.Connect(); err != nil {
t.Fatalf("connect failed: %v", err)
}
defer c.Disconnect()
// Verify peer connectivity through the gateway
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/peers",
}
body, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("peers request failed: %v", err)
}
if status != http.StatusOK {
t.Fatalf("expected status 200, got %d", status)
}
var resp map[string]interface{}
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
peers := resp["peers"].([]interface{})
if len(peers) == 0 {
t.Logf("warning: no peers connected (cluster may still be initializing)")
}
}
func TestLibP2P_BootstrapPeers(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
bootstrapPeers := GetBootstrapPeers()
if len(bootstrapPeers) == 0 {
t.Skipf("E2E_BOOTSTRAP_PEERS not set; skipping")
}
// Create client with bootstrap peers explicitly set
c := NewNetworkClient(t)
if err := c.Connect(); err != nil {
t.Fatalf("connect failed: %v", err)
}
defer c.Disconnect()
// Give peer discovery time
Delay(2000)
// Verify we're connected (check via gateway status)
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/status",
}
body, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("status request failed: %v", err)
}
if status != http.StatusOK {
t.Fatalf("expected status 200, got %d", status)
}
var resp map[string]interface{}
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
if resp["connected"] != true {
t.Logf("warning: client not connected to network (cluster may still be initializing)")
}
}
func TestLibP2P_MultipleClientConnections(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Create multiple clients
c1 := NewNetworkClient(t)
c2 := NewNetworkClient(t)
c3 := NewNetworkClient(t)
if err := c1.Connect(); err != nil {
t.Fatalf("c1 connect failed: %v", err)
}
defer c1.Disconnect()
if err := c2.Connect(); err != nil {
t.Fatalf("c2 connect failed: %v", err)
}
defer c2.Disconnect()
if err := c3.Connect(); err != nil {
t.Fatalf("c3 connect failed: %v", err)
}
defer c3.Disconnect()
// Give peer discovery time
Delay(2000)
// Verify gateway sees multiple peers
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/peers",
}
body, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("peers request failed: %v", err)
}
if status != http.StatusOK {
t.Fatalf("expected status 200, got %d", status)
}
var resp map[string]interface{}
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
peers := resp["peers"].([]interface{})
if len(peers) < 1 {
t.Logf("warning: expected at least 1 peer, got %d", len(peers))
}
}
func TestLibP2P_ReconnectAfterDisconnect(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
c := NewNetworkClient(t)
// Connect
if err := c.Connect(); err != nil {
t.Fatalf("connect failed: %v", err)
}
// Verify connected via gateway
req1 := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/status",
}
_, status1, err := req1.Do(ctx)
if err != nil || status1 != http.StatusOK {
t.Logf("warning: gateway check failed before disconnect: status %d, err %v", status1, err)
}
// Disconnect
if err := c.Disconnect(); err != nil {
t.Logf("warning: disconnect failed: %v", err)
}
// Give time for disconnect to propagate
Delay(500)
// Reconnect
if err := c.Connect(); err != nil {
t.Fatalf("reconnect failed: %v", err)
}
defer c.Disconnect()
// Verify connected via gateway again
req2 := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/status",
}
_, status2, err := req2.Do(ctx)
if err != nil || status2 != http.StatusOK {
t.Logf("warning: gateway check failed after reconnect: status %d, err %v", status2, err)
}
}
func TestLibP2P_PeerDiscovery(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Create client
c := NewNetworkClient(t)
if err := c.Connect(); err != nil {
t.Fatalf("connect failed: %v", err)
}
defer c.Disconnect()
// Give peer discovery time
Delay(3000)
// Get peer list
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/peers",
}
body, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("peers request failed: %v", err)
}
if status != http.StatusOK {
t.Fatalf("expected status 200, got %d", status)
}
var resp map[string]interface{}
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
peers := resp["peers"].([]interface{})
if len(peers) == 0 {
t.Logf("warning: no peers discovered (cluster may not have multiple nodes)")
} else {
// Verify peer format (should be multiaddr strings)
for _, p := range peers {
peerStr := p.(string)
if !strings.Contains(peerStr, "/p2p/") && !strings.Contains(peerStr, "/ipfs/") {
t.Logf("warning: unexpected peer format: %s", peerStr)
}
}
}
}
func TestLibP2P_PeerAddressFormat(t *testing.T) {
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Create client
c := NewNetworkClient(t)
if err := c.Connect(); err != nil {
t.Fatalf("connect failed: %v", err)
}
defer c.Disconnect()
// Get peer list
req := &HTTPRequest{
Method: http.MethodGet,
URL: GetGatewayURL() + "/v1/network/peers",
}
body, status, err := req.Do(ctx)
if err != nil {
t.Fatalf("peers request failed: %v", err)
}
if status != http.StatusOK {
t.Fatalf("expected status 200, got %d", status)
}
var resp map[string]interface{}
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
peers := resp["peers"].([]interface{})
for _, p := range peers {
peerStr := p.(string)
// Multiaddrs should start with /
if !strings.HasPrefix(peerStr, "/") {
t.Fatalf("expected multiaddr format, got %s", peerStr)
}
}
}

View File

@ -1,25 +1,23 @@
//go:build e2e
package shared_test
package e2e
import (
"context"
"net/http"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
func TestNetwork_Health(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/health",
URL: GetGatewayURL() + "/v1/health",
SkipAuth: true,
}
@ -33,7 +31,7 @@ func TestNetwork_Health(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -43,14 +41,14 @@ func TestNetwork_Health(t *testing.T) {
}
func TestNetwork_Status(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/network/status",
URL: GetGatewayURL() + "/v1/network/status",
}
body, status, err := req.Do(ctx)
@ -63,7 +61,7 @@ func TestNetwork_Status(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -77,14 +75,14 @@ func TestNetwork_Status(t *testing.T) {
}
func TestNetwork_Peers(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/network/peers",
URL: GetGatewayURL() + "/v1/network/peers",
}
body, status, err := req.Do(ctx)
@ -97,7 +95,7 @@ func TestNetwork_Peers(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -107,18 +105,18 @@ func TestNetwork_Peers(t *testing.T) {
}
func TestNetwork_ProxyAnonSuccess(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/proxy/anon",
URL: GetGatewayURL() + "/v1/proxy/anon",
Body: map[string]interface{}{
"url": "https://httpbin.org/get",
"method": "GET",
"headers": map[string]string{"User-Agent": "Orama-E2E-Test/1.0"},
"headers": map[string]string{"User-Agent": "DeBros-E2E-Test/1.0"},
},
}
@ -132,7 +130,7 @@ func TestNetwork_ProxyAnonSuccess(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -146,14 +144,14 @@ func TestNetwork_ProxyAnonSuccess(t *testing.T) {
}
func TestNetwork_ProxyAnonBadURL(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/proxy/anon",
URL: GetGatewayURL() + "/v1/proxy/anon",
Body: map[string]interface{}{
"url": "http://localhost:1/nonexistent",
"method": "GET",
@ -167,18 +165,18 @@ func TestNetwork_ProxyAnonBadURL(t *testing.T) {
}
func TestNetwork_ProxyAnonPostRequest(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/proxy/anon",
URL: GetGatewayURL() + "/v1/proxy/anon",
Body: map[string]interface{}{
"url": "https://httpbin.org/post",
"method": "POST",
"headers": map[string]string{"User-Agent": "Orama-E2E-Test/1.0"},
"headers": map[string]string{"User-Agent": "DeBros-E2E-Test/1.0"},
"body": "test_data",
},
}
@ -193,7 +191,7 @@ func TestNetwork_ProxyAnonPostRequest(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -208,9 +206,9 @@ func TestNetwork_Unauthorized(t *testing.T) {
defer cancel()
// Create request without auth
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/network/status",
URL: GetGatewayURL() + "/v1/network/status",
SkipAuth: true,
}

View File

@ -1,136 +0,0 @@
//go:build e2e && production
package production
import (
"encoding/json"
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestCrossNode_ProxyRouting tests that requests routed through the gateway
// are served correctly for a deployment.
func TestCrossNode_ProxyRouting(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
if len(env.Config.Servers) < 2 {
t.Skip("Cross-node testing requires at least 2 servers in config")
}
deploymentName := fmt.Sprintf("proxy-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for deployment to be active
time.Sleep(3 * time.Second)
domain := env.BuildDeploymentDomain(deploymentName)
t.Logf("Testing routing for: %s", domain)
t.Run("Request via gateway succeeds", func(t *testing.T) {
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Request should return 200 (got %d: %s)", resp.StatusCode, string(body))
assert.Contains(t, string(body), "<div id=\"root\">",
"Should serve deployment content")
})
}
// TestCrossNode_APIConsistency tests that API responses are consistent
func TestCrossNode_APIConsistency(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("consistency-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for replication
time.Sleep(5 * time.Second)
t.Run("Deployment list contains our deployment", func(t *testing.T) {
req, err := http.NewRequest("GET", env.GatewayURL+"/v1/deployments/list", nil)
require.NoError(t, err)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
deployments, ok := result["deployments"].([]interface{})
require.True(t, ok, "Response should have deployments array")
t.Logf("Gateway reports %d deployments", len(deployments))
found := false
for _, d := range deployments {
dep, _ := d.(map[string]interface{})
if dep["name"] == deploymentName {
found = true
break
}
}
assert.True(t, found, "Our deployment should be in the list")
})
}
// TestCrossNode_DeploymentGetConsistency tests that deployment details are correct
func TestCrossNode_DeploymentGetConsistency(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("get-consistency-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for replication
time.Sleep(5 * time.Second)
t.Run("Deployment details are correct", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
cid, _ := deployment["content_cid"].(string)
assert.NotEmpty(t, cid, "Should have a content CID")
name, _ := deployment["name"].(string)
assert.Equal(t, deploymentName, name, "Name should match")
t.Logf("Deployment: name=%s, cid=%s, status=%s", name, cid, deployment["status"])
})
}

View File

@ -1,228 +0,0 @@
//go:build e2e && production
package production
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestFailover_HomeNodeDown verifies that when the home node's deployment process
// is down, requests still succeed via the replica node.
func TestFailover_HomeNodeDown(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
if len(env.Config.Servers) < 2 {
t.Skip("Failover testing requires at least 2 servers")
}
// Deploy a Node.js backend so we have a process to stop
deploymentName := fmt.Sprintf("failover-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/node-api")
deploymentID := createNodeJSDeploymentProd(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for deployment and replica
healthy := e2e.WaitForHealthy(t, env, deploymentID, 90*time.Second)
require.True(t, healthy, "Deployment should become healthy")
time.Sleep(20 * time.Second) // Wait for async replica setup
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURLProd(t, deployment)
require.NotEmpty(t, nodeURL)
domain := extractDomainProd(nodeURL)
t.Run("Deployment serves via gateway", func(t *testing.T) {
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/health")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Deployment should be served via gateway (got %d: %s)", resp.StatusCode, string(body))
t.Logf("Gateway response: status=%d body=%s", resp.StatusCode, string(body))
})
}
// TestFailover_5xxRetry verifies that if one node returns a gateway error,
// the middleware retries on the next replica.
func TestFailover_5xxRetry(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
// Deploy a static app (always works via IPFS, no process to crash)
deploymentName := fmt.Sprintf("retry-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
time.Sleep(10 * time.Second)
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURLProd(t, deployment)
if nodeURL == "" {
t.Skip("No node URL")
}
domain := extractDomainProd(nodeURL)
t.Run("Deployment serves successfully", func(t *testing.T) {
resp := e2e.TestDeploymentWithHostHeader(t, env, domain, "/")
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, http.StatusOK, resp.StatusCode,
"Static content should be served (got %d: %s)", resp.StatusCode, string(body))
})
}
// TestFailover_CrossNodeProxyTimeout verifies that cross-node proxy fails fast
// (within a reasonable timeout) rather than hanging.
func TestFailover_CrossNodeProxyTimeout(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
if len(env.Config.Servers) < 2 {
t.Skip("Requires at least 2 servers")
}
// Make a request to a non-existent deployment — should fail fast
domain := fmt.Sprintf("nonexistent-%d.%s", time.Now().Unix(), env.BaseDomain)
start := time.Now()
req, _ := http.NewRequest("GET", env.GatewayURL+"/", nil)
req.Host = domain
resp, err := env.HTTPClient.Do(req)
elapsed := time.Since(start)
if err != nil {
t.Logf("Request failed in %v: %v", elapsed, err)
} else {
resp.Body.Close()
t.Logf("Got status %d in %v", resp.StatusCode, elapsed)
}
// Should respond within 15 seconds (our proxy timeout is 5s)
assert.Less(t, elapsed.Seconds(), 15.0,
"Request to non-existent deployment should fail fast, took %v", elapsed)
}
func createNodeJSDeploymentProd(t *testing.T, env *e2e.E2ETestEnv, name, tarballPath string) string {
t.Helper()
var fileData []byte
info, err := os.Stat(tarballPath)
require.NoError(t, err, "Failed to stat: %s", tarballPath)
if info.IsDir() {
tarData, err := exec.Command("tar", "-czf", "-", "-C", tarballPath, ".").Output()
require.NoError(t, err, "Failed to create tarball from %s", tarballPath)
fileData = tarData
} else {
file, err := os.Open(tarballPath)
require.NoError(t, err, "Failed to open tarball: %s", tarballPath)
defer file.Close()
fileData, _ = io.ReadAll(file)
}
body := &bytes.Buffer{}
boundary := "----WebKitFormBoundary7MA4YWxkTrZu0gW"
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
body.WriteString(name + "\r\n")
body.WriteString("--" + boundary + "\r\n")
body.WriteString("Content-Disposition: form-data; name=\"tarball\"; filename=\"app.tar.gz\"\r\n")
body.WriteString("Content-Type: application/gzip\r\n\r\n")
body.Write(fileData)
body.WriteString("\r\n--" + boundary + "--\r\n")
req, err := http.NewRequest("POST", env.GatewayURL+"/v1/deployments/nodejs/upload", body)
require.NoError(t, err)
req.Header.Set("Content-Type", "multipart/form-data; boundary="+boundary)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Fatalf("Deployment upload failed with status %d: %s", resp.StatusCode, string(bodyBytes))
}
var result map[string]interface{}
require.NoError(t, json.NewDecoder(resp.Body).Decode(&result))
if id, ok := result["deployment_id"].(string); ok {
return id
}
if id, ok := result["id"].(string); ok {
return id
}
t.Fatalf("Deployment response missing id: %+v", result)
return ""
}
func extractNodeURLProd(t *testing.T, deployment map[string]interface{}) string {
t.Helper()
if urls, ok := deployment["urls"].([]interface{}); ok && len(urls) > 0 {
if url, ok := urls[0].(string); ok {
return url
}
}
if urls, ok := deployment["urls"].(map[string]interface{}); ok {
if url, ok := urls["node"].(string); ok {
return url
}
}
return ""
}
func extractDomainProd(url string) string {
domain := url
if len(url) > 8 && url[:8] == "https://" {
domain = url[8:]
} else if len(url) > 7 && url[:7] == "http://" {
domain = url[7:]
}
if len(domain) > 0 && domain[len(domain)-1] == '/' {
domain = domain[:len(domain)-1]
}
return domain
}

View File

@ -1,185 +0,0 @@
//go:build e2e && production
package production
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestHTTPS_CertificateValid tests that HTTPS works with a valid certificate
func TestHTTPS_CertificateValid(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("https-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
deploymentID := e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
defer func() {
if !env.SkipCleanup {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
// Wait for deployment and certificate provisioning
time.Sleep(5 * time.Second)
domain := env.BuildDeploymentDomain(deploymentName)
httpsURL := fmt.Sprintf("https://%s", domain)
t.Run("HTTPS connection with certificate verification", func(t *testing.T) {
// Create client that DOES verify certificates
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
// Do NOT skip verification - we want to test real certs
InsecureSkipVerify: false,
},
},
}
req, err := http.NewRequest("GET", httpsURL+"/", nil)
require.NoError(t, err)
resp, err := client.Do(req)
if err != nil {
// Certificate might not be ready yet, or domain might not resolve
t.Logf("⚠ HTTPS request failed (this may be expected if certs are still provisioning): %v", err)
t.Skip("HTTPS not available or certificate not ready")
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
t.Logf("HTTPS returned %d (deployment may not be routed yet): %s", resp.StatusCode, string(body))
}
// Check TLS connection state
if resp.TLS != nil {
t.Logf("✓ HTTPS works with valid certificate")
t.Logf(" - Domain: %s", domain)
t.Logf(" - TLS Version: %x", resp.TLS.Version)
t.Logf(" - Cipher Suite: %x", resp.TLS.CipherSuite)
if len(resp.TLS.PeerCertificates) > 0 {
cert := resp.TLS.PeerCertificates[0]
t.Logf(" - Certificate Subject: %s", cert.Subject)
t.Logf(" - Certificate Issuer: %s", cert.Issuer)
t.Logf(" - Valid Until: %s", cert.NotAfter)
}
}
})
}
// TestHTTPS_CertificateDetails tests certificate properties
func TestHTTPS_CertificateDetails(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
t.Run("Base domain certificate", func(t *testing.T) {
httpsURL := fmt.Sprintf("https://%s", env.BaseDomain)
// Connect and get certificate info
conn, err := tls.Dial("tcp", env.BaseDomain+":443", &tls.Config{
InsecureSkipVerify: true, // We just want to inspect the cert
})
if err != nil {
t.Logf("⚠ Could not connect to %s:443: %v", env.BaseDomain, err)
t.Skip("HTTPS not available on base domain")
return
}
defer conn.Close()
certs := conn.ConnectionState().PeerCertificates
require.NotEmpty(t, certs, "Should have certificates")
cert := certs[0]
t.Logf("Certificate for %s:", env.BaseDomain)
t.Logf(" - Subject: %s", cert.Subject)
t.Logf(" - DNS Names: %v", cert.DNSNames)
t.Logf(" - Valid From: %s", cert.NotBefore)
t.Logf(" - Valid Until: %s", cert.NotAfter)
t.Logf(" - Issuer: %s", cert.Issuer)
// Check that certificate covers our domain
coversDomain := false
for _, name := range cert.DNSNames {
if name == env.BaseDomain || name == "*."+env.BaseDomain {
coversDomain = true
break
}
}
assert.True(t, coversDomain, "Certificate should cover %s", env.BaseDomain)
// Check certificate is not expired
assert.True(t, time.Now().Before(cert.NotAfter), "Certificate should not be expired")
assert.True(t, time.Now().After(cert.NotBefore), "Certificate should be valid now")
// Make actual HTTPS request to verify it works
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: false,
},
},
}
resp, err := client.Get(httpsURL)
if err != nil {
t.Logf("⚠ HTTPS request failed: %v", err)
} else {
resp.Body.Close()
t.Logf("✓ HTTPS request succeeded with status %d", resp.StatusCode)
}
})
}
// TestHTTPS_HTTPRedirect tests that HTTP requests are redirected to HTTPS
func TestHTTPS_HTTPRedirect(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
t.Run("HTTP redirects to HTTPS", func(t *testing.T) {
// Create client that doesn't follow redirects
client := &http.Client{
Timeout: 30 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
httpURL := fmt.Sprintf("http://%s", env.BaseDomain)
resp, err := client.Get(httpURL)
if err != nil {
t.Logf("⚠ HTTP request failed: %v", err)
t.Skip("HTTP not available or redirects not configured")
return
}
defer resp.Body.Close()
// Check for redirect
if resp.StatusCode >= 300 && resp.StatusCode < 400 {
location := resp.Header.Get("Location")
t.Logf("✓ HTTP redirects to: %s (status %d)", location, resp.StatusCode)
assert.Contains(t, location, "https://", "Should redirect to HTTPS")
} else if resp.StatusCode == http.StatusOK {
// HTTP might just serve content directly in some configurations
t.Logf("⚠ HTTP returned 200 instead of redirect (HTTPS redirect may not be configured)")
} else {
t.Logf("HTTP returned status %d", resp.StatusCode)
}
})
}

View File

@ -1,204 +0,0 @@
//go:build e2e && production
package production
import (
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestHTTPS_ExternalAccess tests that deployed apps are accessible via HTTPS
// from the public internet with valid SSL certificates.
//
// This test requires:
// - Orama deployed on a VPS with a real domain
// - DNS properly configured
// - Run with: go test -v -tags "e2e production" -run TestHTTPS ./e2e/production/...
func TestHTTPS_ExternalAccess(t *testing.T) {
// Skip if not configured for external testing
externalURL := os.Getenv("ORAMA_EXTERNAL_URL")
if externalURL == "" {
t.Skip("ORAMA_EXTERNAL_URL not set - skipping external HTTPS test")
}
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("https-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy static app", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
t.Logf("Created deployment: %s (ID: %s)", deploymentName, deploymentID)
})
var deploymentDomain string
t.Run("Get deployment domain", func(t *testing.T) {
deployment := e2e.GetDeployment(t, env, deploymentID)
nodeURL := extractNodeURL(t, deployment)
require.NotEmpty(t, nodeURL, "Deployment should have node URL")
deploymentDomain = extractDomain(nodeURL)
t.Logf("Deployment domain: %s", deploymentDomain)
})
t.Run("Wait for DNS propagation", func(t *testing.T) {
// Poll DNS until the domain resolves
deadline := time.Now().Add(2 * time.Minute)
for time.Now().Before(deadline) {
ips, err := net.LookupHost(deploymentDomain)
if err == nil && len(ips) > 0 {
t.Logf("DNS resolved: %s -> %v", deploymentDomain, ips)
return
}
t.Logf("DNS not yet resolved, waiting...")
time.Sleep(5 * time.Second)
}
t.Fatalf("DNS did not resolve within timeout for %s", deploymentDomain)
})
t.Run("Test HTTPS access with valid certificate", func(t *testing.T) {
// Create HTTP client that DOES verify certificates
// (no InsecureSkipVerify - we want to test real SSL)
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
// Use default verification (validates certificate)
InsecureSkipVerify: false,
},
},
}
url := fmt.Sprintf("https://%s/", deploymentDomain)
t.Logf("Testing HTTPS: %s", url)
resp, err := client.Get(url)
require.NoError(t, err, "HTTPS request should succeed with valid certificate")
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode, "Should return 200 OK")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
// Verify it's our React app
assert.Contains(t, string(body), "<div id=\"root\">", "Should serve React app")
t.Logf("HTTPS test passed: %s returned %d", url, resp.StatusCode)
})
t.Run("Verify SSL certificate details", func(t *testing.T) {
conn, err := tls.Dial("tcp", deploymentDomain+":443", nil)
require.NoError(t, err, "TLS dial should succeed")
defer conn.Close()
state := conn.ConnectionState()
require.NotEmpty(t, state.PeerCertificates, "Should have peer certificates")
cert := state.PeerCertificates[0]
t.Logf("Certificate subject: %s", cert.Subject)
t.Logf("Certificate issuer: %s", cert.Issuer)
t.Logf("Certificate valid from: %s to %s", cert.NotBefore, cert.NotAfter)
// Verify certificate is not expired
assert.True(t, time.Now().After(cert.NotBefore), "Certificate should be valid (not before)")
assert.True(t, time.Now().Before(cert.NotAfter), "Certificate should be valid (not expired)")
// Verify domain matches
err = cert.VerifyHostname(deploymentDomain)
assert.NoError(t, err, "Certificate should be valid for domain %s", deploymentDomain)
})
}
// TestHTTPS_DomainFormat verifies deployment URL format
func TestHTTPS_DomainFormat(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err, "Failed to load test environment")
deploymentName := fmt.Sprintf("domain-test-%d", time.Now().Unix())
tarballPath := filepath.Join("../../testdata/apps/react-app")
var deploymentID string
// Cleanup after test
defer func() {
if !env.SkipCleanup && deploymentID != "" {
e2e.DeleteDeployment(t, env, deploymentID)
}
}()
t.Run("Deploy app and verify domain format", func(t *testing.T) {
deploymentID = e2e.CreateTestDeployment(t, env, deploymentName, tarballPath)
require.NotEmpty(t, deploymentID)
deployment := e2e.GetDeployment(t, env, deploymentID)
t.Logf("Deployment URLs: %+v", deployment["urls"])
// Get deployment URL (handles both array and map formats)
deploymentURL := extractNodeURL(t, deployment)
assert.NotEmpty(t, deploymentURL, "Should have deployment URL")
// URL should be simple format: {name}.{baseDomain} (NOT {name}.node-{shortID}.{baseDomain})
if deploymentURL != "" {
assert.NotContains(t, deploymentURL, ".node-", "URL should NOT contain node identifier (simplified format)")
assert.Contains(t, deploymentURL, deploymentName, "URL should contain deployment name")
t.Logf("Deployment URL: %s", deploymentURL)
}
})
}
func extractNodeURL(t *testing.T, deployment map[string]interface{}) string {
t.Helper()
if urls, ok := deployment["urls"].([]interface{}); ok && len(urls) > 0 {
if url, ok := urls[0].(string); ok {
return url
}
}
if urls, ok := deployment["urls"].(map[string]interface{}); ok {
if url, ok := urls["node"].(string); ok {
return url
}
}
return ""
}
func extractDomain(url string) string {
domain := url
if len(url) > 8 && url[:8] == "https://" {
domain = url[8:]
} else if len(url) > 7 && url[:7] == "http://" {
domain = url[7:]
}
if len(domain) > 0 && domain[len(domain)-1] == '/' {
domain = domain[:len(domain)-1]
}
return domain
}

View File

@ -1,95 +0,0 @@
//go:build e2e && production
package production
import (
"fmt"
"io"
"net/http"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestMiddleware_NonExistentDeployment verifies that requests to a non-existent
// deployment return 404 (not 502 or hang).
func TestMiddleware_NonExistentDeployment(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
domain := fmt.Sprintf("does-not-exist-%d.%s", time.Now().Unix(), env.BaseDomain)
req, _ := http.NewRequest("GET", env.GatewayURL+"/", nil)
req.Host = domain
start := time.Now()
resp, err := env.HTTPClient.Do(req)
elapsed := time.Since(start)
if err != nil {
t.Logf("Request failed in %v: %v", elapsed, err)
// Connection refused or timeout is acceptable
assert.Less(t, elapsed.Seconds(), 15.0, "Should fail fast")
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
t.Logf("Status: %d, elapsed: %v, body: %s", resp.StatusCode, elapsed, string(body))
// Should be 404 or 502, not 200
assert.NotEqual(t, http.StatusOK, resp.StatusCode,
"Non-existent deployment should not return 200")
assert.Less(t, elapsed.Seconds(), 15.0, "Should respond fast")
}
// TestMiddleware_InternalAPIAuthRejection verifies that internal replica API
// endpoints reject requests without the proper internal auth header.
func TestMiddleware_InternalAPIAuthRejection(t *testing.T) {
env, err := e2e.LoadTestEnv()
require.NoError(t, err)
t.Run("No auth header rejected", func(t *testing.T) {
req, _ := http.NewRequest("POST",
env.GatewayURL+"/v1/internal/deployments/replica/setup", nil)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
// Should be rejected (401 or 403)
assert.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"Internal API without auth should be rejected (got %d)", resp.StatusCode)
})
t.Run("Wrong auth header rejected", func(t *testing.T) {
req, _ := http.NewRequest("POST",
env.GatewayURL+"/v1/internal/deployments/replica/setup", nil)
req.Header.Set("X-Orama-Internal-Auth", "wrong-token")
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusBadRequest,
"Internal API with wrong auth should be rejected (got %d)", resp.StatusCode)
})
t.Run("Regular API key does not grant internal access", func(t *testing.T) {
req, _ := http.NewRequest("POST",
env.GatewayURL+"/v1/internal/deployments/replica/setup", nil)
req.Header.Set("Authorization", "Bearer "+env.APIKey)
resp, err := env.HTTPClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
// The request may pass auth but fail on bad body — 400 is acceptable
// But it should NOT succeed with 200
assert.NotEqual(t, http.StatusOK, resp.StatusCode,
"Regular API key should not fully authenticate internal endpoints")
})
}

View File

@ -1,42 +1,40 @@
//go:build e2e
package shared_test
package e2e
import (
"fmt"
"sync"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
// TestPubSub_SubscribePublish tests basic pub/sub functionality via WebSocket
func TestPubSub_SubscribePublish(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
message := "test-message-from-publisher"
// Create subscriber first
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish message
if err := publisher.Publish([]byte(message)); err != nil {
@ -56,37 +54,37 @@ func TestPubSub_SubscribePublish(t *testing.T) {
// TestPubSub_MultipleSubscribers tests that multiple subscribers receive the same message
func TestPubSub_MultipleSubscribers(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
message1 := "message-1"
message2 := "message-2"
// Create two subscribers
sub1, err := e2e.NewWSPubSubClient(t, topic)
sub1, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber1: %v", err)
}
defer sub1.Close()
sub2, err := e2e.NewWSPubSubClient(t, topic)
sub2, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber2: %v", err)
}
defer sub2.Close()
// Give subscribers time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish first message
if err := publisher.Publish([]byte(message1)); err != nil {
@ -135,30 +133,30 @@ func TestPubSub_MultipleSubscribers(t *testing.T) {
// TestPubSub_Deduplication tests that multiple identical messages are all received
func TestPubSub_Deduplication(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
message := "duplicate-test-message"
// Create subscriber
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish the same message multiple times
for i := 0; i < 3; i++ {
@ -166,7 +164,7 @@ func TestPubSub_Deduplication(t *testing.T) {
t.Fatalf("publish %d failed: %v", i, err)
}
// Small delay between publishes
e2e.Delay(50)
Delay(50)
}
// Receive messages - should get all (no dedup filter)
@ -187,30 +185,30 @@ func TestPubSub_Deduplication(t *testing.T) {
// TestPubSub_ConcurrentPublish tests concurrent message publishing
func TestPubSub_ConcurrentPublish(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
numMessages := 10
// Create subscriber
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish multiple messages concurrently
var wg sync.WaitGroup
@ -243,45 +241,45 @@ func TestPubSub_ConcurrentPublish(t *testing.T) {
// TestPubSub_TopicIsolation tests that messages are isolated to their topics
func TestPubSub_TopicIsolation(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic1 := e2e.GenerateTopic()
topic2 := e2e.GenerateTopic()
topic1 := GenerateTopic()
topic2 := GenerateTopic()
msg1 := "message-on-topic1"
msg2 := "message-on-topic2"
// Create subscriber for topic1
sub1, err := e2e.NewWSPubSubClient(t, topic1)
sub1, err := NewWSPubSubClient(t, topic1)
if err != nil {
t.Fatalf("failed to create subscriber1: %v", err)
}
defer sub1.Close()
// Create subscriber for topic2
sub2, err := e2e.NewWSPubSubClient(t, topic2)
sub2, err := NewWSPubSubClient(t, topic2)
if err != nil {
t.Fatalf("failed to create subscriber2: %v", err)
}
defer sub2.Close()
// Give subscribers time to register
e2e.Delay(200)
Delay(200)
// Create publishers
pub1, err := e2e.NewWSPubSubClient(t, topic1)
pub1, err := NewWSPubSubClient(t, topic1)
if err != nil {
t.Fatalf("failed to create publisher1: %v", err)
}
defer pub1.Close()
pub2, err := e2e.NewWSPubSubClient(t, topic2)
pub2, err := NewWSPubSubClient(t, topic2)
if err != nil {
t.Fatalf("failed to create publisher2: %v", err)
}
defer pub2.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish to topic2 first
if err := pub2.Publish([]byte(msg2)); err != nil {
@ -314,29 +312,29 @@ func TestPubSub_TopicIsolation(t *testing.T) {
// TestPubSub_EmptyMessage tests sending and receiving empty messages
func TestPubSub_EmptyMessage(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
// Create subscriber
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish empty message
if err := publisher.Publish([]byte("")); err != nil {
@ -356,9 +354,9 @@ func TestPubSub_EmptyMessage(t *testing.T) {
// TestPubSub_LargeMessage tests sending and receiving large messages
func TestPubSub_LargeMessage(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
// Create a large message (100KB)
largeMessage := make([]byte, 100*1024)
@ -367,24 +365,24 @@ func TestPubSub_LargeMessage(t *testing.T) {
}
// Create subscriber
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish large message
if err := publisher.Publish(largeMessage); err != nil {
@ -411,30 +409,30 @@ func TestPubSub_LargeMessage(t *testing.T) {
// TestPubSub_RapidPublish tests rapid message publishing
func TestPubSub_RapidPublish(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
numMessages := 50
// Create subscriber
subscriber, err := e2e.NewWSPubSubClient(t, topic)
subscriber, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create subscriber: %v", err)
}
defer subscriber.Close()
// Give subscriber time to register
e2e.Delay(200)
Delay(200)
// Create publisher
publisher, err := e2e.NewWSPubSubClient(t, topic)
publisher, err := NewWSPubSubClient(t, topic)
if err != nil {
t.Fatalf("failed to create publisher: %v", err)
}
defer publisher.Close()
// Give connections time to stabilize
e2e.Delay(200)
Delay(200)
// Publish messages rapidly
for i := 0; i < numMessages; i++ {

View File

@ -1,6 +1,6 @@
//go:build e2e
package shared_test
package e2e
import (
"context"
@ -9,19 +9,17 @@ import (
"net/http"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
func TestPubSub_Presence(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
topic := e2e.GenerateTopic()
topic := GenerateTopic()
memberID := "user123"
memberMeta := map[string]interface{}{"name": "Alice"}
// 1. Subscribe with presence
client1, err := e2e.NewWSPubSubPresenceClient(t, topic, memberID, memberMeta)
client1, err := NewWSPubSubPresenceClient(t, topic, memberID, memberMeta)
if err != nil {
t.Fatalf("failed to create presence client: %v", err)
}
@ -50,9 +48,9 @@ func TestPubSub_Presence(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: fmt.Sprintf("%s/v1/pubsub/presence?topic=%s", e2e.GetGatewayURL(), topic),
URL: fmt.Sprintf("%s/v1/pubsub/presence?topic=%s", GetGatewayURL(), topic),
}
body, status, err := req.Do(ctx)
@ -65,7 +63,7 @@ func TestPubSub_Presence(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -85,7 +83,7 @@ func TestPubSub_Presence(t *testing.T) {
// 3. Subscribe second member
memberID2 := "user456"
client2, err := e2e.NewWSPubSubPresenceClient(t, topic, memberID2, nil)
client2, err := NewWSPubSubPresenceClient(t, topic, memberID2, nil)
if err != nil {
t.Fatalf("failed to create second presence client: %v", err)
}
@ -121,3 +119,4 @@ func TestPubSub_Presence(t *testing.T) {
t.Fatalf("expected presence.leave for %s, got %v for %v", memberID2, event["type"], event["member_id"])
}
}

View File

@ -1,6 +1,6 @@
//go:build e2e
package shared_test
package e2e
import (
"context"
@ -8,36 +8,23 @@ import (
"net/http"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
func TestRQLite_CreateTable(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
table := e2e.GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP)",
table,
)
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -54,32 +41,21 @@ func TestRQLite_CreateTable(t *testing.T) {
}
func TestRQLite_InsertQuery(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
table := e2e.GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)",
table,
)
// Create table
createReq := &e2e.HTTPRequest{
createReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -91,9 +67,9 @@ func TestRQLite_InsertQuery(t *testing.T) {
}
// Insert rows
insertReq := &e2e.HTTPRequest{
insertReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s(name) VALUES ('alice')", table),
@ -108,9 +84,9 @@ func TestRQLite_InsertQuery(t *testing.T) {
}
// Query rows
queryReq := &e2e.HTTPRequest{
queryReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT name FROM %s ORDER BY id", table),
},
@ -126,7 +102,7 @@ func TestRQLite_InsertQuery(t *testing.T) {
}
var queryResp map[string]interface{}
if err := e2e.DecodeJSON(body, &queryResp); err != nil {
if err := DecodeJSON(body, &queryResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -136,21 +112,21 @@ func TestRQLite_InsertQuery(t *testing.T) {
}
func TestRQLite_DropTable(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
table := e2e.GenerateTableName()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY, note TEXT)",
table,
)
// Create table
createReq := &e2e.HTTPRequest{
createReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -162,9 +138,9 @@ func TestRQLite_DropTable(t *testing.T) {
}
// Drop table
dropReq := &e2e.HTTPRequest{
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{
"table": table,
},
@ -180,9 +156,9 @@ func TestRQLite_DropTable(t *testing.T) {
}
// Verify table doesn't exist via schema
schemaReq := &e2e.HTTPRequest{
schemaReq := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/rqlite/schema",
URL: GetGatewayURL() + "/v1/rqlite/schema",
}
body, status, err := schemaReq.Do(ctx)
@ -192,7 +168,7 @@ func TestRQLite_DropTable(t *testing.T) {
}
var schemaResp map[string]interface{}
if err := e2e.DecodeJSON(body, &schemaResp); err != nil {
if err := DecodeJSON(body, &schemaResp); err != nil {
t.Logf("warning: failed to decode schema response: %v", err)
return
}
@ -208,14 +184,14 @@ func TestRQLite_DropTable(t *testing.T) {
}
func TestRQLite_Schema(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/rqlite/schema",
URL: GetGatewayURL() + "/v1/rqlite/schema",
}
body, status, err := req.Do(ctx)
@ -228,7 +204,7 @@ func TestRQLite_Schema(t *testing.T) {
}
var resp map[string]interface{}
if err := e2e.DecodeJSON(body, &resp); err != nil {
if err := DecodeJSON(body, &resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -238,14 +214,14 @@ func TestRQLite_Schema(t *testing.T) {
}
func TestRQLite_MalformedSQL(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req := &e2e.HTTPRequest{
req := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": "SELECT * FROM nonexistent_table WHERE invalid syntax",
},
@ -263,32 +239,21 @@ func TestRQLite_MalformedSQL(t *testing.T) {
}
func TestRQLite_LargeTransaction(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
table := e2e.GenerateTableName()
// Cleanup table after test
defer func() {
dropReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": table},
}
dropReq.Do(context.Background())
}()
table := GenerateTableName()
schema := fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER)",
table,
)
// Create table
createReq := &e2e.HTTPRequest{
createReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": schema,
},
@ -305,9 +270,9 @@ func TestRQLite_LargeTransaction(t *testing.T) {
statements = append(statements, fmt.Sprintf("INSERT INTO %s(value) VALUES (%d)", table, i))
}
txReq := &e2e.HTTPRequest{
txReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": statements,
},
@ -319,9 +284,9 @@ func TestRQLite_LargeTransaction(t *testing.T) {
}
// Verify all rows were inserted
queryReq := &e2e.HTTPRequest{
queryReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT COUNT(*) as count FROM %s", table),
},
@ -333,7 +298,7 @@ func TestRQLite_LargeTransaction(t *testing.T) {
}
var countResp map[string]interface{}
if err := e2e.DecodeJSON(body, &countResp); err != nil {
if err := DecodeJSON(body, &countResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -347,35 +312,18 @@ func TestRQLite_LargeTransaction(t *testing.T) {
}
func TestRQLite_ForeignKeyMigration(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
orgsTable := e2e.GenerateTableName()
usersTable := e2e.GenerateTableName()
// Cleanup tables after test
defer func() {
dropUsersReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": usersTable},
}
dropUsersReq.Do(context.Background())
dropOrgsReq := &e2e.HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{"table": orgsTable},
}
dropOrgsReq.Do(context.Background())
}()
orgsTable := GenerateTableName()
usersTable := GenerateTableName()
// Create base tables
createOrgsReq := &e2e.HTTPRequest{
createOrgsReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY, name TEXT)",
@ -389,9 +337,9 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
t.Fatalf("create orgs table failed: status %d, err %v", status, err)
}
createUsersReq := &e2e.HTTPRequest{
createUsersReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/create-table",
URL: GetGatewayURL() + "/v1/rqlite/create-table",
Body: map[string]interface{}{
"schema": fmt.Sprintf(
"CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY, name TEXT, org_id INTEGER, age TEXT)",
@ -406,9 +354,9 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
}
// Seed data
seedReq := &e2e.HTTPRequest{
seedReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf("INSERT INTO %s(id,name) VALUES (1,'org')", orgsTable),
@ -423,9 +371,9 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
}
// Migrate: change age type and add FK
migrationReq := &e2e.HTTPRequest{
migrationReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/transaction",
URL: GetGatewayURL() + "/v1/rqlite/transaction",
Body: map[string]interface{}{
"statements": []string{
fmt.Sprintf(
@ -448,9 +396,9 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
}
// Verify data is intact
queryReq := &e2e.HTTPRequest{
queryReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/query",
URL: GetGatewayURL() + "/v1/rqlite/query",
Body: map[string]interface{}{
"sql": fmt.Sprintf("SELECT name, org_id, age FROM %s", usersTable),
},
@ -462,7 +410,7 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
}
var queryResp map[string]interface{}
if err := e2e.DecodeJSON(body, &queryResp); err != nil {
if err := DecodeJSON(body, &queryResp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -472,14 +420,14 @@ func TestRQLite_ForeignKeyMigration(t *testing.T) {
}
func TestRQLite_DropNonexistentTable(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dropReq := &e2e.HTTPRequest{
dropReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/rqlite/drop-table",
URL: GetGatewayURL() + "/v1/rqlite/drop-table",
Body: map[string]interface{}{
"table": "nonexistent_table_xyz_" + fmt.Sprintf("%d", time.Now().UnixNano()),
},

View File

@ -1,6 +1,6 @@
//go:build e2e
package shared_test
package e2e
import (
"bytes"
@ -11,12 +11,10 @@ import (
"os"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
func TestServerless_DeployAndInvoke(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -32,11 +30,7 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
}
funcName := "e2e-hello"
// Use namespace from environment or default to test namespace
namespace := os.Getenv("ORAMA_NAMESPACE")
if namespace == "" {
namespace = "default-test-ns" // Match the namespace from LoadTestEnv()
}
namespace := "default"
// 1. Deploy function
var buf bytes.Buffer
@ -45,7 +39,6 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
// Add metadata
_ = writer.WriteField("name", funcName)
_ = writer.WriteField("namespace", namespace)
_ = writer.WriteField("is_public", "true") // Make function public for E2E test
// Add WASM file
part, err := writer.CreateFormFile("wasm", funcName+".wasm")
@ -55,14 +48,14 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
part.Write(wasmBytes)
writer.Close()
deployReq, _ := http.NewRequestWithContext(ctx, "POST", e2e.GetGatewayURL()+"/v1/functions", &buf)
deployReq, _ := http.NewRequestWithContext(ctx, "POST", GetGatewayURL()+"/v1/functions", &buf)
deployReq.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
deployReq.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(1 * time.Minute)
client := NewHTTPClient(1 * time.Minute)
resp, err := client.Do(deployReq)
if err != nil {
t.Fatalf("deploy request failed: %v", err)
@ -76,10 +69,10 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
// 2. Invoke function
invokePayload := []byte(`{"name": "E2E Tester"}`)
invokeReq, _ := http.NewRequestWithContext(ctx, "POST", e2e.GetGatewayURL()+"/v1/functions/"+funcName+"/invoke?namespace="+namespace, bytes.NewReader(invokePayload))
invokeReq, _ := http.NewRequestWithContext(ctx, "POST", GetGatewayURL()+"/v1/functions/"+funcName+"/invoke", bytes.NewReader(invokePayload))
invokeReq.Header.Set("Content-Type", "application/json")
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
invokeReq.Header.Set("Authorization", "Bearer "+apiKey)
}
@ -101,8 +94,8 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
}
// 3. List functions
listReq, _ := http.NewRequestWithContext(ctx, "GET", e2e.GetGatewayURL()+"/v1/functions?namespace="+namespace, nil)
if apiKey := e2e.GetAPIKey(); apiKey != "" {
listReq, _ := http.NewRequestWithContext(ctx, "GET", GetGatewayURL()+"/v1/functions?namespace="+namespace, nil)
if apiKey := GetAPIKey(); apiKey != "" {
listReq.Header.Set("Authorization", "Bearer "+apiKey)
}
resp, err = client.Do(listReq)
@ -115,8 +108,8 @@ func TestServerless_DeployAndInvoke(t *testing.T) {
}
// 4. Delete function
deleteReq, _ := http.NewRequestWithContext(ctx, "DELETE", e2e.GetGatewayURL()+"/v1/functions/"+funcName+"?namespace="+namespace, nil)
if apiKey := e2e.GetAPIKey(); apiKey != "" {
deleteReq, _ := http.NewRequestWithContext(ctx, "DELETE", GetGatewayURL()+"/v1/functions/"+funcName+"?namespace="+namespace, nil)
if apiKey := GetAPIKey(); apiKey != "" {
deleteReq.Header.Set("Authorization", "Bearer "+apiKey)
}
resp, err = client.Do(deleteReq)

View File

@ -1,148 +0,0 @@
//go:build e2e
package shared
import (
"net/http"
"testing"
"time"
"github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestAuth_ExpiredOrInvalidJWT verifies that an expired/invalid JWT token is rejected.
func TestAuth_ExpiredOrInvalidJWT(t *testing.T) {
e2e.SkipIfMissingGateway(t)
gatewayURL := e2e.GetGatewayURL()
// Craft an obviously invalid JWT
invalidJWT := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjoxfQ.invalid"
req, err := http.NewRequest("GET", gatewayURL+"/v1/deployments/list", nil)
require.NoError(t, err)
req.Header.Set("Authorization", "Bearer "+invalidJWT)
client := e2e.NewHTTPClient(10 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode,
"Invalid JWT should return 401")
}
// TestAuth_EmptyAPIKey verifies that an empty API key is rejected.
func TestAuth_EmptyAPIKey(t *testing.T) {
e2e.SkipIfMissingGateway(t)
gatewayURL := e2e.GetGatewayURL()
req, err := http.NewRequest("GET", gatewayURL+"/v1/deployments/list", nil)
require.NoError(t, err)
req.Header.Set("Authorization", "Bearer ")
client := e2e.NewHTTPClient(10 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode,
"Empty API key should return 401")
}
// TestAuth_SQLInjectionInAPIKey verifies that SQL injection in the API key
// does not bypass authentication.
func TestAuth_SQLInjectionInAPIKey(t *testing.T) {
e2e.SkipIfMissingGateway(t)
gatewayURL := e2e.GetGatewayURL()
injectionAttempts := []string{
"' OR '1'='1",
"'; DROP TABLE api_keys; --",
"\" OR \"1\"=\"1",
"admin'--",
}
for _, attempt := range injectionAttempts {
t.Run(attempt, func(t *testing.T) {
req, _ := http.NewRequest("GET", gatewayURL+"/v1/deployments/list", nil)
req.Header.Set("Authorization", "Bearer "+attempt)
client := e2e.NewHTTPClient(10 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode,
"SQL injection attempt should be rejected")
})
}
}
// TestAuth_NamespaceScopedAccess verifies that an API key for one namespace
// cannot access another namespace's deployments.
func TestAuth_NamespaceScopedAccess(t *testing.T) {
// Create two environments with different namespaces
env1, err := e2e.LoadTestEnvWithNamespace("auth-test-ns1")
if err != nil {
t.Skip("Could not create namespace env1: " + err.Error())
}
env2, err := e2e.LoadTestEnvWithNamespace("auth-test-ns2")
if err != nil {
t.Skip("Could not create namespace env2: " + err.Error())
}
t.Run("Namespace 1 key cannot list namespace 2 deployments", func(t *testing.T) {
// Use env1's API key to query env2's gateway
// The namespace should be scoped to the API key
req, _ := http.NewRequest("GET", env2.GatewayURL+"/v1/deployments/list", nil)
req.Header.Set("Authorization", "Bearer "+env1.APIKey)
req.Header.Set("X-Namespace", "auth-test-ns2")
resp, err := env1.HTTPClient.Do(req)
if err != nil {
t.Skip("Gateway unreachable")
}
defer resp.Body.Close()
// The API should either reject (403) or return only ns1's deployments
t.Logf("Cross-namespace access returned: %d", resp.StatusCode)
if resp.StatusCode == http.StatusOK {
t.Log("API returned 200 — namespace isolation may be enforced at data level")
}
})
}
// TestAuth_PublicEndpointsNoAuth verifies that health/status endpoints
// don't require authentication.
func TestAuth_PublicEndpointsNoAuth(t *testing.T) {
e2e.SkipIfMissingGateway(t)
gatewayURL := e2e.GetGatewayURL()
client := e2e.NewHTTPClient(10 * time.Second)
publicPaths := []string{
"/v1/health",
"/v1/status",
}
for _, path := range publicPaths {
t.Run(path, func(t *testing.T) {
req, _ := http.NewRequest("GET", gatewayURL+path, nil)
// No auth header
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode,
"%s should be accessible without auth", path)
})
}
}

View File

@ -1,333 +0,0 @@
//go:build e2e
package shared_test
import (
"context"
"net/http"
"testing"
"time"
"unicode"
e2e "github.com/DeBrosOfficial/network/e2e"
"github.com/stretchr/testify/require"
)
// =============================================================================
// STRICT AUTHENTICATION NEGATIVE TESTS
// These tests verify that authentication is properly enforced.
// Tests FAIL if unauthenticated/invalid requests are allowed through.
// =============================================================================
func TestAuth_MissingAPIKey(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request protected endpoint without auth headers
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: Must reject requests without authentication
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: Protected endpoint allowed request without auth - expected 401/403, got %d", resp.StatusCode)
t.Logf(" ✓ Missing API key correctly rejected with status %d", resp.StatusCode)
}
func TestAuth_InvalidAPIKey(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with invalid API key
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
req.Header.Set("Authorization", "Bearer invalid-key-xyz-123456789")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: Must reject invalid API keys
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: Invalid API key was accepted - expected 401/403, got %d", resp.StatusCode)
t.Logf(" ✓ Invalid API key correctly rejected with status %d", resp.StatusCode)
}
func TestAuth_CacheWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request cache endpoint without auth
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/cache/health",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// STRICT: Cache endpoint must require authentication
require.True(t, status == http.StatusUnauthorized || status == http.StatusForbidden,
"FAIL: Cache endpoint accessible without auth - expected 401/403, got %d", status)
t.Logf(" ✓ Cache endpoint correctly requires auth (status %d)", status)
}
func TestAuth_StorageWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request storage endpoint without auth
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/storage/status/QmTest",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// STRICT: Storage endpoint must require authentication
require.True(t, status == http.StatusUnauthorized || status == http.StatusForbidden,
"FAIL: Storage endpoint accessible without auth - expected 401/403, got %d", status)
t.Logf(" ✓ Storage endpoint correctly requires auth (status %d)", status)
}
func TestAuth_RQLiteWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request rqlite endpoint without auth
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/rqlite/schema",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// STRICT: RQLite endpoint must require authentication
require.True(t, status == http.StatusUnauthorized || status == http.StatusForbidden,
"FAIL: RQLite endpoint accessible without auth - expected 401/403, got %d", status)
t.Logf(" ✓ RQLite endpoint correctly requires auth (status %d)", status)
}
func TestAuth_MalformedBearerToken(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with malformed bearer token (missing "Bearer " prefix)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
req.Header.Set("Authorization", "invalid-token-format-no-bearer")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: Must reject malformed authorization headers
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: Malformed auth header accepted - expected 401/403, got %d", resp.StatusCode)
t.Logf(" ✓ Malformed bearer token correctly rejected (status %d)", resp.StatusCode)
}
func TestAuth_ExpiredJWT(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Test with a clearly invalid JWT structure
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
req.Header.Set("Authorization", "Bearer expired.jwt.token.invalid")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: Must reject invalid/expired JWT tokens
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: Invalid JWT accepted - expected 401/403, got %d", resp.StatusCode)
t.Logf(" ✓ Invalid JWT correctly rejected (status %d)", resp.StatusCode)
}
func TestAuth_EmptyBearerToken(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with empty bearer token
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
req.Header.Set("Authorization", "Bearer ")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: Must reject empty bearer tokens
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: Empty bearer token accepted - expected 401/403, got %d", resp.StatusCode)
t.Logf(" ✓ Empty bearer token correctly rejected (status %d)", resp.StatusCode)
}
func TestAuth_DuplicateAuthHeaders(t *testing.T) {
if e2e.GetAPIKey() == "" {
t.Skip("No API key configured")
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request with both valid API key in Authorization header
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/cache/health",
Headers: map[string]string{
"Authorization": "Bearer " + e2e.GetAPIKey(),
"X-API-Key": e2e.GetAPIKey(),
},
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// Should succeed since we have a valid API key
require.Equal(t, http.StatusOK, status,
"FAIL: Valid API key rejected when multiple auth headers present - got %d", status)
t.Logf(" ✓ Duplicate auth headers with valid key succeeds (status %d)", status)
}
func TestAuth_CaseSensitiveAPIKey(t *testing.T) {
apiKey := e2e.GetAPIKey()
if apiKey == "" {
t.Skip("No API key configured")
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Create incorrectly cased API key
incorrectKey := ""
for i, ch := range apiKey {
if i%2 == 0 && unicode.IsLetter(ch) {
if unicode.IsLower(ch) {
incorrectKey += string(unicode.ToUpper(ch))
} else {
incorrectKey += string(unicode.ToLower(ch))
}
} else {
incorrectKey += string(ch)
}
}
// Skip if the key didn't change (no letters)
if incorrectKey == apiKey {
t.Skip("API key has no letters to change case")
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/cache/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
req.Header.Set("Authorization", "Bearer "+incorrectKey)
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// STRICT: API keys MUST be case-sensitive
require.True(t, resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden,
"FAIL: API key check is not case-sensitive - modified key accepted with status %d", resp.StatusCode)
t.Logf(" ✓ Case-modified API key correctly rejected (status %d)", resp.StatusCode)
}
func TestAuth_HealthEndpointNoAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Health endpoint at /v1/health should NOT require auth
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/health", nil)
require.NoError(t, err, "FAIL: Could not create request")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// Health endpoint should be publicly accessible
require.Equal(t, http.StatusOK, resp.StatusCode,
"FAIL: Health endpoint should not require auth - expected 200, got %d", resp.StatusCode)
t.Logf(" ✓ Health endpoint correctly accessible without auth")
}
func TestAuth_StatusEndpointNoAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Status endpoint at /v1/status should NOT require auth
req, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/status", nil)
require.NoError(t, err, "FAIL: Could not create request")
client := e2e.NewHTTPClient(30 * time.Second)
resp, err := client.Do(req)
require.NoError(t, err, "FAIL: Request failed")
defer resp.Body.Close()
// Status endpoint should be publicly accessible
require.Equal(t, http.StatusOK, resp.StatusCode,
"FAIL: Status endpoint should not require auth - expected 200, got %d", resp.StatusCode)
t.Logf(" ✓ Status endpoint correctly accessible without auth")
}
func TestAuth_DeploymentsWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request deployments endpoint without auth
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/deployments/list",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// STRICT: Deployments endpoint must require authentication
require.True(t, status == http.StatusUnauthorized || status == http.StatusForbidden,
"FAIL: Deployments endpoint accessible without auth - expected 401/403, got %d", status)
t.Logf(" ✓ Deployments endpoint correctly requires auth (status %d)", status)
}
func TestAuth_SQLiteWithoutAuth(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Request SQLite endpoint without auth
req := &e2e.HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/db/sqlite/list",
SkipAuth: true,
}
_, status, err := req.Do(ctx)
require.NoError(t, err, "FAIL: Request failed")
// STRICT: SQLite endpoint must require authentication
require.True(t, status == http.StatusUnauthorized || status == http.StatusForbidden,
"FAIL: SQLite endpoint accessible without auth - expected 401/403, got %d", status)
t.Logf(" ✓ SQLite endpoint correctly requires auth (status %d)", status)
}

View File

@ -1,6 +1,6 @@
//go:build e2e
package shared_test
package e2e
import (
"bytes"
@ -10,8 +10,6 @@ import (
"net/http"
"testing"
"time"
e2e "github.com/DeBrosOfficial/network/e2e"
)
// uploadFile is a helper to upload a file to storage
@ -36,7 +34,7 @@ func uploadFile(t *testing.T, ctx context.Context, content []byte, filename stri
}
// Create request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
@ -44,13 +42,13 @@ func uploadFile(t *testing.T, ctx context.Context, content []byte, filename stri
req.Header.Set("Content-Type", writer.FormDataContentType())
// Add auth headers
if jwt := e2e.GetJWT(); jwt != "" {
if jwt := GetJWT(); jwt != "" {
req.Header.Set("Authorization", "Bearer "+jwt)
} else if apiKey := e2e.GetAPIKey(); apiKey != "" {
} else if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload request failed: %v", err)
@ -62,20 +60,28 @@ func uploadFile(t *testing.T, ctx context.Context, content []byte, filename stri
t.Fatalf("upload failed with status %d: %s", resp.StatusCode, string(body))
}
body, err := io.ReadAll(resp.Body)
result, err := DecodeJSONFromReader(resp.Body)
if err != nil {
t.Fatalf("failed to read upload response: %v", err)
}
var result map[string]interface{}
if err := e2e.DecodeJSON(body, &result); err != nil {
t.Fatalf("failed to decode upload response: %v", err)
}
return result["cid"].(string)
}
// DecodeJSON is a helper to decode JSON from io.ReadCloser
func DecodeJSONFromReader(rc io.ReadCloser) (map[string]interface{}, error) {
defer rc.Close()
body, err := io.ReadAll(rc)
if err != nil {
return nil, err
}
var result map[string]interface{}
err = DecodeJSON(body, &result)
return result, err
}
func TestStorage_UploadText(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -101,18 +107,18 @@ func TestStorage_UploadText(t *testing.T) {
}
// Create request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload request failed: %v", err)
@ -126,7 +132,7 @@ func TestStorage_UploadText(t *testing.T) {
var result map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &result); err != nil {
if err := DecodeJSON(body, &result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -144,7 +150,7 @@ func TestStorage_UploadText(t *testing.T) {
}
func TestStorage_UploadBinary(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -171,18 +177,18 @@ func TestStorage_UploadBinary(t *testing.T) {
}
// Create request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload request failed: %v", err)
@ -196,7 +202,7 @@ func TestStorage_UploadBinary(t *testing.T) {
var result map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &result); err != nil {
if err := DecodeJSON(body, &result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -206,7 +212,7 @@ func TestStorage_UploadBinary(t *testing.T) {
}
func TestStorage_UploadLarge(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -233,18 +239,18 @@ func TestStorage_UploadLarge(t *testing.T) {
}
// Create request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload request failed: %v", err)
@ -258,7 +264,7 @@ func TestStorage_UploadLarge(t *testing.T) {
var result map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &result); err != nil {
if err := DecodeJSON(body, &result); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
@ -268,7 +274,7 @@ func TestStorage_UploadLarge(t *testing.T) {
}
func TestStorage_PinUnpin(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -293,18 +299,18 @@ func TestStorage_PinUnpin(t *testing.T) {
}
// Create upload request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload failed: %v", err)
@ -313,23 +319,16 @@ func TestStorage_PinUnpin(t *testing.T) {
var uploadResult map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &uploadResult); err != nil {
if err := DecodeJSON(body, &uploadResult); err != nil {
t.Fatalf("failed to decode upload response: %v", err)
}
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
t.Fatalf("upload failed with status %d: %s", resp.StatusCode, string(body))
}
cid, ok := uploadResult["cid"].(string)
if !ok || cid == "" {
t.Fatalf("no CID in upload response: %v", uploadResult)
}
cid := uploadResult["cid"].(string)
// Pin the file
pinReq := &e2e.HTTPRequest{
pinReq := &HTTPRequest{
Method: http.MethodPost,
URL: e2e.GetGatewayURL() + "/v1/storage/pin",
URL: GetGatewayURL() + "/v1/storage/pin",
Body: map[string]interface{}{
"cid": cid,
"name": "pinned-file",
@ -346,7 +345,7 @@ func TestStorage_PinUnpin(t *testing.T) {
}
var pinResult map[string]interface{}
if err := e2e.DecodeJSON(body2, &pinResult); err != nil {
if err := DecodeJSON(body2, &pinResult); err != nil {
t.Fatalf("failed to decode pin response: %v", err)
}
@ -355,9 +354,9 @@ func TestStorage_PinUnpin(t *testing.T) {
}
// Unpin the file
unpinReq := &e2e.HTTPRequest{
unpinReq := &HTTPRequest{
Method: http.MethodDelete,
URL: e2e.GetGatewayURL() + "/v1/storage/unpin/" + cid,
URL: GetGatewayURL() + "/v1/storage/unpin/" + cid,
}
body3, status, err := unpinReq.Do(ctx)
@ -371,7 +370,7 @@ func TestStorage_PinUnpin(t *testing.T) {
}
func TestStorage_Status(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -396,18 +395,18 @@ func TestStorage_Status(t *testing.T) {
}
// Create upload request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload failed: %v", err)
@ -416,16 +415,16 @@ func TestStorage_Status(t *testing.T) {
var uploadResult map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &uploadResult); err != nil {
if err := DecodeJSON(body, &uploadResult); err != nil {
t.Fatalf("failed to decode upload response: %v", err)
}
cid := uploadResult["cid"].(string)
// Get status
statusReq := &e2e.HTTPRequest{
statusReq := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/storage/status/" + cid,
URL: GetGatewayURL() + "/v1/storage/status/" + cid,
}
statusBody, status, err := statusReq.Do(ctx)
@ -438,7 +437,7 @@ func TestStorage_Status(t *testing.T) {
}
var statusResult map[string]interface{}
if err := e2e.DecodeJSON(statusBody, &statusResult); err != nil {
if err := DecodeJSON(statusBody, &statusResult); err != nil {
t.Fatalf("failed to decode status response: %v", err)
}
@ -448,14 +447,14 @@ func TestStorage_Status(t *testing.T) {
}
func TestStorage_InvalidCID(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
statusReq := &e2e.HTTPRequest{
statusReq := &HTTPRequest{
Method: http.MethodGet,
URL: e2e.GetGatewayURL() + "/v1/storage/status/QmInvalidCID123456789",
URL: GetGatewayURL() + "/v1/storage/status/QmInvalidCID123456789",
}
_, status, err := statusReq.Do(ctx)
@ -469,7 +468,7 @@ func TestStorage_InvalidCID(t *testing.T) {
}
func TestStorage_GetByteRange(t *testing.T) {
e2e.SkipIfMissingGateway(t)
SkipIfMissingGateway(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@ -494,18 +493,18 @@ func TestStorage_GetByteRange(t *testing.T) {
}
// Create upload request
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e2e.GetGatewayURL()+"/v1/storage/upload", &buf)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, GetGatewayURL()+"/v1/storage/upload", &buf)
if err != nil {
t.Fatalf("failed to create request: %v", err)
}
req.Header.Set("Content-Type", writer.FormDataContentType())
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
req.Header.Set("Authorization", "Bearer "+apiKey)
}
client := e2e.NewHTTPClient(5 * time.Minute)
client := NewHTTPClient(5 * time.Minute)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("upload failed: %v", err)
@ -514,19 +513,19 @@ func TestStorage_GetByteRange(t *testing.T) {
var uploadResult map[string]interface{}
body, _ := io.ReadAll(resp.Body)
if err := e2e.DecodeJSON(body, &uploadResult); err != nil {
if err := DecodeJSON(body, &uploadResult); err != nil {
t.Fatalf("failed to decode upload response: %v", err)
}
cid := uploadResult["cid"].(string)
// Get full content
getReq, err := http.NewRequestWithContext(ctx, http.MethodGet, e2e.GetGatewayURL()+"/v1/storage/get/"+cid, nil)
getReq, err := http.NewRequestWithContext(ctx, http.MethodGet, GetGatewayURL()+"/v1/storage/get/"+cid, nil)
if err != nil {
t.Fatalf("failed to create get request: %v", err)
}
if apiKey := e2e.GetAPIKey(); apiKey != "" {
if apiKey := GetAPIKey(); apiKey != "" {
getReq.Header.Set("Authorization", "Bearer "+apiKey)
}

BIN
gateway Executable file

Binary file not shown.

87
go.mod
View File

@ -1,39 +1,34 @@
module github.com/DeBrosOfficial/network
go 1.24.6
go 1.24.0
toolchain go1.24.1
require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/lipgloss v1.0.0
github.com/coredns/caddy v1.1.4
github.com/coredns/coredns v1.12.1
github.com/ethereum/go-ethereum v1.13.14
github.com/go-chi/chi/v5 v5.2.3
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
github.com/gorilla/websocket v1.5.3
github.com/libp2p/go-libp2p v0.41.1
github.com/libp2p/go-libp2p-pubsub v0.14.2
github.com/mackerelio/go-osstat v0.2.6
github.com/mattn/go-sqlite3 v1.14.32
github.com/mdp/qrterminal/v3 v3.2.1
github.com/miekg/dns v1.1.70
github.com/multiformats/go-multiaddr v0.16.0
github.com/multiformats/go-multiaddr v0.15.0
github.com/olric-data/olric v0.7.0
github.com/rqlite/gorqlite v0.0.0-20250609141355-ac86a4a1c9a8
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/tetratelabs/wazero v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.47.0
golang.org/x/net v0.49.0
golang.org/x/crypto v0.40.0
golang.org/x/net v0.42.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/RoaringBitmap/roaring v1.9.4 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
@ -47,14 +42,12 @@ require (
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.3 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
@ -63,40 +56,38 @@ require (
github.com/google/btree v1.1.3 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.4 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-sockaddr v1.0.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/memberlist v0.5.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.5.0 // indirect
github.com/ipfs/go-log/v2 v2.6.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/koron/go-ssdp v0.0.6 // indirect
github.com/koron/go-ssdp v0.0.5 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.2.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-netroute v0.3.0 // indirect
github.com/libp2p/go-netroute v0.2.2 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v5 v5.0.1 // indirect
github.com/libp2p/go-yamux/v5 v5.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/miekg/dns v1.1.66 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
@ -110,39 +101,37 @@ require (
github.com/multiformats/go-multiaddr-dns v0.4.1 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.1 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.6.1 // indirect
github.com/multiformats/go-multistream v0.6.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pion/datachannel v1.5.10 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/dtls/v3 v3.0.6 // indirect
github.com/pion/ice/v4 v4.0.10 // indirect
github.com/pion/interceptor v0.1.40 // indirect
github.com/pion/dtls/v3 v3.0.4 // indirect
github.com/pion/ice/v4 v4.0.8 // indirect
github.com/pion/interceptor v0.1.37 // indirect
github.com/pion/logging v0.2.3 // indirect
github.com/pion/mdns/v2 v2.0.7 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.15 // indirect
github.com/pion/rtp v1.8.19 // indirect
github.com/pion/sctp v1.8.39 // indirect
github.com/pion/sdp/v3 v3.0.13 // indirect
github.com/pion/srtp/v3 v3.0.6 // indirect
github.com/pion/rtp v1.8.11 // indirect
github.com/pion/sctp v1.8.37 // indirect
github.com/pion/sdp/v3 v3.0.10 // indirect
github.com/pion/srtp/v3 v3.0.4 // indirect
github.com/pion/stun v0.6.1 // indirect
github.com/pion/stun/v3 v3.0.0 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pion/turn/v4 v4.0.2 // indirect
github.com/pion/webrtc/v4 v4.1.2 // indirect
github.com/pion/turn/v4 v4.0.0 // indirect
github.com/pion/webrtc/v4 v4.0.10 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.23.0 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/common v0.63.0 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.50.1 // indirect
@ -150,33 +139,25 @@ require (
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/redis/go-redis/v9 v9.8.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/redcon v1.6.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
go.uber.org/dig v1.19.0 // indirect
go.uber.org/fx v1.24.0 // indirect
go.uber.org/mock v0.6.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.23.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.40.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
google.golang.org/grpc v1.78.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
golang.org/x/mod v0.26.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.27.0 // indirect
golang.org/x/tools v0.35.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
rsc.io/qr v0.2.0 // indirect
)

200
go.sum
View File

@ -17,8 +17,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
@ -67,21 +65,15 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/coredns/caddy v1.1.4 h1:+Lls5xASB0QsA2jpCroCOwpPlb5GjIGlxdjXxdX0XVo=
github.com/coredns/caddy v1.1.4/go.mod h1:A6ntJQlAWuQfFlsd9hvigKbo2WS0VUs2l1e2F+BawD4=
github.com/coredns/coredns v1.12.1 h1:haptbGscSbdWU46xrjdPj1vp3wvH1Z2FgCSQKEdgN5s=
github.com/coredns/coredns v1.12.1/go.mod h1:V26ngiKdNvAiEre5PTAvklrvTjnNjl6lakq1nbE/NbU=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU=
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
@ -101,7 +93,6 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ=
github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg=
github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
@ -119,10 +110,8 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
@ -148,8 +137,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
@ -171,18 +158,15 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20250208200701-d0013a598941 h1:43XjGa6toxLpeksjcxs1jIoIyr+vUfOqY2c6HB4bpoc=
github.com/google/pprof v0.0.0-20250208200701-d0013a598941/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 h1:MJG/KsmcqMwFAkh8mTnAwhyKoB+sTAnY4CACC110tbU=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@ -199,9 +183,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-sockaddr v1.0.7 h1:G+pTkSO01HpR5qCxg7lxfsFEZaG+C0VssTy/9dbT+Fw=
github.com/hashicorp/go-sockaddr v1.0.7/go.mod h1:FZQbEYa1pxkQ7WLpyXJ6cbjpT8q0YgQaK/JakXqGyWw=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
@ -215,8 +198,6 @@ github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ipfs/go-cid v0.5.0 h1:goEKKhaGm0ul11IHA7I6p1GmKz8kEYniqFopaB5Otwg=
github.com/ipfs/go-cid v0.5.0/go.mod h1:0L7vmeNXpQpUS9vt+yEARkJ8rOg43DF3iPgn4GIN0mk=
github.com/ipfs/go-log/v2 v2.6.0 h1:2Nu1KKQQ2ayonKp4MPo6pXCjqw1ULc9iohRqWV5EYqg=
@ -243,8 +224,8 @@ github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=
github.com/koron/go-ssdp v0.0.6/go.mod h1:0R9LfRJGek1zWTjN3JUNlm5INCDYGpRDfAptnct63fI=
github.com/koron/go-ssdp v0.0.5 h1:E1iSMxIs4WqxTbIBLtmNBeOOC+1sCIXQeqTWVnpmwhk=
github.com/koron/go-ssdp v0.0.5/go.mod h1:Qm59B7hpKpDqfyRNWRNr00jGwLdXjDyZh6y7rH6VS0w=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@ -269,12 +250,12 @@ github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUI
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
github.com/libp2p/go-netroute v0.3.0 h1:nqPCXHmeNmgTJnktosJ/sIef9hvwYCrsLxXmfNks/oc=
github.com/libp2p/go-netroute v0.3.0/go.mod h1:Nkd5ShYgSMS5MUKy/MU2T57xFoOKvvLR92Lic48LEyA=
github.com/libp2p/go-netroute v0.2.2 h1:Dejd8cQ47Qx2kRABg6lPwknU7+nBnFRpko45/fFPuZ8=
github.com/libp2p/go-netroute v0.2.2/go.mod h1:Rntq6jUAH0l9Gg17w5bFGhcC9a+vk4KNXs6s7IljKYE=
github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s=
github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU=
github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfYRSg=
github.com/libp2p/go-yamux/v5 v5.0.1/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU=
github.com/libp2p/go-yamux/v5 v5.0.0 h1:2djUh96d3Jiac/JpGkKs4TO49YhsfLopAoryfPmf+Po=
github.com/libp2p/go-yamux/v5 v5.0.0/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
@ -292,13 +273,9 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mdp/qrterminal/v3 v3.2.1 h1:6+yQjiiOsSuXT5n9/m60E54vdgFsw0zhADHhHLrFet4=
github.com/mdp/qrterminal/v3 v3.2.1/go.mod h1:jOTmXvnBsMy5xqLniO0R++Jmjs2sTm9dFSuQ5kpz/SU=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/miekg/dns v1.1.70 h1:DZ4u2AV35VJxdD9Fo9fIWm119BsQL5cZU1cQ9s0LkqA=
github.com/miekg/dns v1.1.70/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
github.com/miekg/dns v1.1.66 h1:FeZXOS3VCVsKnEAd+wBkjMC3D2K+ww66Cq3VnCINuJE=
github.com/miekg/dns v1.1.66/go.mod h1:jGFzBsSNbJw6z1HYut1RKBKHA9PBdxeHrZG8J+gC2WE=
github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8=
github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms=
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc=
@ -329,21 +306,21 @@ github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYg
github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0=
github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo=
github.com/multiformats/go-multiaddr v0.16.0 h1:oGWEVKioVQcdIOBlYM8BH1rZDWOGJSqr9/BKl6zQ4qc=
github.com/multiformats/go-multiaddr v0.16.0/go.mod h1:JSVUmXDjsVFiW7RjIFMP7+Ev+h1DTbiJgVeTV/tcmP0=
github.com/multiformats/go-multiaddr v0.15.0 h1:zB/HeaI/apcZiTDwhY5YqMvNVl/oQYvs3XySU+qeAVo=
github.com/multiformats/go-multiaddr v0.15.0/go.mod h1:JSVUmXDjsVFiW7RjIFMP7+Ev+h1DTbiJgVeTV/tcmP0=
github.com/multiformats/go-multiaddr-dns v0.4.1 h1:whi/uCLbDS3mSEUMb1MsoT4uzUeZB0N32yzufqS0i5M=
github.com/multiformats/go-multiaddr-dns v0.4.1/go.mod h1:7hfthtB4E4pQwirrz+J0CcDUfbWzTqEzVyYKKIKpgkc=
github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E=
github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo=
github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g=
github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multicodec v0.9.1 h1:x/Fuxr7ZuR4jJV4Os5g444F7xC4XmyUaT/FWtE+9Zjo=
github.com/multiformats/go-multicodec v0.9.1/go.mod h1:LLWNMtyV5ithSBUo3vFIMaeDy+h3EbkMTek1m+Fybbo=
github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg=
github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-multistream v0.6.1 h1:4aoX5v6T+yWmc2raBHsTvzmFhOI8WVOer28DeBBEYdQ=
github.com/multiformats/go-multistream v0.6.1/go.mod h1:ksQf6kqHAb6zIsyw7Zm+gAuVo57Qbq84E27YlYqavqw=
github.com/multiformats/go-multistream v0.6.0 h1:ZaHKbsL404720283o4c/IHQXiS6gb8qAN5EIJ4PN5EA=
github.com/multiformats/go-multistream v0.6.0/go.mod h1:MOyoG5otO24cHIg8kf9QW2/NozURlkP/rvi2FQJyCPg=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
@ -361,8 +338,6 @@ github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlR
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@ -373,12 +348,12 @@ github.com/pion/datachannel v1.5.10/go.mod h1:p/jJfC9arb29W7WrxyKbepTU20CFgyx5oL
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
github.com/pion/dtls/v2 v2.2.12 h1:KP7H5/c1EiVAAKUmXyCzPiQe5+bCJrpOeKg/L05dunk=
github.com/pion/dtls/v2 v2.2.12/go.mod h1:d9SYc9fch0CqK90mRk1dC7AkzzpwJj6u2GU3u+9pqFE=
github.com/pion/dtls/v3 v3.0.6 h1:7Hkd8WhAJNbRgq9RgdNh1aaWlZlGpYTzdqjy9x9sK2E=
github.com/pion/dtls/v3 v3.0.6/go.mod h1:iJxNQ3Uhn1NZWOMWlLxEEHAN5yX7GyPvvKw04v9bzYU=
github.com/pion/ice/v4 v4.0.10 h1:P59w1iauC/wPk9PdY8Vjl4fOFL5B+USq1+xbDcN6gT4=
github.com/pion/ice/v4 v4.0.10/go.mod h1:y3M18aPhIxLlcO/4dn9X8LzLLSma84cx6emMSu14FGw=
github.com/pion/interceptor v0.1.40 h1:e0BjnPcGpr2CFQgKhrQisBU7V3GXK6wrfYrGYaU6Jq4=
github.com/pion/interceptor v0.1.40/go.mod h1:Z6kqH7M/FYirg3frjGJ21VLSRJGBXB/KqaTIrdqnOic=
github.com/pion/dtls/v3 v3.0.4 h1:44CZekewMzfrn9pmGrj5BNnTMDCFwr+6sLH+cCuLM7U=
github.com/pion/dtls/v3 v3.0.4/go.mod h1:R373CsjxWqNPf6MEkfdy3aSe9niZvL/JaKlGeFphtMg=
github.com/pion/ice/v4 v4.0.8 h1:ajNx0idNG+S+v9Phu4LSn2cs8JEfTsA1/tEjkkAVpFY=
github.com/pion/ice/v4 v4.0.8/go.mod h1:y3M18aPhIxLlcO/4dn9X8LzLLSma84cx6emMSu14FGw=
github.com/pion/interceptor v0.1.37 h1:aRA8Zpab/wE7/c0O3fh1PqY0AJI3fCSEM5lRWJVorwI=
github.com/pion/interceptor v0.1.37/go.mod h1:JzxbJ4umVTlZAf+/utHzNesY8tmRkM2lVmkS82TTj8Y=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/logging v0.2.3 h1:gHuf0zpoh1GW67Nr6Gj4cv5Z9ZscU7g/EaoC/Ke/igI=
github.com/pion/logging v0.2.3/go.mod h1:z8YfknkquMe1csOrxK5kc+5/ZPAzMxbKLX5aXpbpC90=
@ -388,14 +363,14 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo=
github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0=
github.com/pion/rtp v1.8.19 h1:jhdO/3XhL/aKm/wARFVmvTfq0lC/CvN1xwYKmduly3c=
github.com/pion/rtp v1.8.19/go.mod h1:bAu2UFKScgzyFqvUKmbvzSdPr+NGbZtv6UB2hesqXBk=
github.com/pion/sctp v1.8.39 h1:PJma40vRHa3UTO3C4MyeJDQ+KIobVYRZQZ0Nt7SjQnE=
github.com/pion/sctp v1.8.39/go.mod h1:cNiLdchXra8fHQwmIoqw0MbLLMs+f7uQ+dGMG2gWebE=
github.com/pion/sdp/v3 v3.0.13 h1:uN3SS2b+QDZnWXgdr69SM8KB4EbcnPnPf2Laxhty/l4=
github.com/pion/sdp/v3 v3.0.13/go.mod h1:88GMahN5xnScv1hIMTqLdu/cOcUkj6a9ytbncwMCq2E=
github.com/pion/srtp/v3 v3.0.6 h1:E2gyj1f5X10sB/qILUGIkL4C2CqK269Xq167PbGCc/4=
github.com/pion/srtp/v3 v3.0.6/go.mod h1:BxvziG3v/armJHAaJ87euvkhHqWe9I7iiOy50K2QkhY=
github.com/pion/rtp v1.8.11 h1:17xjnY5WO5hgO6SD3/NTIUPvSFw/PbLsIJyz1r1yNIk=
github.com/pion/rtp v1.8.11/go.mod h1:8uMBJj32Pa1wwx8Fuv/AsFhn8jsgw+3rUC2PfoBZ8p4=
github.com/pion/sctp v1.8.37 h1:ZDmGPtRPX9mKCiVXtMbTWybFw3z/hVKAZgU81wcOrqs=
github.com/pion/sctp v1.8.37/go.mod h1:cNiLdchXra8fHQwmIoqw0MbLLMs+f7uQ+dGMG2gWebE=
github.com/pion/sdp/v3 v3.0.10 h1:6MChLE/1xYB+CjumMw+gZ9ufp2DPApuVSnDT8t5MIgA=
github.com/pion/sdp/v3 v3.0.10/go.mod h1:88GMahN5xnScv1hIMTqLdu/cOcUkj6a9ytbncwMCq2E=
github.com/pion/srtp/v3 v3.0.4 h1:2Z6vDVxzrX3UHEgrUyIGM4rRouoC7v+NiF1IHtp9B5M=
github.com/pion/srtp/v3 v3.0.4/go.mod h1:1Jx3FwDoxpRaTh1oRV8A/6G1BnFL+QI82eK4ms8EEJQ=
github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4=
github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8=
github.com/pion/stun/v3 v3.0.0 h1:4h1gwhWLWuZWOJIJR9s2ferRO+W3zA/b6ijOI6mKzUw=
@ -406,25 +381,24 @@ github.com/pion/transport/v2 v2.2.10 h1:ucLBLE8nuxiHfvkFKnkDQRYWYfp8ejf4YBOPfaQp
github.com/pion/transport/v2 v2.2.10/go.mod h1:sq1kSLWs+cHW9E+2fJP95QudkzbK7wscs8yYgQToO5E=
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
github.com/pion/turn/v4 v4.0.2 h1:ZqgQ3+MjP32ug30xAbD6Mn+/K4Sxi3SdNOTFf+7mpps=
github.com/pion/turn/v4 v4.0.2/go.mod h1:pMMKP/ieNAG/fN5cZiN4SDuyKsXtNTr0ccN7IToA1zs=
github.com/pion/webrtc/v4 v4.1.2 h1:mpuUo/EJ1zMNKGE79fAdYNFZBX790KE7kQQpLMjjR54=
github.com/pion/webrtc/v4 v4.1.2/go.mod h1:xsCXiNAmMEjIdFxAYU0MbB3RwRieJsegSB2JZsGN+8U=
github.com/pion/turn/v4 v4.0.0 h1:qxplo3Rxa9Yg1xXDxxH8xaqcyGUtbHYw4QSCvmFWvhM=
github.com/pion/turn/v4 v4.0.0/go.mod h1:MuPDkm15nYSklKpN8vWJ9W2M0PlyQZqYt1McGuxG7mA=
github.com/pion/webrtc/v4 v4.0.10 h1:Hq/JLjhqLxi+NmCtE8lnRPDr8H4LcNvwg8OxVcdv56Q=
github.com/pion/webrtc/v4 v4.0.10/go.mod h1:ViHLVaNpiuvaH8pdiuQxuA9awuE6KVzAXx3vVWilOck=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@ -435,8 +409,8 @@ github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k=
github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
@ -458,13 +432,12 @@ github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rqlite/gorqlite v0.0.0-20250609141355-ac86a4a1c9a8 h1:BoxiqWvhprOB2isgM59s8wkgKwAoyQH66Twfmof41oE=
github.com/rqlite/gorqlite v0.0.0-20250609141355-ac86a4a1c9a8/go.mod h1:xF/KoXmrRyahPfo5L7Szb5cAAUl53dMWBh9cMruGEZg=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
@ -499,10 +472,6 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@ -515,8 +484,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
@ -542,33 +511,18 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
go.uber.org/dig v1.19.0 h1:BACLhebsYdpQ7IROQ1AGPjrXcP5dF80U3gKoFzbaq/4=
go.uber.org/dig v1.19.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.24.0 h1:wE8mruvpg2kiiL1Vqd0CC+tr0/24XIB10Iwp2lLWzkg=
go.uber.org/fx v1.24.0/go.mod h1:AmDeGyS+ZARGKM4tlH4FY2Jr63VjbEDJHtqXTGP5hbo=
go.uber.org/dig v1.18.0 h1:imUL1UiY0Mg4bqbFfsRQO5G4CGRBec/ZujWTvSVp3pw=
go.uber.org/dig v1.18.0/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.23.0 h1:lIr/gYWQGfTwGcSXWXu4vP5Ws6iqnNEIY+F/aFzCKTg=
go.uber.org/fx v1.23.0/go.mod h1:o/D9n+2mLP6v1EG+qsdT1O8wKopYAsqZasju97SDFCU=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@ -584,8 +538,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4=
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=
@ -598,8 +552,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -623,8 +577,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@ -641,8 +595,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -675,10 +629,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc h1:bH6xUXay0AIFMElXG2rQ4uiE+7ncwtiOdPfYK1NK2XA=
golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc/go.mod h1:hKdjCMrbv9skySur+Nek8Hd0uJ0GuxJIoIX2payrIdQ=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@ -686,8 +638,6 @@ golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@ -697,12 +647,12 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@ -715,14 +665,12 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y=
@ -735,14 +683,10 @@ google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg=
google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b h1:Mv8VFug0MP9e5vUxfBcE3vUkV6CImK3cMNMIDFjmzxU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@ -750,8 +694,8 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@ -775,7 +719,5 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg=
lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo=
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=

View File

@ -1,4 +1,4 @@
-- Orama Gateway - Initial database schema (SQLite/RQLite dialect)
-- DeBros Gateway - Initial database schema (SQLite/RQLite dialect)
-- This file scaffolds core tables used by the HTTP gateway for auth, observability, and namespacing.
-- Apply via your migration tooling or manual execution in RQLite.

View File

@ -1,4 +1,4 @@
-- Orama Gateway - Core schema (Phase 2)
-- DeBros Gateway - Core schema (Phase 2)
-- Adds apps, nonces, subscriptions, refresh_tokens, audit_events, namespace_ownership
-- SQLite/RQLite dialect

View File

@ -1,4 +1,4 @@
-- Orama Gateway - Wallet to API Key linkage (Phase 3)
-- DeBros Gateway - Wallet to API Key linkage (Phase 3)
-- Ensures one API key per (namespace, wallet) and enables lookup
BEGIN;

View File

@ -1,77 +0,0 @@
-- Migration 005: DNS Records for CoreDNS Integration
-- This migration creates tables for managing DNS records with RQLite backend for CoreDNS
BEGIN;
-- DNS records table for dynamic DNS management
CREATE TABLE IF NOT EXISTS dns_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fqdn TEXT NOT NULL UNIQUE, -- Fully qualified domain name (e.g., myapp.node-7prvNa.orama.network)
record_type TEXT NOT NULL DEFAULT 'A', -- DNS record type: A, AAAA, CNAME, TXT
value TEXT NOT NULL, -- IP address or target value
ttl INTEGER NOT NULL DEFAULT 300, -- Time to live in seconds
namespace TEXT NOT NULL, -- Namespace that owns this record
deployment_id TEXT, -- Optional: deployment that created this record
node_id TEXT, -- Optional: specific node ID for node-specific routing
is_active BOOLEAN NOT NULL DEFAULT TRUE,-- Enable/disable without deleting
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by TEXT NOT NULL -- Wallet address or 'system' for auto-created records
);
-- Indexes for fast DNS lookups
CREATE INDEX IF NOT EXISTS idx_dns_records_fqdn ON dns_records(fqdn);
CREATE INDEX IF NOT EXISTS idx_dns_records_namespace ON dns_records(namespace);
CREATE INDEX IF NOT EXISTS idx_dns_records_deployment ON dns_records(deployment_id);
CREATE INDEX IF NOT EXISTS idx_dns_records_node_id ON dns_records(node_id);
CREATE INDEX IF NOT EXISTS idx_dns_records_active ON dns_records(is_active);
-- DNS nodes registry for tracking active nodes
CREATE TABLE IF NOT EXISTS dns_nodes (
id TEXT PRIMARY KEY, -- Node ID (e.g., node-7prvNa)
ip_address TEXT NOT NULL, -- Public IP address
internal_ip TEXT, -- Private IP for cluster communication
region TEXT, -- Geographic region
status TEXT NOT NULL DEFAULT 'active', -- active, draining, offline
last_seen TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
capabilities TEXT, -- JSON: ["wasm", "ipfs", "cache"]
metadata TEXT, -- JSON: additional node info
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for node health monitoring
CREATE INDEX IF NOT EXISTS idx_dns_nodes_status ON dns_nodes(status);
CREATE INDEX IF NOT EXISTS idx_dns_nodes_last_seen ON dns_nodes(last_seen);
-- Reserved domains table to prevent subdomain collisions
CREATE TABLE IF NOT EXISTS reserved_domains (
domain TEXT PRIMARY KEY,
reason TEXT NOT NULL,
reserved_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Seed reserved domains
INSERT INTO reserved_domains (domain, reason) VALUES
('api.orama.network', 'API gateway endpoint'),
('www.orama.network', 'Marketing website'),
('admin.orama.network', 'Admin panel'),
('ns1.orama.network', 'Nameserver 1'),
('ns2.orama.network', 'Nameserver 2'),
('ns3.orama.network', 'Nameserver 3'),
('ns4.orama.network', 'Nameserver 4'),
('mail.orama.network', 'Email service'),
('cdn.orama.network', 'Content delivery'),
('docs.orama.network', 'Documentation'),
('status.orama.network', 'Status page')
ON CONFLICT(domain) DO NOTHING;
-- Mark migration as applied
CREATE TABLE IF NOT EXISTS schema_migrations (
version INTEGER PRIMARY KEY,
applied_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO schema_migrations(version) VALUES (5);
COMMIT;

View File

@ -1,74 +0,0 @@
-- Migration 006: Per-Namespace SQLite Databases
-- This migration creates infrastructure for isolated SQLite databases per namespace
BEGIN;
-- Namespace SQLite databases registry
CREATE TABLE IF NOT EXISTS namespace_sqlite_databases (
id TEXT PRIMARY KEY, -- UUID
namespace TEXT NOT NULL, -- Namespace that owns this database
database_name TEXT NOT NULL, -- Database name (unique per namespace)
home_node_id TEXT NOT NULL, -- Node ID where database file resides
file_path TEXT NOT NULL, -- Absolute path on home node
size_bytes BIGINT DEFAULT 0, -- Current database size
backup_cid TEXT, -- Latest backup CID in IPFS
last_backup_at TIMESTAMP, -- Last backup timestamp
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by TEXT NOT NULL, -- Wallet address that created the database
UNIQUE(namespace, database_name)
);
-- Indexes for database lookups
CREATE INDEX IF NOT EXISTS idx_sqlite_databases_namespace ON namespace_sqlite_databases(namespace);
CREATE INDEX IF NOT EXISTS idx_sqlite_databases_home_node ON namespace_sqlite_databases(home_node_id);
CREATE INDEX IF NOT EXISTS idx_sqlite_databases_name ON namespace_sqlite_databases(namespace, database_name);
-- SQLite database backups history
CREATE TABLE IF NOT EXISTS namespace_sqlite_backups (
id TEXT PRIMARY KEY, -- UUID
database_id TEXT NOT NULL, -- References namespace_sqlite_databases.id
backup_cid TEXT NOT NULL, -- IPFS CID of backup file
size_bytes BIGINT NOT NULL, -- Backup file size
backup_type TEXT NOT NULL, -- 'manual', 'scheduled', 'migration'
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by TEXT NOT NULL,
FOREIGN KEY (database_id) REFERENCES namespace_sqlite_databases(id) ON DELETE CASCADE
);
-- Index for backup history queries
CREATE INDEX IF NOT EXISTS idx_sqlite_backups_database ON namespace_sqlite_backups(database_id, created_at DESC);
-- Namespace quotas for resource management (future use)
CREATE TABLE IF NOT EXISTS namespace_quotas (
namespace TEXT PRIMARY KEY,
-- Storage quotas
max_sqlite_databases INTEGER DEFAULT 10, -- Max SQLite databases per namespace
max_storage_bytes BIGINT DEFAULT 5368709120, -- 5GB default
max_ipfs_pins INTEGER DEFAULT 1000, -- Max pinned IPFS objects
-- Compute quotas
max_deployments INTEGER DEFAULT 20, -- Max concurrent deployments
max_cpu_percent INTEGER DEFAULT 200, -- Total CPU quota (2 cores)
max_memory_mb INTEGER DEFAULT 2048, -- Total memory quota
-- Rate limits
max_rqlite_queries_per_minute INTEGER DEFAULT 1000,
max_olric_ops_per_minute INTEGER DEFAULT 10000,
-- Current usage (updated periodically)
current_storage_bytes BIGINT DEFAULT 0,
current_deployments INTEGER DEFAULT 0,
current_sqlite_databases INTEGER DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Mark migration as applied
INSERT OR IGNORE INTO schema_migrations(version) VALUES (6);
COMMIT;

View File

@ -1,178 +0,0 @@
-- Migration 007: Deployments System
-- This migration creates the complete schema for managing custom deployments
-- (Static sites, Next.js, Go backends, Node.js backends)
BEGIN;
-- Main deployments table
CREATE TABLE IF NOT EXISTS deployments (
id TEXT PRIMARY KEY, -- UUID
namespace TEXT NOT NULL, -- Owner namespace
name TEXT NOT NULL, -- Deployment name (unique per namespace)
type TEXT NOT NULL, -- 'static', 'nextjs', 'nextjs-static', 'go-backend', 'go-wasm', 'nodejs-backend'
version INTEGER NOT NULL DEFAULT 1, -- Monotonic version counter
status TEXT NOT NULL DEFAULT 'deploying', -- 'deploying', 'active', 'failed', 'stopped', 'updating'
-- Content storage
content_cid TEXT, -- IPFS CID for static content or built assets
build_cid TEXT, -- IPFS CID for build artifacts (Next.js SSR, binaries)
-- Runtime configuration
home_node_id TEXT, -- Node ID hosting stateful data/processes
port INTEGER, -- Allocated port (NULL for static/WASM)
subdomain TEXT, -- Custom subdomain (e.g., myapp)
environment TEXT, -- JSON: {"KEY": "value", ...}
-- Resource limits
memory_limit_mb INTEGER DEFAULT 256,
cpu_limit_percent INTEGER DEFAULT 50,
disk_limit_mb INTEGER DEFAULT 1024,
-- Health & monitoring
health_check_path TEXT DEFAULT '/health', -- HTTP path for health checks
health_check_interval INTEGER DEFAULT 30, -- Seconds between health checks
restart_policy TEXT DEFAULT 'always', -- 'always', 'on-failure', 'never'
max_restart_count INTEGER DEFAULT 10, -- Max restarts before marking as failed
-- Metadata
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deployed_by TEXT NOT NULL, -- Wallet address or API key
UNIQUE(namespace, name)
);
-- Indexes for deployment lookups
CREATE INDEX IF NOT EXISTS idx_deployments_namespace ON deployments(namespace);
CREATE INDEX IF NOT EXISTS idx_deployments_status ON deployments(status);
CREATE INDEX IF NOT EXISTS idx_deployments_home_node ON deployments(home_node_id);
CREATE INDEX IF NOT EXISTS idx_deployments_type ON deployments(type);
CREATE INDEX IF NOT EXISTS idx_deployments_subdomain ON deployments(subdomain);
-- Port allocations table (prevents port conflicts)
CREATE TABLE IF NOT EXISTS port_allocations (
node_id TEXT NOT NULL,
port INTEGER NOT NULL,
deployment_id TEXT NOT NULL,
allocated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (node_id, port),
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Index for finding allocated ports by node
CREATE INDEX IF NOT EXISTS idx_port_allocations_node ON port_allocations(node_id, port);
CREATE INDEX IF NOT EXISTS idx_port_allocations_deployment ON port_allocations(deployment_id);
-- Home node assignments (namespace → node mapping)
CREATE TABLE IF NOT EXISTS home_node_assignments (
namespace TEXT PRIMARY KEY,
home_node_id TEXT NOT NULL,
assigned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_heartbeat TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deployment_count INTEGER DEFAULT 0, -- Cached count for capacity planning
total_memory_mb INTEGER DEFAULT 0, -- Cached total memory usage
total_cpu_percent INTEGER DEFAULT 0 -- Cached total CPU usage
);
-- Index for querying by node
CREATE INDEX IF NOT EXISTS idx_home_node_by_node ON home_node_assignments(home_node_id);
-- Deployment domains (custom domain mapping)
CREATE TABLE IF NOT EXISTS deployment_domains (
id TEXT PRIMARY KEY, -- UUID
deployment_id TEXT NOT NULL,
namespace TEXT NOT NULL,
domain TEXT NOT NULL UNIQUE, -- Full domain (e.g., myapp.orama.network or custom)
routing_type TEXT NOT NULL DEFAULT 'balanced', -- 'balanced' or 'node_specific'
node_id TEXT, -- For node_specific routing
is_custom BOOLEAN DEFAULT FALSE, -- True for user's own domain
tls_cert_cid TEXT, -- IPFS CID for custom TLS certificate
verified_at TIMESTAMP, -- When custom domain was verified
verification_token TEXT, -- TXT record token for domain verification
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Indexes for domain lookups
CREATE INDEX IF NOT EXISTS idx_deployment_domains_deployment ON deployment_domains(deployment_id);
CREATE INDEX IF NOT EXISTS idx_deployment_domains_domain ON deployment_domains(domain);
CREATE INDEX IF NOT EXISTS idx_deployment_domains_namespace ON deployment_domains(namespace);
-- Deployment history (version tracking and rollback)
CREATE TABLE IF NOT EXISTS deployment_history (
id TEXT PRIMARY KEY, -- UUID
deployment_id TEXT NOT NULL,
version INTEGER NOT NULL,
content_cid TEXT,
build_cid TEXT,
deployed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deployed_by TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'success', -- 'success', 'failed', 'rolled_back'
error_message TEXT,
rollback_from_version INTEGER, -- If this is a rollback, original version
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Indexes for history queries
CREATE INDEX IF NOT EXISTS idx_deployment_history_deployment ON deployment_history(deployment_id, version DESC);
CREATE INDEX IF NOT EXISTS idx_deployment_history_status ON deployment_history(status);
-- Deployment environment variables (separate for security)
CREATE TABLE IF NOT EXISTS deployment_env_vars (
id TEXT PRIMARY KEY, -- UUID
deployment_id TEXT NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL, -- Encrypted in production
is_secret BOOLEAN DEFAULT FALSE, -- True for sensitive values
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(deployment_id, key),
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Index for env var lookups
CREATE INDEX IF NOT EXISTS idx_deployment_env_vars_deployment ON deployment_env_vars(deployment_id);
-- Deployment events log (audit trail)
CREATE TABLE IF NOT EXISTS deployment_events (
id TEXT PRIMARY KEY, -- UUID
deployment_id TEXT NOT NULL,
event_type TEXT NOT NULL, -- 'created', 'started', 'stopped', 'restarted', 'updated', 'deleted', 'health_check_failed'
message TEXT,
metadata TEXT, -- JSON: additional context
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by TEXT, -- Wallet address or 'system'
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Index for event queries
CREATE INDEX IF NOT EXISTS idx_deployment_events_deployment ON deployment_events(deployment_id, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_deployment_events_type ON deployment_events(event_type);
-- Process health checks (for dynamic deployments)
CREATE TABLE IF NOT EXISTS deployment_health_checks (
id TEXT PRIMARY KEY, -- UUID
deployment_id TEXT NOT NULL,
node_id TEXT NOT NULL,
status TEXT NOT NULL, -- 'healthy', 'unhealthy', 'unknown'
response_time_ms INTEGER,
status_code INTEGER,
error_message TEXT,
checked_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
-- Index for health check queries (keep only recent checks)
CREATE INDEX IF NOT EXISTS idx_health_checks_deployment ON deployment_health_checks(deployment_id, checked_at DESC);
-- Mark migration as applied
INSERT OR IGNORE INTO schema_migrations(version) VALUES (7);
COMMIT;

View File

@ -1,31 +0,0 @@
-- Migration 008: IPFS Namespace Tracking
-- This migration adds namespace isolation for IPFS content by tracking CID ownership.
-- Table: ipfs_content_ownership
-- Tracks which namespace owns each CID uploaded to IPFS.
-- This enables namespace isolation so that:
-- - Namespace-A cannot GET/PIN/UNPIN Namespace-B's content
-- - Same CID can be uploaded by different namespaces (shared content)
CREATE TABLE IF NOT EXISTS ipfs_content_ownership (
id TEXT PRIMARY KEY,
cid TEXT NOT NULL,
namespace TEXT NOT NULL,
name TEXT,
size_bytes BIGINT DEFAULT 0,
is_pinned BOOLEAN DEFAULT FALSE,
uploaded_at TIMESTAMP NOT NULL,
uploaded_by TEXT NOT NULL,
UNIQUE(cid, namespace)
);
-- Index for fast namespace + CID lookup
CREATE INDEX IF NOT EXISTS idx_ipfs_ownership_namespace_cid
ON ipfs_content_ownership(namespace, cid);
-- Index for fast CID lookup across all namespaces
CREATE INDEX IF NOT EXISTS idx_ipfs_ownership_cid
ON ipfs_content_ownership(cid);
-- Index for namespace-only queries (list all content for a namespace)
CREATE INDEX IF NOT EXISTS idx_ipfs_ownership_namespace
ON ipfs_content_ownership(namespace);

View File

@ -1,45 +0,0 @@
-- Migration 009: Update DNS Records to Support Multiple Records per FQDN
-- This allows round-robin A records and multiple NS records for the same domain
BEGIN;
-- SQLite doesn't support DROP CONSTRAINT, so we recreate the table
-- First, create the new table structure
CREATE TABLE IF NOT EXISTS dns_records_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fqdn TEXT NOT NULL, -- Fully qualified domain name (e.g., myapp.node-7prvNa.orama.network)
record_type TEXT NOT NULL DEFAULT 'A',-- DNS record type: A, AAAA, CNAME, TXT, NS, SOA
value TEXT NOT NULL, -- IP address or target value
ttl INTEGER NOT NULL DEFAULT 300, -- Time to live in seconds
priority INTEGER DEFAULT 0, -- Priority for MX/SRV records, or weight for round-robin
namespace TEXT NOT NULL DEFAULT 'system', -- Namespace that owns this record
deployment_id TEXT, -- Optional: deployment that created this record
node_id TEXT, -- Optional: specific node ID for node-specific routing
is_active BOOLEAN NOT NULL DEFAULT TRUE,-- Enable/disable without deleting
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by TEXT NOT NULL DEFAULT 'system', -- Wallet address or 'system' for auto-created records
UNIQUE(fqdn, record_type, value) -- Allow multiple records of same type for same FQDN, but not duplicates
);
-- Copy existing data if the old table exists
INSERT OR IGNORE INTO dns_records_new (id, fqdn, record_type, value, ttl, namespace, deployment_id, node_id, is_active, created_at, updated_at, created_by)
SELECT id, fqdn, record_type, value, ttl, namespace, deployment_id, node_id, is_active, created_at, updated_at, created_by
FROM dns_records WHERE 1=1;
-- Drop old table and rename new one
DROP TABLE IF EXISTS dns_records;
ALTER TABLE dns_records_new RENAME TO dns_records;
-- Recreate indexes
CREATE INDEX IF NOT EXISTS idx_dns_records_fqdn ON dns_records(fqdn);
CREATE INDEX IF NOT EXISTS idx_dns_records_fqdn_type ON dns_records(fqdn, record_type);
CREATE INDEX IF NOT EXISTS idx_dns_records_namespace ON dns_records(namespace);
CREATE INDEX IF NOT EXISTS idx_dns_records_deployment ON dns_records(deployment_id);
CREATE INDEX IF NOT EXISTS idx_dns_records_node_id ON dns_records(node_id);
CREATE INDEX IF NOT EXISTS idx_dns_records_active ON dns_records(is_active);
-- Mark migration as applied
INSERT OR IGNORE INTO schema_migrations(version) VALUES (9);
COMMIT;

View File

@ -1,190 +0,0 @@
-- Migration 010: Namespace Clusters for Physical Isolation
-- Creates tables to manage per-namespace RQLite and Olric clusters
-- Each namespace gets its own 3-node cluster for complete isolation
BEGIN;
-- Extend namespaces table with cluster status tracking
-- Note: SQLite doesn't support ADD COLUMN IF NOT EXISTS, so we handle this carefully
-- These columns track the provisioning state of the namespace's dedicated cluster
-- First check if columns exist, if not add them
-- cluster_status: 'none', 'provisioning', 'ready', 'degraded', 'failed', 'deprovisioning'
-- Create a new namespaces table with additional columns if needed
CREATE TABLE IF NOT EXISTS namespaces_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cluster_status TEXT DEFAULT 'none',
cluster_created_at TIMESTAMP,
cluster_ready_at TIMESTAMP
);
-- Copy data from old table if it exists and new columns don't
INSERT OR IGNORE INTO namespaces_new (id, name, created_at, cluster_status)
SELECT id, name, created_at, 'none' FROM namespaces WHERE NOT EXISTS (
SELECT 1 FROM pragma_table_info('namespaces') WHERE name = 'cluster_status'
);
-- If the column already exists, this migration was partially applied - skip the table swap
-- We'll use a different approach: just ensure the new tables exist
-- Namespace clusters registry
-- One record per namespace that has a dedicated cluster
CREATE TABLE IF NOT EXISTS namespace_clusters (
id TEXT PRIMARY KEY, -- UUID
namespace_id INTEGER NOT NULL UNIQUE, -- FK to namespaces
namespace_name TEXT NOT NULL, -- Cached for easier lookups
status TEXT NOT NULL DEFAULT 'provisioning', -- provisioning, ready, degraded, failed, deprovisioning
-- Cluster configuration
rqlite_node_count INTEGER NOT NULL DEFAULT 3,
olric_node_count INTEGER NOT NULL DEFAULT 3,
gateway_node_count INTEGER NOT NULL DEFAULT 3,
-- Provisioning metadata
provisioned_by TEXT NOT NULL, -- Wallet address that triggered provisioning
provisioned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ready_at TIMESTAMP,
last_health_check TIMESTAMP,
-- Error tracking
error_message TEXT,
retry_count INTEGER DEFAULT 0,
FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_namespace_clusters_status ON namespace_clusters(status);
CREATE INDEX IF NOT EXISTS idx_namespace_clusters_namespace ON namespace_clusters(namespace_id);
CREATE INDEX IF NOT EXISTS idx_namespace_clusters_name ON namespace_clusters(namespace_name);
-- Namespace cluster nodes
-- Tracks which physical nodes host services for each namespace cluster
CREATE TABLE IF NOT EXISTS namespace_cluster_nodes (
id TEXT PRIMARY KEY, -- UUID
namespace_cluster_id TEXT NOT NULL, -- FK to namespace_clusters
node_id TEXT NOT NULL, -- FK to dns_nodes (physical node)
-- Role in the cluster
-- Each node can have multiple roles (rqlite + olric + gateway)
role TEXT NOT NULL, -- 'rqlite_leader', 'rqlite_follower', 'olric', 'gateway'
-- Service ports (allocated from reserved range 10000-10099)
rqlite_http_port INTEGER, -- Port for RQLite HTTP API
rqlite_raft_port INTEGER, -- Port for RQLite Raft consensus
olric_http_port INTEGER, -- Port for Olric HTTP API
olric_memberlist_port INTEGER, -- Port for Olric memberlist gossip
gateway_http_port INTEGER, -- Port for Gateway HTTP
-- Service status
status TEXT NOT NULL DEFAULT 'pending', -- pending, starting, running, stopped, failed
process_pid INTEGER, -- PID of running process (for local management)
last_heartbeat TIMESTAMP,
error_message TEXT,
-- Join addresses for cluster formation
rqlite_join_address TEXT, -- Address to join RQLite cluster
olric_peers TEXT, -- JSON array of Olric peer addresses
-- Metadata
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(namespace_cluster_id, node_id, role),
FOREIGN KEY (namespace_cluster_id) REFERENCES namespace_clusters(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_cluster_nodes_cluster ON namespace_cluster_nodes(namespace_cluster_id);
CREATE INDEX IF NOT EXISTS idx_cluster_nodes_node ON namespace_cluster_nodes(node_id);
CREATE INDEX IF NOT EXISTS idx_cluster_nodes_status ON namespace_cluster_nodes(status);
CREATE INDEX IF NOT EXISTS idx_cluster_nodes_role ON namespace_cluster_nodes(role);
-- Namespace port allocations
-- Manages the reserved port range (10000-10099) for namespace services
-- Each namespace instance on a node gets a block of 5 consecutive ports
CREATE TABLE IF NOT EXISTS namespace_port_allocations (
id TEXT PRIMARY KEY, -- UUID
node_id TEXT NOT NULL, -- Physical node ID
namespace_cluster_id TEXT NOT NULL, -- Namespace cluster this allocation belongs to
-- Port block (5 consecutive ports)
port_start INTEGER NOT NULL, -- Start of port block (e.g., 10000)
port_end INTEGER NOT NULL, -- End of port block (e.g., 10004)
-- Individual port assignments within the block
rqlite_http_port INTEGER NOT NULL, -- port_start + 0
rqlite_raft_port INTEGER NOT NULL, -- port_start + 1
olric_http_port INTEGER NOT NULL, -- port_start + 2
olric_memberlist_port INTEGER NOT NULL, -- port_start + 3
gateway_http_port INTEGER NOT NULL, -- port_start + 4
allocated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- Prevent overlapping allocations on same node
UNIQUE(node_id, port_start),
-- One allocation per namespace per node
UNIQUE(namespace_cluster_id, node_id),
FOREIGN KEY (namespace_cluster_id) REFERENCES namespace_clusters(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_ns_port_alloc_node ON namespace_port_allocations(node_id);
CREATE INDEX IF NOT EXISTS idx_ns_port_alloc_cluster ON namespace_port_allocations(namespace_cluster_id);
-- Namespace cluster events
-- Audit log for cluster provisioning and lifecycle events
CREATE TABLE IF NOT EXISTS namespace_cluster_events (
id TEXT PRIMARY KEY, -- UUID
namespace_cluster_id TEXT NOT NULL,
event_type TEXT NOT NULL, -- Event types listed below
node_id TEXT, -- Optional: specific node this event relates to
message TEXT,
metadata TEXT, -- JSON for additional event data
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (namespace_cluster_id) REFERENCES namespace_clusters(id) ON DELETE CASCADE
);
-- Event types:
-- 'provisioning_started' - Cluster provisioning began
-- 'nodes_selected' - 3 nodes were selected for the cluster
-- 'ports_allocated' - Ports allocated on a node
-- 'rqlite_started' - RQLite instance started on a node
-- 'rqlite_joined' - RQLite instance joined the cluster
-- 'rqlite_leader_elected' - RQLite leader election completed
-- 'olric_started' - Olric instance started on a node
-- 'olric_joined' - Olric instance joined memberlist
-- 'gateway_started' - Gateway instance started on a node
-- 'dns_created' - DNS records created for namespace
-- 'cluster_ready' - All services ready, cluster is operational
-- 'cluster_degraded' - One or more nodes are unhealthy
-- 'cluster_failed' - Cluster failed to provision or operate
-- 'node_failed' - Specific node became unhealthy
-- 'node_recovered' - Node recovered from failure
-- 'deprovisioning_started' - Cluster deprovisioning began
-- 'deprovisioned' - Cluster fully deprovisioned
CREATE INDEX IF NOT EXISTS idx_cluster_events_cluster ON namespace_cluster_events(namespace_cluster_id, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_cluster_events_type ON namespace_cluster_events(event_type);
-- Global deployment registry
-- Prevents duplicate deployment subdomains across all namespaces
-- Since deployments now use {name}-{random}.{domain}, we track used subdomains globally
CREATE TABLE IF NOT EXISTS global_deployment_subdomains (
subdomain TEXT PRIMARY KEY, -- Full subdomain (e.g., 'myapp-f3o4if')
namespace TEXT NOT NULL, -- Owner namespace
deployment_id TEXT NOT NULL, -- FK to deployments (in namespace cluster)
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- No FK to deployments since deployments are in namespace-specific clusters
UNIQUE(subdomain)
);
CREATE INDEX IF NOT EXISTS idx_global_subdomains_namespace ON global_deployment_subdomains(namespace);
CREATE INDEX IF NOT EXISTS idx_global_subdomains_deployment ON global_deployment_subdomains(deployment_id);
-- Mark migration as applied
INSERT OR IGNORE INTO schema_migrations(version) VALUES (10);
COMMIT;

View File

@ -1,19 +0,0 @@
-- Migration 011: DNS Nameservers Table
-- Maps NS hostnames (ns1, ns2, ns3) to specific node IDs and IPs
-- Provides stable NS assignment that survives restarts and re-seeding
BEGIN;
CREATE TABLE IF NOT EXISTS dns_nameservers (
hostname TEXT PRIMARY KEY, -- e.g., "ns1", "ns2", "ns3"
node_id TEXT NOT NULL, -- Peer ID of the assigned node
ip_address TEXT NOT NULL, -- IP address of the assigned node
domain TEXT NOT NULL, -- Base domain (e.g., "dbrs.space")
assigned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE(node_id, domain) -- A node can only hold one NS slot per domain
);
INSERT OR IGNORE INTO schema_migrations(version) VALUES (11);
COMMIT;

View File

@ -1,15 +0,0 @@
-- Deployment replicas: tracks which nodes host replicas of each deployment
CREATE TABLE IF NOT EXISTS deployment_replicas (
deployment_id TEXT NOT NULL,
node_id TEXT NOT NULL,
port INTEGER DEFAULT 0,
status TEXT NOT NULL DEFAULT 'pending',
is_primary BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (deployment_id, node_id),
FOREIGN KEY (deployment_id) REFERENCES deployments(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_deployment_replicas_node ON deployment_replicas(node_id);
CREATE INDEX IF NOT EXISTS idx_deployment_replicas_status ON deployment_replicas(deployment_id, status);

View File

@ -1,9 +0,0 @@
-- WireGuard mesh peer tracking
CREATE TABLE IF NOT EXISTS wireguard_peers (
node_id TEXT PRIMARY KEY,
wg_ip TEXT NOT NULL UNIQUE,
public_key TEXT NOT NULL UNIQUE,
public_ip TEXT NOT NULL,
wg_port INTEGER DEFAULT 51820,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

View File

@ -1,8 +0,0 @@
CREATE TABLE IF NOT EXISTS invite_tokens (
token TEXT PRIMARY KEY,
created_by TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
used_at DATETIME,
used_by_ip TEXT
);

View File

@ -1,3 +0,0 @@
-- Store IPFS peer IDs alongside WireGuard peers for automatic swarm discovery
-- Each node registers its IPFS peer ID so other nodes can connect via ipfs swarm connect
ALTER TABLE wireguard_peers ADD COLUMN ipfs_peer_id TEXT DEFAULT '';

View File

@ -1,19 +0,0 @@
-- Migration 016: Node health events for failure detection
-- Tracks peer-to-peer health observations for quorum-based dead node detection
BEGIN;
CREATE TABLE IF NOT EXISTS node_health_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
observer_id TEXT NOT NULL, -- node that detected the failure
target_id TEXT NOT NULL, -- node that is suspect/dead
status TEXT NOT NULL, -- 'suspect', 'dead', 'recovered'
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_nhe_target_status ON node_health_events(target_id, status);
CREATE INDEX IF NOT EXISTS idx_nhe_created_at ON node_health_events(created_at);
INSERT OR IGNORE INTO schema_migrations(version) VALUES (16);
COMMIT;

View File

@ -1,21 +0,0 @@
-- Migration 017: Phantom auth sessions for QR code + deep link authentication
-- Stores session state for the CLI-to-phone relay pattern via the gateway
BEGIN;
CREATE TABLE IF NOT EXISTS phantom_auth_sessions (
id TEXT PRIMARY KEY,
namespace TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
wallet TEXT,
api_key TEXT,
error_message TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMP NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_phantom_sessions_status ON phantom_auth_sessions(status);
INSERT OR IGNORE INTO schema_migrations(version) VALUES (17);
COMMIT;

View File

@ -1,6 +0,0 @@
package migrations
import "embed"
//go:embed *.sql
var FS embed.FS

View File

@ -1,350 +0,0 @@
package auth
import (
"encoding/hex"
"os"
"strings"
"testing"
)
// ---------------------------------------------------------------------------
// extractDomainFromURL
// ---------------------------------------------------------------------------
func TestExtractDomainFromURL(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{
name: "https with domain only",
input: "https://example.com",
want: "example.com",
},
{
name: "http with port and path",
input: "http://example.com:8080/path",
want: "example.com",
},
{
name: "https with subdomain and path",
input: "https://sub.domain.com/api/v1",
want: "sub.domain.com",
},
{
name: "no scheme bare domain",
input: "example.com",
want: "example.com",
},
{
name: "https with IP and port",
input: "https://192.168.1.1:443",
want: "192.168.1.1",
},
{
name: "empty string",
input: "",
want: "",
},
{
name: "bare domain no scheme",
input: "gateway.orama.network",
want: "gateway.orama.network",
},
{
name: "https with query params",
input: "https://example.com?foo=bar",
want: "example.com",
},
{
name: "https with path and query params",
input: "https://example.com/page?q=1&r=2",
want: "example.com",
},
{
name: "bare domain with port",
input: "example.com:9090",
want: "example.com",
},
{
name: "https with fragment",
input: "https://example.com/page#section",
want: "example.com",
},
{
name: "https with user info",
input: "https://user:pass@example.com/path",
want: "example.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractDomainFromURL(tt.input)
if got != tt.want {
t.Errorf("extractDomainFromURL(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
// ---------------------------------------------------------------------------
// ValidateWalletAddress
// ---------------------------------------------------------------------------
func TestValidateWalletAddress(t *testing.T) {
validHex40 := "aabbccddee1122334455aabbccddee1122334455"
tests := []struct {
name string
address string
want bool
}{
{
name: "valid 40 char hex with 0x prefix",
address: "0x" + validHex40,
want: true,
},
{
name: "valid 40 char hex without prefix",
address: validHex40,
want: true,
},
{
name: "valid uppercase hex with 0x prefix",
address: "0x" + strings.ToUpper(validHex40),
want: true,
},
{
name: "too short",
address: "0xaabbccdd",
want: false,
},
{
name: "too long",
address: "0x" + validHex40 + "ff",
want: false,
},
{
name: "non hex characters",
address: "0x" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
want: false,
},
{
name: "empty string",
address: "",
want: false,
},
{
name: "just 0x prefix",
address: "0x",
want: false,
},
{
name: "39 hex chars with 0x prefix",
address: "0x" + validHex40[:39],
want: false,
},
{
name: "41 hex chars with 0x prefix",
address: "0x" + validHex40 + "a",
want: false,
},
{
name: "mixed case hex is valid",
address: "0xAaBbCcDdEe1122334455aAbBcCdDeE1122334455",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ValidateWalletAddress(tt.address)
if got != tt.want {
t.Errorf("ValidateWalletAddress(%q) = %v, want %v", tt.address, got, tt.want)
}
})
}
}
// ---------------------------------------------------------------------------
// FormatWalletAddress
// ---------------------------------------------------------------------------
func TestFormatWalletAddress(t *testing.T) {
tests := []struct {
name string
address string
want string
}{
{
name: "already lowercase with 0x",
address: "0xaabbccddee1122334455aabbccddee1122334455",
want: "0xaabbccddee1122334455aabbccddee1122334455",
},
{
name: "uppercase gets lowercased",
address: "0xAABBCCDDEE1122334455AABBCCDDEE1122334455",
want: "0xaabbccddee1122334455aabbccddee1122334455",
},
{
name: "without 0x prefix gets it added",
address: "aabbccddee1122334455aabbccddee1122334455",
want: "0xaabbccddee1122334455aabbccddee1122334455",
},
{
name: "0X uppercase prefix gets normalized",
address: "0XAABBCCDDEE1122334455AABBCCDDEE1122334455",
want: "0xaabbccddee1122334455aabbccddee1122334455",
},
{
name: "mixed case gets normalized",
address: "0xAaBbCcDdEe1122334455AaBbCcDdEe1122334455",
want: "0xaabbccddee1122334455aabbccddee1122334455",
},
{
name: "empty string gets 0x prefix",
address: "",
want: "0x",
},
{
name: "just 0x stays as 0x",
address: "0x",
want: "0x",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := FormatWalletAddress(tt.address)
if got != tt.want {
t.Errorf("FormatWalletAddress(%q) = %q, want %q", tt.address, got, tt.want)
}
})
}
}
// ---------------------------------------------------------------------------
// GenerateRandomString
// ---------------------------------------------------------------------------
func TestGenerateRandomString(t *testing.T) {
t.Run("returns correct length", func(t *testing.T) {
lengths := []int{8, 16, 32, 64}
for _, l := range lengths {
s, err := GenerateRandomString(l)
if err != nil {
t.Fatalf("GenerateRandomString(%d) returned error: %v", l, err)
}
if len(s) != l {
t.Errorf("GenerateRandomString(%d) returned string of length %d, want %d", l, len(s), l)
}
}
})
t.Run("two calls produce different values", func(t *testing.T) {
s1, err := GenerateRandomString(32)
if err != nil {
t.Fatalf("first call returned error: %v", err)
}
s2, err := GenerateRandomString(32)
if err != nil {
t.Fatalf("second call returned error: %v", err)
}
if s1 == s2 {
t.Errorf("two calls to GenerateRandomString(32) produced the same value: %q", s1)
}
})
t.Run("returns hex characters only", func(t *testing.T) {
s, err := GenerateRandomString(32)
if err != nil {
t.Fatalf("GenerateRandomString(32) returned error: %v", err)
}
// hex.DecodeString requires even-length input; pad if needed
toDecode := s
if len(toDecode)%2 != 0 {
toDecode = toDecode + "0"
}
if _, err := hex.DecodeString(toDecode); err != nil {
t.Errorf("GenerateRandomString(32) returned non-hex string: %q, err: %v", s, err)
}
})
t.Run("length zero returns empty string", func(t *testing.T) {
s, err := GenerateRandomString(0)
if err != nil {
t.Fatalf("GenerateRandomString(0) returned error: %v", err)
}
if s != "" {
t.Errorf("GenerateRandomString(0) = %q, want empty string", s)
}
})
t.Run("length one returns single hex char", func(t *testing.T) {
s, err := GenerateRandomString(1)
if err != nil {
t.Fatalf("GenerateRandomString(1) returned error: %v", err)
}
if len(s) != 1 {
t.Errorf("GenerateRandomString(1) returned string of length %d, want 1", len(s))
}
// Must be a valid hex character
const hexChars = "0123456789abcdef"
if !strings.Contains(hexChars, s) {
t.Errorf("GenerateRandomString(1) = %q, not a valid hex character", s)
}
})
}
// ---------------------------------------------------------------------------
// phantomAuthURL
// ---------------------------------------------------------------------------
func TestPhantomAuthURL(t *testing.T) {
t.Run("returns default when env var not set", func(t *testing.T) {
// Ensure the env var is not set
os.Unsetenv("ORAMA_PHANTOM_AUTH_URL")
got := phantomAuthURL()
if got != defaultPhantomAuthURL {
t.Errorf("phantomAuthURL() = %q, want default %q", got, defaultPhantomAuthURL)
}
})
t.Run("returns custom URL when env var is set", func(t *testing.T) {
custom := "https://custom-phantom.example.com"
os.Setenv("ORAMA_PHANTOM_AUTH_URL", custom)
defer os.Unsetenv("ORAMA_PHANTOM_AUTH_URL")
got := phantomAuthURL()
if got != custom {
t.Errorf("phantomAuthURL() = %q, want %q", got, custom)
}
})
t.Run("trailing slash stripped from env var", func(t *testing.T) {
custom := "https://custom-phantom.example.com/"
os.Setenv("ORAMA_PHANTOM_AUTH_URL", custom)
defer os.Unsetenv("ORAMA_PHANTOM_AUTH_URL")
got := phantomAuthURL()
want := "https://custom-phantom.example.com"
if got != want {
t.Errorf("phantomAuthURL() = %q, want %q (trailing slash should be stripped)", got, want)
}
})
t.Run("multiple trailing slashes stripped from env var", func(t *testing.T) {
custom := "https://custom-phantom.example.com///"
os.Setenv("ORAMA_PHANTOM_AUTH_URL", custom)
defer os.Unsetenv("ORAMA_PHANTOM_AUTH_URL")
got := phantomAuthURL()
want := "https://custom-phantom.example.com"
if got != want {
t.Errorf("phantomAuthURL() = %q, want %q (trailing slashes should be stripped)", got, want)
}
})
}

View File

@ -19,11 +19,6 @@ type Credentials struct {
IssuedAt time.Time `json:"issued_at"`
LastUsedAt time.Time `json:"last_used_at,omitempty"`
Plan string `json:"plan,omitempty"`
NamespaceURL string `json:"namespace_url,omitempty"`
// ProvisioningPollURL is set when namespace cluster is being provisioned.
// Used only during the login flow, not persisted.
ProvisioningPollURL string `json:"-"`
}
// CredentialStore manages credentials for multiple gateways
@ -170,57 +165,15 @@ func (creds *Credentials) UpdateLastUsed() {
creds.LastUsedAt = time.Now()
}
// GetDefaultGatewayURL returns the default gateway URL from environment config, env vars, or fallback
// GetDefaultGatewayURL returns the default gateway URL from environment or fallback
func GetDefaultGatewayURL() string {
// Check environment variables first (for backwards compatibility)
if envURL := os.Getenv("ORAMA_GATEWAY_URL"); envURL != "" {
if envURL := os.Getenv("DEBROS_GATEWAY_URL"); envURL != "" {
return envURL
}
if envURL := os.Getenv("ORAMA_GATEWAY"); envURL != "" {
if envURL := os.Getenv("DEBROS_GATEWAY"); envURL != "" {
return envURL
}
// Try to read from environment config file
if gwURL := getGatewayFromEnvConfig(); gwURL != "" {
return gwURL
}
return "https://orama-devnet.network"
}
// getGatewayFromEnvConfig reads the active environment's gateway URL from the config file
func getGatewayFromEnvConfig() string {
homeDir, err := os.UserHomeDir()
if err != nil {
return ""
}
envConfigPath := filepath.Join(homeDir, ".orama", "environments.json")
data, err := os.ReadFile(envConfigPath)
if err != nil {
return ""
}
var config struct {
Environments []struct {
Name string `json:"name"`
GatewayURL string `json:"gateway_url"`
} `json:"environments"`
ActiveEnvironment string `json:"active_environment"`
}
if err := json.Unmarshal(data, &config); err != nil {
return ""
}
// Find the active environment
for _, env := range config.Environments {
if env.Name == config.ActiveEnvironment {
return env.GatewayURL
}
}
return ""
return "http://localhost:6001"
}
// HasValidCredentials checks if there are valid credentials for the default gateway

View File

@ -86,8 +86,7 @@ func LoadEnhancedCredentials() (*EnhancedCredentialStore, error) {
}
}
// Parse as legacy format (single credential per gateway) and migrate
// Supports both v1.0 and v2.0 legacy formats
// Parse as legacy v2.0 format (single credential per gateway) and migrate
var legacyStore struct {
Gateways map[string]*Credentials `json:"gateways"`
Version string `json:"version"`
@ -97,8 +96,8 @@ func LoadEnhancedCredentials() (*EnhancedCredentialStore, error) {
return nil, fmt.Errorf("invalid credentials file format: %w", err)
}
if legacyStore.Version != "1.0" && legacyStore.Version != "2.0" {
return nil, fmt.Errorf("unsupported credentials version %q; expected \"1.0\" or \"2.0\"", legacyStore.Version)
if legacyStore.Version != "2.0" {
return nil, fmt.Errorf("unsupported credentials version %q; expected \"2.0\"", legacyStore.Version)
}
// Convert legacy format to enhanced format
@ -218,37 +217,6 @@ func (store *EnhancedCredentialStore) SetDefaultCredential(gatewayURL string, in
return true
}
// RemoveCredentialByNamespace removes the credential for a specific namespace from a gateway.
// Returns true if a credential was removed.
func (store *EnhancedCredentialStore) RemoveCredentialByNamespace(gatewayURL, namespace string) bool {
gwCreds := store.Gateways[gatewayURL]
if gwCreds == nil || len(gwCreds.Credentials) == 0 {
return false
}
for i, cred := range gwCreds.Credentials {
if cred.Namespace == namespace {
// Remove this credential from the slice
gwCreds.Credentials = append(gwCreds.Credentials[:i], gwCreds.Credentials[i+1:]...)
// Fix indices if they now point beyond the slice
if len(gwCreds.Credentials) == 0 {
gwCreds.DefaultIndex = 0
gwCreds.LastUsedIndex = 0
} else {
if gwCreds.DefaultIndex >= len(gwCreds.Credentials) {
gwCreds.DefaultIndex = len(gwCreds.Credentials) - 1
}
if gwCreds.LastUsedIndex >= len(gwCreds.Credentials) {
gwCreds.LastUsedIndex = gwCreds.DefaultIndex
}
}
return true
}
}
return false
}
// ClearAllCredentials removes all credentials
func (store *EnhancedCredentialStore) ClearAllCredentials() {
store.Gateways = make(map[string]*GatewayCredentials)

View File

@ -1,22 +0,0 @@
package auth
import "net"
// WireGuardSubnet is the internal WireGuard mesh CIDR.
const WireGuardSubnet = "10.0.0.0/24"
// IsWireGuardPeer checks whether remoteAddr (host:port format) originates
// from the WireGuard mesh subnet. This provides cryptographic peer
// authentication since WireGuard validates keys at the tunnel layer.
func IsWireGuardPeer(remoteAddr string) bool {
host, _, err := net.SplitHostPort(remoteAddr)
if err != nil {
return false
}
ip := net.ParseIP(host)
if ip == nil {
return false
}
_, wgNet, _ := net.ParseCIDR(WireGuardSubnet)
return wgNet.Contains(ip)
}

View File

@ -1,214 +0,0 @@
package auth
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"time"
"github.com/DeBrosOfficial/network/pkg/tlsutil"
qrterminal "github.com/mdp/qrterminal/v3"
)
// defaultPhantomAuthURL is the default Phantom auth React app URL (deployed on Orama devnet).
// Override with ORAMA_PHANTOM_AUTH_URL environment variable.
const defaultPhantomAuthURL = "https://phantom-auth-y0w9aa.orama-devnet.network"
// phantomAuthURL returns the Phantom auth URL, preferring the environment variable.
func phantomAuthURL() string {
if u := os.Getenv("ORAMA_PHANTOM_AUTH_URL"); u != "" {
return strings.TrimRight(u, "/")
}
return defaultPhantomAuthURL
}
// PhantomSession represents a phantom auth session from the gateway.
type PhantomSession struct {
SessionID string `json:"session_id"`
ExpiresAt string `json:"expires_at"`
}
// PhantomSessionStatus represents the polled status of a phantom auth session.
type PhantomSessionStatus struct {
SessionID string `json:"session_id"`
Status string `json:"status"`
Wallet string `json:"wallet"`
APIKey string `json:"api_key"`
Namespace string `json:"namespace"`
Error string `json:"error"`
}
// PerformPhantomAuthentication runs the Phantom Solana auth flow:
// 1. Prompt for namespace
// 2. Create session via gateway
// 3. Display QR code in terminal
// 4. Poll for completion
// 5. Return credentials
func PerformPhantomAuthentication(gatewayURL, namespace string) (*Credentials, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println("\n🟣 Phantom Wallet Authentication (Solana)")
fmt.Println("==========================================")
fmt.Println("Requires an NFT from the authorized collection.")
// Prompt for namespace if empty
if namespace == "" {
for {
fmt.Print("Enter namespace (required): ")
nsInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read namespace: %w", err)
}
namespace = strings.TrimSpace(nsInput)
if namespace != "" {
break
}
fmt.Println("Namespace cannot be empty.")
}
}
domain := extractDomainFromURL(gatewayURL)
client := tlsutil.NewHTTPClientForDomain(30*time.Second, domain)
// 1. Create phantom session
fmt.Println("\nCreating authentication session...")
session, err := createPhantomSession(client, gatewayURL, namespace)
if err != nil {
return nil, fmt.Errorf("failed to create session: %w", err)
}
// 2. Build auth URL and display QR code
authURL := fmt.Sprintf("%s/?session=%s&gateway=%s&namespace=%s",
phantomAuthURL(), session.SessionID, url.QueryEscape(gatewayURL), url.QueryEscape(namespace))
fmt.Println("\nScan this QR code with your phone to authenticate:")
fmt.Println()
qrterminal.GenerateWithConfig(authURL, qrterminal.Config{
Level: qrterminal.M,
Writer: os.Stdout,
BlackChar: qrterminal.BLACK,
WhiteChar: qrterminal.WHITE,
QuietZone: 1,
})
fmt.Println()
fmt.Printf("Or open this URL on your phone:\n%s\n\n", authURL)
fmt.Println("Waiting for authentication... (timeout: 5 minutes)")
// 3. Poll for completion
creds, err := pollPhantomSession(client, gatewayURL, session.SessionID)
if err != nil {
return nil, err
}
// Set namespace and build namespace URL
creds.Namespace = namespace
if domain := extractDomainFromURL(gatewayURL); domain != "" {
if namespace == "default" {
creds.NamespaceURL = fmt.Sprintf("https://%s", domain)
} else {
creds.NamespaceURL = fmt.Sprintf("https://ns-%s.%s", namespace, domain)
}
}
fmt.Printf("\n🎉 Authentication successful!\n")
truncatedKey := creds.APIKey
if len(truncatedKey) > 8 {
truncatedKey = truncatedKey[:8] + "..."
}
fmt.Printf("📝 API Key: %s\n", truncatedKey)
return creds, nil
}
// createPhantomSession creates a new phantom auth session via the gateway.
func createPhantomSession(client *http.Client, gatewayURL, namespace string) (*PhantomSession, error) {
reqBody := map[string]string{
"namespace": namespace,
}
payload, err := json.Marshal(reqBody)
if err != nil {
return nil, err
}
resp, err := client.Post(gatewayURL+"/v1/auth/phantom/session", "application/json", bytes.NewReader(payload))
if err != nil {
return nil, fmt.Errorf("failed to call gateway: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("gateway returned status %d: %s", resp.StatusCode, string(body))
}
var session PhantomSession
if err := json.NewDecoder(resp.Body).Decode(&session); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
}
return &session, nil
}
// pollPhantomSession polls the gateway for session completion.
func pollPhantomSession(client *http.Client, gatewayURL, sessionID string) (*Credentials, error) {
pollInterval := 2 * time.Second
maxDuration := 5 * time.Minute
deadline := time.Now().Add(maxDuration)
spinnerChars := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
spinnerIdx := 0
for time.Now().Before(deadline) {
resp, err := client.Get(gatewayURL + "/v1/auth/phantom/session/" + sessionID)
if err != nil {
time.Sleep(pollInterval)
continue
}
var status PhantomSessionStatus
if err := json.NewDecoder(resp.Body).Decode(&status); err != nil {
resp.Body.Close()
time.Sleep(pollInterval)
continue
}
resp.Body.Close()
switch status.Status {
case "completed":
fmt.Printf("\r✅ Authenticated! \n")
return &Credentials{
APIKey: status.APIKey,
Wallet: status.Wallet,
UserID: status.Wallet,
IssuedAt: time.Now(),
}, nil
case "failed":
fmt.Printf("\r❌ Authentication failed \n")
errMsg := status.Error
if errMsg == "" {
errMsg = "unknown error"
}
return nil, fmt.Errorf("authentication failed: %s", errMsg)
case "expired":
fmt.Printf("\r⏰ Session expired \n")
return nil, fmt.Errorf("authentication session expired")
case "pending":
fmt.Printf("\r%s Waiting for phone authentication... ", spinnerChars[spinnerIdx%len(spinnerChars)])
spinnerIdx++
}
time.Sleep(pollInterval)
}
fmt.Printf("\r⏰ Timeout \n")
return nil, fmt.Errorf("authentication timed out after 5 minutes")
}

View File

@ -1,290 +0,0 @@
package auth
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"strings"
"time"
"github.com/DeBrosOfficial/network/pkg/tlsutil"
)
// IsRootWalletInstalled checks if the `rw` CLI is available in PATH
func IsRootWalletInstalled() bool {
_, err := exec.LookPath("rw")
return err == nil
}
// getRootWalletAddress gets the EVM address from the RootWallet keystore
func getRootWalletAddress() (string, error) {
cmd := exec.Command("rw", "address", "--chain", "evm")
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to get address from rw: %w", err)
}
addr := strings.TrimSpace(string(out))
if addr == "" {
return "", fmt.Errorf("rw returned empty address — run 'rw init' first")
}
return addr, nil
}
// signWithRootWallet signs a message using RootWallet's EVM key.
// Stdin is passed through so the user can enter their password if the session is expired.
func signWithRootWallet(message string) (string, error) {
cmd := exec.Command("rw", "sign", message, "--chain", "evm")
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to sign with rw: %w", err)
}
sig := strings.TrimSpace(string(out))
if sig == "" {
return "", fmt.Errorf("rw returned empty signature")
}
return sig, nil
}
// PerformRootWalletAuthentication performs a challenge-response authentication flow
// using the RootWallet CLI to sign a gateway-issued nonce
func PerformRootWalletAuthentication(gatewayURL, namespace string) (*Credentials, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println("\n🔐 RootWallet Authentication")
fmt.Println("=============================")
// 1. Get wallet address from RootWallet
fmt.Println("⏳ Reading wallet address from RootWallet...")
wallet, err := getRootWalletAddress()
if err != nil {
return nil, fmt.Errorf("failed to get wallet address: %w", err)
}
if !ValidateWalletAddress(wallet) {
return nil, fmt.Errorf("invalid wallet address from rw: %s", wallet)
}
fmt.Printf("✅ Wallet: %s\n", wallet)
// 2. Prompt for namespace if not provided
if namespace == "" {
for {
fmt.Print("Enter namespace (required): ")
nsInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read namespace: %w", err)
}
namespace = strings.TrimSpace(nsInput)
if namespace != "" {
break
}
fmt.Println("⚠️ Namespace cannot be empty. Please enter a namespace.")
}
}
fmt.Printf("✅ Namespace: %s\n", namespace)
// 3. Request challenge nonce from gateway
fmt.Println("⏳ Requesting authentication challenge...")
domain := extractDomainFromURL(gatewayURL)
client := tlsutil.NewHTTPClientForDomain(30*time.Second, domain)
nonce, err := requestChallenge(client, gatewayURL, wallet, namespace)
if err != nil {
return nil, fmt.Errorf("failed to get challenge: %w", err)
}
// 4. Sign the nonce with RootWallet
fmt.Println("⏳ Signing challenge with RootWallet...")
signature, err := signWithRootWallet(nonce)
if err != nil {
return nil, fmt.Errorf("failed to sign challenge: %w", err)
}
fmt.Println("✅ Challenge signed")
// 5. Verify signature with gateway
fmt.Println("⏳ Verifying signature with gateway...")
creds, err := verifySignature(client, gatewayURL, wallet, nonce, signature, namespace)
if err != nil {
return nil, fmt.Errorf("failed to verify signature: %w", err)
}
// If namespace cluster is being provisioned, poll until ready
if creds.ProvisioningPollURL != "" {
fmt.Println("⏳ Provisioning namespace cluster...")
pollErr := pollNamespaceProvisioning(client, gatewayURL, creds.ProvisioningPollURL)
if pollErr != nil {
fmt.Printf("⚠️ Provisioning poll failed: %v\n", pollErr)
fmt.Println(" Credentials are saved. Cluster may still be provisioning in background.")
} else {
fmt.Println("✅ Namespace cluster ready!")
}
}
fmt.Printf("\n🎉 Authentication successful!\n")
fmt.Printf("🏢 Namespace: %s\n", creds.Namespace)
return creds, nil
}
// requestChallenge sends POST /v1/auth/challenge and returns the nonce
func requestChallenge(client *http.Client, gatewayURL, wallet, namespace string) (string, error) {
reqBody := map[string]string{
"wallet": wallet,
"namespace": namespace,
}
payload, err := json.Marshal(reqBody)
if err != nil {
return "", fmt.Errorf("failed to marshal request: %w", err)
}
resp, err := client.Post(gatewayURL+"/v1/auth/challenge", "application/json", bytes.NewReader(payload))
if err != nil {
return "", fmt.Errorf("failed to call gateway: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("gateway returned status %d: %s", resp.StatusCode, string(body))
}
var result struct {
Nonce string `json:"nonce"`
Wallet string `json:"wallet"`
Namespace string `json:"namespace"`
ExpiresAt string `json:"expires_at"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("failed to decode response: %w", err)
}
if result.Nonce == "" {
return "", fmt.Errorf("no nonce in challenge response")
}
return result.Nonce, nil
}
// verifySignature sends POST /v1/auth/verify and returns credentials
func verifySignature(client *http.Client, gatewayURL, wallet, nonce, signature, namespace string) (*Credentials, error) {
reqBody := map[string]string{
"wallet": wallet,
"nonce": nonce,
"signature": signature,
"namespace": namespace,
"chain_type": "ETH",
}
payload, err := json.Marshal(reqBody)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
resp, err := client.Post(gatewayURL+"/v1/auth/verify", "application/json", bytes.NewReader(payload))
if err != nil {
return nil, fmt.Errorf("failed to call gateway: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
body, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("gateway returned status %d: %s", resp.StatusCode, string(body))
}
var result struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
Subject string `json:"subject"`
Namespace string `json:"namespace"`
APIKey string `json:"api_key"`
// Provisioning fields (202 Accepted)
Status string `json:"status"`
PollURL string `json:"poll_url"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
}
if result.APIKey == "" {
return nil, fmt.Errorf("no api_key in verify response")
}
// Build namespace gateway URL
namespaceURL := ""
if d := extractDomainFromURL(gatewayURL); d != "" {
if namespace == "default" {
namespaceURL = fmt.Sprintf("https://%s", d)
} else {
namespaceURL = fmt.Sprintf("https://ns-%s.%s", namespace, d)
}
}
creds := &Credentials{
APIKey: result.APIKey,
RefreshToken: result.RefreshToken,
Namespace: result.Namespace,
UserID: result.Subject,
Wallet: result.Subject,
IssuedAt: time.Now(),
NamespaceURL: namespaceURL,
}
// If 202, namespace cluster is being provisioned — set poll URL
if resp.StatusCode == http.StatusAccepted && result.PollURL != "" {
creds.ProvisioningPollURL = result.PollURL
}
// Note: result.ExpiresIn is the JWT access token lifetime (15min),
// NOT the API key lifetime. Don't set ExpiresAt — the API key is permanent.
return creds, nil
}
// pollNamespaceProvisioning polls the namespace status endpoint until the cluster is ready.
func pollNamespaceProvisioning(client *http.Client, gatewayURL, pollPath string) error {
pollURL := gatewayURL + pollPath
timeout := time.After(120 * time.Second)
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-timeout:
return fmt.Errorf("timed out after 120s waiting for namespace cluster")
case <-ticker.C:
resp, err := client.Get(pollURL)
if err != nil {
continue // Retry on network error
}
var status struct {
Status string `json:"status"`
}
decErr := json.NewDecoder(resp.Body).Decode(&status)
resp.Body.Close()
if decErr != nil {
continue
}
switch status.Status {
case "ready":
return nil
case "failed", "error":
return fmt.Errorf("namespace provisioning failed")
}
// "provisioning" or other — keep polling
fmt.Print(".")
}
}
}

View File

@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"time"
@ -16,24 +15,21 @@ import (
)
// PerformSimpleAuthentication performs a simple authentication flow where the user
// provides a wallet address and receives an API key without signature verification.
// Requires an existing valid API key (convenience re-auth only).
func PerformSimpleAuthentication(gatewayURL, wallet, namespace, existingAPIKey string) (*Credentials, error) {
// provides a wallet address and receives an API key without signature verification
func PerformSimpleAuthentication(gatewayURL string) (*Credentials, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println("\n🔐 Simple Wallet Authentication")
fmt.Println("================================")
// Read wallet address (skip prompt if provided via flag)
if wallet == "" {
fmt.Print("Enter your wallet address (0x...): ")
walletInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read wallet address: %w", err)
}
wallet = strings.TrimSpace(walletInput)
// Read wallet address
fmt.Print("Enter your wallet address (0x...): ")
walletInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read wallet address: %w", err)
}
wallet := strings.TrimSpace(walletInput)
if wallet == "" {
return nil, fmt.Errorf("wallet address cannot be empty")
}
@ -47,21 +43,16 @@ func PerformSimpleAuthentication(gatewayURL, wallet, namespace, existingAPIKey s
return nil, fmt.Errorf("invalid wallet address format")
}
// Read namespace (skip prompt if provided via flag)
if namespace == "" {
for {
fmt.Print("Enter namespace (required): ")
nsInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read namespace: %w", err)
}
// Read namespace (optional)
fmt.Print("Enter namespace (press Enter for 'default'): ")
nsInput, err := reader.ReadString('\n')
if err != nil {
return nil, fmt.Errorf("failed to read namespace: %w", err)
}
namespace = strings.TrimSpace(nsInput)
if namespace != "" {
break
}
fmt.Println("⚠️ Namespace cannot be empty. Please enter a namespace.")
}
namespace := strings.TrimSpace(nsInput)
if namespace == "" {
namespace = "default"
}
fmt.Printf("\n✅ Wallet: %s\n", wallet)
@ -69,44 +60,28 @@ func PerformSimpleAuthentication(gatewayURL, wallet, namespace, existingAPIKey s
fmt.Println("⏳ Requesting API key from gateway...")
// Request API key from gateway
apiKey, err := requestAPIKeyFromGateway(gatewayURL, wallet, namespace, existingAPIKey)
apiKey, err := requestAPIKeyFromGateway(gatewayURL, wallet, namespace)
if err != nil {
return nil, fmt.Errorf("failed to request API key: %w", err)
}
// Build namespace gateway URL from the gateway URL
namespaceURL := ""
if domain := extractDomainFromURL(gatewayURL); domain != "" {
if namespace == "default" {
namespaceURL = fmt.Sprintf("https://%s", domain)
} else {
namespaceURL = fmt.Sprintf("https://ns-%s.%s", namespace, domain)
}
}
// Create credentials
creds := &Credentials{
APIKey: apiKey,
Namespace: namespace,
UserID: wallet,
Wallet: wallet,
IssuedAt: time.Now(),
NamespaceURL: namespaceURL,
APIKey: apiKey,
Namespace: namespace,
UserID: wallet,
Wallet: wallet,
IssuedAt: time.Now(),
}
fmt.Printf("\n🎉 Authentication successful!\n")
truncatedKey := creds.APIKey
if len(truncatedKey) > 8 {
truncatedKey = truncatedKey[:8] + "..."
}
fmt.Printf("📝 API Key: %s\n", truncatedKey)
fmt.Printf("📝 API Key: %s\n", creds.APIKey)
return creds, nil
}
// requestAPIKeyFromGateway calls the gateway's simple-key endpoint to generate an API key
// For non-default namespaces, this may trigger cluster provisioning and require polling
func requestAPIKeyFromGateway(gatewayURL, wallet, namespace, existingAPIKey string) (string, error) {
func requestAPIKeyFromGateway(gatewayURL, wallet, namespace string) (string, error) {
reqBody := map[string]string{
"wallet": wallet,
"namespace": namespace,
@ -120,30 +95,16 @@ func requestAPIKeyFromGateway(gatewayURL, wallet, namespace, existingAPIKey stri
endpoint := gatewayURL + "/v1/auth/simple-key"
// Extract domain from URL for TLS configuration
// This uses tlsutil which handles Let's Encrypt staging certificates for *.orama.network
// This uses tlsutil which handles Let's Encrypt staging certificates for *.debros.network
domain := extractDomainFromURL(gatewayURL)
client := tlsutil.NewHTTPClientForDomain(30*time.Second, domain)
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(payload))
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
if existingAPIKey != "" {
req.Header.Set("X-API-Key", existingAPIKey)
}
resp, err := client.Do(req)
resp, err := client.Post(endpoint, "application/json", bytes.NewReader(payload))
if err != nil {
return "", fmt.Errorf("failed to call gateway: %w", err)
}
defer resp.Body.Close()
// Handle 202 Accepted - namespace cluster is being provisioned
if resp.StatusCode == http.StatusAccepted {
return handleProvisioningResponse(gatewayURL, client, resp, wallet, namespace, existingAPIKey)
}
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("gateway returned status %d: %s", resp.StatusCode, string(body))
@ -162,190 +123,22 @@ func requestAPIKeyFromGateway(gatewayURL, wallet, namespace, existingAPIKey stri
return apiKey, nil
}
// handleProvisioningResponse handles 202 Accepted responses when namespace cluster provisioning is needed
func handleProvisioningResponse(gatewayURL string, client *http.Client, resp *http.Response, wallet, namespace, existingAPIKey string) (string, error) {
var provResp map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&provResp); err != nil {
return "", fmt.Errorf("failed to decode provisioning response: %w", err)
// extractDomainFromURL extracts the domain from a URL
// Removes protocol (https://, http://), path, and port components
func extractDomainFromURL(url string) string {
// Remove protocol prefixes
url = strings.TrimPrefix(url, "https://")
url = strings.TrimPrefix(url, "http://")
// Remove path component
if idx := strings.Index(url, "/"); idx != -1 {
url = url[:idx]
}
status, _ := provResp["status"].(string)
pollURL, _ := provResp["poll_url"].(string)
clusterID, _ := provResp["cluster_id"].(string)
message, _ := provResp["message"].(string)
if status != "provisioning" {
return "", fmt.Errorf("unexpected status: %s", status)
// Remove port component
if idx := strings.Index(url, ":"); idx != -1 {
url = url[:idx]
}
fmt.Printf("\n🏗 Provisioning namespace cluster...\n")
if message != "" {
fmt.Printf(" %s\n", message)
}
if clusterID != "" {
fmt.Printf(" Cluster ID: %s\n", clusterID)
}
fmt.Println()
// Poll until cluster is ready
if err := pollProvisioningStatus(gatewayURL, client, pollURL); err != nil {
return "", err
}
// Cluster is ready, retry the API key request
fmt.Println("\n✅ Namespace cluster ready!")
fmt.Println("⏳ Retrieving API key...")
return retryAPIKeyRequest(gatewayURL, client, wallet, namespace, existingAPIKey)
}
// pollProvisioningStatus polls the status endpoint until the cluster is ready
func pollProvisioningStatus(gatewayURL string, client *http.Client, pollURL string) error {
// Build full poll URL if it's a relative path
if strings.HasPrefix(pollURL, "/") {
pollURL = gatewayURL + pollURL
} else {
// Validate that absolute poll URLs point to the same gateway domain
gatewayDomain := extractDomainFromURL(gatewayURL)
pollDomain := extractDomainFromURL(pollURL)
if gatewayDomain != pollDomain {
return fmt.Errorf("poll URL domain mismatch: expected %s, got %s", gatewayDomain, pollDomain)
}
}
maxAttempts := 120 // 10 minutes (5 seconds per poll)
pollInterval := 5 * time.Second
spinnerChars := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
spinnerIdx := 0
for i := 0; i < maxAttempts; i++ {
// Show progress spinner
fmt.Printf("\r%s Waiting for cluster... ", spinnerChars[spinnerIdx%len(spinnerChars)])
spinnerIdx++
resp, err := client.Get(pollURL)
if err != nil {
time.Sleep(pollInterval)
continue
}
var statusResp map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&statusResp); err != nil {
resp.Body.Close()
time.Sleep(pollInterval)
continue
}
resp.Body.Close()
status, _ := statusResp["status"].(string)
switch status {
case "ready":
fmt.Printf("\r✅ Cluster ready! \n")
return nil
case "failed":
errMsg, _ := statusResp["error"].(string)
fmt.Printf("\r❌ Provisioning failed \n")
return fmt.Errorf("cluster provisioning failed: %s", errMsg)
case "provisioning":
// Show progress details
rqliteReady, _ := statusResp["rqlite_ready"].(bool)
olricReady, _ := statusResp["olric_ready"].(bool)
gatewayReady, _ := statusResp["gateway_ready"].(bool)
dnsReady, _ := statusResp["dns_ready"].(bool)
progressStr := ""
if rqliteReady {
progressStr += "RQLite✓ "
}
if olricReady {
progressStr += "Olric✓ "
}
if gatewayReady {
progressStr += "Gateway✓ "
}
if dnsReady {
progressStr += "DNS✓"
}
if progressStr != "" {
fmt.Printf("\r%s Provisioning... [%s]", spinnerChars[spinnerIdx%len(spinnerChars)], progressStr)
}
default:
// Unknown status, continue polling
}
time.Sleep(pollInterval)
}
fmt.Printf("\r⚠ Timeout waiting for cluster \n")
return fmt.Errorf("timeout waiting for namespace cluster provisioning")
}
// retryAPIKeyRequest retries the API key request after cluster provisioning
func retryAPIKeyRequest(gatewayURL string, client *http.Client, wallet, namespace, existingAPIKey string) (string, error) {
reqBody := map[string]string{
"wallet": wallet,
"namespace": namespace,
}
payload, err := json.Marshal(reqBody)
if err != nil {
return "", fmt.Errorf("failed to marshal request: %w", err)
}
endpoint := gatewayURL + "/v1/auth/simple-key"
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(payload))
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
if existingAPIKey != "" {
req.Header.Set("X-API-Key", existingAPIKey)
}
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("failed to call gateway: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusAccepted {
// Still provisioning? This shouldn't happen but handle gracefully
return "", fmt.Errorf("cluster still provisioning, please try again")
}
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return "", fmt.Errorf("gateway returned status %d: %s", resp.StatusCode, string(body))
}
var respBody map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
return "", fmt.Errorf("failed to decode response: %w", err)
}
apiKey, ok := respBody["api_key"].(string)
if !ok || apiKey == "" {
return "", fmt.Errorf("no api_key in response")
}
return apiKey, nil
}
// extractDomainFromURL extracts the hostname from a URL, stripping scheme, port, and path.
func extractDomainFromURL(rawURL string) string {
// Ensure the URL has a scheme so net/url.Parse works correctly
if !strings.Contains(rawURL, "://") {
rawURL = "https://" + rawURL
}
u, err := url.Parse(rawURL)
if err != nil {
return ""
}
return u.Hostname()
return url
}

View File

@ -168,7 +168,7 @@ func (as *AuthServer) handleCallback(w http.ResponseWriter, r *http.Request) {
return
}
// Send success response to browser (API key is never exposed in HTML)
// Send success response to browser
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
@ -181,25 +181,30 @@ func (as *AuthServer) handleCallback(w http.ResponseWriter, r *http.Request) {
.container { background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 500px; margin: 0 auto; }
.success { color: #4CAF50; font-size: 48px; margin-bottom: 20px; }
.details { background: #f8f9fa; padding: 20px; border-radius: 5px; margin: 20px 0; text-align: left; }
.key { font-family: monospace; background: #e9ecef; padding: 10px; border-radius: 3px; word-break: break-all; }
</style>
</head>
<body>
<div class="container">
<div class="success">&#10003;</div>
<div class="success"></div>
<h1>Authentication Successful!</h1>
<p>You have successfully authenticated with your wallet.</p>
<div class="details">
<h3>🔑 Your Credentials:</h3>
<p><strong>API Key:</strong></p>
<div class="key">%s</div>
<p><strong>Namespace:</strong> %s</p>
<p><strong>Wallet:</strong> %s</p>
%s
</div>
<p>Your credentials have been saved securely. Return to your terminal to continue.</p>
<p><strong>You can now close this browser window.</strong></p>
<p>Your credentials have been saved securely to <code>~/.orama/credentials.json</code></p>
<p><strong>You can now close this browser window and return to your terminal.</strong></p>
</div>
</body>
</html>`,
result.APIKey,
result.Namespace,
result.Wallet,
func() string {
@ -225,7 +230,7 @@ func (as *AuthServer) handleHealth(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{
"status": "ok",
"server": "orama-auth-callback",
"server": "debros-auth-callback",
})
}

View File

@ -115,8 +115,8 @@ func (cm *CertificateManager) generateCACertificate() ([]byte, []byte, error) {
template := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
CommonName: "Orama Network Root CA",
Organization: []string{"Orama"},
CommonName: "DeBros Network Root CA",
Organization: []string{"DeBros"},
},
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(10, 0, 0), // 10 year validity
@ -179,11 +179,11 @@ func (cm *CertificateManager) generateNodeCertificate(hostname string, caCertPEM
DNSNames: []string{hostname},
}
// Add wildcard support if hostname contains *.orama.network
if hostname == "*.orama.network" {
template.DNSNames = []string{"*.orama.network", "orama.network"}
} else if hostname == "orama.network" {
template.DNSNames = []string{"*.orama.network", "orama.network"}
// Add wildcard support if hostname contains *.debros.network
if hostname == "*.debros.network" {
template.DNSNames = []string{"*.debros.network", "debros.network"}
} else if hostname == "debros.network" {
template.DNSNames = []string{"*.debros.network", "debros.network"}
}
// Try to parse as IP address for IP-based certificates
@ -254,3 +254,4 @@ func (cm *CertificateManager) parseCACertificate(caCertPEM, caKeyPEM []byte) (*x
func LoadTLSCertificate(certPEM, keyPEM []byte) (tls.Certificate, error) {
return tls.X509KeyPair(certPEM, keyPEM)
}

View File

@ -2,7 +2,6 @@ package cli
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
@ -20,24 +19,13 @@ func HandleAuthCommand(args []string) {
subcommand := args[0]
switch subcommand {
case "login":
var wallet, namespace string
var simple bool
fs := flag.NewFlagSet("auth login", flag.ExitOnError)
fs.StringVar(&wallet, "wallet", "", "Wallet address (implies --simple)")
fs.StringVar(&namespace, "namespace", "", "Namespace name")
fs.BoolVar(&simple, "simple", false, "Use simple auth without signature verification")
_ = fs.Parse(args[1:])
handleAuthLogin(wallet, namespace, simple)
handleAuthLogin()
case "logout":
handleAuthLogout()
case "whoami":
handleAuthWhoami()
case "status":
handleAuthStatus()
case "list":
handleAuthList()
case "switch":
handleAuthSwitch()
default:
fmt.Fprintf(os.Stderr, "Unknown auth command: %s\n", subcommand)
showAuthHelp()
@ -47,149 +35,42 @@ func HandleAuthCommand(args []string) {
func showAuthHelp() {
fmt.Printf("🔐 Authentication Commands\n\n")
fmt.Printf("Usage: orama auth <subcommand>\n\n")
fmt.Printf("Usage: dbn auth <subcommand>\n\n")
fmt.Printf("Subcommands:\n")
fmt.Printf(" login - Authenticate with RootWallet (default) or simple auth\n")
fmt.Printf(" login - Authenticate by providing your wallet address\n")
fmt.Printf(" logout - Clear stored credentials\n")
fmt.Printf(" whoami - Show current authentication status\n")
fmt.Printf(" status - Show detailed authentication info\n")
fmt.Printf(" list - List all stored credentials for current environment\n")
fmt.Printf(" switch - Switch between stored credentials\n\n")
fmt.Printf("Login Flags:\n")
fmt.Printf(" --namespace <name> - Target namespace\n")
fmt.Printf(" --simple - Use simple auth (no signature, dev only)\n")
fmt.Printf(" --wallet <0x...> - Wallet address (implies --simple)\n\n")
fmt.Printf(" status - Show detailed authentication info\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" orama auth login # Sign with RootWallet (default)\n")
fmt.Printf(" orama auth login --namespace myns # Sign with RootWallet + namespace\n")
fmt.Printf(" orama auth login --simple # Simple auth (no signature)\n")
fmt.Printf(" orama auth whoami # Check who you're logged in as\n")
fmt.Printf(" orama auth logout # Clear all stored credentials\n\n")
fmt.Printf(" dbn auth login # Enter wallet address interactively\n")
fmt.Printf(" dbn auth whoami # Check who you're logged in as\n")
fmt.Printf(" dbn auth status # View detailed authentication info\n")
fmt.Printf(" dbn auth logout # Clear all stored credentials\n\n")
fmt.Printf("Environment Variables:\n")
fmt.Printf(" ORAMA_GATEWAY_URL - Gateway URL (overrides environment config)\n\n")
fmt.Printf("Authentication Flow (RootWallet):\n")
fmt.Printf(" 1. Run 'orama auth login'\n")
fmt.Printf(" 2. Your wallet address is read from RootWallet automatically\n")
fmt.Printf(" 3. Enter your namespace when prompted\n")
fmt.Printf(" 4. A challenge nonce is signed with your wallet key\n")
fmt.Printf(" 5. Credentials are saved to ~/.orama/credentials.json\n\n")
fmt.Printf("Note: Requires RootWallet CLI (rw) in PATH.\n")
fmt.Printf(" Install: cd rootwallet/cli && ./install.sh\n")
fmt.Printf(" Authentication uses the currently active environment.\n")
fmt.Printf(" Use 'orama env current' to see your active environment.\n")
fmt.Printf(" DEBROS_GATEWAY_URL - Gateway URL (overrides environment config)\n\n")
fmt.Printf("Authentication Flow:\n")
fmt.Printf(" 1. Run 'dbn auth login'\n")
fmt.Printf(" 2. Enter your wallet address when prompted\n")
fmt.Printf(" 3. Enter your namespace (or press Enter for 'default')\n")
fmt.Printf(" 4. An API key will be generated and saved to ~/.orama/credentials.json\n\n")
fmt.Printf("Note: Authentication uses the currently active environment.\n")
fmt.Printf(" Use 'dbn env current' to see your active environment.\n")
}
func handleAuthLogin(wallet, namespace string, simple bool) {
// Get gateway URL from active environment
gatewayURL := getGatewayURL()
// Show active environment
env, err := GetActiveEnvironment()
if err == nil {
fmt.Printf("🌍 Environment: %s\n", env.Name)
}
fmt.Printf("🔐 Authenticating with gateway at: %s\n\n", gatewayURL)
// Load enhanced credential store
store, err := auth.LoadEnhancedCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to load credentials: %v\n", err)
os.Exit(1)
}
// Check if we already have credentials for this gateway
gwCreds := store.Gateways[gatewayURL]
if gwCreds != nil && len(gwCreds.Credentials) > 0 {
// Show existing credentials and offer choice
choice, credIndex, err := store.DisplayCredentialMenu(gatewayURL)
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Menu selection failed: %v\n", err)
os.Exit(1)
}
switch choice {
case auth.AuthChoiceUseCredential:
selectedCreds := gwCreds.Credentials[credIndex]
store.SetDefaultCredential(gatewayURL, credIndex)
selectedCreds.UpdateLastUsed()
if err := store.Save(); err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to save credentials: %v\n", err)
os.Exit(1)
}
fmt.Printf("✅ Switched to wallet: %s\n", selectedCreds.Wallet)
fmt.Printf("🏢 Namespace: %s\n", selectedCreds.Namespace)
return
case auth.AuthChoiceLogout:
store.ClearAllCredentials()
if err := store.Save(); err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to clear credentials: %v\n", err)
os.Exit(1)
}
fmt.Println("✅ All credentials cleared")
return
case auth.AuthChoiceExit:
fmt.Println("Exiting...")
return
case auth.AuthChoiceAddCredential:
// Fall through to add new credential
}
}
// Choose authentication method
var creds *auth.Credentials
reader := bufio.NewReader(os.Stdin)
if simple || wallet != "" {
// Explicit simple auth — requires existing credentials
existingCreds := store.GetDefaultCredential(gatewayURL)
if existingCreds == nil || !existingCreds.IsValid() {
fmt.Fprintf(os.Stderr, "❌ Simple auth requires existing credentials. Authenticate with RootWallet or Phantom first.\n")
os.Exit(1)
}
creds, err = auth.PerformSimpleAuthentication(gatewayURL, wallet, namespace, existingCreds.APIKey)
} else {
// Show auth method selection
fmt.Println("How would you like to authenticate?")
fmt.Println(" 1. RootWallet (EVM signature)")
fmt.Println(" 2. Phantom (Solana + NFT required)")
fmt.Print("\nSelect [1/2]: ")
choice, _ := reader.ReadString('\n')
choice = strings.TrimSpace(choice)
switch choice {
case "2":
creds, err = auth.PerformPhantomAuthentication(gatewayURL, namespace)
default:
// Default to RootWallet
if auth.IsRootWalletInstalled() {
creds, err = auth.PerformRootWalletAuthentication(gatewayURL, namespace)
} else {
fmt.Println("\n⚠ RootWallet CLI (rw) not found in PATH.")
fmt.Println(" Install it: cd rootwallet/cli && ./install.sh")
os.Exit(1)
}
}
}
func handleAuthLogin() {
// Prompt for node selection
gatewayURL := promptForGatewayURL()
fmt.Printf("🔐 Authenticating with gateway at: %s\n", gatewayURL)
// Use the simple authentication flow
creds, err := auth.PerformSimpleAuthentication(gatewayURL)
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Authentication failed: %v\n", err)
os.Exit(1)
}
// Add to enhanced store
store.AddCredential(gatewayURL, creds)
// Set as default
gwCreds = store.Gateways[gatewayURL]
if gwCreds != nil {
store.SetDefaultCredential(gatewayURL, len(gwCreds.Credentials)-1)
}
if err := store.Save(); err != nil {
// Save credentials to file
if err := auth.SaveCredentialsForDefaultGateway(creds); err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to save credentials: %v\n", err)
os.Exit(1)
}
@ -199,9 +80,7 @@ func handleAuthLogin(wallet, namespace string, simple bool) {
fmt.Printf("📁 Credentials saved to: %s\n", credsPath)
fmt.Printf("🎯 Wallet: %s\n", creds.Wallet)
fmt.Printf("🏢 Namespace: %s\n", creds.Namespace)
if creds.NamespaceURL != "" {
fmt.Printf("🌐 Namespace URL: %s\n", creds.NamespaceURL)
}
fmt.Printf("🔑 API Key: %s\n", creds.APIKey)
}
func handleAuthLogout() {
@ -213,26 +92,23 @@ func handleAuthLogout() {
}
func handleAuthWhoami() {
store, err := auth.LoadEnhancedCredentials()
store, err := auth.LoadCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to load credentials: %v\n", err)
os.Exit(1)
}
gatewayURL := getGatewayURL()
creds := store.GetDefaultCredential(gatewayURL)
creds, exists := store.GetCredentialsForGateway(gatewayURL)
if creds == nil || !creds.IsValid() {
fmt.Println("❌ Not authenticated - run 'orama auth login' to authenticate")
if !exists || !creds.IsValid() {
fmt.Println("❌ Not authenticated - run 'dbn auth login' to authenticate")
os.Exit(1)
}
fmt.Println("✅ Authenticated")
fmt.Printf(" Wallet: %s\n", creds.Wallet)
fmt.Printf(" Namespace: %s\n", creds.Namespace)
if creds.NamespaceURL != "" {
fmt.Printf(" NS Gateway: %s\n", creds.NamespaceURL)
}
fmt.Printf(" Issued At: %s\n", creds.IssuedAt.Format("2006-01-02 15:04:05"))
if !creds.ExpiresAt.IsZero() {
fmt.Printf(" Expires At: %s\n", creds.ExpiresAt.Format("2006-01-02 15:04:05"))
@ -246,14 +122,14 @@ func handleAuthWhoami() {
}
func handleAuthStatus() {
store, err := auth.LoadEnhancedCredentials()
store, err := auth.LoadCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to load credentials: %v\n", err)
os.Exit(1)
}
gatewayURL := getGatewayURL()
creds := store.GetDefaultCredential(gatewayURL)
creds, exists := store.GetCredentialsForGateway(gatewayURL)
// Show active environment
env, err := GetActiveEnvironment()
@ -264,7 +140,7 @@ func handleAuthStatus() {
fmt.Println("🔐 Authentication Status")
fmt.Printf(" Gateway URL: %s\n", gatewayURL)
if creds == nil {
if !exists || creds == nil {
fmt.Println(" Status: ❌ Not authenticated")
return
}
@ -280,9 +156,6 @@ func handleAuthStatus() {
fmt.Println(" Status: ✅ Authenticated")
fmt.Printf(" Wallet: %s\n", creds.Wallet)
fmt.Printf(" Namespace: %s\n", creds.Namespace)
if creds.NamespaceURL != "" {
fmt.Printf(" NS Gateway: %s\n", creds.NamespaceURL)
}
if !creds.ExpiresAt.IsZero() {
fmt.Printf(" Expires: %s\n", creds.ExpiresAt.Format("2006-01-02 15:04:05"))
}
@ -292,61 +165,57 @@ func handleAuthStatus() {
}
// promptForGatewayURL interactively prompts for the gateway URL
// Uses the active environment or allows entering a custom domain
// Allows user to choose between local node or remote node by domain
func promptForGatewayURL() string {
// Check environment variable first (allows override without prompting)
if url := os.Getenv("ORAMA_GATEWAY_URL"); url != "" {
if url := os.Getenv("DEBROS_GATEWAY_URL"); url != "" {
return url
}
// Try active environment
env, err := GetActiveEnvironment()
if err == nil {
reader := bufio.NewReader(os.Stdin)
reader := bufio.NewReader(os.Stdin)
fmt.Println("\n🌐 Node Connection")
fmt.Println("==================")
fmt.Printf("1. Use active environment: %s (%s)\n", env.Name, env.GatewayURL)
fmt.Println("2. Enter custom domain")
fmt.Print("\nSelect option [1/2]: ")
fmt.Println("\n🌐 Node Connection")
fmt.Println("==================")
fmt.Println("1. Local node (localhost:6001)")
fmt.Println("2. Remote node (enter domain)")
fmt.Print("\nSelect option [1/2]: ")
choice, _ := reader.ReadString('\n')
choice = strings.TrimSpace(choice)
choice, _ := reader.ReadString('\n')
choice = strings.TrimSpace(choice)
if choice == "1" || choice == "" {
return env.GatewayURL
}
if choice == "2" {
fmt.Print("Enter node domain (e.g., node-hk19de.orama.network): ")
domain, _ := reader.ReadString('\n')
domain = strings.TrimSpace(domain)
if domain == "" {
fmt.Printf("⚠️ No domain entered, using %s\n", env.Name)
return env.GatewayURL
}
// Remove any protocol prefix if user included it
domain = strings.TrimPrefix(domain, "https://")
domain = strings.TrimPrefix(domain, "http://")
// Remove trailing slash
domain = strings.TrimSuffix(domain, "/")
return fmt.Sprintf("https://%s", domain)
}
return env.GatewayURL
if choice == "1" || choice == "" {
return "http://localhost:6001"
}
return "https://orama-devnet.network"
if choice != "2" {
fmt.Println("⚠️ Invalid option, using localhost")
return "http://localhost:6001"
}
fmt.Print("Enter node domain (e.g., node-hk19de.debros.network): ")
domain, _ := reader.ReadString('\n')
domain = strings.TrimSpace(domain)
if domain == "" {
fmt.Println("⚠️ No domain entered, using localhost")
return "http://localhost:6001"
}
// Remove any protocol prefix if user included it
domain = strings.TrimPrefix(domain, "https://")
domain = strings.TrimPrefix(domain, "http://")
// Remove trailing slash
domain = strings.TrimSuffix(domain, "/")
// Use HTTPS for remote domains
return fmt.Sprintf("https://%s", domain)
}
// getGatewayURL returns the gateway URL based on environment or env var
// Used by other commands that don't need interactive node selection
func getGatewayURL() string {
// Check environment variable first (for backwards compatibility)
if url := os.Getenv("ORAMA_GATEWAY_URL"); url != "" {
if url := os.Getenv("DEBROS_GATEWAY_URL"); url != "" {
return url
}
@ -356,111 +225,6 @@ func getGatewayURL() string {
return env.GatewayURL
}
// Fallback to devnet
return "https://orama-devnet.network"
}
func handleAuthList() {
store, err := auth.LoadEnhancedCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to load credentials: %v\n", err)
os.Exit(1)
}
gatewayURL := getGatewayURL()
// Show active environment
env, err := GetActiveEnvironment()
if err == nil {
fmt.Printf("🌍 Environment: %s\n", env.Name)
}
fmt.Printf("🔗 Gateway: %s\n\n", gatewayURL)
gwCreds := store.Gateways[gatewayURL]
if gwCreds == nil || len(gwCreds.Credentials) == 0 {
fmt.Println("No credentials stored for this environment.")
fmt.Println("Run 'orama auth login' to authenticate.")
return
}
fmt.Printf("🔐 Stored Credentials (%d):\n\n", len(gwCreds.Credentials))
for i, creds := range gwCreds.Credentials {
defaultMark := ""
if i == gwCreds.DefaultIndex {
defaultMark = " ← active"
}
statusEmoji := "✅"
statusText := "valid"
if !creds.IsValid() {
statusEmoji = "❌"
statusText = "expired"
}
fmt.Printf(" %d. %s Wallet: %s%s\n", i+1, statusEmoji, creds.Wallet, defaultMark)
fmt.Printf(" Namespace: %s | Status: %s\n", creds.Namespace, statusText)
if creds.Plan != "" {
fmt.Printf(" Plan: %s\n", creds.Plan)
}
if !creds.IssuedAt.IsZero() {
fmt.Printf(" Issued: %s\n", creds.IssuedAt.Format("2006-01-02 15:04:05"))
}
fmt.Println()
}
}
func handleAuthSwitch() {
store, err := auth.LoadEnhancedCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to load credentials: %v\n", err)
os.Exit(1)
}
gatewayURL := getGatewayURL()
gwCreds := store.Gateways[gatewayURL]
if gwCreds == nil || len(gwCreds.Credentials) == 0 {
fmt.Println("No credentials stored for this environment.")
fmt.Println("Run 'orama auth login' to authenticate first.")
os.Exit(1)
}
if len(gwCreds.Credentials) == 1 {
fmt.Println("Only one credential stored. Nothing to switch to.")
return
}
// Display menu
choice, credIndex, err := store.DisplayCredentialMenu(gatewayURL)
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Menu selection failed: %v\n", err)
os.Exit(1)
}
switch choice {
case auth.AuthChoiceUseCredential:
selectedCreds := gwCreds.Credentials[credIndex]
store.SetDefaultCredential(gatewayURL, credIndex)
selectedCreds.UpdateLastUsed()
if err := store.Save(); err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to save credentials: %v\n", err)
os.Exit(1)
}
fmt.Printf("✅ Switched to wallet: %s\n", selectedCreds.Wallet)
fmt.Printf("🏢 Namespace: %s\n", selectedCreds.Namespace)
case auth.AuthChoiceAddCredential:
fmt.Println("Use 'orama auth login' to add a new credential.")
case auth.AuthChoiceLogout:
store.ClearAllCredentials()
if err := store.Save(); err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to clear credentials: %v\n", err)
os.Exit(1)
}
fmt.Println("✅ All credentials cleared")
case auth.AuthChoiceExit:
fmt.Println("Cancelled.")
}
// Fallback to default (node-1)
return "http://localhost:6001"
}

423
pkg/cli/basic_commands.go Normal file
View File

@ -0,0 +1,423 @@
package cli
import (
"context"
"encoding/json"
"fmt"
"os"
"strconv"
"time"
"github.com/DeBrosOfficial/network/pkg/auth"
"github.com/DeBrosOfficial/network/pkg/client"
)
// HandleHealthCommand handles the health command
func HandleHealthCommand(format string, timeout time.Duration) {
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
health, err := cli.Health()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get health: %v\n", err)
os.Exit(1)
}
if format == "json" {
printJSON(health)
} else {
printHealth(health)
}
}
// HandlePeersCommand handles the peers command
func HandlePeersCommand(format string, timeout time.Duration) {
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
peers, err := cli.Network().GetPeers(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get peers: %v\n", err)
os.Exit(1)
}
if format == "json" {
printJSON(peers)
} else {
printPeers(peers)
}
}
// HandleStatusCommand handles the status command
func HandleStatusCommand(format string, timeout time.Duration) {
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
status, err := cli.Network().GetStatus(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get status: %v\n", err)
os.Exit(1)
}
if format == "json" {
printJSON(status)
} else {
printStatus(status)
}
}
// HandleQueryCommand handles the query command
func HandleQueryCommand(sql, format string, timeout time.Duration) {
// Ensure user is authenticated
_ = ensureAuthenticated()
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
result, err := cli.Database().Query(ctx, sql)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to execute query: %v\n", err)
os.Exit(1)
}
if format == "json" {
printJSON(result)
} else {
printQueryResult(result)
}
}
// HandleConnectCommand handles the connect command
func HandleConnectCommand(peerAddr string, timeout time.Duration) {
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
err = cli.Network().ConnectToPeer(ctx, peerAddr)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to connect to peer: %v\n", err)
os.Exit(1)
}
fmt.Printf("✅ Connected to peer: %s\n", peerAddr)
}
// HandlePeerIDCommand handles the peer-id command
func HandlePeerIDCommand(format string, timeout time.Duration) {
cli, err := createClient()
if err == nil {
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
if status, err := cli.Network().GetStatus(ctx); err == nil {
if format == "json" {
printJSON(map[string]string{"peer_id": status.NodeID})
} else {
fmt.Printf("🆔 Peer ID: %s\n", status.NodeID)
}
return
}
}
fmt.Fprintf(os.Stderr, "❌ Could not find peer ID. Make sure the node is running or identity files exist.\n")
os.Exit(1)
}
// HandlePubSubCommand handles pubsub commands
func HandlePubSubCommand(args []string, format string, timeout time.Duration) {
if len(args) == 0 {
fmt.Fprintf(os.Stderr, "Usage: dbn pubsub <publish|subscribe|topics> [args...]\n")
os.Exit(1)
}
// Ensure user is authenticated
_ = ensureAuthenticated()
cli, err := createClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
os.Exit(1)
}
defer cli.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
subcommand := args[0]
switch subcommand {
case "publish":
if len(args) < 3 {
fmt.Fprintf(os.Stderr, "Usage: dbn pubsub publish <topic> <message>\n")
os.Exit(1)
}
err := cli.PubSub().Publish(ctx, args[1], []byte(args[2]))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to publish message: %v\n", err)
os.Exit(1)
}
fmt.Printf("✅ Published message to topic: %s\n", args[1])
case "subscribe":
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: dbn pubsub subscribe <topic> [duration]\n")
os.Exit(1)
}
duration := 30 * time.Second
if len(args) > 2 {
if d, err := time.ParseDuration(args[2]); err == nil {
duration = d
}
}
ctx, cancel := context.WithTimeout(context.Background(), duration)
defer cancel()
fmt.Printf("🔔 Subscribing to topic '%s' for %v...\n", args[1], duration)
messageHandler := func(topic string, data []byte) error {
fmt.Printf("📨 [%s] %s: %s\n", time.Now().Format("15:04:05"), topic, string(data))
return nil
}
err := cli.PubSub().Subscribe(ctx, args[1], messageHandler)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to subscribe: %v\n", err)
os.Exit(1)
}
<-ctx.Done()
fmt.Printf("✅ Subscription ended\n")
case "topics":
topics, err := cli.PubSub().ListTopics(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list topics: %v\n", err)
os.Exit(1)
}
if format == "json" {
printJSON(topics)
} else {
for _, topic := range topics {
fmt.Println(topic)
}
}
default:
fmt.Fprintf(os.Stderr, "Unknown pubsub command: %s\n", subcommand)
os.Exit(1)
}
}
// Helper functions
func createClient() (client.NetworkClient, error) {
config := client.DefaultClientConfig("dbn")
// Use active environment's gateway URL
gatewayURL := getGatewayURL()
config.GatewayURL = gatewayURL
// Try to get peer configuration from active environment
env, err := GetActiveEnvironment()
if err == nil && env != nil {
// Environment loaded successfully - gateway URL already set above
_ = env // Reserve for future peer configuration
}
// Check for existing credentials using enhanced authentication
creds, err := auth.GetValidEnhancedCredentials()
if err != nil {
// No valid credentials found, use the enhanced authentication flow
newCreds, authErr := auth.GetOrPromptForCredentials(gatewayURL)
if authErr != nil {
return nil, fmt.Errorf("authentication failed: %w", authErr)
}
creds = newCreds
}
// Configure client with API key
config.APIKey = creds.APIKey
// Update last used time - the enhanced store handles saving automatically
creds.UpdateLastUsed()
networkClient, err := client.NewClient(config)
if err != nil {
return nil, err
}
if err := networkClient.Connect(); err != nil {
return nil, err
}
return networkClient, nil
}
func ensureAuthenticated() *auth.Credentials {
gatewayURL := getGatewayURL()
credentials, err := auth.GetOrPromptForCredentials(gatewayURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err)
os.Exit(1)
}
return credentials
}
func printHealth(health *client.HealthStatus) {
fmt.Printf("🏥 Network Health\n")
fmt.Printf("Status: %s\n", getStatusEmoji(health.Status)+health.Status)
fmt.Printf("Last Updated: %s\n", health.LastUpdated.Format("2006-01-02 15:04:05"))
fmt.Printf("Response Time: %v\n", health.ResponseTime)
fmt.Printf("\nChecks:\n")
for check, status := range health.Checks {
emoji := "✅"
if status != "ok" {
emoji = "❌"
}
fmt.Printf(" %s %s: %s\n", emoji, check, status)
}
}
func printPeers(peers []client.PeerInfo) {
fmt.Printf("👥 Connected Peers (%d)\n\n", len(peers))
if len(peers) == 0 {
fmt.Printf("No peers connected\n")
return
}
for i, peer := range peers {
connEmoji := "🔴"
if peer.Connected {
connEmoji = "🟢"
}
fmt.Printf("%d. %s %s\n", i+1, connEmoji, peer.ID)
fmt.Printf(" Addresses: %v\n", peer.Addresses)
fmt.Printf(" Last Seen: %s\n", peer.LastSeen.Format("2006-01-02 15:04:05"))
fmt.Println()
}
}
func printStatus(status *client.NetworkStatus) {
fmt.Printf("🌐 Network Status\n")
fmt.Printf("Node ID: %s\n", status.NodeID)
fmt.Printf("Connected: %s\n", getBoolEmoji(status.Connected)+strconv.FormatBool(status.Connected))
fmt.Printf("Peer Count: %d\n", status.PeerCount)
fmt.Printf("Database Size: %s\n", formatBytes(status.DatabaseSize))
fmt.Printf("Uptime: %v\n", status.Uptime.Round(time.Second))
}
func printQueryResult(result *client.QueryResult) {
fmt.Printf("📊 Query Result\n")
fmt.Printf("Rows: %d\n\n", result.Count)
if len(result.Rows) == 0 {
fmt.Printf("No data returned\n")
return
}
// Print header
for i, col := range result.Columns {
if i > 0 {
fmt.Printf(" | ")
}
fmt.Printf("%-15s", col)
}
fmt.Println()
// Print separator
for i := range result.Columns {
if i > 0 {
fmt.Printf("-+-")
}
fmt.Printf("%-15s", "---------------")
}
fmt.Println()
// Print rows
for _, row := range result.Rows {
for i, cell := range row {
if i > 0 {
fmt.Printf(" | ")
}
fmt.Printf("%-15v", cell)
}
fmt.Println()
}
}
func printJSON(data interface{}) {
jsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to marshal JSON: %v\n", err)
return
}
fmt.Println(string(jsonData))
}
func getStatusEmoji(status string) string {
switch status {
case "healthy":
return "🟢 "
case "degraded":
return "🟡 "
case "unhealthy":
return "🔴 "
default:
return "⚪ "
}
}
func getBoolEmoji(b bool) string {
if b {
return "✅ "
}
return "❌ "
}
func formatBytes(bytes int64) string {
const unit = 1024
if bytes < unit {
return fmt.Sprintf("%d B", bytes)
}
div, exp := int64(unit), 0
for n := bytes / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
}

View File

@ -1,80 +0,0 @@
package cluster
import (
"fmt"
"os"
)
// HandleCommand handles cluster subcommands.
func HandleCommand(args []string) {
if len(args) == 0 {
ShowHelp()
return
}
subcommand := args[0]
subargs := args[1:]
switch subcommand {
case "status":
HandleStatus(subargs)
case "health":
HandleHealth(subargs)
case "rqlite":
HandleRQLite(subargs)
case "watch":
HandleWatch(subargs)
case "help":
ShowHelp()
default:
fmt.Fprintf(os.Stderr, "Unknown cluster subcommand: %s\n", subcommand)
ShowHelp()
os.Exit(1)
}
}
// hasFlag checks if a flag is present in the args slice.
func hasFlag(args []string, flag string) bool {
for _, a := range args {
if a == flag {
return true
}
}
return false
}
// getFlagValue returns the value of a flag from the args slice.
// Returns empty string if the flag is not found or has no value.
func getFlagValue(args []string, flag string) string {
for i, a := range args {
if a == flag && i+1 < len(args) {
return args[i+1]
}
}
return ""
}
// ShowHelp displays help information for cluster commands.
func ShowHelp() {
fmt.Printf("Cluster Management Commands\n\n")
fmt.Printf("Usage: orama cluster <subcommand> [options]\n\n")
fmt.Printf("Subcommands:\n")
fmt.Printf(" status - Show cluster node status (RQLite + Olric)\n")
fmt.Printf(" Options:\n")
fmt.Printf(" --all - SSH into all nodes from remote-nodes.conf (TODO)\n")
fmt.Printf(" health - Run cluster health checks\n")
fmt.Printf(" rqlite <subcommand> - RQLite-specific commands\n")
fmt.Printf(" status - Show detailed Raft state for local node\n")
fmt.Printf(" voters - Show current voter list\n")
fmt.Printf(" backup [--output FILE] - Trigger manual backup\n")
fmt.Printf(" watch - Live cluster status monitor\n")
fmt.Printf(" Options:\n")
fmt.Printf(" --interval SECONDS - Refresh interval (default: 10)\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" orama cluster status\n")
fmt.Printf(" orama cluster health\n")
fmt.Printf(" orama cluster rqlite status\n")
fmt.Printf(" orama cluster rqlite voters\n")
fmt.Printf(" orama cluster rqlite backup --output /tmp/backup.db\n")
fmt.Printf(" orama cluster watch --interval 5\n")
}

View File

@ -1,244 +0,0 @@
package cluster
import (
"fmt"
"os"
)
// checkResult represents the outcome of a single health check.
type checkResult struct {
Name string
Status string // "PASS", "FAIL", "WARN"
Detail string
}
// HandleHealth handles the "orama cluster health" command.
func HandleHealth(args []string) {
fmt.Printf("Cluster Health Check\n")
fmt.Printf("====================\n\n")
var results []checkResult
// Check 1: RQLite reachable
status, err := queryRQLiteStatus()
if err != nil {
results = append(results, checkResult{
Name: "RQLite reachable",
Status: "FAIL",
Detail: fmt.Sprintf("Cannot connect to RQLite: %v", err),
})
printHealthResults(results)
os.Exit(1)
return
}
results = append(results, checkResult{
Name: "RQLite reachable",
Status: "PASS",
Detail: fmt.Sprintf("HTTP API responding on %s", status.HTTP.Address),
})
// Check 2: Raft state is leader or follower (not candidate or shutdown)
raftState := status.Store.Raft.State
switch raftState {
case "Leader", "Follower":
results = append(results, checkResult{
Name: "Raft state healthy",
Status: "PASS",
Detail: fmt.Sprintf("Node is %s", raftState),
})
case "Candidate":
results = append(results, checkResult{
Name: "Raft state healthy",
Status: "WARN",
Detail: "Node is Candidate (election in progress)",
})
default:
results = append(results, checkResult{
Name: "Raft state healthy",
Status: "FAIL",
Detail: fmt.Sprintf("Node is in unexpected state: %s", raftState),
})
}
// Check 3: Leader exists
if status.Store.Raft.Leader != "" {
results = append(results, checkResult{
Name: "Leader exists",
Status: "PASS",
Detail: fmt.Sprintf("Leader: %s", status.Store.Raft.Leader),
})
} else {
results = append(results, checkResult{
Name: "Leader exists",
Status: "FAIL",
Detail: "No leader detected in Raft cluster",
})
}
// Check 4: Applied index is advancing (commit == applied means caught up)
if status.Store.Raft.AppliedIndex >= status.Store.Raft.CommitIndex {
results = append(results, checkResult{
Name: "Log replication",
Status: "PASS",
Detail: fmt.Sprintf("Applied index (%d) >= commit index (%d)",
status.Store.Raft.AppliedIndex, status.Store.Raft.CommitIndex),
})
} else {
lag := status.Store.Raft.CommitIndex - status.Store.Raft.AppliedIndex
severity := "WARN"
if lag > 1000 {
severity = "FAIL"
}
results = append(results, checkResult{
Name: "Log replication",
Status: severity,
Detail: fmt.Sprintf("Applied index (%d) behind commit index (%d) by %d entries",
status.Store.Raft.AppliedIndex, status.Store.Raft.CommitIndex, lag),
})
}
// Check 5: Query nodes to validate cluster membership
nodes, err := queryRQLiteNodes(true)
if err != nil {
results = append(results, checkResult{
Name: "Cluster nodes reachable",
Status: "FAIL",
Detail: fmt.Sprintf("Cannot query /nodes: %v", err),
})
} else {
totalNodes := len(nodes)
voters := 0
nonVoters := 0
reachable := 0
leaders := 0
for _, node := range nodes {
if node.Voter {
voters++
} else {
nonVoters++
}
if node.Reachable {
reachable++
}
if node.Leader {
leaders++
}
}
// Check 5a: Node count
results = append(results, checkResult{
Name: "Cluster membership",
Status: "PASS",
Detail: fmt.Sprintf("%d nodes (%d voters, %d non-voters)", totalNodes, voters, nonVoters),
})
// Check 5b: All nodes reachable
if reachable == totalNodes {
results = append(results, checkResult{
Name: "All nodes reachable",
Status: "PASS",
Detail: fmt.Sprintf("%d/%d nodes reachable", reachable, totalNodes),
})
} else {
unreachable := totalNodes - reachable
results = append(results, checkResult{
Name: "All nodes reachable",
Status: "WARN",
Detail: fmt.Sprintf("%d/%d nodes reachable (%d unreachable)", reachable, totalNodes, unreachable),
})
}
// Check 5c: Exactly one leader
if leaders == 1 {
results = append(results, checkResult{
Name: "Single leader",
Status: "PASS",
Detail: "Exactly 1 leader in cluster",
})
} else if leaders == 0 {
results = append(results, checkResult{
Name: "Single leader",
Status: "FAIL",
Detail: "No leader found among nodes",
})
} else {
results = append(results, checkResult{
Name: "Single leader",
Status: "FAIL",
Detail: fmt.Sprintf("Multiple leaders detected: %d (split-brain?)", leaders),
})
}
// Check 5d: Quorum check (majority of voters must be reachable)
quorum := (voters / 2) + 1
reachableVoters := 0
for _, node := range nodes {
if node.Voter && node.Reachable {
reachableVoters++
}
}
if reachableVoters >= quorum {
results = append(results, checkResult{
Name: "Quorum healthy",
Status: "PASS",
Detail: fmt.Sprintf("%d/%d voters reachable (quorum requires %d)", reachableVoters, voters, quorum),
})
} else {
results = append(results, checkResult{
Name: "Quorum healthy",
Status: "FAIL",
Detail: fmt.Sprintf("%d/%d voters reachable (quorum requires %d)", reachableVoters, voters, quorum),
})
}
}
printHealthResults(results)
// Exit with non-zero if any failures
for _, r := range results {
if r.Status == "FAIL" {
os.Exit(1)
}
}
}
// printHealthResults prints the health check results in a formatted table.
func printHealthResults(results []checkResult) {
// Find the longest check name for alignment
maxName := 0
for _, r := range results {
if len(r.Name) > maxName {
maxName = len(r.Name)
}
}
for _, r := range results {
indicator := " "
switch r.Status {
case "PASS":
indicator = "PASS"
case "FAIL":
indicator = "FAIL"
case "WARN":
indicator = "WARN"
}
fmt.Printf(" [%s] %-*s %s\n", indicator, maxName, r.Name, r.Detail)
}
fmt.Println()
// Summary
pass, fail, warn := 0, 0, 0
for _, r := range results {
switch r.Status {
case "PASS":
pass++
case "FAIL":
fail++
case "WARN":
warn++
}
}
fmt.Printf("Summary: %d passed, %d failed, %d warnings\n", pass, fail, warn)
}

View File

@ -1,187 +0,0 @@
package cluster
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
)
// HandleRQLite handles the "orama cluster rqlite" subcommand group.
func HandleRQLite(args []string) {
if len(args) == 0 {
showRQLiteHelp()
return
}
subcommand := args[0]
subargs := args[1:]
switch subcommand {
case "status":
handleRQLiteStatus()
case "voters":
handleRQLiteVoters()
case "backup":
handleRQLiteBackup(subargs)
case "help":
showRQLiteHelp()
default:
fmt.Fprintf(os.Stderr, "Unknown rqlite subcommand: %s\n", subcommand)
showRQLiteHelp()
os.Exit(1)
}
}
// handleRQLiteStatus shows detailed Raft state for the local node.
func handleRQLiteStatus() {
fmt.Printf("RQLite Raft Status\n")
fmt.Printf("==================\n\n")
status, err := queryRQLiteStatus()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
fmt.Printf("Node Configuration\n")
fmt.Printf(" Node ID: %s\n", status.Store.NodeID)
fmt.Printf(" Raft Address: %s\n", status.Store.Address)
fmt.Printf(" HTTP Address: %s\n", status.HTTP.Address)
fmt.Printf(" Data Directory: %s\n", status.Store.Dir)
fmt.Println()
fmt.Printf("Raft State\n")
fmt.Printf(" State: %s\n", strings.ToUpper(status.Store.Raft.State))
fmt.Printf(" Current Term: %d\n", status.Store.Raft.Term)
fmt.Printf(" Applied Index: %d\n", status.Store.Raft.AppliedIndex)
fmt.Printf(" Commit Index: %d\n", status.Store.Raft.CommitIndex)
fmt.Printf(" Leader: %s\n", status.Store.Raft.Leader)
if status.Store.Raft.AppliedIndex < status.Store.Raft.CommitIndex {
lag := status.Store.Raft.CommitIndex - status.Store.Raft.AppliedIndex
fmt.Printf(" Replication Lag: %d entries behind\n", lag)
} else {
fmt.Printf(" Replication Lag: none (fully caught up)\n")
}
if status.Node.Uptime != "" {
fmt.Printf(" Uptime: %s\n", status.Node.Uptime)
}
fmt.Println()
}
// handleRQLiteVoters shows the current voter list from /nodes.
func handleRQLiteVoters() {
fmt.Printf("RQLite Cluster Voters\n")
fmt.Printf("=====================\n\n")
nodes, err := queryRQLiteNodes(true)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
voters := 0
nonVoters := 0
fmt.Printf("%-20s %-30s %-8s %-10s %-10s\n",
"NODE ID", "ADDRESS", "ROLE", "LEADER", "REACHABLE")
fmt.Printf("%-20s %-30s %-8s %-10s %-10s\n",
strings.Repeat("-", 20),
strings.Repeat("-", 30),
strings.Repeat("-", 8),
strings.Repeat("-", 10),
strings.Repeat("-", 10))
for id, node := range nodes {
nodeID := id
if len(nodeID) > 20 {
nodeID = nodeID[:17] + "..."
}
role := "non-voter"
if node.Voter {
role = "voter"
voters++
} else {
nonVoters++
}
leader := "no"
if node.Leader {
leader = "yes"
}
reachable := "no"
if node.Reachable {
reachable = "yes"
}
fmt.Printf("%-20s %-30s %-8s %-10s %-10s\n",
nodeID, node.Address, role, leader, reachable)
}
fmt.Printf("\nTotal: %d voters, %d non-voters\n", voters, nonVoters)
quorum := (voters / 2) + 1
fmt.Printf("Quorum requirement: %d/%d voters\n", quorum, voters)
}
// handleRQLiteBackup triggers a manual backup via the RQLite backup endpoint.
func handleRQLiteBackup(args []string) {
outputFile := getFlagValue(args, "--output")
if outputFile == "" {
outputFile = fmt.Sprintf("rqlite-backup-%s.db", time.Now().Format("20060102-150405"))
}
fmt.Printf("RQLite Backup\n")
fmt.Printf("=============\n\n")
fmt.Printf("Requesting backup from %s/db/backup ...\n", rqliteBaseURL)
client := &http.Client{Timeout: 60 * time.Second}
resp, err := client.Get(rqliteBaseURL + "/db/backup")
if err != nil {
fmt.Fprintf(os.Stderr, "Error: cannot connect to RQLite: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
fmt.Fprintf(os.Stderr, "Error: backup request returned HTTP %d: %s\n", resp.StatusCode, string(body))
os.Exit(1)
}
outFile, err := os.Create(outputFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: cannot create output file: %v\n", err)
os.Exit(1)
}
defer outFile.Close()
written, err := io.Copy(outFile, resp.Body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to write backup: %v\n", err)
os.Exit(1)
}
fmt.Printf("Backup saved to: %s (%d bytes)\n", outputFile, written)
}
// showRQLiteHelp displays help for rqlite subcommands.
func showRQLiteHelp() {
fmt.Printf("RQLite Commands\n\n")
fmt.Printf("Usage: orama cluster rqlite <subcommand> [options]\n\n")
fmt.Printf("Subcommands:\n")
fmt.Printf(" status - Show detailed Raft state for local node\n")
fmt.Printf(" voters - Show current voter list from cluster\n")
fmt.Printf(" backup - Trigger manual database backup\n")
fmt.Printf(" Options:\n")
fmt.Printf(" --output FILE - Output file path (default: rqlite-backup-<timestamp>.db)\n\n")
fmt.Printf("Examples:\n")
fmt.Printf(" orama cluster rqlite status\n")
fmt.Printf(" orama cluster rqlite voters\n")
fmt.Printf(" orama cluster rqlite backup --output /tmp/backup.db\n")
}

View File

@ -1,248 +0,0 @@
package cluster
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
)
const (
rqliteBaseURL = "http://localhost:5001"
httpTimeout = 10 * time.Second
)
// rqliteStatus represents the relevant fields from the RQLite /status endpoint.
type rqliteStatus struct {
Store struct {
Raft struct {
State string `json:"state"`
AppliedIndex uint64 `json:"applied_index"`
CommitIndex uint64 `json:"commit_index"`
Term uint64 `json:"current_term"`
Leader string `json:"leader"`
} `json:"raft"`
Dir string `json:"dir"`
NodeID string `json:"node_id"`
Address string `json:"addr"`
} `json:"store"`
HTTP struct {
Address string `json:"addr"`
} `json:"http"`
Node struct {
Uptime string `json:"uptime"`
} `json:"node"`
}
// rqliteNode represents a node from the /nodes endpoint.
type rqliteNode struct {
ID string `json:"id"`
Address string `json:"addr"`
Leader bool `json:"leader"`
Voter bool `json:"voter"`
Reachable bool `json:"reachable"`
Time float64 `json:"time"`
TimeS string `json:"time_s"`
}
// HandleStatus handles the "orama cluster status" command.
func HandleStatus(args []string) {
if hasFlag(args, "--all") {
fmt.Printf("Remote node aggregation via SSH is not yet implemented.\n")
fmt.Printf("Currently showing local node status only.\n\n")
}
fmt.Printf("Cluster Status\n")
fmt.Printf("==============\n\n")
// Query RQLite status
status, err := queryRQLiteStatus()
if err != nil {
fmt.Fprintf(os.Stderr, "Error querying RQLite status: %v\n", err)
fmt.Printf("RQLite may not be running on this node.\n\n")
} else {
printLocalStatus(status)
}
// Query RQLite nodes
nodes, err := queryRQLiteNodes(true)
if err != nil {
fmt.Fprintf(os.Stderr, "Error querying RQLite nodes: %v\n", err)
} else {
printNodesTable(nodes)
}
// Query Olric status (best-effort)
printOlricStatus()
}
// queryRQLiteStatus queries the local RQLite /status endpoint.
func queryRQLiteStatus() (*rqliteStatus, error) {
client := &http.Client{Timeout: httpTimeout}
resp, err := client.Get(rqliteBaseURL + "/status")
if err != nil {
return nil, fmt.Errorf("connect to RQLite: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read response: %w", err)
}
var status rqliteStatus
if err := json.Unmarshal(body, &status); err != nil {
return nil, fmt.Errorf("parse response: %w", err)
}
return &status, nil
}
// queryRQLiteNodes queries the local RQLite /nodes endpoint.
// If includeNonVoters is true, appends ?nonvoters to the query.
func queryRQLiteNodes(includeNonVoters bool) (map[string]*rqliteNode, error) {
client := &http.Client{Timeout: httpTimeout}
url := rqliteBaseURL + "/nodes"
if includeNonVoters {
url += "?nonvoters"
}
resp, err := client.Get(url)
if err != nil {
return nil, fmt.Errorf("connect to RQLite: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read response: %w", err)
}
var nodes map[string]*rqliteNode
if err := json.Unmarshal(body, &nodes); err != nil {
return nil, fmt.Errorf("parse response: %w", err)
}
return nodes, nil
}
// printLocalStatus prints the local node's RQLite status.
func printLocalStatus(s *rqliteStatus) {
fmt.Printf("Local Node\n")
fmt.Printf(" Node ID: %s\n", s.Store.NodeID)
fmt.Printf(" Raft Address: %s\n", s.Store.Address)
fmt.Printf(" HTTP Address: %s\n", s.HTTP.Address)
fmt.Printf(" Raft State: %s\n", strings.ToUpper(s.Store.Raft.State))
fmt.Printf(" Raft Term: %d\n", s.Store.Raft.Term)
fmt.Printf(" Applied Index: %d\n", s.Store.Raft.AppliedIndex)
fmt.Printf(" Commit Index: %d\n", s.Store.Raft.CommitIndex)
fmt.Printf(" Leader: %s\n", s.Store.Raft.Leader)
if s.Node.Uptime != "" {
fmt.Printf(" Uptime: %s\n", s.Node.Uptime)
}
fmt.Println()
}
// printNodesTable prints a formatted table of all cluster nodes.
func printNodesTable(nodes map[string]*rqliteNode) {
if len(nodes) == 0 {
fmt.Printf("No nodes found in cluster.\n\n")
return
}
fmt.Printf("Cluster Nodes (%d total)\n", len(nodes))
fmt.Printf("%-20s %-30s %-8s %-10s %-10s %-12s\n",
"NODE ID", "ADDRESS", "VOTER", "LEADER", "REACHABLE", "LATENCY")
fmt.Printf("%-20s %-30s %-8s %-10s %-10s %-12s\n",
strings.Repeat("-", 20),
strings.Repeat("-", 30),
strings.Repeat("-", 8),
strings.Repeat("-", 10),
strings.Repeat("-", 10),
strings.Repeat("-", 12))
for id, node := range nodes {
nodeID := id
if len(nodeID) > 20 {
nodeID = nodeID[:17] + "..."
}
voter := "no"
if node.Voter {
voter = "yes"
}
leader := "no"
if node.Leader {
leader = "yes"
}
reachable := "no"
if node.Reachable {
reachable = "yes"
}
latency := "-"
if node.TimeS != "" {
latency = node.TimeS
} else if node.Time > 0 {
latency = fmt.Sprintf("%.3fs", node.Time)
}
fmt.Printf("%-20s %-30s %-8s %-10s %-10s %-12s\n",
nodeID, node.Address, voter, leader, reachable, latency)
}
fmt.Println()
}
// printOlricStatus attempts to query the local Olric status endpoint.
func printOlricStatus() {
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Get("http://localhost:3320/")
if err != nil {
fmt.Printf("Olric: not reachable on localhost:3320 (%v)\n\n", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Olric: reachable but could not read response\n\n")
return
}
if resp.StatusCode == http.StatusOK {
fmt.Printf("Olric: reachable (HTTP %d)\n", resp.StatusCode)
// Try to parse as JSON for a nicer display
var data map[string]interface{}
if err := json.Unmarshal(body, &data); err == nil {
for key, val := range data {
fmt.Printf(" %s: %v\n", key, val)
}
} else {
// Not JSON, print raw (truncated)
raw := strings.TrimSpace(string(body))
if len(raw) > 200 {
raw = raw[:200] + "..."
}
if raw != "" {
fmt.Printf(" Response: %s\n", raw)
}
}
} else {
fmt.Printf("Olric: reachable but returned HTTP %d\n", resp.StatusCode)
}
fmt.Println()
}

View File

@ -1,136 +0,0 @@
package cluster
import (
"fmt"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
)
// HandleWatch handles the "orama cluster watch" command.
// It polls RQLite status and nodes at a configurable interval and reprints a summary.
func HandleWatch(args []string) {
interval := 10 * time.Second
// Parse --interval flag
intervalStr := getFlagValue(args, "--interval")
if intervalStr != "" {
secs, err := strconv.Atoi(intervalStr)
if err != nil || secs < 1 {
fmt.Fprintf(os.Stderr, "Error: --interval must be a positive integer (seconds)\n")
os.Exit(1)
}
interval = time.Duration(secs) * time.Second
}
// Set up signal handling for clean exit
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
fmt.Printf("Watching cluster status (interval: %s, Ctrl+C to exit)\n\n", interval)
// Initial render
renderWatchScreen()
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
renderWatchScreen()
case <-sigCh:
fmt.Printf("\nWatch stopped.\n")
return
}
}
}
// renderWatchScreen clears the terminal and prints a summary of cluster state.
func renderWatchScreen() {
// Clear screen using ANSI escape codes
fmt.Print("\033[2J\033[H")
now := time.Now().Format("2006-01-02 15:04:05")
fmt.Printf("Cluster Watch [%s]\n", now)
fmt.Printf("=======================================\n\n")
// Query RQLite status
status, err := queryRQLiteStatus()
if err != nil {
fmt.Printf("RQLite: UNREACHABLE (%v)\n\n", err)
} else {
fmt.Printf("Local Node: %s\n", status.Store.NodeID)
fmt.Printf(" State: %-10s Term: %-6d Applied: %-8d Commit: %-8d\n",
strings.ToUpper(status.Store.Raft.State),
status.Store.Raft.Term,
status.Store.Raft.AppliedIndex,
status.Store.Raft.CommitIndex)
fmt.Printf(" Leader: %s\n", status.Store.Raft.Leader)
if status.Node.Uptime != "" {
fmt.Printf(" Uptime: %s\n", status.Node.Uptime)
}
fmt.Println()
}
// Query nodes
nodes, err := queryRQLiteNodes(true)
if err != nil {
fmt.Printf("Nodes: UNAVAILABLE (%v)\n\n", err)
} else {
total := len(nodes)
voters := 0
reachable := 0
for _, n := range nodes {
if n.Voter {
voters++
}
if n.Reachable {
reachable++
}
}
fmt.Printf("Cluster: %d nodes (%d voters), %d/%d reachable\n\n",
total, voters, reachable, total)
// Compact table
fmt.Printf("%-18s %-28s %-7s %-7s %-7s\n",
"ID", "ADDRESS", "VOTER", "LEADER", "UP")
fmt.Printf("%-18s %-28s %-7s %-7s %-7s\n",
strings.Repeat("-", 18),
strings.Repeat("-", 28),
strings.Repeat("-", 7),
strings.Repeat("-", 7),
strings.Repeat("-", 7))
for id, node := range nodes {
nodeID := id
if len(nodeID) > 18 {
nodeID = nodeID[:15] + "..."
}
voter := " "
if node.Voter {
voter = "yes"
}
leader := " "
if node.Leader {
leader = "yes"
}
up := "no"
if node.Reachable {
up = "yes"
}
fmt.Printf("%-18s %-28s %-7s %-7s %-7s\n",
nodeID, node.Address, voter, leader, up)
}
}
fmt.Printf("\nPress Ctrl+C to exit\n")
}

Some files were not shown because too many files have changed in this diff Show More