Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kesconf: expose public API #414

Merged
merged 2 commits into from
Nov 9, 2023
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
36 changes: 13 additions & 23 deletions cmd/kes/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
Expand All @@ -16,8 +17,8 @@ import (

"github.com/fatih/color"
"github.com/minio/kes-go"
"github.com/minio/kes/edge"
"github.com/minio/kes/internal/cli"
"github.com/minio/kes/kesconf"
flag "github.com/spf13/pflag"
"golang.org/x/term"
)
Expand Down Expand Up @@ -86,26 +87,15 @@ func migrateCmd(args []string) {
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
defer cancel()

file, err := os.Open(fromPath)
sourceConfig, err := kesconf.ReadFile(fromPath)
if err != nil {
cli.Fatalf("failed to read '--from' config file: %v", err)
}
sourceConfig, err := edge.ReadServerConfigYAML(file)
if err != nil {
cli.Fatalf("failed to read '--from' config file: %v", err)
}
file.Close()

file, err = os.Open(toPath)
if err != nil {
cli.Fatalf("failed to read '--to' config file: %v", err)
}

targetConfig, err := edge.ReadServerConfigYAML(file)
targetConfig, err := kesconf.ReadFile(toPath)
if err != nil {
cli.Fatalf("failed to read '--to' config file: %v", err)
}
file.Close()

src, err := sourceConfig.KeyStore.Connect(ctx)
if err != nil {
Expand All @@ -123,9 +113,8 @@ func migrateCmd(args []string) {
defer uiTicker.Stop()

// Now, we start listing the keys at the source.
iterator, err := src.List(ctx)
if err != nil {
cli.Fatal(err)
iterator := &kes.ListIter[string]{
NextFunc: src.List,
}

// Then, we start the UI which prints how many keys have
Expand All @@ -145,10 +134,15 @@ func migrateCmd(args []string) {

// Finally, we start the actual migration.
for {
name, ok := iterator.Next()
if !ok {
name, err := iterator.Next(ctx)
if err == io.EOF {
break
}
if err != nil {
quiet.ClearLine()
cli.Fatalf("failed to migrate %q: %v\nMigrated keys: %d", name, err, atomic.LoadUint64(&n))
}

if ok, _ := filepath.Match(pattern, name); !ok {
continue
}
Expand Down Expand Up @@ -176,10 +170,6 @@ func migrateCmd(args []string) {
}
atomic.AddUint64(&n, 1)
}
if err = iterator.Close(); err != nil {
quiet.ClearLine()
cli.Fatalf("failed to list keys: %v\nMigrated keys: %d", err, atomic.LoadUint64(&n))
}
cancel()

// At the end we show how many keys we have migrated successfully.
Expand Down
Loading
Loading