backup_svc

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptBackup

func DecryptBackup(envelopeJSON []byte, password string) ([]byte, error)

DecryptBackup 使用密码解密备份数据

func EncryptBackup

func EncryptBackup(plainJSON []byte, password string) ([]byte, error)

EncryptBackup 使用密码加密备份数据

func GetGistContent

func GetGistContent(token, gistID string) ([]byte, error)

GetGistContent 读取 Gist 中的备份内容

func GetWebDAVBackupContent added in v1.4.0

func GetWebDAVBackupContent(cfg WebDAVConfig, name string) ([]byte, error)

GetWebDAVBackupContent downloads a selected OpsKat backup file from WebDAV.

func IsEncryptedBackup

func IsEncryptedBackup(data []byte) bool

IsEncryptedBackup 检测数据是否为加密备份

func PollDeviceAuth

func PollDeviceAuth(ctx context.Context, deviceCode string, interval int) (string, error)

PollDeviceAuth 轮询 Device Flow 授权结果,返回 access_token

func TestWebDAVConnection added in v1.4.0

func TestWebDAVConnection(cfg WebDAVConfig) error

TestWebDAVConnection verifies that the configured WebDAV directory is reachable AND writable. 仅靠 PROPFIND/列表无法验证写权限:只读只读账号或路径配置错误时也可能返回 200/207 或 404, 因此这里走一遍 MKCOL → PUT(probe) → DELETE(probe) 探测,让 UI 的“测试连接”能给出真实结果。

func ValidateWebDAVConfig added in v1.4.0

func ValidateWebDAVConfig(cfg WebDAVConfig) error

ValidateWebDAVConfig 校验 URL 与 AuthType 必填字段。 app 层在 Save / Test 入口处调用,避免发出无意义请求。

func ValidateWebDAVURL added in v1.4.0

func ValidateWebDAVURL(raw string) error

ValidateWebDAVURL 校验给定的 WebDAV URL 是否符合保存条件:scheme 为 http/https、有 host、不内嵌账号密码。 在 App 层保存配置之前调用,确保不会把含明文凭据的 URL 写到 config.json。

Types

type BackupCredential

type BackupCredential struct {
	credential_entity.Credential
	PlainPassword   string `json:"plain_password,omitempty"`
	PlainPrivateKey string `json:"plain_private_key,omitempty"`
}

BackupCredential 凭据备份条目(含明文敏感字段)

type BackupData

type BackupData struct {
	Version             string                             `json:"version"`
	ExportedAt          string                             `json:"exported_at"`
	IncludesCredentials bool                               `json:"includes_credentials,omitempty"`
	Groups              []*group_entity.Group              `json:"groups,omitempty"`
	Assets              []*asset_entity.Asset              `json:"assets,omitempty"`
	Credentials         []*BackupCredential                `json:"credentials,omitempty"`
	PolicyGroups        []*policy_group_entity.PolicyGroup `json:"policy_groups,omitempty"`
	Forwards            []*BackupForward                   `json:"forwards,omitempty"`
	Shortcuts           json.RawMessage                    `json:"shortcuts,omitempty"`
	CustomThemes        json.RawMessage                    `json:"custom_themes,omitempty"`
}

BackupData 备份数据结构

func Export

func Export(ctx context.Context, opts *ExportOptions, crypto CredentialCrypto) (*BackupData, error)

Export 导出数据

func (*BackupData) Summary

func (d *BackupData) Summary() *BackupSummary

Summary 返回备份概览

type BackupForward

type BackupForward struct {
	forward_entity.ForwardConfig
	Rules []*forward_entity.ForwardRule `json:"rules"`
}

BackupForward 端口转发备份条目(config + rules 打包)

type BackupSummary

type BackupSummary struct {
	Version             string `json:"version"`
	ExportedAt          string `json:"exported_at"`
	Encrypted           bool   `json:"encrypted"`
	IncludesCredentials bool   `json:"includes_credentials"`
	AssetCount          int    `json:"asset_count"`
	GroupCount          int    `json:"group_count"`
	CredentialCount     int    `json:"credential_count"`
	PolicyGroupCount    int    `json:"policy_group_count"`
	ForwardCount        int    `json:"forward_count"`
	HasShortcuts        bool   `json:"has_shortcuts"`
	HasCustomThemes     bool   `json:"has_custom_themes"`
}

BackupSummary 备份概览信息(用于导入前预览)

type CredentialCrypto

type CredentialCrypto interface {
	Encrypt(plaintext string) (string, error)
	Decrypt(ciphertext string) (string, error)
}

CredentialCrypto 凭证加解密接口

type DeviceFlowInfo

type DeviceFlowInfo struct {
	DeviceCode      string `json:"deviceCode"`
	UserCode        string `json:"userCode"`
	VerificationURI string `json:"verificationUri"`
	ExpiresIn       int    `json:"expiresIn"`
	Interval        int    `json:"interval"`
}

DeviceFlowInfo Device Flow 初始化返回

func StartDeviceFlow

func StartDeviceFlow() (*DeviceFlowInfo, error)

StartDeviceFlow 发起 GitHub Device Flow

type EncryptedBackup

type EncryptedBackup struct {
	Format     string           `json:"format"`
	Version    int              `json:"version"`
	KDF        KDFParams        `json:"kdf"`
	Encryption EncryptionParams `json:"encryption"`
	Ciphertext string           `json:"ciphertext"`
}

EncryptedBackup 加密备份信封

type EncryptionParams

type EncryptionParams struct {
	Algorithm string `json:"algorithm"`
	Nonce     string `json:"nonce"`
}

EncryptionParams 加密参数

type ExportOptions

type ExportOptions struct {
	AssetIDs            []int64 `json:"asset_ids"`             // 空=全部
	IncludeCredentials  bool    `json:"include_credentials"`   // 包含凭据(强制加密)
	IncludeForwards     bool    `json:"include_forwards"`      // 包含端口转发
	IncludePolicyGroups bool    `json:"include_policy_groups"` // 包含策略组
	IncludeShortcuts    bool    `json:"include_shortcuts"`     // 包含快捷键
	IncludeThemes       bool    `json:"include_themes"`        // 包含终端主题
	Shortcuts           string  `json:"shortcuts,omitempty"`   // JSON 字符串
	CustomThemes        string  `json:"custom_themes,omitempty"`
}

ExportOptions 导出选项

type GistInfo

type GistInfo struct {
	ID          string `json:"id"`
	Description string `json:"description"`
	UpdatedAt   string `json:"updatedAt"`
	HTMLURL     string `json:"htmlUrl"`
}

GistInfo Gist 概要信息

func CreateOrUpdateGist

func CreateOrUpdateGist(token, gistID string, content []byte) (*GistInfo, error)

CreateOrUpdateGist 创建或更新 Gist gistID 为空时创建新 Gist,否则更新已有 Gist

func ListBackupGists

func ListBackupGists(token string) ([]*GistInfo, error)

ListBackupGists 列出用户的 OpsKat 备份 Gist

type GitHubUser

type GitHubUser struct {
	Login     string `json:"login"`
	AvatarURL string `json:"avatarUrl"`
}

GitHubUser GitHub 用户信息

func GetGitHubUser

func GetGitHubUser(token string) (*GitHubUser, error)

GetGitHubUser 获取当前用户信息

type ImportOptions

type ImportOptions struct {
	ImportAssets       bool   `json:"import_assets"`
	ImportCredentials  bool   `json:"import_credentials"`
	ImportForwards     bool   `json:"import_forwards"`
	ImportPolicyGroups bool   `json:"import_policy_groups"`
	ImportShortcuts    bool   `json:"import_shortcuts"`
	ImportThemes       bool   `json:"import_themes"`
	Mode               string `json:"mode"` // "replace" | "merge"
}

ImportOptions 导入选项

type ImportResult

type ImportResult struct {
	AssetsImported       int    `json:"assets_imported"`
	GroupsImported       int    `json:"groups_imported"`
	CredentialsImported  int    `json:"credentials_imported"`
	PolicyGroupsImported int    `json:"policy_groups_imported"`
	ForwardsImported     int    `json:"forwards_imported"`
	Shortcuts            string `json:"shortcuts,omitempty"` // JSON 字符串,前端处理
	CustomThemes         string `json:"custom_themes,omitempty"`
}

ImportResult 导入结果

func Import

func Import(ctx context.Context, data *BackupData, opts *ImportOptions, crypto CredentialCrypto) (*ImportResult, error)

Import 导入备份数据

type KDFParams

type KDFParams struct {
	Algorithm string `json:"algorithm"`
	Time      uint32 `json:"time"`
	Memory    uint32 `json:"memory"`
	Threads   uint8  `json:"threads"`
	Salt      string `json:"salt"`
}

KDFParams 密钥派生参数

type WebDAVAuthType added in v1.4.0

type WebDAVAuthType string

WebDAVAuthType 描述 WebDAV 服务器接受的鉴权方式。

const (
	WebDAVAuthNone   WebDAVAuthType = "none"
	WebDAVAuthBasic  WebDAVAuthType = "basic"
	WebDAVAuthBearer WebDAVAuthType = "bearer"
)

type WebDAVBackupInfo added in v1.4.0

type WebDAVBackupInfo struct {
	Name      string `json:"name"`
	Path      string `json:"path"`
	UpdatedAt string `json:"updatedAt"`
	Size      int64  `json:"size"`
}

WebDAVBackupInfo is the frontend-facing metadata for a remote backup file.

func CreateOrUpdateWebDAVBackup added in v1.4.0

func CreateOrUpdateWebDAVBackup(cfg WebDAVConfig, content []byte) (*WebDAVBackupInfo, error)

CreateOrUpdateWebDAVBackup uploads the canonical encrypted backup file to WebDAV.

func ListWebDAVBackups added in v1.4.0

func ListWebDAVBackups(cfg WebDAVConfig) ([]*WebDAVBackupInfo, error)

ListWebDAVBackups lists OpsKat backup files from the configured WebDAV directory.

type WebDAVConfig added in v1.4.0

type WebDAVConfig struct {
	URL      string         `json:"url"`
	AuthType WebDAVAuthType `json:"authType"`
	Username string         `json:"username,omitempty"` // 仅 basic
	Password string         `json:"password,omitempty"` // 仅 basic
	Token    string         `json:"token,omitempty"`    // 仅 bearer
}

WebDAVConfig contains the connection details used for WebDAV backup transport.

Jump to

Keyboard shortcuts

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