add api framework
Some checks failed
CI / test-build (push) Failing after 59s

This commit is contained in:
2025-12-14 22:15:56 +07:00
parent f4683eeb73
commit a6da313dfc
13 changed files with 915 additions and 84 deletions

36
internal/models/auth.go Normal file
View File

@@ -0,0 +1,36 @@
package models
import "time"
// Role represents a user role
type Role string
const (
RoleAdministrator Role = "administrator"
RoleOperator Role = "operator"
RoleViewer Role = "viewer"
)
// User represents a system user
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email,omitempty"`
Role Role `json:"role"`
Active bool `json:"active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AuditLog represents an audit log entry
type AuditLog struct {
ID string `json:"id"`
Actor string `json:"actor"` // user ID or system
Action string `json:"action"` // "pool.create", "share.delete", etc.
Resource string `json:"resource"` // resource type and ID
Result string `json:"result"` // "success", "failure"
Message string `json:"message,omitempty"`
IP string `json:"ip,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Timestamp time.Time `json:"timestamp"`
}

28
internal/models/job.go Normal file
View File

@@ -0,0 +1,28 @@
package models
import "time"
// JobStatus represents the state of a job
type JobStatus string
const (
JobStatusPending JobStatus = "pending"
JobStatusRunning JobStatus = "running"
JobStatusCompleted JobStatus = "completed"
JobStatusFailed JobStatus = "failed"
JobStatusCancelled JobStatus = "cancelled"
)
// Job represents a long-running asynchronous operation
type Job struct {
ID string `json:"id"`
Type string `json:"type"` // "pool_create", "snapshot_create", etc.
Status JobStatus `json:"status"`
Progress int `json:"progress"` // 0-100
Message string `json:"message"`
Error string `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
}

View File

@@ -0,0 +1,42 @@
package models
// SMBShare represents an SMB/CIFS share
type SMBShare struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"` // dataset mountpoint
Dataset string `json:"dataset"` // ZFS dataset name
Description string `json:"description"`
ReadOnly bool `json:"read_only"`
GuestOK bool `json:"guest_ok"`
ValidUsers []string `json:"valid_users"`
Enabled bool `json:"enabled"`
}
// NFSExport represents an NFS export
type NFSExport struct {
ID string `json:"id"`
Path string `json:"path"` // dataset mountpoint
Dataset string `json:"dataset"` // ZFS dataset name
Clients []string `json:"clients"` // allowed clients (CIDR or hostnames)
ReadOnly bool `json:"read_only"`
RootSquash bool `json:"root_squash"`
Enabled bool `json:"enabled"`
}
// ISCSITarget represents an iSCSI target
type ISCSITarget struct {
ID string `json:"id"`
IQN string `json:"iqn"` // iSCSI Qualified Name
LUNs []LUN `json:"luns"`
Initiators []string `json:"initiators"` // ACL list
Enabled bool `json:"enabled"`
}
// LUN represents a Logical Unit Number backed by a ZVOL
type LUN struct {
ID int `json:"id"` // LUN number
ZVOL string `json:"zvol"` // ZVOL name
Size uint64 `json:"size"` // bytes
Backend string `json:"backend"` // "zvol"
}

56
internal/models/zfs.go Normal file
View File

@@ -0,0 +1,56 @@
package models
import "time"
// Pool represents a ZFS pool
type Pool struct {
Name string `json:"name"`
Status string `json:"status"` // ONLINE, DEGRADED, FAULTED, etc.
Size uint64 `json:"size"` // bytes
Allocated uint64 `json:"allocated"`
Free uint64 `json:"free"`
Health string `json:"health"`
CreatedAt time.Time `json:"created_at"`
}
// Dataset represents a ZFS filesystem
type Dataset struct {
Name string `json:"name"`
Pool string `json:"pool"`
Type string `json:"type"` // filesystem, volume
Size uint64 `json:"size"`
Used uint64 `json:"used"`
Available uint64 `json:"available"`
Mountpoint string `json:"mountpoint"`
CreatedAt time.Time `json:"created_at"`
}
// ZVOL represents a ZFS block device
type ZVOL struct {
Name string `json:"name"`
Pool string `json:"pool"`
Size uint64 `json:"size"` // bytes
Used uint64 `json:"used"`
CreatedAt time.Time `json:"created_at"`
}
// Snapshot represents a ZFS snapshot
type Snapshot struct {
Name string `json:"name"`
Dataset string `json:"dataset"`
Size uint64 `json:"size"`
CreatedAt time.Time `json:"created_at"`
}
// SnapshotPolicy defines automated snapshot rules
type SnapshotPolicy struct {
Dataset string `json:"dataset"`
Frequent int `json:"frequent"` // keep N frequent snapshots
Hourly int `json:"hourly"` // keep N hourly snapshots
Daily int `json:"daily"` // keep N daily snapshots
Weekly int `json:"weekly"` // keep N weekly snapshots
Monthly int `json:"monthly"` // keep N monthly snapshots
Yearly int `json:"yearly"` // keep N yearly snapshots
Autosnap bool `json:"autosnap"` // enable/disable
Autoprune bool `json:"autoprune"` // enable/disable
}