api

package
v0.0.0-...-96588ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(db *gorm.DB, jwtSecret string) echo.MiddlewareFunc

func CleanExpiredTokens

func CleanExpiredTokens(db *gorm.DB)

CleanExpiredTokens removes revocation entries whose JWTs have naturally expired. Called periodically to keep the table small.

func CustomErrorHandler

func CustomErrorHandler(err error, c echo.Context)

func GetUserFromContext

func GetUserFromContext(c echo.Context) (userID, email, role string)

func HashToken

func HashToken(token string) string

HashToken returns the SHA-256 hex digest of a raw JWT string.

func IsTokenRevoked

func IsTokenRevoked(db *gorm.DB, token string) bool

IsTokenRevoked checks whether a token has been explicitly revoked.

func NewPublicS3Wrapper

func NewPublicS3Wrapper(s3Proxy http.Handler, db *gorm.DB, s3Client bucketClient) http.Handler

NewPublicS3Wrapper wraps the existing S3 proxy to serve objects from public buckets without authentication. Unauthenticated GET/HEAD requests for public buckets are served directly via the minio client. All other requests (or requests for non-public buckets) pass through to the underlying S3 proxy.

func NewS3Proxy

func NewS3Proxy(s3Endpoint string, requireSigV4 bool) http.Handler

NewS3Proxy creates a reverse proxy that forwards requests to the SeaweedFS S3 endpoint. When requireSigV4 is true, unsigned requests are rejected before proxying.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, db *gorm.DB, cfg *config.Config, store *storage.Manager, serverVersion string, workerEngine *worker.Engine, s3Client *minio.Client, presignClient *minio.Client, iamClient *seaweedfs.Client, region string)

func RequireAdmin

func RequireAdmin() echo.MiddlewareFunc

func RequireRole

func RequireRole(roles ...string) echo.MiddlewareFunc

func RequireSiteOwner

func RequireSiteOwner(db *gorm.DB) echo.MiddlewareFunc

RequireSiteOwner checks that the authenticated user owns the site identified by the :id path parameter, or has an admin/superadmin role.

func RevokeToken

func RevokeToken(db *gorm.DB, token string, expiresAt time.Time) error

RevokeToken adds a token to the revocation table. The expiresAt should match the token's natural expiry so the entry can be cleaned up later.

func SubdomainRouter

func SubdomainRouter(db *gorm.DB, store *storage.Manager, cache *storage.SiteRulesCache, domain string, workerEngine *worker.Engine, s3Proxy http.Handler) echo.MiddlewareFunc

SubdomainRouter inspects the Host header and routes subdomain requests to the static site handler. Bare-domain requests pass through to the API.

func VersionCheckMiddleware

func VersionCheckMiddleware(minVersion string) echo.MiddlewareFunc

VersionCheckMiddleware rejects requests from CLI clients whose version is below the configured minimum. Skips if no minimum is set, if the header is absent (browser/curl), or if the version is unparseable (dev builds).

Types

type APIKeyHandler

type APIKeyHandler struct {
	DB *gorm.DB
}

func (*APIKeyHandler) Create

func (h *APIKeyHandler) Create(c echo.Context) error

func (*APIKeyHandler) Delete

func (h *APIKeyHandler) Delete(c echo.Context) error

func (*APIKeyHandler) List

func (h *APIKeyHandler) List(c echo.Context) error

type AdminHandler

type AdminHandler struct {
	DB        *gorm.DB
	Storage   *storage.Manager
	S3Client  *minio.Client     // optional; nil when object storage is disabled
	IAMClient *seaweedfs.Client // optional; nil when object storage is disabled
}

func (*AdminHandler) CreateInvite

func (h *AdminHandler) CreateInvite(c echo.Context) error

func (*AdminHandler) DeleteUser

func (h *AdminHandler) DeleteUser(c echo.Context) error

func (*AdminHandler) GetSettings

func (h *AdminHandler) GetSettings(c echo.Context) error

func (*AdminHandler) ListInvites

func (h *AdminHandler) ListInvites(c echo.Context) error

func (*AdminHandler) ListUsers

func (h *AdminHandler) ListUsers(c echo.Context) error

func (*AdminHandler) RevokeInvite

func (h *AdminHandler) RevokeInvite(c echo.Context) error

func (*AdminHandler) UpdateSettings

func (h *AdminHandler) UpdateSettings(c echo.Context) error

func (*AdminHandler) UpdateUserRole

func (h *AdminHandler) UpdateUserRole(c echo.Context) error

type AuthHandler

type AuthHandler struct {
	DB        *gorm.DB
	JWTSecret string
}

func (*AuthHandler) CLILogin

func (h *AuthHandler) CLILogin(c echo.Context) error

CLILogin serves a self-contained HTML login form for CLI authentication. GET /api/v1/auth/cli?port=PORT&state=STATE&code_challenge=CHALLENGE&code_challenge_method=S256

func (*AuthHandler) CLILoginSubmit

func (h *AuthHandler) CLILoginSubmit(c echo.Context) error

CLILoginSubmit validates credentials and returns a redirect URL with an auth code. POST /api/v1/auth/cli

func (*AuthHandler) Login

func (h *AuthHandler) Login(c echo.Context) error

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(c echo.Context) error

func (*AuthHandler) Register

func (h *AuthHandler) Register(c echo.Context) error

func (*AuthHandler) TokenExchange

func (h *AuthHandler) TokenExchange(c echo.Context) error

TokenExchange exchanges an authorization code + PKCE code verifier for a JWT. POST /api/v1/auth/token

type DeployHandler

type DeployHandler struct {
	DB              *gorm.DB
	Storage         *storage.Manager
	MaxScriptSizeKB int
	WorkerEngine    interface {
		CompileAndCache(siteID string, deployKey string, source string) ([]byte, error)
		InvalidatePool(siteID string, deployKey string)
	}
}

func (*DeployHandler) Deploy

func (h *DeployHandler) Deploy(c echo.Context) error

func (*DeployHandler) List

func (h *DeployHandler) List(c echo.Context) error

func (*DeployHandler) Rollback

func (h *DeployHandler) Rollback(c echo.Context) error

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type SiteHandler

type SiteHandler struct {
	DB        *gorm.DB
	Storage   *storage.Manager
	S3Client  *minio.Client     // optional; nil when object storage is disabled
	IAMClient *seaweedfs.Client // optional; nil when object storage is disabled
}

func (*SiteHandler) Create

func (h *SiteHandler) Create(c echo.Context) error

func (*SiteHandler) Delete

func (h *SiteHandler) Delete(c echo.Context) error

func (*SiteHandler) Get

func (h *SiteHandler) Get(c echo.Context) error

func (*SiteHandler) List

func (h *SiteHandler) List(c echo.Context) error

func (*SiteHandler) Update

func (h *SiteHandler) Update(c echo.Context) error

type StorageHandler

type StorageHandler struct {
	DB            *gorm.DB
	S3Client      bucketClient
	PresignClient bucketClient // minio client configured with public S3 endpoint for presigned URL generation
	IAMClient     iamClient
	Region        string
	PublicS3URL   string // public-facing S3 URL for presigned URLs (e.g. https://storage.example.com)
}

StorageHandler manages object storage buckets and S3 credentials.

func (*StorageHandler) CreateBucket

func (h *StorageHandler) CreateBucket(c echo.Context) error

CreateBucket creates a storage bucket bound to a site.

func (*StorageHandler) CreateS3Credential

func (h *StorageHandler) CreateS3Credential(c echo.Context) error

CreateS3Credential creates an S3 credential for the current user.

func (*StorageHandler) DeleteBucket

func (h *StorageHandler) DeleteBucket(c echo.Context) error

DeleteBucket deletes a storage bucket.

func (*StorageHandler) DeleteS3Credential

func (h *StorageHandler) DeleteS3Credential(c echo.Context) error

DeleteS3Credential deletes an S3 credential.

func (*StorageHandler) ListBuckets

func (h *StorageHandler) ListBuckets(c echo.Context) error

ListBuckets returns all storage buckets for a site.

func (*StorageHandler) ListS3Credentials

func (h *StorageHandler) ListS3Credentials(c echo.Context) error

ListS3Credentials returns the user's S3 credentials (no secrets).

func (*StorageHandler) UpdateBucket

func (h *StorageHandler) UpdateBucket(c echo.Context) error

UpdateBucket updates a storage bucket's settings (e.g. public access toggle).

func (*StorageHandler) UploadURL

func (h *StorageHandler) UploadURL(c echo.Context) error

UploadURL generates a presigned PUT URL for uploading an object to a bucket.

type WorkerHandler

type WorkerHandler struct {
	DB *gorm.DB
}

func (*WorkerHandler) CreateCronSchedule

func (h *WorkerHandler) CreateCronSchedule(c echo.Context) error

func (*WorkerHandler) CreateD1Database

func (h *WorkerHandler) CreateD1Database(c echo.Context) error

func (*WorkerHandler) CreateDurableObjectNamespace

func (h *WorkerHandler) CreateDurableObjectNamespace(c echo.Context) error

func (*WorkerHandler) CreateKVNamespace

func (h *WorkerHandler) CreateKVNamespace(c echo.Context) error

func (*WorkerHandler) DeleteCronSchedule

func (h *WorkerHandler) DeleteCronSchedule(c echo.Context) error

func (*WorkerHandler) DeleteD1Database

func (h *WorkerHandler) DeleteD1Database(c echo.Context) error

func (*WorkerHandler) DeleteDurableObjectNamespace

func (h *WorkerHandler) DeleteDurableObjectNamespace(c echo.Context) error

func (*WorkerHandler) DeleteEnvVar

func (h *WorkerHandler) DeleteEnvVar(c echo.Context) error

func (*WorkerHandler) DeleteKVNamespace

func (h *WorkerHandler) DeleteKVNamespace(c echo.Context) error

func (*WorkerHandler) GetLogs

func (h *WorkerHandler) GetLogs(c echo.Context) error

func (*WorkerHandler) ListCronSchedules

func (h *WorkerHandler) ListCronSchedules(c echo.Context) error

func (*WorkerHandler) ListD1Databases

func (h *WorkerHandler) ListD1Databases(c echo.Context) error

func (*WorkerHandler) ListDurableObjectNamespaces

func (h *WorkerHandler) ListDurableObjectNamespaces(c echo.Context) error

func (*WorkerHandler) ListEnvVars

func (h *WorkerHandler) ListEnvVars(c echo.Context) error

func (*WorkerHandler) ListKVNamespaces

func (h *WorkerHandler) ListKVNamespaces(c echo.Context) error

func (*WorkerHandler) SetEnvVar

func (h *WorkerHandler) SetEnvVar(c echo.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL