mirror of
https://github.com/status-im/consul.git
synced 2025-01-24 12:40:17 +00:00
agent: PUT /v1/connect/intentions/:id
This commit is contained in:
parent
faeb583162
commit
dca483b4a2
@ -76,7 +76,7 @@ func (s *HTTPServer) IntentionSpecific(resp http.ResponseWriter, req *http.Reque
|
|||||||
return s.IntentionSpecificGet(id, resp, req)
|
return s.IntentionSpecificGet(id, resp, req)
|
||||||
|
|
||||||
case "PUT":
|
case "PUT":
|
||||||
panic("TODO")
|
return s.IntentionSpecificUpdate(id, resp, req)
|
||||||
|
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
return s.IntentionSpecificDelete(id, resp, req)
|
return s.IntentionSpecificDelete(id, resp, req)
|
||||||
@ -113,6 +113,33 @@ func (s *HTTPServer) IntentionSpecificGet(id string, resp http.ResponseWriter, r
|
|||||||
return reply.Intentions[0], nil
|
return reply.Intentions[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PUT /v1/connect/intentions/:id
|
||||||
|
func (s *HTTPServer) IntentionSpecificUpdate(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
// Method is tested in IntentionEndpoint
|
||||||
|
|
||||||
|
args := structs.IntentionRequest{
|
||||||
|
Op: structs.IntentionOpUpdate,
|
||||||
|
}
|
||||||
|
s.parseDC(req, &args.Datacenter)
|
||||||
|
s.parseToken(req, &args.Token)
|
||||||
|
if err := decodeBody(req, &args.Intention, nil); err != nil {
|
||||||
|
resp.WriteHeader(http.StatusBadRequest)
|
||||||
|
fmt.Fprintf(resp, "Request decode failed: %v", err)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the ID from the URL
|
||||||
|
args.Intention.ID = id
|
||||||
|
|
||||||
|
var reply string
|
||||||
|
if err := s.agent.RPC("Intention.Apply", &args, &reply); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// DELETE /v1/connect/intentions/:id
|
// DELETE /v1/connect/intentions/:id
|
||||||
func (s *HTTPServer) IntentionSpecificDelete(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) IntentionSpecificDelete(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
// Method is tested in IntentionEndpoint
|
// Method is tested in IntentionEndpoint
|
||||||
|
@ -154,6 +154,61 @@ func TestIntentionsSpecificGet_good(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIntentionsSpecificUpdate_good(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
a := NewTestAgent(t.Name(), "")
|
||||||
|
defer a.Shutdown()
|
||||||
|
|
||||||
|
// The intention
|
||||||
|
ixn := &structs.Intention{SourceName: "foo"}
|
||||||
|
|
||||||
|
// Create an intention directly
|
||||||
|
var reply string
|
||||||
|
{
|
||||||
|
req := structs.IntentionRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
Op: structs.IntentionOpCreate,
|
||||||
|
Intention: ixn,
|
||||||
|
}
|
||||||
|
if err := a.RPC("Intention.Apply", &req, &reply); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the intention
|
||||||
|
ixn.ID = "bogus"
|
||||||
|
ixn.SourceName = "bar"
|
||||||
|
req, _ := http.NewRequest("PUT", fmt.Sprintf("/v1/connect/intentions/%s", reply), jsonReader(ixn))
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
obj, err := a.srv.IntentionSpecific(resp, req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
if obj != nil {
|
||||||
|
t.Fatalf("obj should be nil: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the value
|
||||||
|
{
|
||||||
|
req := &structs.IntentionQueryRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
IntentionID: reply,
|
||||||
|
}
|
||||||
|
var resp structs.IndexedIntentions
|
||||||
|
if err := a.RPC("Intention.Get", req, &resp); err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
if len(resp.Intentions) != 1 {
|
||||||
|
t.Fatalf("bad: %v", resp)
|
||||||
|
}
|
||||||
|
actual := resp.Intentions[0]
|
||||||
|
if actual.SourceName != "bar" {
|
||||||
|
t.Fatalf("bad: %#v", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIntentionsSpecificDelete_good(t *testing.T) {
|
func TestIntentionsSpecificDelete_good(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user