Skip to content

Commit

Permalink
🔧 feat: update configuration defaults and add environment variables s…
Browse files Browse the repository at this point in the history
…upport

The commit message is too long to fit in a single line, so I'll split it into subject and body:

🔧 feat: update security and performance defaults in configuration

• Reduce max upload size from 50MB to 5MB for better resource management
• Lower rate limit from 60 to 10 requests per minute
• Add environment variables support with 0X prefix
• Update SMTP configuration documentation for PostPilot integration
  • Loading branch information
watzon committed Nov 12, 2024
1 parent c90bc45 commit 289da1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ server:
# Public-facing URL (used for generating links)
base_url: http://localhost:3000

# Maximum upload size in bytes (default: 50MB)
max_upload_size: 52428800 # 50 * 1024 * 1024
# Maximum upload size in bytes (default: 5MB)
max_upload_size: 5242880 # 5 * 1024 * 1024

# Rate limiting configuration
rate_limit:
enabled: true
requests: 60 # Number of requests
requests: 10 # Number of requests
duration: 60 # Time window in seconds

# Security settings
Expand All @@ -68,7 +68,7 @@ server:
interval: 3600 # Cleanup interval in seconds
max_age: 168h # Maximum age for temporary pastes (7 days)

# SMTP configuration for sending emails
# SMTP configuration for sending emails with PostPilot
smtp:
enabled: true # Set to true to enable email features
host: localhost
Expand Down
8 changes: 7 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"strings"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -64,7 +65,7 @@ func Load() (*Config, error) {
viper.SetDefault("storage.type", "local")
viper.SetDefault("storage.path", "./uploads")
viper.SetDefault("server.address", ":3000")
viper.SetDefault("server.max_upload_size", 50*1024*1024) // 50MB default
viper.SetDefault("server.max_upload_size", 5*1024*1024) // 5MB default
viper.SetDefault("server.cleanup.enabled", true)
viper.SetDefault("server.cleanup.interval", 3600)
viper.SetDefault("server.cleanup.max_age", "168h")
Expand All @@ -76,6 +77,11 @@ func Load() (*Config, error) {
viper.SetDefault("smtp.tls_verify", true)
viper.SetDefault("smtp.from_name", "Paste69")

// Enable environment variables
viper.AutomaticEnv()
viper.SetEnvPrefix("0X")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // Converts nested keys to env format

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return nil, fmt.Errorf("error reading config file: %w", err)
Expand Down

0 comments on commit 289da1d

Please sign in to comment.