From 388114d53664ed24ea1ec9b3f22c7e9151ac41db Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Sat, 9 Aug 2025 18:30:33 +0200 Subject: [PATCH] feat: missing endpoints --- internal/driver/create.go | 9 ++++++++- internal/driver/get.go | 29 +++++++++++++++++++++++++++++ internal/driver/list.go | 22 ++++++++++++++++++++++ main.go | 8 ++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 internal/driver/get.go create mode 100644 internal/driver/list.go diff --git a/internal/driver/create.go b/internal/driver/create.go index a25ed25..7e46492 100644 --- a/internal/driver/create.go +++ b/internal/driver/create.go @@ -14,6 +14,7 @@ func Create(w http.ResponseWriter, r *http.Request) { var req struct { Name string + Opts map[string]string `json:"Opts,omitempty"` } _ = json.NewDecoder(r.Body).Decode(&req) @@ -23,6 +24,12 @@ func Create(w http.ResponseWriter, r *http.Request) { return } + response := map[string]string{ + "Name": req.Name, + "Mountpoint": volPath, + "Err": "", + } + volumes[req.Name] = Volume{Name: req.Name, Path: volPath} - _ = json.NewEncoder(w).Encode(map[string]string{"Err": ""}) + _ = json.NewEncoder(w).Encode(response) } diff --git a/internal/driver/get.go b/internal/driver/get.go new file mode 100644 index 0000000..725f27d --- /dev/null +++ b/internal/driver/get.go @@ -0,0 +1,29 @@ +package driver + +import ( + "encoding/json" + "log" + "net/http" +) + +func Get(w http.ResponseWriter, r *http.Request) { + log.Printf("Received get request: %s", r.URL.Path) + + var req struct { + Name string + } + _ = json.NewDecoder(r.Body).Decode(&req) + + vol := volumes[req.Name] + + response := map[string]any{ + "Volume": map[string]any{ + "Name": vol.Name, + "Mountpoint": vol.Path, + "Status": map[string]string{}, + }, + "Err": "", + } + + _ = json.NewEncoder(w).Encode(response) +} diff --git a/internal/driver/list.go b/internal/driver/list.go new file mode 100644 index 0000000..0523ba4 --- /dev/null +++ b/internal/driver/list.go @@ -0,0 +1,22 @@ +package driver + +import ( + "encoding/json" + "log" + "net/http" +) + +func List(w http.ResponseWriter, r *http.Request) { + log.Printf("Received list request: %s", r.URL.Path) + + var vols []map[string]string + for _, v := range volumes { + vols = append(vols, map[string]string{ + "Name": v.Name, + }) + } + json.NewEncoder(w).Encode(map[string]interface{}{ + "Volumes": vols, + "Err": "", + }) +} diff --git a/main.go b/main.go index 97d537b..b887f56 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,14 @@ func main() { http.HandleFunc("/VolumeDriver.Mount", driver.Mount) http.HandleFunc("/VolumeDriver.Unmount", driver.Unmount) http.HandleFunc("/VolumeDriver.Path", driver.Path) + http.HandleFunc("/VolumeDriver.Get", driver.Get) + http.HandleFunc("/VolumeDriver.List", driver.List) + + // Catch all other paths to return an error + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + log.Printf("Received unknown request: %s", r.URL.Path) + http.Error(w, "Not Found", http.StatusNotFound) + }) listener, err := net.Listen("unix", socketPath) if err != nil {