Skip to content

Commit

Permalink
kesconf: expose public API (#414)
Browse files Browse the repository at this point in the history
* kesconf: expose public API

This commit exposes kes server confguration API and
provides a dev server.

Now, the `github.com/minio/kes/kesconf` package exposes
a stable API for reading the KES server configuration.
This supersedes the `kv` package and removes the `edge`
package.

Further, the KES server provides the `--dev` flag to start
a KES server in development mode with a in-memory keystore.
The `--key`, `--cert` and `--auth` are deprecated. Users should
use the config file to provide such config options.

Signed-off-by: Andreas Auernhammer <[email protected]>
  • Loading branch information
aead authored Nov 9, 2023
1 parent 73fa12c commit 2b39c33
Show file tree
Hide file tree
Showing 47 changed files with 1,151 additions and 2,041 deletions.
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

0 comments on commit 2b39c33

Please sign in to comment.