drivepolicy

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package drivepolicy exposes the effective Drive upload policy over an authenticated internal HTTP surface for the octo-drive backend (②).

octo-server is the configuration single source of truth for the Drive upload limit and the chunked-upload parameters; octo-drive polls GET /v1/internal/drive/upload-policy (≤60s cache) to learn the effective policy so its server-side gate stays in lockstep with what the clients were told via appconfig. This module owns only that one endpoint and its enablement gate; the byte-level upload enforcement lives entirely in ②.

The endpoint reuses OCTO_DRIVE_INTERNAL_TOKEN (the same peer already presents it inbound on modules/internal_resolve) and is gated fail-closed + constant- time via internalAuthMiddleware; see Route for the middleware-order contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	log.Log
	// contains filtered or unexported fields
}

Module is the module handle registered with the wkhttp router. Field layout matches the octo-server convention (see modules/internal_resolve/api.go:48).

func New

func New(ctx *config.Context) *Module

New loads OCTO_DRIVE_INTERNAL_TOKEN at construction. When it is unset, too short, or collides with a sibling fixed internal-token env, the reason is logged and every request is refused (fail-closed via internalAuthMiddleware). The module still mounts, so a misconfigured deployment fails closed on the endpoint rather than failing to boot the whole server — the same posture modules/internal_resolve and modules/internal_membership take.

ctx is retained so Route can construct the rate-limit Redis client the same way modules/internal_resolve does, without threading extra plumbing.

func (*Module) Route

func (m *Module) Route(r *wkhttp.WKHttp)

Route mounts the internal drive upload-policy endpoint under /v1/internal, gated by X-Internal-Token.

Middleware EXECUTION ORDER on this route (matters):

  1. per-endpoint IP strict rate limit — MUST run FIRST so IP-abusive traffic never reaches the token compare (a Redis Lua round trip) or the DB path.
  2. internalAuthMiddleware — X-Internal-Token constant-time compare + fail-closed on unset.

Both middlewares are mounted on the CONCRETE GET route, NOT the group. Gin runs group handlers ahead of route handlers, so auth-on-group + limiter-on- route would execute as auth → limiter: a missing / wrong token would abort before ever consuming the strict-IP bucket, and token-probing traffic would fall back to the wider global bucket. modules/internal_resolve and modules/internal_membership document having been bitten by exactly this ordering; route_runtime_order_test.go pins the observed order here too.

Jump to

Keyboard shortcuts

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