Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
32 changes: 0 additions & 32 deletions cmd/docker-mcp/backup/dump.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we get rid of the entire backup package. It's superseded by profiles and secrets and now that the policy dump and set commands are gone, can we verify whether this entire package can be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, I think we are safe to remove it. Could be another PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, will address in a follow-up PR

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/docker/mcp-gateway/cmd/docker-mcp/catalog"
"github.com/docker/mcp-gateway/pkg/config"
"github.com/docker/mcp-gateway/pkg/desktop"
"github.com/docker/mcp-gateway/pkg/docker"
)

Expand Down Expand Up @@ -45,43 +44,12 @@ func Dump(ctx context.Context, docker docker.Client) ([]byte, error) {
catalogFiles[name] = string(catalogFileContent)
}

secretsClient := desktop.NewSecretsClient()
storedSecrets, err := secretsClient.ListJfsSecrets(ctx)
if err != nil {
return nil, err
}

var secretNames []string
for _, secret := range storedSecrets {
secretNames = append(secretNames, secret.Name)
}
secretValues, err := docker.ReadSecrets(ctx, secretNames, false)
if err != nil {
return nil, err
}

var secrets []desktop.Secret
for _, secret := range storedSecrets {
secrets = append(secrets, desktop.Secret{
Name: secret.Name,
Provider: secret.Provider,
Value: secretValues[secret.Name],
})
}

policy, err := secretsClient.GetJfsPolicy(ctx)
if err != nil {
return nil, err
}

backup := Backup{
Config: string(configContent),
Registry: string(registryContent),
Catalog: string(catalogContent),
CatalogFiles: catalogFiles,
Tools: string(toolsConfig),
Secrets: secrets,
Policy: policy,
}

return json.Marshal(backup)
Expand Down
34 changes: 1 addition & 33 deletions cmd/docker-mcp/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

"github.com/docker/mcp-gateway/cmd/docker-mcp/catalog"
"github.com/docker/mcp-gateway/pkg/config"
"github.com/docker/mcp-gateway/pkg/desktop"
)

func Restore(ctx context.Context, backupData []byte) error {
func Restore(_ context.Context, backupData []byte) error {
var backup Backup
if err := json.Unmarshal(backupData, &backup); err != nil {
return err
Expand Down Expand Up @@ -50,36 +49,5 @@ func Restore(ctx context.Context, backupData []byte) error {
}
}

secretsClient := desktop.NewSecretsClient()

secretsBefore, err := secretsClient.ListJfsSecrets(ctx)
if err != nil {
return err
}

secretsKeep := map[string]bool{}
for _, secret := range backup.Secrets {
if err := secretsClient.SetJfsSecret(ctx, desktop.Secret{
Name: secret.Name,
Value: secret.Value,
Provider: secret.Provider,
}); err != nil {
return err
}
secretsKeep[secret.Name] = true
}

for _, secret := range secretsBefore {
if !secretsKeep[secret.Name] {
if err := secretsClient.DeleteJfsSecret(ctx, secret.Name); err != nil {
return err
}
}
}

if err := secretsClient.SetJfsPolicy(ctx, backup.Policy); err != nil {
return err
}

return nil
}
4 changes: 0 additions & 4 deletions cmd/docker-mcp/backup/types.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package backup

import "github.com/docker/mcp-gateway/pkg/desktop"

type Backup struct {
Config string `json:"config"`
Registry string `json:"registry"`
Catalog string `json:"catalog"`
CatalogFiles map[string]string `json:"catalogFiles"`
Tools string `json:"tools"`
Secrets []desktop.Secret `json:"secrets"`
Policy string `json:"policy"`
}
58 changes: 0 additions & 58 deletions cmd/docker-mcp/commands/policy.go

This file was deleted.

3 changes: 1 addition & 2 deletions cmd/docker-mcp/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
HiddenDefaultCmd: true,
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
cmd.SetContext(ctx)
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
return err
}
Expand All @@ -60,6 +59,7 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
},
Version: version.Version,
}
cmd.SetContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: What was the reason for this change? Curious only because I'm pretty sure this cmd is different than the cmd inside of PersistentPreRunE. e.g. the one in that function is the actual subcommand that got run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, reverted this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, reverted this

cmd.SetVersionTemplate("{{.Version}}\n")
cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
cmd.SetHelpTemplate(helpTemplate)
Expand All @@ -80,7 +80,6 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
cmd.AddCommand(featureCommand(dockerCli))
cmd.AddCommand(gatewayCommand(dockerClient, dockerCli))
cmd.AddCommand(oauthCommand())
cmd.AddCommand(policyCommand())
cmd.AddCommand(registryCommand())
cmd.AddCommand(secretCommand(dockerClient))
cmd.AddCommand(serverCommand(dockerClient, dockerCli))
Expand Down
Loading
Loading