feat: add CLI commands and server default behavior
- Introduced CLI commands for server, login, upload, sign, verify, and more using `clap`. - Updated Dockerfile and docker-compose to default to `server` command on startup. - Enhanced `test_local.sh` for testing the server and client operations. - Added multipart support to `reqwest` and new CLI documentation in `README.md`. - Updated `Cargo.toml` with new dependencies to support CLI and multipart uploads.
This commit is contained in:
parent
c662dfbfd8
commit
26e81cef17
7 changed files with 461 additions and 29 deletions
106
test_local.sh
106
test_local.sh
|
@ -85,29 +85,102 @@ for i in {1..10}; do
|
|||
sleep 2
|
||||
done
|
||||
|
||||
# Build and run the Rust application
|
||||
echo "Building and running the Rust application..."
|
||||
cargo build && cargo run
|
||||
# Build and run the Rust application with the server command
|
||||
echo "Building and running the vault-hier server..."
|
||||
cargo build && cargo run server --vault-addr "$VAULT_ADDR" &
|
||||
SERVER_PID=$!
|
||||
|
||||
# Check if the credentials file was created
|
||||
if [ -f "vault-credentials.txt" ]; then
|
||||
echo "Test successful! Credentials were saved to vault-credentials.txt"
|
||||
# Extract the unseal keys for demonstration
|
||||
UNSEAL_KEYS=$(grep "Key" vault-credentials.txt | head -n 3 | awk '{print $3}')
|
||||
ROOT_TOKEN=$(grep "Root Token" vault-credentials.txt | awk '{print $3}')
|
||||
# Wait for the server to start
|
||||
echo "Waiting for the server to start..."
|
||||
sleep 5
|
||||
|
||||
echo "Root Token: $ROOT_TOKEN"
|
||||
echo "First 3 Unseal Keys (needed for threshold):"
|
||||
echo "$UNSEAL_KEYS"
|
||||
# Test the server with some client operations
|
||||
echo "Testing the client operations..."
|
||||
|
||||
# Clean up temporary files
|
||||
rm -f vault-credentials.txt
|
||||
else
|
||||
echo "Test failed! Credentials file was not created."
|
||||
# Create a sample file for testing
|
||||
echo "Creating a sample file for testing..."
|
||||
echo "This is a test document" > test_document.txt
|
||||
|
||||
# Test login
|
||||
echo "Testing login with legal1 user..."
|
||||
LOGIN_OUTPUT=$(cargo run login --username legal1 --password legal1pass)
|
||||
TOKEN=$(echo "$LOGIN_OUTPUT" | grep "Token:" | awk '{print $2}')
|
||||
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "Login failed. Could not get token."
|
||||
cat test_document.txt
|
||||
kill -9 $SERVER_PID
|
||||
kill -9 $VAULT_PID
|
||||
rm "$VAULT_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Login successful, got token: ${TOKEN:0:8}..."
|
||||
|
||||
# Test upload
|
||||
echo "Testing document upload..."
|
||||
UPLOAD_OUTPUT=$(cargo run upload --name "Test Document" --file test_document.txt)
|
||||
DOC_ID=$(echo "$UPLOAD_OUTPUT" | grep "Document ID:" | awk '{print $3}')
|
||||
|
||||
if [ -z "$DOC_ID" ]; then
|
||||
echo "Upload failed. Could not get document ID."
|
||||
kill -9 $SERVER_PID
|
||||
kill -9 $VAULT_PID
|
||||
rm "$VAULT_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Upload successful, got document ID: $DOC_ID"
|
||||
|
||||
# Test signing
|
||||
echo "Testing document signing..."
|
||||
SIGN_OUTPUT=$(cargo run sign --document-id "$DOC_ID" --username legal1 --token "$TOKEN")
|
||||
|
||||
if echo "$SIGN_OUTPUT" | grep -q "Document signed successfully"; then
|
||||
echo "Document signed successfully"
|
||||
else
|
||||
echo "Signing failed"
|
||||
kill -9 $SERVER_PID
|
||||
kill -9 $VAULT_PID
|
||||
rm "$VAULT_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test verification
|
||||
echo "Testing document verification..."
|
||||
VERIFY_OUTPUT=$(cargo run verify --document-id "$DOC_ID")
|
||||
|
||||
if echo "$VERIFY_OUTPUT" | grep -q "Verification result"; then
|
||||
echo "Verification successful"
|
||||
else
|
||||
echo "Verification failed"
|
||||
kill -9 $SERVER_PID
|
||||
kill -9 $VAULT_PID
|
||||
rm "$VAULT_PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the credentials file was created
|
||||
if [ -f "vault-credentials.txt" ] || [ -f "vault-credentials.json" ]; then
|
||||
echo "Test successful! Credentials were saved"
|
||||
|
||||
if [ -f "vault-credentials.txt" ]; then
|
||||
# Extract the unseal keys for demonstration
|
||||
UNSEAL_KEYS=$(grep "Key" vault-credentials.txt | head -n 3 | awk '{print $3}')
|
||||
ROOT_TOKEN=$(grep "Root Token" vault-credentials.txt | awk '{print $3}')
|
||||
|
||||
echo "Root Token: $ROOT_TOKEN"
|
||||
echo "First 3 Unseal Keys (needed for threshold):"
|
||||
echo "$UNSEAL_KEYS"
|
||||
fi
|
||||
else
|
||||
echo "Warning: Credentials file was not created."
|
||||
fi
|
||||
|
||||
echo -e "\nTest complete! Cleaning up..."
|
||||
# Stop vault-hier server
|
||||
kill -9 $SERVER_PID
|
||||
|
||||
# Stop Vault server
|
||||
kill -9 $VAULT_PID
|
||||
rm "$VAULT_PID_FILE"
|
||||
|
@ -115,5 +188,6 @@ rm "$VAULT_PID_FILE"
|
|||
# Clean up test environment
|
||||
rm -rf /tmp/vault-test
|
||||
rm -f ./vault_server.log
|
||||
rm -f test_document.txt
|
||||
|
||||
echo "All cleaned up. Test successful!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue