@@ -14,10 +14,6 @@ import (
1414 managerdb "github.com/spiffe/tornjak/pkg/manager/db"
1515)
1616
17- var (
18- jsonContentType string = "application/json"
19- )
20-
2117const (
2218 keyShowLen int = 40
2319 certShowLen int = 50
@@ -63,7 +59,7 @@ func copyHeader(dst, src http.Header) {
6359}
6460
6561// Returns a post proxy function for tornjak api, where path is the path from the base URL, i.e. "/api/entry/delete"
66- func (s * Server ) apiServerProxyFunc (apiPath string ) func (w http.ResponseWriter , r * http.Request ) {
62+ func (s * Server ) apiServerProxyFunc (apiPath string , apiMethod string ) func (w http.ResponseWriter , r * http.Request ) {
6763 return func (w http.ResponseWriter , r * http.Request ) {
6864 vars := mux .Vars (r )
6965 serverName := vars ["server" ]
@@ -111,7 +107,16 @@ func (s *Server) apiServerProxyFunc(apiPath string) func(w http.ResponseWriter,
111107 retError (w , emsg , http .StatusBadRequest )
112108 return
113109 }
114- resp , err := client .Post (strings .TrimSuffix (sinfo .Address , "/" )+ apiPath , jsonContentType , r .Body )
110+
111+ req , err := http .NewRequest (apiMethod , strings .TrimSuffix (sinfo .Address , "/" ) + apiPath , r .Body )
112+ if err != nil {
113+ emsg := fmt .Sprintf ("Error creating http request: %v" , err .Error ())
114+ retError (w , emsg , http .StatusBadRequest )
115+ return
116+ }
117+
118+
119+ resp , err := client .Do (req )
115120 if err != nil {
116121 emsg := fmt .Sprintf ("Error making api call to server: %v" , err .Error ())
117122 retError (w , emsg , http .StatusBadRequest )
@@ -180,27 +185,27 @@ func (s *Server) HandleRequests() {
180185 rtr .HandleFunc ("/manager-api/server/register" , corsHandler (s .serverRegister ))
181186
182187 // Entries
183- rtr .HandleFunc ("/manager-api/entry/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/entry/list" )))
184- rtr .HandleFunc ("/manager-api/entry/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/entry/delete" )))
185- rtr .HandleFunc ("/manager-api/entry/create/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/entry/create" )))
188+ rtr .HandleFunc ("/manager-api/entry/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/entries" , http . MethodGet )))
189+ rtr .HandleFunc ("/manager-api/entry/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/entries" , http . MethodDelete )))
190+ rtr .HandleFunc ("/manager-api/entry/create/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/entries" , http . MethodPost )))
186191
187192 // Agents
188- rtr .HandleFunc ("/manager-api/agent/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/agent/list" )))
189- rtr .HandleFunc ("/manager-api/agent/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/agent/delete" )))
190- rtr .HandleFunc ("/manager-api/agent/ban/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/agent/ ban" )))
191- rtr .HandleFunc ("/manager-api/agent/createjointoken/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/agent/createjointoken" )))
193+ rtr .HandleFunc ("/manager-api/agent/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/agents" , http . MethodGet )))
194+ rtr .HandleFunc ("/manager-api/agent/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/agents" , http . MethodDelete )))
195+ rtr .HandleFunc ("/manager-api/agent/ban/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/agents/ ban" , http . MethodPost )))
196+ rtr .HandleFunc ("/manager-api/agent/createjointoken/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/spire/agents/jointoken" , http . MethodPost )))
192197
193198 // Tornjak-specific
194- rtr .HandleFunc ("/manager-api/tornjak/serverinfo/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/serverinfo" )))
199+ rtr .HandleFunc ("/manager-api/tornjak/serverinfo/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/serverinfo" , http . MethodGet )))
195200 // Agents Selectors
196- rtr .HandleFunc ("/manager-api/tornjak/selectors/register/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/selectors/register" )))
197- rtr .HandleFunc ("/manager-api/tornjak/selectors/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/selectors/list" )))
198- rtr .HandleFunc ("/manager-api/tornjak/agents/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/agents/list" )))
201+ rtr .HandleFunc ("/manager-api/tornjak/selectors/register/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/selectors" , http . MethodPost )))
202+ rtr .HandleFunc ("/manager-api/tornjak/selectors/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/selectors" , http . MethodGet )))
203+ rtr .HandleFunc ("/manager-api/tornjak/agents/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/agents" , http . MethodGet )))
199204 // Agents Clusters
200- rtr .HandleFunc ("/manager-api/tornjak/clusters/create/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/clusters/create" )))
201- rtr .HandleFunc ("/manager-api/tornjak/clusters/edit/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/clusters/edit" )))
202- rtr .HandleFunc ("/manager-api/tornjak/clusters/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/clusters/list" )))
203- rtr .HandleFunc ("/manager-api/tornjak/clusters/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/tornjak/clusters/delete" )))
205+ rtr .HandleFunc ("/manager-api/tornjak/clusters/create/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/clusters" , http . MethodPost )))
206+ rtr .HandleFunc ("/manager-api/tornjak/clusters/edit/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/clusters" , http . MethodPatch )))
207+ rtr .HandleFunc ("/manager-api/tornjak/clusters/list/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/clusters" , http . MethodGet )))
208+ rtr .HandleFunc ("/manager-api/tornjak/clusters/delete/{server:.*}" , corsHandler (s .apiServerProxyFunc ("/api/v1/ tornjak/clusters" , http . MethodDelete )))
204209
205210 //http.HandleFunc("/manager-api/get-server-info", s.agentList)
206211 //http.HandleFunc("/manager-api/agent/list/:id", s.agentList)
0 commit comments