native

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package native implements the platform package's routes in the package itself: the backup list and statistics on the kernel's v2_backup_record table adopted in place (kernel.storage.adopt), the system audit log through the kapi_system_audit_log_v1 kernel view, and the backup configuration, read and updated through the kernel's KernelSettings contract (namespace backup, kernel.settings.backup.read.v1 and kernel.settings.backup.write.v1). Legacy handlers and native routes share the rows, so a route can switch between them at any time. Responses are byte-compatible with the legacy handlers (internal/tests/platformcompat).

The package never sees the S3 keys: it holds no secrets capability, so KernelSettings answers them masked, as the kernel's handler shows them, and it has no access to the v2_backup_config row. The update is written by the kernel: it records the audit entry its own handler records, in the protected v2_operation_log, and makes its backup service reload the copy of the configuration it keeps in memory, from which backup creation takes its storage path.

Seven routes have no native handler and stay bridged:

  • The system configuration routes (list, get, set, delete) work on any key of v2_system_config, a protected kernel table. KernelSettings reaches only the keys of a namespace, and a grant over every key would amount to every secret: the answers mask secrets, but writing an address (the NodeX or SMTP host) next to a secret the kernel sends there amounts to reading it. Their reason is in docs/architecture/settings-service.md.
  • Creating, deleting and restoring a backup write, remove and restore archives of the whole database and the kernel's files on the kernel's disk (restoring closes the kernel's database connection), and record audit entries: kernel operations with no table-level equivalent.

Index

Constants

View Source
const (
	BackupConfigGetRouteID    = "platform.admin.system.backup.config.get"
	BackupConfigUpdateRouteID = "platform.admin.system.backup.config.put"
)

Route ids of the routes that read and update the backup configuration through KernelSettings.

Variables

This section is empty.

Functions

func BackupConfigRequestID

func BackupConfigRequestID(token string) string

BackupConfigRequestID names a backup configuration update in the kernel's settings request ledger, so a retried request is applied once. token identifies the HTTP request: its Idempotency-Key, else its request id, else a fresh value.

Types

type AuditLog

type AuditLog struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	UserID     *uint  `gorm:"index" json:"user_id"`
	Username   string `gorm:"size:100" json:"username"`
	Action     string `gorm:"size:50;index" json:"action"`
	Module     string `gorm:"size:50;index" json:"module"`
	TargetType string `gorm:"size:50" json:"target_type"`
	TargetID   *uint  `json:"target_id"`
	Content    string `gorm:"type:text" json:"content"`
	IP         string `gorm:"size:45" json:"ip"`
	UserAgent  string `gorm:"size:255" json:"user_agent"`
	Status     int    `gorm:"default:1" json:"status"`

	CreatedAt time.Time `gorm:"index" json:"created_at"`
}

AuditLog is a row of kapi_system_audit_log_v1, the kernel's read-only view of the v2_operation_log rows of module "system". Its fields and tags are the kernel model's.

func (AuditLog) TableName

func (AuditLog) TableName() string

TableName is the kernel view.

type BackupRecord

type BackupRecord struct {
	ID        uint   `gorm:"primaryKey" json:"id"`
	Name      string `gorm:"size:100" json:"name"`
	Type      string `gorm:"size:20" json:"type"`
	Size      int64  `json:"size"`
	Path      string `gorm:"size:255" json:"path"`
	Status    int    `gorm:"default:0" json:"status"`
	Error     string `gorm:"type:text" json:"error"`
	Auto      bool   `gorm:"default:false" json:"auto"`
	CreatedBy *uint  `json:"created_by"`

	CompletedAt *time.Time `json:"completed_at"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

BackupRecord is a v2_backup_record row, as the kernel model declares it.

func (BackupRecord) TableName

func (BackupRecord) TableName() string

TableName is the adopted kernel table.

type Service

type Service struct {
	// Open returns the package's storage connection, on which the adopted
	// tables and the kapi_system_audit_log_v1 view are visible.
	Open func(ctx context.Context) (*gorm.DB, error)
	// Settings is the kernel's KernelSettings; without it the backup
	// configuration routes have no native handler and stay legacy.
	Settings Settings
	// NewToken names a request that carries neither an Idempotency-Key
	// nor a request id; it defaults to a random UUID.
	NewToken func() string
	// Now defaults to time.Now.
	Now func() time.Time
}

Service holds what the native routes need.

func (*Service) GetAuditLogs

GetAuditLogs is GET /api/v2/admin/system/audit-logs: the system audit trail, newest first, by target type and action.

func (*Service) GetBackupConfig

GetBackupConfig is GET /api/v2/admin/system/backup/config: the configuration read through KernelSettings, with the S3 keys masked.

func (*Service) GetBackupStats

GetBackupStats is GET /api/v2/admin/system/backup/stats: count, total size and time of the successful backups. Like the kernel's service it ignores failed queries, which count as nothing.

func (*Service) Handlers

func (s *Service) Handlers() map[string]pluginhostsdk.NativeHandler

Handlers returns the native handlers by route id.

func (*Service) ListBackups

ListBackups is GET /api/v2/admin/system/backups: the backup records, newest first. Like the kernel's service it ignores a failed count.

func (*Service) UpdateBackupConfig

func (s *Service) UpdateBackupConfig(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)

UpdateBackupConfig is PUT /api/v2/admin/system/backup/config. The kernel writes the configuration through KernelSettings (namespace backup): it saves the row, records the audit entry its own handler records and makes its backup service reload the configuration it keeps in memory, from which backup creation takes its storage path. The answer is the stored configuration, read back through KernelSettings with the S3 keys masked.

type Settings

Settings is the part of the kernel's KernelSettings contract the native routes call.

Jump to

Keyboard shortcuts

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