Skip to content

Commit

Permalink
kes: add Status API to client SDK
Browse files Browse the repository at this point in the history
This commit adds the `Status` API call
to the client SDK.

The current client API only contains a
subset of the status information exposed
by the server due to API instability.

Signed-off-by: Andreas Auernhammer <[email protected]>
  • Loading branch information
aead committed Feb 3, 2022
1 parent edeadf3 commit 7457bf3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ func (c *Client) Version(ctx context.Context) (string, error) {
return response.Version, nil
}

// Status returns the current state of the KES server.
func (c *Client) Status(ctx context.Context) (State, error) {
client := retry(c.HTTPClient)
resp, err := client.Send(ctx, http.MethodGet, c.Endpoints, "/v1/status", nil)
if err != nil {
return State{}, err
}
if resp.StatusCode != http.StatusOK {
return State{}, parseErrorResponse(resp)
}

type Response struct {
Version string `json:"version"`
UpTime time.Duration `json:"uptime"`
}
const limit = 1 << 20
var response Response
if err = json.NewDecoder(io.LimitReader(resp.Body, limit)).Decode(&response); err != nil {
return State{}, err
}
return State(response), nil
}

// CreateKey creates a new cryptographic key. The key will
// be generated by the KES server.
//
Expand Down
18 changes: 18 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ func TestVersion(t *testing.T) {
}
}

func TestStatus(t *testing.T) {
if !*IsIntegrationTest {
t.SkipNow()
}

client, err := newClient()
if err != nil {
t.Fatalf("Failed to create KES client: %v", err)
}
state, err := client.Status(context.Background())
if err != nil {
t.Fatalf("Failed to fetch KES server state: %v", err)
}
if state.UpTime == 0 {
t.Fatal("The KES server up time cannot be 0")
}
}

func TestCreateKey(t *testing.T) {
if !*IsIntegrationTest {
t.SkipNow()
Expand Down
14 changes: 14 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2022 - MinIO, Inc. All rights reserved.
// Use of this source code is governed by the AGPLv3
// license that can be found in the LICENSE file.

package kes

import "time"

// State is a KES server status snapshot.
type State struct {
Version string // The KES server version

UpTime time.Duration // The time the KES server has been up and running
}

0 comments on commit 7457bf3

Please sign in to comment.