feature-21, ajoute de la gestion des subnets #24

Manually merged
nicolas.boufideline merged 44 commits from feature-21 into main 2026-04-26 14:16:57 +00:00
2 changed files with 35 additions and 2 deletions
Showing only changes of commit 77cf180b10 - Show all commits

f-21: api: make vpc get

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
GnomeZworc 2026-04-23 22:29:43 +02:00
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632

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) {

View file

@ -3,8 +3,10 @@ package agentapi
import (
"encoding/json"
"net/http"
"strings"
"git.g3e.fr/syonad/two/internal/dispatcher"
"git.g3e.fr/syonad/two/pkg/db/kv"
)
func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
@ -20,8 +22,32 @@ func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) listVpcs(w http.ResponseWriter, _ *http.Request) {
entries, err := kv.ListByPrefix(s.db, "vpc/")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(ErrorResponse{Error: "failed to list vpcs"})
return
}
vpcs := make(map[string]*VPC)
for key, value := range entries {
parts := strings.Split(key, "/")
if len(parts) != 3 {
continue
}
name := parts[1]
if _, ok := vpcs[name]; !ok {
vpcs[name] = &VPC{Name: name}
}
if parts[2] == "state" {
vpcs[name].State = value
}
}
result := make([]VPC, 0, len(vpcs))
for _, v := range vpcs {
result = append(result, *v)
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode([]VPC{})
json.NewEncoder(w).Encode(result)
}
func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {