soteria/internal/api/types.go

239 lines
9.8 KiB
Go
Raw Normal View History

2026-01-31 03:34:34 -03:00
package api
// BackupRequest is the request payload for a namespace or PVC backup.
2026-01-31 03:34:34 -03:00
type BackupRequest struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
Tags []string `json:"tags,omitempty"`
Snapshot bool `json:"snapshot"`
DryRun bool `json:"dry_run"`
Dedupe *bool `json:"dedupe,omitempty"`
KeepLast *int `json:"keep_last,omitempty"`
2026-01-31 03:34:34 -03:00
}
// BackupResponse is the response payload returned after a backup request.
2026-01-31 03:34:34 -03:00
type BackupResponse struct {
Driver string `json:"driver,omitempty"`
Volume string `json:"volume,omitempty"`
Backup string `json:"backup,omitempty"`
JobName string `json:"job_name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Secret string `json:"secret,omitempty"`
RequestedBy string `json:"requested_by,omitempty"`
DryRun bool `json:"dry_run"`
Dedupe bool `json:"dedupe"`
KeepLast int `json:"keep_last"`
2026-01-31 03:34:34 -03:00
}
// RestoreTestRequest is the request payload for a restore test.
2026-01-31 03:34:34 -03:00
type RestoreTestRequest struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
BackupURL string `json:"backup_url,omitempty"`
Repository string `json:"repository,omitempty"`
TargetNamespace string `json:"target_namespace,omitempty"`
TargetPVC string `json:"target_pvc,omitempty"`
DryRun bool `json:"dry_run"`
2026-01-31 03:34:34 -03:00
}
// RestoreTestResponse is the response payload returned after a restore test.
2026-01-31 03:34:34 -03:00
type RestoreTestResponse struct {
Driver string `json:"driver,omitempty"`
Volume string `json:"volume,omitempty"`
TargetNamespace string `json:"target_namespace,omitempty"`
TargetPVC string `json:"target_pvc,omitempty"`
BackupURL string `json:"backup_url,omitempty"`
JobName string `json:"job_name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Secret string `json:"secret,omitempty"`
RequestedBy string `json:"requested_by,omitempty"`
DryRun bool `json:"dry_run"`
}
// InventoryResponse wraps the full backup inventory view returned to the UI.
type InventoryResponse struct {
GeneratedAt string `json:"generated_at"`
Namespaces []NamespaceInventory `json:"namespaces"`
}
// NamespaceInventory groups PVC inventory for a single namespace.
type NamespaceInventory struct {
Name string `json:"name"`
PVCs []PVCInventory `json:"pvcs"`
}
// PVCInventory captures the backup health snapshot for one PVC.
type PVCInventory struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
Volume string `json:"volume,omitempty"`
Phase string `json:"phase,omitempty"`
StorageClass string `json:"storage_class,omitempty"`
Capacity string `json:"capacity,omitempty"`
AccessModes []string `json:"access_modes,omitempty"`
Driver string `json:"driver,omitempty"`
LastBackupAt string `json:"last_backup_at,omitempty"`
LastBackupAgeHours float64 `json:"last_backup_age_hours,omitempty"`
BackupCount int `json:"backup_count"`
CompletedBackups int `json:"completed_backups"`
ActiveBackups int `json:"active_backups"`
LastJobName string `json:"last_job_name,omitempty"`
LastJobState string `json:"last_job_state,omitempty"`
LastJobStartedAt string `json:"last_job_started_at,omitempty"`
LastJobProgressPct int `json:"last_job_progress_pct"`
LastBackupSizeBytes float64 `json:"last_backup_size_bytes"`
TotalBackupSizeBytes float64 `json:"total_backup_size_bytes"`
Healthy bool `json:"healthy"`
HealthReason string `json:"health_reason,omitempty"`
Error string `json:"error,omitempty"`
}
// BackupListResponse returns the backup history for a PVC.
type BackupListResponse struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
Volume string `json:"volume"`
Backups []BackupRecord `json:"backups"`
}
// BackupRecord summarizes one backup entry in a history list.
type BackupRecord struct {
Name string `json:"name"`
SnapshotName string `json:"snapshot_name,omitempty"`
Created string `json:"created,omitempty"`
State string `json:"state,omitempty"`
URL string `json:"url,omitempty"`
Size string `json:"size,omitempty"`
Latest bool `json:"latest,omitempty"`
}
// AuthInfoResponse reports the authenticated user and the allowed groups.
type AuthInfoResponse struct {
Authenticated bool `json:"authenticated"`
User string `json:"user,omitempty"`
Email string `json:"email,omitempty"`
Groups []string `json:"groups,omitempty"`
AllowedGroups []string `json:"allowed_groups,omitempty"`
2026-01-31 03:34:34 -03:00
}
// BackupPolicy stores the scheduling policy for a namespace or PVC.
type BackupPolicy struct {
ID string `json:"id"`
Namespace string `json:"namespace"`
PVC string `json:"pvc,omitempty"`
IntervalHours float64 `json:"interval_hours"`
Enabled bool `json:"enabled"`
Dedupe bool `json:"dedupe"`
KeepLast int `json:"keep_last"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
// BackupPolicyUpsertRequest updates the stored backup policy for a scope.
type BackupPolicyUpsertRequest struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc,omitempty"`
IntervalHours float64 `json:"interval_hours"`
Enabled *bool `json:"enabled,omitempty"`
Dedupe *bool `json:"dedupe,omitempty"`
KeepLast *int `json:"keep_last,omitempty"`
}
// BackupPolicyListResponse returns the configured backup policies.
type BackupPolicyListResponse struct {
Policies []BackupPolicy `json:"policies"`
}
// NamespaceBackupRequest requests a backup sweep across a namespace.
type NamespaceBackupRequest struct {
Namespace string `json:"namespace"`
DryRun bool `json:"dry_run"`
Dedupe *bool `json:"dedupe,omitempty"`
KeepLast *int `json:"keep_last,omitempty"`
}
// NamespaceBackupResult reports the outcome for a single PVC backup.
type NamespaceBackupResult struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
Status string `json:"status"`
Volume string `json:"volume,omitempty"`
Backup string `json:"backup,omitempty"`
Error string `json:"error,omitempty"`
}
// NamespaceBackupResponse summarizes the namespace backup sweep results.
type NamespaceBackupResponse struct {
Namespace string `json:"namespace"`
RequestedBy string `json:"requested_by,omitempty"`
Driver string `json:"driver"`
DryRun bool `json:"dry_run"`
Dedupe bool `json:"dedupe"`
KeepLast int `json:"keep_last"`
Total int `json:"total"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
Results []NamespaceBackupResult `json:"results"`
}
// NamespaceRestoreRequest requests a restore sweep across a namespace.
type NamespaceRestoreRequest struct {
Namespace string `json:"namespace"`
TargetNamespace string `json:"target_namespace,omitempty"`
TargetPrefix string `json:"target_prefix,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
DryRun bool `json:"dry_run"`
}
// NamespaceRestoreResult reports the outcome for a single PVC restore.
type NamespaceRestoreResult struct {
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
TargetNamespace string `json:"target_namespace"`
TargetPVC string `json:"target_pvc"`
Status string `json:"status"`
Volume string `json:"volume,omitempty"`
BackupURL string `json:"backup_url,omitempty"`
Error string `json:"error,omitempty"`
}
// NamespaceRestoreResponse summarizes the namespace restore sweep results.
type NamespaceRestoreResponse struct {
Namespace string `json:"namespace"`
TargetNamespace string `json:"target_namespace"`
RequestedBy string `json:"requested_by,omitempty"`
Driver string `json:"driver"`
DryRun bool `json:"dry_run"`
Total int `json:"total"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
Results []NamespaceRestoreResult `json:"results"`
}
// B2UsageResponse reports account and per-bucket Backblaze B2 usage.
type B2UsageResponse struct {
Enabled bool `json:"enabled"`
Available bool `json:"available"`
Endpoint string `json:"endpoint,omitempty"`
Region string `json:"region,omitempty"`
ScannedAt string `json:"scanned_at,omitempty"`
ScanDurationMS int64 `json:"scan_duration_ms,omitempty"`
TotalObjects int64 `json:"total_objects"`
TotalBytes int64 `json:"total_bytes"`
RecentObjects24h int64 `json:"recent_objects_24h"`
RecentBytes24h int64 `json:"recent_bytes_24h"`
Buckets []B2BucketUsage `json:"buckets,omitempty"`
Error string `json:"error,omitempty"`
}
// B2BucketUsage captures the usage metrics for one Backblaze B2 bucket.
type B2BucketUsage struct {
Name string `json:"name"`
ObjectCount int64 `json:"object_count"`
TotalBytes int64 `json:"total_bytes"`
RecentObjects24h int64 `json:"recent_objects_24h"`
RecentBytes24h int64 `json:"recent_bytes_24h"`
LastModifiedAt string `json:"last_modified_at,omitempty"`
}