Skip to content

Commit 169d025

Browse files
kvapsclaude
andcommitted
feat(rest): external-file endpoints stub
LIST returns []; GET /{path} returns 404. Cozystack manages host config via Talos system extensions and kubelet, not via LINSTOR's external-file delivery; the endpoints exist so linstor CLI doesn't 404 on `external-file list`. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 558d80f commit 169d025

4 files changed

Lines changed: 106 additions & 1 deletion

File tree

PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Full scope list lives in `docs/csi-api-surface.md` (to be created in Phase 1).
260260
- [x] DRBD proxy enable/disable/configure: 501 Not Implemented stubs (`/v1/resource-definitions/{rd}/drbd-proxy*`). Cozystack-style clusters run flat L2 so DRBD-9's native protocol suffices; proxy isn't needed. Endpoints exist so `linstor drbd-proxy *` returns a deterministic error.
261261
- [ ] DRBD options: full set from `drbdoptions.json`
262262
- [x] file storage provider (`pkg/storage/file`): FILE / FILE_THIN behind same Provider seam — fallocate (thick) / truncate (thin) for create, statfs(2) for pool capacity, snapshots intentionally unsupported (caller routes to LVM/ZFS instead). 9 contract tests.
263-
- [ ] External-file management
263+
- [x] External-file management stub (`/v1/files` LIST returns []; GET /{path} → 404). Cozystack manages host config via Talos extensions; the endpoints exist so `linstor external-file list` doesn't 404.
264264

265265
### Phase 7 — Cluster operations + admin
266266

pkg/rest/external_files.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2026 Cozystack contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package rest
18+
19+
import (
20+
"net/http"
21+
)
22+
23+
// registerExternalFiles wires linstor's external-file endpoints. We
24+
// don't yet ship arbitrary files to satellites — cozystack manages
25+
// host config via Talos extensions / kubelet — but the `external-file
26+
// list` CLI hits these on startup.
27+
//
28+
// LIST → []. GET on a single path → 404. Wider implementation lands
29+
// when a real per-cluster need shows up.
30+
func (s *Server) registerExternalFiles(mux *http.ServeMux) {
31+
mux.HandleFunc("GET /v1/files", handleExternalFilesList)
32+
mux.HandleFunc("GET /v1/files/{path...}", handleExternalFileGet)
33+
}
34+
35+
func handleExternalFilesList(w http.ResponseWriter, _ *http.Request) {
36+
writeJSON(w, http.StatusOK, []map[string]string{})
37+
}
38+
39+
func handleExternalFileGet(w http.ResponseWriter, _ *http.Request) {
40+
writeError(w, http.StatusNotFound, "external file not found")
41+
}

pkg/rest/external_files_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2026 Cozystack contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package rest
18+
19+
import (
20+
"encoding/json"
21+
"net/http"
22+
"testing"
23+
24+
"github.com/cozystack/blockstor/pkg/store"
25+
)
26+
27+
// TestExternalFilesEmpty: an empty cluster returns [], not 404. CLI's
28+
// `external-file list` calls this on every invocation.
29+
func TestExternalFilesEmpty(t *testing.T) {
30+
base, stop := startServerWithStore(t, store.NewInMemory())
31+
defer stop()
32+
33+
resp := httpGet(t, base+"/v1/files")
34+
defer func() { _ = resp.Body.Close() }()
35+
36+
if resp.StatusCode != http.StatusOK {
37+
t.Fatalf("status: got %d", resp.StatusCode)
38+
}
39+
40+
var got []any
41+
42+
err := json.NewDecoder(resp.Body).Decode(&got)
43+
if err != nil {
44+
t.Fatalf("decode: %v", err)
45+
}
46+
47+
if len(got) != 0 {
48+
t.Errorf("expected empty list; got %d", len(got))
49+
}
50+
}
51+
52+
// TestExternalFileGetMissing: 404 on unknown path.
53+
func TestExternalFileGetMissing(t *testing.T) {
54+
base, stop := startServerWithStore(t, store.NewInMemory())
55+
defer stop()
56+
57+
resp := httpGet(t, base+"/v1/files/some-path")
58+
_ = resp.Body.Close()
59+
60+
if resp.StatusCode != http.StatusNotFound {
61+
t.Errorf("status: got %d, want 404", resp.StatusCode)
62+
}
63+
}

pkg/rest/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (s *Server) Start(ctx context.Context) error {
7676
s.registerEncryption(mux)
7777
s.registerNodeLifecycle(mux)
7878
s.registerDRBDProxy(mux)
79+
s.registerExternalFiles(mux)
7980

8081
srv := &http.Server{
8182
Addr: s.Addr,

0 commit comments

Comments
 (0)