From 3a6a750972c53956ec8a8fbd9f7bf4efea416a5f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 May 2018 08:53:33 -0700 Subject: [PATCH] api: IntentionUpdate API --- api/connect_intention.go | 17 +++++++++++++++++ api/connect_intention_test.go | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/api/connect_intention.go b/api/connect_intention.go index 3d10b219c7..eb79731004 100644 --- a/api/connect_intention.go +++ b/api/connect_intention.go @@ -273,3 +273,20 @@ func (c *Connect) IntentionCreate(ixn *Intention, q *WriteOptions) (string, *Wri } return out.ID, wm, nil } + +// IntentionUpdate will update an existing intention. The ID in the given +// structure must be non-empty. +func (c *Connect) IntentionUpdate(ixn *Intention, q *WriteOptions) (*WriteMeta, error) { + r := c.c.newRequest("PUT", "/v1/connect/intentions/"+ixn.ID) + r.setWriteOptions(q) + r.obj = ixn + rtt, resp, err := requireOK(c.c.doRequest(r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + wm := &WriteMeta{} + wm.RequestTime = rtt + return wm, nil +} diff --git a/api/connect_intention_test.go b/api/connect_intention_test.go index 436d0de0cb..83f86d3ab1 100644 --- a/api/connect_intention_test.go +++ b/api/connect_intention_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestAPI_ConnectIntentionCreateListGetDelete(t *testing.T) { +func TestAPI_ConnectIntentionCreateListGetUpdateDelete(t *testing.T) { t.Parallel() require := require.New(t) @@ -39,6 +39,18 @@ func TestAPI_ConnectIntentionCreateListGetDelete(t *testing.T) { require.Nil(err) require.Equal(ixn, actual) + // Update it + ixn.SourceNS = ixn.SourceNS + "-different" + _, err = connect.IntentionUpdate(ixn, nil) + require.NoError(err) + + // Get it + actual, _, err = connect.IntentionGet(id, nil) + require.NoError(err) + ixn.UpdatedAt = actual.UpdatedAt + ixn.ModifyIndex = actual.ModifyIndex + require.Equal(ixn, actual) + // Delete it _, err = connect.IntentionDelete(id, nil) require.Nil(err)