766 lines
15 KiB
Bash
Executable File
766 lines
15 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Bruno API Collection Generator for Private API
|
||
# Creates a complete Bruno collection structure for testing the private API endpoints
|
||
|
||
set -e
|
||
|
||
# Configuration
|
||
COLLECTION_NAME="private"
|
||
BASE_URL="https://api.local/api/private"
|
||
DEFAULT_EMAIL="alexis@example.com"
|
||
DEFAULT_USERNAME="alexis"
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
echo_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
echo_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
echo_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
echo_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
# Function to create directory structure
|
||
create_directories() {
|
||
local base_dir="$1"
|
||
|
||
echo_info "Creating directory structure..."
|
||
|
||
mkdir -p "${base_dir}"/{environments,auth,user,invitations,galleries,artworks,gallery-reviews,artwork-reviews}
|
||
|
||
echo_success "Directory structure created"
|
||
}
|
||
|
||
# Function to create a file with content
|
||
create_file() {
|
||
local filepath="$1"
|
||
local content="$2"
|
||
|
||
echo "$content" > "$filepath"
|
||
echo_success "Created: $filepath"
|
||
}
|
||
|
||
# Generate collection files
|
||
generate_files() {
|
||
local base_dir="$1"
|
||
|
||
echo_info "Generating Bruno collection files..."
|
||
|
||
# Main collection file
|
||
cat > "${base_dir}/bruno.json" << EOF
|
||
{
|
||
"version": "1",
|
||
"name": "Private API",
|
||
"type": "collection"
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/bruno.json"
|
||
|
||
# Environment file
|
||
cat > "${base_dir}/environments/local.bru" << EOF
|
||
vars {
|
||
baseUrl: ${BASE_URL}
|
||
email: ${DEFAULT_EMAIL}
|
||
username: ${DEFAULT_USERNAME}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/environments/local.bru"
|
||
|
||
# Auth files
|
||
cat > "${base_dir}/auth/debug-headers.bru" << 'EOF'
|
||
meta {
|
||
name: Debug Headers
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/debug-headers
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/auth/debug-headers.bru"
|
||
|
||
cat > "${base_dir}/auth/redirect.bru" << 'EOF'
|
||
meta {
|
||
name: OIDC Redirect
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/redirect
|
||
}
|
||
|
||
params:query {
|
||
code: authorization_code_here
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/auth/redirect.bru"
|
||
|
||
# User files
|
||
cat > "${base_dir}/user/get-me.bru" << 'EOF'
|
||
meta {
|
||
name: Get My Profile
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/me
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/user/get-me.bru"
|
||
|
||
cat > "${base_dir}/user/update-me.bru" << 'EOF'
|
||
meta {
|
||
name: Update My Profile
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/me
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"alias": "Alexis Updated",
|
||
"first_name": "Alexis",
|
||
"last_name": "Doe",
|
||
"bio": "Art enthusiast and gallery curator",
|
||
"profile_picture_url": "https://example.com/avatar.jpg"
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/user/update-me.bru"
|
||
|
||
# Invitation files
|
||
cat > "${base_dir}/invitations/invite-user.bru" << 'EOF'
|
||
meta {
|
||
name: Invite User to Gallery
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
post {
|
||
url: {{baseUrl}}/gallery/1/invite
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"user_id": 2,
|
||
"role": "viewer"
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/invitations/invite-user.bru"
|
||
|
||
cat > "${base_dir}/invitations/respond-invitation.bru" << 'EOF'
|
||
meta {
|
||
name: Respond to Invitation
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/invitations/1/respond
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"status": "accepted"
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/invitations/respond-invitation.bru"
|
||
|
||
cat > "${base_dir}/invitations/received-invitations.bru" << 'EOF'
|
||
meta {
|
||
name: Get Received Invitations
|
||
type: http
|
||
seq: 3
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/invitations/received
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/invitations/received-invitations.bru"
|
||
|
||
# Gallery files
|
||
cat > "${base_dir}/galleries/list-galleries.bru" << 'EOF'
|
||
meta {
|
||
name: List All Galleries
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/galleries
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/list-galleries.bru"
|
||
|
||
cat > "${base_dir}/galleries/get-gallery.bru" << 'EOF'
|
||
meta {
|
||
name: Get Gallery Details
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/gallery/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/get-gallery.bru"
|
||
|
||
cat > "${base_dir}/galleries/create-gallery.bru" << 'EOF'
|
||
meta {
|
||
name: Create Gallery
|
||
type: http
|
||
seq: 3
|
||
}
|
||
|
||
post {
|
||
url: {{baseUrl}}/gallery
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"title": "Modern Art Collection",
|
||
"description": "A curated collection of contemporary artworks",
|
||
"is_public": true,
|
||
"publication_date": "2025-06-28T10:00:00Z"
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/create-gallery.bru"
|
||
|
||
cat > "${base_dir}/galleries/update-gallery.bru" << 'EOF'
|
||
meta {
|
||
name: Update Gallery
|
||
type: http
|
||
seq: 4
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/gallery/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"title": "Updated Modern Art Collection",
|
||
"description": "An updated curated collection of contemporary artworks",
|
||
"is_public": false
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/update-gallery.bru"
|
||
|
||
cat > "${base_dir}/galleries/my-galleries.bru" << 'EOF'
|
||
meta {
|
||
name: Get My Galleries
|
||
type: http
|
||
seq: 5
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/galleries/mine
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/my-galleries.bru"
|
||
|
||
cat > "${base_dir}/galleries/gallery-members.bru" << 'EOF'
|
||
meta {
|
||
name: Get Gallery Members
|
||
type: http
|
||
seq: 6
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/gallery/1/members
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/galleries/gallery-members.bru"
|
||
|
||
# Artwork files
|
||
cat > "${base_dir}/artworks/gallery-artworks.bru" << 'EOF'
|
||
meta {
|
||
name: Get Gallery Artworks
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/gallery/1/artworks
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artworks/gallery-artworks.bru"
|
||
|
||
cat > "${base_dir}/artworks/get-artwork.bru" << 'EOF'
|
||
meta {
|
||
name: Get Artwork Details
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/artwork/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artworks/get-artwork.bru"
|
||
|
||
cat > "${base_dir}/artworks/create-artwork.bru" << 'EOF'
|
||
meta {
|
||
name: Create Artwork
|
||
type: http
|
||
seq: 3
|
||
}
|
||
|
||
post {
|
||
url: {{baseUrl}}/gallery/1/artwork
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"title": "Sunset Over Mountains",
|
||
"description": "A beautiful landscape painting capturing the golden hour",
|
||
"image_url": "https://example.com/artwork1.jpg",
|
||
"medium": "Oil on Canvas",
|
||
"dimensions": "24x36 inches",
|
||
"creation_year": 2024,
|
||
"price": 1500.00,
|
||
"is_visible": true,
|
||
"is_for_sale": true
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artworks/create-artwork.bru"
|
||
|
||
cat > "${base_dir}/artworks/update-artwork.bru" << 'EOF'
|
||
meta {
|
||
name: Update Artwork
|
||
type: http
|
||
seq: 4
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/artwork/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"title": "Updated Sunset Over Mountains",
|
||
"description": "An updated beautiful landscape painting",
|
||
"price": 1800.00,
|
||
"is_for_sale": false
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artworks/update-artwork.bru"
|
||
|
||
cat > "${base_dir}/artworks/my-artworks.bru" << 'EOF'
|
||
meta {
|
||
name: Get My Artworks
|
||
type: http
|
||
seq: 5
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/artworks/mine
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artworks/my-artworks.bru"
|
||
|
||
# Gallery review files
|
||
cat > "${base_dir}/gallery-reviews/gallery-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Gallery Reviews
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/gallery/1/reviews
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/gallery-reviews/gallery-reviews.bru"
|
||
|
||
cat > "${base_dir}/gallery-reviews/create-gallery-review.bru" << 'EOF'
|
||
meta {
|
||
name: Create Gallery Review
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
post {
|
||
url: {{baseUrl}}/gallery/1/review
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"grade": 5,
|
||
"description": "Excellent gallery with amazing artwork collection!",
|
||
"parent_gr_id": null
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/gallery-reviews/create-gallery-review.bru"
|
||
|
||
cat > "${base_dir}/gallery-reviews/update-gallery-review.bru" << 'EOF'
|
||
meta {
|
||
name: Update Gallery Review
|
||
type: http
|
||
seq: 3
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/galleries/review/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"grade": 4,
|
||
"description": "Updated: Very good gallery with great artwork collection!"
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/gallery-reviews/update-gallery-review.bru"
|
||
|
||
cat > "${base_dir}/gallery-reviews/given-gallery-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Given Gallery Reviews
|
||
type: http
|
||
seq: 4
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/galleries/reviews/given
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/gallery-reviews/given-gallery-reviews.bru"
|
||
|
||
cat > "${base_dir}/gallery-reviews/received-gallery-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Received Gallery Reviews
|
||
type: http
|
||
seq: 5
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/galleries/reviews/received
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/gallery-reviews/received-gallery-reviews.bru"
|
||
|
||
# Artwork review files
|
||
cat > "${base_dir}/artwork-reviews/artwork-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Artwork Reviews
|
||
type: http
|
||
seq: 1
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/artwork/1/reviews
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artwork-reviews/artwork-reviews.bru"
|
||
|
||
cat > "${base_dir}/artwork-reviews/create-artwork-review.bru" << 'EOF'
|
||
meta {
|
||
name: Create Artwork Review
|
||
type: http
|
||
seq: 2
|
||
}
|
||
|
||
post {
|
||
url: {{baseUrl}}/artwork/1/review
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"grade": 5,
|
||
"description": "Absolutely stunning artwork! The colors and technique are magnificent.",
|
||
"parent_ar_id": null
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artwork-reviews/create-artwork-review.bru"
|
||
|
||
cat > "${base_dir}/artwork-reviews/update-artwork-review.bru" << 'EOF'
|
||
meta {
|
||
name: Update Artwork Review
|
||
type: http
|
||
seq: 3
|
||
}
|
||
|
||
put {
|
||
url: {{baseUrl}}/artworks/review/1
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
Content-Type: application/json
|
||
}
|
||
|
||
body:json {
|
||
{
|
||
"grade": 4,
|
||
"description": "Updated: Very beautiful artwork! Great technique and composition."
|
||
}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artwork-reviews/update-artwork-review.bru"
|
||
|
||
cat > "${base_dir}/artwork-reviews/given-artwork-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Given Artwork Reviews
|
||
type: http
|
||
seq: 4
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/artworks/reviews/given
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artwork-reviews/given-artwork-reviews.bru"
|
||
|
||
cat > "${base_dir}/artwork-reviews/received-artwork-reviews.bru" << 'EOF'
|
||
meta {
|
||
name: Get Received Artwork Reviews
|
||
type: http
|
||
seq: 5
|
||
}
|
||
|
||
get {
|
||
url: {{baseUrl}}/artworks/reviews/received
|
||
}
|
||
|
||
headers {
|
||
OIDC_email: {{email}}
|
||
OIDC_user: {{username}}
|
||
}
|
||
EOF
|
||
echo_success "Created: ${base_dir}/artwork-reviews/received-artwork-reviews.bru"
|
||
}
|
||
|
||
# Main function
|
||
main() {
|
||
echo_info "🚀 Generating Bruno API Collection for Private API..."
|
||
echo_info "📁 Collection name: ${COLLECTION_NAME}"
|
||
echo_info "🌐 Base URL: ${BASE_URL}"
|
||
echo_info "👤 Default user: ${DEFAULT_USERNAME} (${DEFAULT_EMAIL})"
|
||
echo ""
|
||
|
||
# Get current directory or use provided path
|
||
local target_dir="${1:-$(pwd)}"
|
||
local base_dir="${target_dir}/${COLLECTION_NAME}"
|
||
|
||
echo_info "📍 Creating collection in: ${base_dir}"
|
||
echo ""
|
||
|
||
# Create directory structure
|
||
create_directories "$base_dir"
|
||
echo ""
|
||
|
||
# Generate all files
|
||
generate_files "$base_dir"
|
||
echo ""
|
||
|
||
echo_success "Bruno collection generated successfully!"
|
||
echo ""
|
||
echo_info "📋 Next steps:"
|
||
echo " 1. Open Bruno and import the collection"
|
||
echo " 2. Select the 'local' environment"
|
||
echo " 3. Update variables in environments/local.bru if needed"
|
||
echo " 4. Start testing with auth/debug-headers.bru"
|
||
echo ""
|
||
echo_info "🔧 To customize:"
|
||
echo " - Edit environments/local.bru to change baseUrl, email, username"
|
||
echo " - Update gallery/artwork IDs in individual requests"
|
||
echo " - Modify request bodies to match your test data"
|
||
echo ""
|
||
echo_warning "💡 Don't forget to update the OIDC headers if your user changes!"
|
||
}
|
||
|
||
# Help function
|
||
show_help() {
|
||
echo "Bruno API Collection Generator"
|
||
echo ""
|
||
echo "Usage: $0 [target_directory]"
|
||
echo ""
|
||
echo "Arguments:"
|
||
echo " target_directory Directory where to create the collection (default: current directory)"
|
||
echo ""
|
||
echo "Examples:"
|
||
echo " $0 # Create in current directory"
|
||
echo " $0 ~/bruno # Create in ~/bruno directory"
|
||
echo " $0 /path/to/bruno # Create in specific path"
|
||
echo ""
|
||
echo "Configuration (edit script to change):"
|
||
echo " Collection name: ${COLLECTION_NAME}"
|
||
echo " Base URL: ${BASE_URL}"
|
||
echo " Default email: ${DEFAULT_EMAIL}"
|
||
echo " Default username: ${DEFAULT_USERNAME}"
|
||
}
|
||
|
||
# Check for help flag
|
||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||
show_help
|
||
exit 0
|
||
fi
|
||
|
||
# Run main function
|
||
main "$@"}
|