limit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package limit — use-cases of InternalLimitService: the lifecycle of a resource-count ceiling, plus the two reads owner-services live on.

Clean Architecture: this package defines the narrow ports below and depends on nothing but domain + the corelib operation envelope. The concrete adapter (pgx) lives in internal/repo and is wired in cmd/kaname/wiring.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangedResult

type ChangedResult struct {
	Changes    []domain.Limit
	NextCursor string
}

ChangedResult — the delta page plus the cursor to pass next time.

type CreateUseCase

type CreateUseCase struct {
	// contains filtered or unexported fields
}

CreateUseCase — states a ceiling for one triple.

func NewCreateUseCase

func NewCreateUseCase(r limitRepo, ops operations.Repo, logger *slog.Logger) *CreateUseCase

NewCreateUseCase — constructor.

func (*CreateUseCase) Execute

Execute — validate → persist Operation → insert.

The Operation row is persisted BEFORE the write, so the id the caller receives is always pollable; a failure is recorded on it as a terminal error rather than leaving the caller polling a row that does not exist.

type DeleteUseCase

type DeleteUseCase struct {
	// contains filtered or unexported fields
}

DeleteUseCase — withdraws a ceiling.

func NewDeleteUseCase

func NewDeleteUseCase(r limitRepo, ops operations.Repo, logger *slog.Logger) *DeleteUseCase

NewDeleteUseCase — constructor.

func (*DeleteUseCase) Execute

func (uc *DeleteUseCase) Execute(ctx context.Context, id string) (*operationpb.Operation, error)

Execute — idempotent by construction: withdrawing an already-withdrawn ceiling succeeds and reports the same code as the first withdrawal, because the caller asked for the ceiling to be gone and it is.

type GetUseCase

type GetUseCase struct {
	// contains filtered or unexported fields
}

GetUseCase — sync read of one limit.

func NewGetUseCase

func NewGetUseCase(r limitRepo) *GetUseCase

NewGetUseCase — constructor.

func (*GetUseCase) Execute

func (uc *GetUseCase) Execute(ctx context.Context, id string) (domain.Limit, error)

Execute — direct-read lane: a well-formed id with no row is NOT_FOUND.

type Handler

type Handler struct {
	iamv1.UnimplementedInternalLimitServiceServer
	// contains filtered or unexported fields
}

Handler implements iamv1.InternalLimitServiceServer.

func NewHandler

NewHandler assembles the Handler. Composition root: cmd/kaname/wiring.go.

func (*Handler) Create

Create — async; returns the Operation envelope.

func (*Handler) Delete

Delete — async; returns the Operation envelope.

func (*Handler) Get

func (h *Handler) Get(ctx context.Context, req *iamv1.GetLimitRequest) (*iamv1.Limit, error)

Get — sync read of one limit.

func (*Handler) List

List — sync cursor-paginated read.

func (*Handler) ListChangedSince

ListChangedSince — sync read of the delta after the caller's cursor.

func (*Handler) Resolve

Resolve — sync read of the ceilings in force for one scope object.

func (*Handler) Update

Update — async; returns the Operation envelope.

type ListChangedUseCase

type ListChangedUseCase struct {
	// contains filtered or unexported fields
}

ListChangedUseCase — the delta an owner pulls to keep its projection fresh.

func NewListChangedUseCase

func NewListChangedUseCase(r limitRepo, c deltaCursorCodec) *ListChangedUseCase

NewListChangedUseCase — constructor.

func (*ListChangedUseCase) Execute

func (uc *ListChangedUseCase) Execute(ctx context.Context, cursor string, pageSize int64) (ChangedResult, error)

Execute — narrow gate, cursor format, then the page.

The next cursor is returned even when the page is empty: a puller that only advanced on non-empty pages would re-scan the same tail forever once it caught up.

func (*ListChangedUseCase) WithLogger

func (uc *ListChangedUseCase) WithLogger(l *slog.Logger) *ListChangedUseCase

WithLogger заменяет журнал по умолчанию. Пустой не принимается.

func (*ListChangedUseCase) WithQuotaReaderChecker

func (uc *ListChangedUseCase) WithQuotaReaderChecker(c authzguard.RelationChecker) *ListChangedUseCase

WithQuotaReaderChecker wires the narrow ReBAC gate. nil-safe, fail-closed.

type ListResult

type ListResult struct {
	Limits        []domain.Limit
	NextPageToken string
}

ListResult — one page plus the cursor for the next.

type ListUseCase

type ListUseCase struct {
	// contains filtered or unexported fields
}

ListUseCase — sync cursor-paginated read.

func NewListUseCase

func NewListUseCase(r limitRepo) *ListUseCase

NewListUseCase — constructor.

func (*ListUseCase) Execute

func (uc *ListUseCase) Execute(
	ctx context.Context, pageSize int64, pageToken string, f domain.LimitFilter,
) (ListResult, error)

Execute — pagination format is validated FIRST, so a garbage token or an out-of-range page size is INVALID_ARGUMENT independently of what the caller holds and of what the store contains. `page_size` out of range is REJECTED, never clamped.

type PublicHandler

type PublicHandler struct {
	iamv1.UnimplementedLimitServiceServer
	// contains filtered or unexported fields
}

PublicHandler — реализация `iamv1.LimitServiceServer`: та же административная поверхность пределов на ПУБЛИЧНОМ слушателе, под правом `system_admin` @ `cluster` (ADM-1 S1, #878).

Почему поверхность вообще переезжает

Величины назначает администратор облака, и назначает он их через край. Объявленные только внутренним сервисом, глаголы наружу не выходили, и страница пределов консоли получала **404** — отказ, неотличимый от «такого раздела нет вовсе». Сервис при этом был исправен: класс жил целиком на крае, и ни одна проба сервиса не видела его by construction.

Тонкий транспорт, и «тонкий» здесь проверяемо

Ни одной строки собственной логики: composition root передаёт сюда указатель на УЖЕ СОБРАННЫЙ внутренний handler — не копию его зависимостей, а его самого, — поэтому «оба пути делают одно» держится построением, а не совпадением сборки. Заведи мы здесь свои вызовы use-case'ов, два пути разошлись бы на первой же правке одного из них, и разошлись бы молча.

Что переезд НЕ меняет

Решение о доступе. Обе записи каталога требуют `system_admin` @ `cluster` при одном и том же подтверждении личности; согласие двух записей держит проба `TestLimits_AdminSurfaceIsReachableFromOutside` тем же предикатом, каким гейт общей пары стережёт пул адресов. Публикация адреса не расширяет круг — она делает отказ ЧЕСТНЫМ: 403 вместо 404, «нет права» вместо «нет продукта».

Чего здесь нет

`Resolve` и `ListChangedSince` — сервисная поверхность под узким `quota_reader`, её зовут владельцы типов, а не человек. Они остаются внутренними: публиковать их значило бы расширить поверхность ради предмета, которого у арендатора нет.

func NewPublicHandler

func NewPublicHandler(admin *Handler) *PublicHandler

NewPublicHandler собирает публичный транспорт поверх уже собранного внутреннего handler'а.

func (*PublicHandler) Create

func (*PublicHandler) Delete

func (*PublicHandler) Get

func (*PublicHandler) List

func (*PublicHandler) Update

type ResolveUseCase

type ResolveUseCase struct {
	// contains filtered or unexported fields
}

ResolveUseCase — the ceilings in force for one scope object, per kind of one service. Read by owner services; gated by the narrow relation.

func NewResolveUseCase

func NewResolveUseCase(r limitRepo) *ResolveUseCase

NewResolveUseCase — constructor.

func (*ResolveUseCase) Execute

func (uc *ResolveUseCase) Execute(ctx context.Context, scopeID, service string) ([]domain.EffectiveLimit, error)

Execute — narrow gate, then one read of the whole stated set, then precedence.

func (*ResolveUseCase) WithLogger

func (uc *ResolveUseCase) WithLogger(l *slog.Logger) *ResolveUseCase

WithLogger заменяет журнал по умолчанию. Пустой не принимается: молчание — не настройка, а потеря причины.

func (*ResolveUseCase) WithQuotaReaderChecker

func (uc *ResolveUseCase) WithQuotaReaderChecker(c authzguard.RelationChecker) *ResolveUseCase

WithQuotaReaderChecker wires the narrow ReBAC gate (defense-in-depth behind the edge's catalog entry). nil-safe: an unwired checker fails CLOSED — an unauthorised read of the platform's ceilings is not a lesser failure than an unauthorised write.

type UpdateUseCase

type UpdateUseCase struct {
	// contains filtered or unexported fields
}

UpdateUseCase — changes the ceiling.

func NewUpdateUseCase

func NewUpdateUseCase(r limitRepo, ops operations.Repo, logger *slog.Logger) *UpdateUseCase

NewUpdateUseCase — constructor.

func (*UpdateUseCase) Execute

Execute — mask discipline, then the write.

Jump to

Keyboard shortcuts

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