catalog

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package catalog owns catalog persistence and relation validation.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("revision conflict")
View Source
var ErrInvalid = errors.New("invalid change")
View Source
var ErrSecret = secrets.ErrSecret

Functions

func CheckSecrets

func CheckSecrets(v any) error

func EditableFields added in v0.3.0

func EditableFields(typ string) []string

EditableFields returns a copy of the business fields accepted for this type.

func ValidHTTPURL added in v0.3.0

func ValidHTTPURL(value string) bool

ValidHTTPURL 也用于导入直写数据表之前的校验。

Types

type AssetDetail added in v0.4.0

type AssetDetail struct {
	Object       Object   `json:"object"`
	Notes        []Object `json:"notes"`
	Credentials  []Object `json:"credentials"`
	Changes      []Object `json:"changes"`
	ReferencedBy []Object `json:"referenced_by"`
}

AssetDetail 汇总详情页需要的关联数据;凭据仅含管理器引用。

type ConflictError added in v0.3.0

type ConflictError struct {
	Fields []FieldError `json:"fields"`
}

func (*ConflictError) Error added in v0.3.0

func (e *ConflictError) Error() string

func (*ConflictError) Is added in v0.3.0

func (e *ConflictError) Is(target error) bool

type FieldError added in v0.3.0

type FieldError struct {
	Field      string   `json:"field"`
	Reason     string   `json:"reason"`
	Expected   string   `json:"expected,omitempty"`
	References []string `json:"references,omitempty"`
}

FieldError 描述被拒绝的字段,不保存提交的值。

type Object

type Object struct {
	ID         string         `json:"id"`
	Type       string         `json:"type"`
	Name       string         `json:"name"`
	Aliases    []string       `json:"aliases"`
	Tags       []string       `json:"tags"`
	Status     string         `json:"status"`
	Source     string         `json:"source"`
	Confidence string         `json:"confidence"`
	VerifiedAt *time.Time     `json:"verified_at,omitempty"`
	VerifiedBy string         `json:"verified_by,omitempty"`
	Rev        int64          `json:"rev"`
	CreatedAt  time.Time      `json:"created_at"`
	CreatedBy  string         `json:"created_by"`
	UpdatedAt  time.Time      `json:"updated_at"`
	UpdatedBy  string         `json:"updated_by"`
	Fields     map[string]any `json:"fields"`
}

type OfflineOptions added in v0.3.0

type OfflineOptions struct {
	Services  bool `json:"services"`
	IPs       bool `json:"ips"`
	Endpoints bool `json:"endpoints"`
}

type OfflinePreview added in v0.3.0

type OfflinePreview struct {
	Host      Object   `json:"host"`
	Services  []Object `json:"services"`
	IPs       []Object `json:"ips"`
	Endpoints []Object `json:"endpoints"`
}

type Patch

type Patch struct {
	Name       *string        `json:"name,omitempty"`
	Aliases    *[]string      `json:"aliases,omitempty"`
	Tags       *[]string      `json:"tags,omitempty"`
	Status     *string        `json:"status,omitempty"`
	Source     *string        `json:"source,omitempty"`
	Confidence *string        `json:"confidence,omitempty"`
	Fields     map[string]any `json:"fields,omitempty"`
}

type Query

type Query struct{ Service Service }

Query 将所有传输入口的读取请求收敛到同一个授权边界。

func (Query) AssetDetail added in v0.4.0

func (q Query) AssetDetail(ctx context.Context, p auth.Principal, id string) (AssetDetail, error)

func (Query) Browse

func (q Query) Browse(ctx context.Context, p auth.Principal, typ string) ([]Object, error)

func (Query) Changes

func (q Query) Changes(ctx context.Context, p auth.Principal, objectID, state string) ([]Object, error)

func (Query) CheckVersions

func (q Query) CheckVersions(ctx context.Context, p auth.Principal) (versioncheck.Summary, error)

func (Query) Contexts

func (q Query) Contexts(ctx context.Context, p auth.Principal, archived bool) ([]Object, error)

func (Query) FilterChanges added in v0.4.0

func (q Query) FilterChanges(ctx context.Context, p auth.Principal, objectID, state, key, objectType, since, until string) ([]Object, error)

func (Query) Inventory

func (q Query) Inventory(ctx context.Context, p auth.Principal, typ, id string) (search.Inventory, error)

func (Query) Outdated

func (q Query) Outdated(ctx context.Context, p auth.Principal) ([]Object, error)

func (Query) Search

func (q Query) Search(ctx context.Context, p auth.Principal, term string) ([]search.Result, error)

func (Query) ServiceDetail

func (q Query) ServiceDetail(ctx context.Context, p auth.Principal, idOrName string) (ServiceDetail, error)

func (Query) Site

func (q Query) Site(ctx context.Context, p auth.Principal, id string) (search.Site, error)

func (Query) Topology

func (q Query) Topology(ctx context.Context, p auth.Principal, id string, depth int) (search.Topology, error)

func (Query) TopologyView added in v0.4.0

func (q Query) TopologyView(ctx context.Context, p auth.Principal, id string, depth int, view string) (search.Topology, error)

func (Query) Unverified

func (q Query) Unverified(ctx context.Context, p auth.Principal) ([]Object, error)

type RestoreResult added in v0.3.0

type RestoreResult struct {
	Restored []string `json:"restored"`
	Skipped  []string `json:"skipped"`
}

type Service

type Service struct{ Store Store }

func (Service) AssertNoSecret

func (s Service) AssertNoSecret(v any) error

func (Service) CheckVersionsAllowed

func (s Service) CheckVersionsAllowed(p auth.Principal) error

func (Service) CreateAsset

func (s Service) CreateAsset(ctx context.Context, p auth.Principal, o Object, baseRev int64, reason, via string) (Object, error)

CreateAsset accepts a new object at base revision zero and audits its creation.

func (Service) CreateContext

func (s Service) CreateContext(ctx context.Context, p auth.Principal, o Object, reason, via string) (Object, error)

func (Service) DeleteAllowed

func (s Service) DeleteAllowed(p auth.Principal) error

func (Service) DeleteAsset added in v0.3.0

func (s Service) DeleteAsset(ctx context.Context, p auth.Principal, id string, rev int64, reason string) error

DeleteAsset is reserved for a signed-in web user. Referenced objects are reported before deletion.

func (Service) Get

func (s Service) Get(ctx context.Context, p auth.Principal, id string) (Object, error)

func (Service) LatestOfflineOperation added in v0.3.0

func (s Service) LatestOfflineOperation(ctx context.Context, p auth.Principal, hostID string) (string, error)

func (Service) MarkVerified

func (s Service) MarkVerified(ctx context.Context, p auth.Principal, id string, rev int64, reason, via string) (Object, error)

func (Service) OfflineHost added in v0.3.0

func (s Service) OfflineHost(ctx context.Context, p auth.Principal, id string, rev int64, opts OfflineOptions, reason string) (string, error)

OfflineHost changes selected objects atomically and keeps their prior state for a guarded restore.

func (Service) OfflinePreview added in v0.3.0

func (s Service) OfflinePreview(ctx context.Context, p auth.Principal, hostID string) (OfflinePreview, error)

func (Service) Propose

func (s Service) Propose(ctx context.Context, p auth.Principal, id string, rev int64, patch Patch, reason, via string) (string, error)

Propose records an immutable review request; approval rechecks its base revision.

func (Service) ProposeCreate added in v0.3.0

func (s Service) ProposeCreate(ctx context.Context, p auth.Principal, o Object, baseRev int64, reason, via string) (string, error)

ProposeCreate 先校验候选对象;审批时在落库事务中再次校验。

func (Service) ProposeDelete

func (s Service) ProposeDelete(ctx context.Context, p auth.Principal, id string, rev int64, reason, via string) (string, error)

func (Service) PutContext

func (s Service) PutContext(ctx context.Context, p auth.Principal, id string, rev int64, body string, expires time.Time, reason, via string) error

PutContext only permits keys to create or renew their own records.

func (Service) RecordNote

func (s Service) RecordNote(ctx context.Context, p auth.Principal, target string, rev int64, kind, body, reason, via string) (string, error)

func (Service) RestoreHost added in v0.3.0

func (s Service) RestoreHost(ctx context.Context, p auth.Principal, hostID, opID, reason string) (RestoreResult, error)

func (Service) Review

func (s Service) Review(ctx context.Context, p auth.Principal, changeID string, approve bool) (Object, error)

func (Service) Update

func (s Service) Update(ctx context.Context, p auth.Principal, id string, rev int64, patch Patch, reason, via string) (Object, error)

Update applies a typed patch with a mandatory revision and audit row in one transaction.

func (Service) VerifyBatch added in v0.3.0

func (s Service) VerifyBatch(ctx context.Context, p auth.Principal, ids []string, withRelated bool, reason, via string) ([]VerifyResult, error)

VerifyBatch 保留逐对象审计,且逐条返回结果,避免把部分成功误报为全部成功。

type ServiceDetail

type ServiceDetail struct {
	Object       Object   `json:"service"`
	Host         Object   `json:"host"`
	IPs          []Object `json:"ips"`
	Ports        []Object `json:"ports"`
	Endpoints    []Object `json:"endpoints"`
	Versions     []Object `json:"versions"`
	Dependencies []Object `json:"dependencies"`
	Credentials  []Object `json:"credentials"`
	Notes        []Object `json:"notes"`
	Changes      []Object `json:"changes"`
}

type Store

type Store struct{ DB *sql.DB }

func (Store) ArchiveExpired

func (s Store) ArchiveExpired(ctx context.Context, now time.Time) (int64, error)

ArchiveExpired keeps context rows but hides them from active queries.

func (Store) Contexts

func (s Store) Contexts(ctx context.Context, archived bool, now time.Time) ([]Object, error)

func (Store) Create

func (s Store) Create(ctx context.Context, o Object, actor string) (Object, error)

Create validates and inserts an object atomically. Actor is supplied by the caller's auth layer.

func (Store) Get

func (s Store) Get(ctx context.Context, id string) (Object, error)

Get loads public fields and all type-specific fields.

func (Store) Unverified

func (s Store) Unverified(ctx context.Context, now time.Time) ([]string, error)

type ValidationError added in v0.3.0

type ValidationError struct {
	Fields []FieldError `json:"fields"`
	// contains filtered or unexported fields
}

func (*ValidationError) Error added in v0.3.0

func (e *ValidationError) Error() string

func (*ValidationError) Is added in v0.3.0

func (e *ValidationError) Is(target error) bool

type VerifyResult added in v0.3.0

type VerifyResult struct {
	ID    string `json:"id"`
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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