- Change all commands to use flags (--bucket, --prefix, etc.) - Add --config flag to backup command - Support VAULTIK_CONFIG environment variable for config path - Use /etc/vaultik/config.yml as default config location - Add test/config.yaml for testing - Update tests to use environment variable for config path - Add .gitignore for build artifacts and local configs - Update documentation to reflect new CLI syntax
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.eeqj.de/sneak/vaultik/internal/globals"
|
|
"github.com/spf13/cobra"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
// RestoreOptions contains options for the restore command
|
|
type RestoreOptions struct {
|
|
Bucket string
|
|
Prefix string
|
|
SnapshotID string
|
|
TargetDir string
|
|
}
|
|
|
|
// NewRestoreCommand creates the restore command
|
|
func NewRestoreCommand() *cobra.Command {
|
|
opts := &RestoreOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "restore",
|
|
Short: "Restore files from backup",
|
|
Long: `Download and decrypt files from a backup snapshot`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
// Validate required flags
|
|
if opts.Bucket == "" {
|
|
return fmt.Errorf("--bucket is required")
|
|
}
|
|
if opts.Prefix == "" {
|
|
return fmt.Errorf("--prefix is required")
|
|
}
|
|
if opts.SnapshotID == "" {
|
|
return fmt.Errorf("--snapshot is required")
|
|
}
|
|
if opts.TargetDir == "" {
|
|
return fmt.Errorf("--target is required")
|
|
}
|
|
return runRestore(cmd.Context(), opts)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&opts.Bucket, "bucket", "", "S3 bucket name")
|
|
cmd.Flags().StringVar(&opts.Prefix, "prefix", "", "S3 prefix")
|
|
cmd.Flags().StringVar(&opts.SnapshotID, "snapshot", "", "Snapshot ID to restore")
|
|
cmd.Flags().StringVar(&opts.TargetDir, "target", "", "Target directory for restore")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runRestore(ctx context.Context, opts *RestoreOptions) error {
|
|
if os.Getenv("VAULTIK_PRIVATE_KEY") == "" {
|
|
return fmt.Errorf("VAULTIK_PRIVATE_KEY environment variable must be set")
|
|
}
|
|
|
|
app := fx.New(
|
|
fx.Supply(opts),
|
|
fx.Provide(globals.New),
|
|
// Additional modules will be added here
|
|
fx.Invoke(func(g *globals.Globals) error {
|
|
// TODO: Implement restore logic
|
|
fmt.Printf("Restoring snapshot %s to %s\n", opts.SnapshotID, opts.TargetDir)
|
|
return nil
|
|
}),
|
|
fx.NopLogger,
|
|
)
|
|
|
|
if err := app.Start(ctx); err != nil {
|
|
return fmt.Errorf("failed to start restore: %w", err)
|
|
}
|
|
defer func() {
|
|
if err := app.Stop(ctx); err != nil {
|
|
fmt.Printf("error stopping app: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
return nil
|
|
} |