Documentation ¶
Index ¶
- Constants
- Variables
- func RateLimiter(next http.Handler) http.Handler
- func RequestLogger(next http.Handler) http.Handler
- func RequestSizeLimiter(next http.Handler) http.Handler
- func SecurityHeaders(next http.Handler) http.Handler
- func ShutdownRateLimiter()
- func ValidateFilePath(path string) error
- type AuthResult
- type Authenticator
- type AuthenticatorInterface
- type S3Client
- type S3Interface
- type Server
- type WebDAVHandler
Constants ¶
const ( MaxFileSize = 100 * 1024 * 1024 // 100MB MaxRequestSize = 110 * 1024 * 1024 // 110MB to account for multipart form data RateLimitRequests = 100 // requests per minute // Time to keep IP rate limiters in memory RateLimitWindow = 1 * time.Hour )
const ( DefaultAddr = ":80" DefaultReadTimeout = 30 * time.Second DefaultWriteTimeout = 30 * time.Second DefaultIdleTimeout = 120 * time.Second ShutdownTimeout = 30 * time.Second )
Server configuration constants
Variables ¶
var ( ErrInvalidCredentials = errors.New("invalid credentials") ErrAuthFailed = errors.New("authentication failed") )
Common errors
var ( AllowedFileExtensions = []string{ ".txt", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".jpg", ".jpeg", ".png", ".gif", ".zip", ".csv", } DisallowedPaths = []string{ "..", "//", "\\", "%2e", "%2f", } )
var ( ErrEmptyBucket = fmt.Errorf("bucket name cannot be empty") ErrEmptyUserID = fmt.Errorf("userID cannot be empty") ErrEmptyFilename = fmt.Errorf("filename cannot be empty") ErrNilContent = fmt.Errorf("content cannot be nil") ErrNilContext = fmt.Errorf("context cannot be nil") )
Common errors
var (
ErrInvalidFilename = fmt.Errorf("invalid filename")
)
Common errors
var (
ErrMissingEnvVar = errors.New("required environment variable not set")
)
Common errors
var RequiredEnvVars = []string{
"AUTH_API_URL",
"S3_BUCKET",
}
RequiredEnvVars lists the environment variables that must be set
Functions ¶
func RateLimiter ¶
RateLimiter implements a per-IP rate limiting middleware
func RequestLogger ¶
RequestLogger logs all incoming requests
func RequestSizeLimiter ¶
RequestSizeLimiter limits the size of incoming requests
func SecurityHeaders ¶
SecurityHeaders adds security-related HTTP headers to the response
func ShutdownRateLimiter ¶
func ShutdownRateLimiter()
ShutdownRateLimiter gracefully shuts down the rate limiter
func ValidateFilePath ¶
ValidateFilePath checks if the file path is safe and allowed
Types ¶
type AuthResult ¶
AuthResult represents the result of an authentication attempt
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator handles user authentication against an external API
func NewAuthenticator ¶
func NewAuthenticator() *Authenticator
NewAuthenticator creates a new authenticator with the configured auth URL
func (*Authenticator) Authenticate ¶
func (a *Authenticator) Authenticate(ctx context.Context, username, password string) (AuthResult, error)
Authenticate validates user credentials against the authentication API. It returns an AuthResult containing the authentication status and user details. If authentication fails, it returns an appropriate error.
type AuthenticatorInterface ¶
type AuthenticatorInterface interface {
Authenticate(ctx context.Context, username, password string) (AuthResult, error)
}
Authenticator defines the interface for authentication operations
type S3Client ¶
type S3Client struct {
// contains filtered or unexported fields
}
S3Client handles S3 operations
func NewS3Client ¶
NewS3Client creates a new S3 client with the provided bucket
type S3Interface ¶
type S3Interface interface {
UploadFile(ctx context.Context, userID string, filename string, content io.Reader) error
}
S3Interface defines the interface for S3 operations
type Server ¶
type Server struct { Addr string ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration Handler http.Handler }
Server represents the WebDAV server configuration
func NewServer ¶
NewServer creates a new WebDAV server with default configuration. It loads environment variables and initializes all required components.
func (*Server) ListenAndServe ¶
ListenAndServe starts the WebDAV server with graceful shutdown support
type WebDAVHandler ¶
type WebDAVHandler struct {
// contains filtered or unexported fields
}
WebDAVHandler handles WebDAV requests, supporting only PUT operations for file uploads to S3 storage.
func NewWebDAVHandler ¶
func NewWebDAVHandler(authenticator AuthenticatorInterface, s3Client S3Interface) *WebDAVHandler
NewWebDAVHandler creates a new WebDAV handler with the given authenticator and S3 client. The handler only supports PUT operations, all other operations return 405 Method Not Allowed.
func (*WebDAVHandler) ServeHTTP ¶
func (h *WebDAVHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface. It handles authentication and routes PUT requests to handlePut.