f-21: api: make vpc get

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-23 22:29:43 +02:00
commit 77cf180b10
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 35 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"strings"
"git.g3e.fr/syonad/two/internal/dispatcher"
"git.g3e.fr/syonad/two/pkg/db/kv"
)
func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
@ -28,8 +29,14 @@ func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
state, err := kv.GetFromDB(s.db, "vpc/"+name+"/state")
if err != nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(ErrorResponse{Error: "vpc not found"})
return
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(VPC{Name: name, State: "created"})
json.NewEncoder(w).Encode(VPC{Name: name, State: state})
}
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {