api: IntentionUpdate API

This commit is contained in:
Mitchell Hashimoto 2018-05-16 08:53:33 -07:00
parent f03fa81e6a
commit a316ba7f39
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 30 additions and 1 deletions

View File

@ -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
}

View File

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