core

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package core/migrate.go defines schema migrations applied in order.

Package core defines the shared types and interfaces used across CLI and TUI layers.

Package core — resource type display labels, kept provider-specific since the same short code can mean different things (or not exist) across cloud vendors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Columns

func Columns(resourceType string) []string

Columns returns the compact display column headers for a resource type (table view).

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns ~/.cloudres/data.db

func ResourceTypeLabel

func ResourceTypeLabel(provider, resourceType string) string

ResourceTypeLabel returns the human-readable label for a provider's resource type code, or "" if the provider/code isn't known — callers should fall back to showing the bare code in that case.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps a SQLite database connection.

func Open

func Open() (*DB, error)

Open opens (or creates) the SQLite database and runs migrations.

func OpenPath

func OpenPath(path string) (*DB, error)

OpenPath opens a database at a specific path.

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection.

func (*DB) GetLastSyncTime

func (d *DB) GetLastSyncTime(provider, profile, resourceType string) (time.Time, error)

GetLastSyncTime returns the last successful sync time for a provider+profile+resource type.

func (*DB) InsertSyncLog

func (d *DB) InsertSyncLog(provider, profile, resourceType, region string) (int64, error)

InsertSyncLog creates a new sync log entry.

func (*DB) ListProviders

func (d *DB) ListProviders() ([]Provider, error)

ListProviders returns all detected providers.

func (*DB) ListResources

func (d *DB) ListResources(provider, profile, resourceType, region string) ([]Resource, error)

ListResources returns resources filtered by provider, profile, type, and optional region.

func (*DB) SearchResources

func (d *DB) SearchResources(provider, profile, resourceType, query string) ([]Resource, error)

SearchResources searches resources by name or ID.

func (*DB) UpdateSyncLog

func (d *DB) UpdateSyncLog(id int64, status, errMsg string, count int) error

UpdateSyncLog updates a sync log entry with completion info.

func (*DB) UpsertProvider

func (d *DB) UpsertProvider(p Provider) error

UpsertProvider inserts or updates a provider record.

func (*DB) UpsertResources

func (d *DB) UpsertResources(resources []Resource) error

UpsertResources batch inserts or updates resources.

type Provider

type Provider struct {
	Name           string              `json:"name"`
	CLIPath        string              `json:"cli_path"`
	ConfigPath     string              `json:"config_path"`
	Profiles       []string            `json:"profiles"`
	Regions        []string            `json:"regions"`
	ProfileRegions map[string][]string `json:"profile_regions"` // profile name → regions
	ActiveProfile  string              `json:"active_profile"`  // TUI 选中的 profile,CLI 调用时传 --profile
	DetectedAt     time.Time           `json:"detected_at"`
}

Provider represents a detected cloud provider with CLI access.

type ProviderDetector

type ProviderDetector interface {
	Name() string
	Detect(ctx context.Context) (*Provider, error)
	ResourceTypes() []string
	Fetchers() []ResourceFetcher
}

ProviderDetector can scan for and detect a cloud provider.

type ProviderError

type ProviderError struct {
	Provider  string
	Operation string
	Stderr    string
	ExitCode  int
}

ProviderError represents a cloud CLI execution failure.

func (*ProviderError) Error

func (e *ProviderError) Error() string

type Resource

type Resource struct {
	Provider     string    `json:"provider"`
	Profile      string    `json:"profile"`
	ResourceType string    `json:"resource_type"`
	Region       string    `json:"region"`
	ResourceID   string    `json:"resource_id"`
	ResourceName string    `json:"resource_name"`
	Status       string    `json:"status"`
	RawJSON      string    `json:"raw_json"`
	SyncedAt     time.Time `json:"synced_at"`
}

Resource represents a single cloud resource cached in SQLite.

func Sync

func Sync(ctx context.Context, db *DB, provider *Provider, fetcher ResourceFetcher, region string) ([]Resource, error)

Sync fetches resources from a provider if the cache is stale, then returns the list.

func SyncAndList

func SyncAndList(ctx context.Context, db *DB, provider *Provider, fetcher ResourceFetcher, region string) ([]Resource, error)

SyncAndList forces a sync and returns fresh results.

func (Resource) Detail

func (r Resource) Detail() [][2]string

Detail returns key-value pairs for the detail view of a resource.

func (Resource) Row

func (r Resource) Row() []string

Row extracts display columns from a Resource as strings.

type ResourceFetcher

type ResourceFetcher interface {
	ResourceType() string
	Fetch(ctx context.Context, p *Provider) ([]Resource, error)
}

ResourceFetcher fetches resources of a specific type from a provider.

type SyncLog

type SyncLog struct {
	ID            int64
	Provider      string
	ResourceType  string
	Region        string
	StartedAt     time.Time
	CompletedAt   *time.Time
	Status        string
	Error         string
	ResourceCount int
}

SyncLog records a sync operation.

Jump to

Keyboard shortcuts

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