Compare commits
No commits in common. "6dd21a465dc765c1aae36b76cc9cef0387936eee" and "b0c73b29522bdf6660ea1de898ee62fe9d4c7e25" have entirely different histories.
6dd21a465d
...
b0c73b2952
4 changed files with 10 additions and 31 deletions
|
|
@ -35,7 +35,7 @@ func main() {
|
|||
apiAddr := fmt.Sprintf("%s:%d", cfg.Api.Address, cfg.Api.Port)
|
||||
promAddr := fmt.Sprintf("%s:%d", cfg.Prometheus.Address, cfg.Prometheus.Port)
|
||||
|
||||
go agentapi.New(q, db).Start(apiAddr)
|
||||
go agentapi.New(q).Start(apiAddr)
|
||||
go promserver.Start(promAddr, registry)
|
||||
|
||||
select {}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,14 @@ import (
|
|||
"net/http"
|
||||
|
||||
"git.g3e.fr/syonad/two/pkg/worker"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
queue *worker.Queue
|
||||
db *badger.DB
|
||||
}
|
||||
|
||||
func New(queue *worker.Queue, db *badger.DB) *Server {
|
||||
return &Server{queue: queue, db: db}
|
||||
func New(queue *worker.Queue) *Server {
|
||||
return &Server{queue: queue}
|
||||
}
|
||||
|
||||
func (s *Server) Start(address string) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,8 @@ package agentapi
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/vpc"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
)
|
||||
|
||||
func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -30,23 +25,14 @@ func (s *Server) VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) getVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
||||
func (s *Server) getVpc(w http.ResponseWriter, r *http.Request, name string) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(VPC{Name: name, State: "created"})
|
||||
}
|
||||
|
||||
func (s *Server) deleteVpc(w http.ResponseWriter, _ *http.Request, name string) {
|
||||
func (s *Server) deleteVpc(w http.ResponseWriter, r *http.Request, name string) {
|
||||
s.queue.Submit(func() {
|
||||
kv.AddInDB(s.db, "vpc/"+name+"/state", "deleting")
|
||||
if err := vpc.DeleteVPC(s.db, name); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if state, err := kv.GetFromDB(s.db, "vpc/"+name+"/state"); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
} else if state == "deleted" {
|
||||
kv.DeleteInDB(s.db, "vpc/"+name)
|
||||
}
|
||||
destroyVpc(name)
|
||||
})
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
json.NewEncoder(w).Encode(VPC{Name: name, State: "deleting"})
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@ package agentapi
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/vpc"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
)
|
||||
|
||||
func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -21,7 +17,7 @@ func (s *Server) VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Server) listVpcs(w http.ResponseWriter, _ *http.Request) {
|
||||
func (s *Server) listVpcs(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode([]VPC{})
|
||||
}
|
||||
|
|
@ -39,11 +35,10 @@ func (s *Server) postVpc(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
s.queue.Submit(func() {
|
||||
kv.AddInDB(s.db, "vpc/"+req.Name+"/state", "creating")
|
||||
if err := vpc.CreateVPC(s.db, req.Name); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
createVpc(req.Name)
|
||||
})
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
json.NewEncoder(w).Encode(VPC{Name: req.Name, State: "creating"})
|
||||
}
|
||||
|
||||
func createVpc(name string) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue