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
26 changes: 26 additions & 0 deletions cmd/providers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
Comment on lines +1 to +3
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new command file is missing the standard DBDeployer Apache 2.0 license header comment that appears at the top of the other cmd/*.go files (e.g. cmd/root.go:1-15, cmd/versions.go:1-15). Please add the same header here for consistency and to avoid licensing ambiguity.

Copilot uses AI. Check for mistakes.
"fmt"

"github.com/ProxySQL/dbdeployer/providers"
"github.com/spf13/cobra"
)

var providersCmd = &cobra.Command{
Use: "providers",
Short: "Shows available deployment providers",
Long: "Lists all registered providers that can be used for sandbox deployment",
Run: func(cmd *cobra.Command, args []string) {
for _, name := range providers.DefaultRegistry.List() {
p, _ := providers.DefaultRegistry.Get(name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The error returned from providers.DefaultRegistry.Get(name) is ignored. While it's unlikely to fail in the current logic (as you're iterating over a list from the same registry), not handling the error could lead to a panic on the next line if p is nil. It's safer to handle the error.

You will also need to import the os package to use os.Stderr.

p, err := providers.DefaultRegistry.Get(name)
if err != nil {
	fmt.Fprintf(os.Stderr, "error getting provider %q: %v\n", name, err)
	continue
}

Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providers.DefaultRegistry.Get(name) errors are currently ignored, which would lead to a nil dereference on p.DefaultPorts() if the registry ever becomes inconsistent. Even if this is unlikely given name comes from List(), it’s safer to handle the error (e.g., exit or print a clear message and continue).

Suggested change
p, _ := providers.DefaultRegistry.Get(name)
p, err := providers.DefaultRegistry.Get(name)
if err != nil {
fmt.Fprintf(cmd.ErrOrStderr(), "failed to get provider %q: %v\n", name, err)
continue
}

Copilot uses AI. Check for mistakes.
ports := p.DefaultPorts()
fmt.Printf("%-15s (base port: %d, ports per instance: %d)\n",
name, ports.BasePort, ports.PortsPerInstance)
}
},
}

func init() {
rootCmd.AddCommand(providersCmd)
}
10 changes: 10 additions & 0 deletions cmd/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ProxySQL/dbdeployer/common"
"github.com/ProxySQL/dbdeployer/defaults"
"github.com/ProxySQL/dbdeployer/globals"
"github.com/ProxySQL/dbdeployer/providers"
"github.com/ProxySQL/dbdeployer/sandbox"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -445,6 +446,15 @@ func singleSandbox(cmd *cobra.Command, args []string) {
if err != nil {
common.Exitf(1, "error while filling the sandbox definition: %+v", err)
}
// Validate version with provider
// TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql"
p, provErr := providers.DefaultRegistry.Get("mysql")
if provErr != nil {
common.Exitf(1, "provider error: %s", provErr)
}
if provErr = p.ValidateVersion(sd.Version); provErr != nil {
common.Exitf(1, "version validation failed: %s", provErr)
}
Comment on lines +450 to +457
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provider lookup is hardcoded to "mysql" even though fillSandboxDefinition detects/sets sd.Flavor. This will validate versions against the wrong provider for non-MySQL flavors (e.g. MariaDB/Percona) and will likely break once providers implement flavor-specific ValidateVersion logic. Please select the provider based on sd.Flavor (or skip provider validation when no matching provider is registered) instead of hardcoding "mysql".

Suggested change
// TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql"
p, provErr := providers.DefaultRegistry.Get("mysql")
if provErr != nil {
common.Exitf(1, "provider error: %s", provErr)
}
if provErr = p.ValidateVersion(sd.Version); provErr != nil {
common.Exitf(1, "version validation failed: %s", provErr)
}
// Determine provider from sd.Flavor, defaulting to "mysql" for backward compatibility
providerName := sd.Flavor
if providerName == "" {
providerName = "mysql"
}
p, provErr := providers.DefaultRegistry.Get(providerName)
if provErr != nil {
// For non-MySQL flavors, skip provider validation if no matching provider is registered
if providerName == "mysql" {
common.Exitf(1, "provider error: %s", provErr)
}
} else {
if err := p.ValidateVersion(sd.Version); err != nil {
common.Exitf(1, "version validation failed: %s", err)
}
}

Copilot uses AI. Check for mistakes.
// When deploying a single sandbox, we disable concurrency
sd.RunConcurrently = false
err = sandbox.CreateStandaloneSandbox(sd)
Expand Down
Loading