Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions cmd/update/moni.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package update
import (
"fmt"

"github.com/CodeMonkeyCybersecurity/eos/pkg/bionicgpt/apikeys"
"github.com/CodeMonkeyCybersecurity/eos/pkg/bionicgpt/postinstall"
"github.com/CodeMonkeyCybersecurity/eos/pkg/bionicgpt/refresh"
eos "github.com/CodeMonkeyCybersecurity/eos/pkg/eos_cli"
"github.com/CodeMonkeyCybersecurity/eos/pkg/eos_io"
Expand All @@ -21,6 +23,11 @@ var (
moniRefreshNoBackup bool
moniRefreshValidateOnly bool
moniRefreshInstallDir string

// Moni post-install and API key rotation flags
moniPostInstall bool
moniRotateAPIKeys bool
moniInstallDir string
)

// MoniCmd is the command for Moni (BionicGPT) operations
Expand All @@ -31,13 +38,16 @@ var MoniCmd = &cobra.Command{
Long: `Update Moni (BionicGPT) multi-tenant LLM platform configuration.

The 'moni' command provides operations to manage your BionicGPT deployment:
• Post-installation configuration (--post-install)
• API key rotation (--rotate-api-keys)
• Configuration refresh (--refresh)
• Service restart
• Cache clearing
• Database configuration updates

BionicGPT (also known as Moni) is a multi-tenant RAG-enabled LLM platform
with document processing, embeddings, and Azure OpenAI integration.`,
RunE: eos.Wrap(runMoniOperations),
}

func init() {
Expand Down Expand Up @@ -90,9 +100,96 @@ Examples:
MoniCmd.Flags().BoolVar(&moniRefreshForce, "refresh", false,
"Refresh Moni configuration and restart services")

// Add post-install flag
MoniCmd.Flags().BoolVar(&moniPostInstall, "post-install", false,
"Run post-installation configuration (upsert models, regenerate API keys)")

// Add rotate-api-keys flag
MoniCmd.Flags().BoolVar(&moniRotateAPIKeys, "rotate-api-keys", false,
"Rotate API keys (generate new virtual key, update .env and database)")

// Add install-dir flag for both operations
MoniCmd.Flags().StringVar(&moniInstallDir, "install-dir", "/opt/bionicgpt",
"Path to Moni installation directory")

MoniCmd.AddCommand(refreshCmd)
}

// runMoniOperations handles the main moni command flags
// Orchestration layer: delegates to appropriate package based on flag
func runMoniOperations(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string) error {
logger := otelzap.Ctx(rc.Ctx)

// Check which operation was requested
if moniPostInstall {
return runMoniPostInstall(rc, cmd, args)
}

if moniRotateAPIKeys {
return runMoniRotateAPIKeys(rc, cmd, args)
}

// If no operation specified, show help
logger.Info("No operation specified. Use --post-install or --rotate-api-keys")
return cmd.Help()
}

// runMoniPostInstall handles the post-installation configuration
// Orchestration layer: delegates to pkg/bionicgpt/postinstall for business logic
func runMoniPostInstall(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string) error {
logger := otelzap.Ctx(rc.Ctx)

logger.Info("Starting Moni post-installation configuration",
zap.String("install_dir", moniInstallDir))

// Build configuration
config := &postinstall.Config{
InstallDir: moniInstallDir,
}

// Validate configuration
if err := config.Validate(); err != nil {
return fmt.Errorf("invalid configuration: %w", err)
}

// Execute post-installation
if err := postinstall.Execute(rc, config); err != nil {
logger.Error("Post-installation failed", zap.Error(err))
return fmt.Errorf("post-installation failed: %w", err)
}

logger.Info("Post-installation completed successfully")
return nil
}

// runMoniRotateAPIKeys handles the API key rotation
// Orchestration layer: delegates to pkg/bionicgpt/apikeys for business logic
func runMoniRotateAPIKeys(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string) error {
logger := otelzap.Ctx(rc.Ctx)

logger.Info("Starting Moni API key rotation",
zap.String("install_dir", moniInstallDir))

// Build configuration
config := &apikeys.Config{
InstallDir: moniInstallDir,
}

// Validate configuration
if err := config.Validate(); err != nil {
return fmt.Errorf("invalid configuration: %w", err)
}

// Execute API key rotation
if err := apikeys.Execute(rc, config); err != nil {
logger.Error("API key rotation failed", zap.Error(err))
return fmt.Errorf("API key rotation failed: %w", err)
}

logger.Info("API key rotation completed successfully")
return nil
}

// runMoniRefresh handles the refresh operation
// Orchestration layer: delegates to pkg/bionicgpt/refresh for business logic
func runMoniRefresh(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string) error {
Expand Down
Loading
Loading