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
143 changes: 103 additions & 40 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,14 @@ <h2>Table of Contents</h2>
<a href="#metalstack%2fadmin%2fv2%2fpartition.proto">metalstack/admin/v2/partition.proto</a>
<ul>

<li>
<a href="#metalstack.admin.v2.MachineSizeCapacity"><span class="badge">M</span>MachineSizeCapacity</a>
</li>

<li>
<a href="#metalstack.admin.v2.PartitionCapacity"><span class="badge">M</span>PartitionCapacity</a>
</li>

<li>
<a href="#metalstack.admin.v2.PartitionServiceCapacityRequest"><span class="badge">M</span>PartitionServiceCapacityRequest</a>
</li>
Expand Down Expand Up @@ -10819,46 +10827,8 @@ <h2 id="metalstack/admin/v2/partition.proto">metalstack/admin/v2/partition.proto
<p></p>


<h3 id="metalstack.admin.v2.PartitionServiceCapacityRequest">PartitionServiceCapacityRequest</h3>
<p>PartitionServiceListRequest is the request payload for a partition capacity request</p>


<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>

<tr>
<td>id</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>ID of the partition to get </p></td>
</tr>

<tr>
<td>size</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>Size of machines to show the capacity </p></td>
</tr>

<tr>
<td>project</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>Project of machines to show the capacity </p></td>
</tr>

</tbody>
</table>





<h3 id="metalstack.admin.v2.PartitionServiceCapacityResponse">PartitionServiceCapacityResponse</h3>
<p>PartitionServiceCapacityResponse is the response payload for a partition capacity request</p>
<h3 id="metalstack.admin.v2.MachineSizeCapacity">MachineSizeCapacity</h3>
<p>ServerCapacity is the capacity of one server type, eg machine size</p>


<table class="field-table">
Expand Down Expand Up @@ -10982,6 +10952,99 @@ <h3 id="metalstack.admin.v2.PartitionServiceCapacityResponse">PartitionServiceCa



<h3 id="metalstack.admin.v2.PartitionCapacity">PartitionCapacity</h3>
<p>PartitionCapacity is the capacity of one partition</p>


<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>

<tr>
<td>partition</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>Partition of which this capacity is reported. </p></td>
</tr>

<tr>
<td>machine_size_capacities</td>
<td><a href="#metalstack.admin.v2.MachineSizeCapacity">MachineSizeCapacity</a></td>
<td>repeated</td>
<td><p>MachineSizeCapacities is the capacity per machine size. </p></td>
</tr>

</tbody>
</table>





<h3 id="metalstack.admin.v2.PartitionServiceCapacityRequest">PartitionServiceCapacityRequest</h3>
<p>PartitionServiceListRequest is the request payload for a partition capacity request</p>


<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>

<tr>
<td>id</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>ID of the partition to get </p></td>
</tr>

<tr>
<td>size</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>Size of machines to show the capacity </p></td>
</tr>

<tr>
<td>project</td>
<td><a href="#string">string</a></td>
<td>optional</td>
<td><p>Project of machines to show the capacity </p></td>
</tr>

</tbody>
</table>





<h3 id="metalstack.admin.v2.PartitionServiceCapacityResponse">PartitionServiceCapacityResponse</h3>
<p>PartitionServiceCapacityResponse is the response payload for a partition capacity request</p>


<table class="field-table">
<thead>
<tr><td>Field</td><td>Type</td><td>Label</td><td>Description</td></tr>
</thead>
<tbody>

<tr>
<td>partition_capacity</td>
<td><a href="#metalstack.admin.v2.PartitionCapacity">PartitionCapacity</a></td>
<td>repeated</td>
<td><p>PartitionCapacity is a capacity report per partition </p></td>
</tr>

</tbody>
</table>





<h3 id="metalstack.admin.v2.PartitionServiceCreateRequest">PartitionServiceCreateRequest</h3>
<p>PartitionServiceCreateRequest is the request payload for a partition create request</p>

Expand Down
59 changes: 5 additions & 54 deletions go/client/token-persistent-funcs_test.go
Original file line number Diff line number Diff line change
@@ -1,77 +1,28 @@
package client_test

import (
"log/slog"
"net/http"
"net/http/httptest"
"os"
"path"
"testing"
"time"

"github.com/metal-stack/api/go/client"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/api/go/metalstack/api/v2/apiv2connect"
"github.com/stretchr/testify/require"
)

func TestNewFilesystemTokenPersiter(t *testing.T) {
var (
vs = &mockVersionService{}
ts = &mockTokenService{}
mux = http.NewServeMux()
)
tokenPath := path.Join(t.TempDir(), "token")

mux.Handle(apiv2connect.NewVersionServiceHandler(vs))
mux.Handle(apiv2connect.NewTokenServiceHandler(ts))
server := httptest.NewTLSServer(mux)
server.EnableHTTP2 = true
defer func() {
server.Close()
}()

tokenString, err := generateToken(1 * time.Second)
require.NoError(t, err)

log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))

tokenDir, err := os.MkdirTemp("/tmp", "token-")
require.NoError(t, err)
tokenPath := path.Join(tokenDir, "token")

_, err = os.OpenFile(tokenPath, os.O_RDONLY|os.O_CREATE, 0600)
_, err := os.OpenFile(tokenPath, os.O_RDONLY|os.O_CREATE, 0600)
require.NoError(t, err)

filesystemPersister, err := client.NewFilesystemTokenPersister(tokenPath)
require.NoError(t, err)

c, err := client.New(&client.DialConfig{
BaseURL: server.URL,
Token: tokenString,
Transport: server.Client().Transport,
TokenRenewal: &client.TokenRenewal{
PersistTokenFn: filesystemPersister,
},
Log: log,
})
require.NoError(t, err)
v, err := c.Apiv2().Version().Get(t.Context(), &apiv2.VersionServiceGetRequest{})
require.NoError(t, err)
require.NotNil(t, v)
require.Equal(t, "1.0", v.Version.Version)
require.False(t, ts.wasCalled)
require.Equal(t, tokenString, vs.token)
token := "a-token"

time.Sleep(2 * time.Second)
v, err = c.Apiv2().Version().Get(t.Context(), &apiv2.VersionServiceGetRequest{})
err = filesystemPersister(token)
require.NoError(t, err)
require.NotNil(t, v)
require.Equal(t, "1.0", v.Version.Version)
require.True(t, ts.wasCalled)
require.NotEqual(t, tokenString, vs.token, "token must have changed")

tokenBytes, err := os.ReadFile(tokenPath)
require.NoError(t, err)
require.Equal(t, string(tokenBytes), vs.token)

require.Equal(t, token, string(tokenBytes))
}
Loading
Loading