Skip to content
This repository was archived by the owner on Dec 19, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,11 @@ type KeyPairsResp struct {
Keys []KeyPair `xml:"keySet>item"`
}

type DescribeKeyPairsResp struct {
RequestId string `xml:"requestId"`
KeyPairs []KeyPair `xml:"keySet>item"`
}

type CreateKeyPairResp struct {
RequestId string `xml:"requestId"`
KeyName string `xml:"keyName"`
Expand All @@ -1772,6 +1777,18 @@ type ImportKeyPairResponse struct {
KeyFingerprint string `xml:"keyFingerprint"`
}

// DescribeKeyPairs returns all the key pairs for the current region
//
// See http://goo.gl/pTMbH0
func (ec2 *EC2) DescribeKeyPairs() (resp *DescribeKeyPairsResp, err error) {
params := makeParams("DescribeKeyPairs")

resp = &DescribeKeyPairsResp{}
err = ec2.query(params, resp)

return
}

// CreateKeyPair creates a new key pair and returns the private key contents.
//
// See http://goo.gl/0S6hV
Expand Down
21 changes: 20 additions & 1 deletion ec2/ec2_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ec2_test

import (
"testing"

"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/testutil"
. "github.com/motain/gocheck"
"testing"
)

func Test(t *testing.T) {
Expand Down Expand Up @@ -694,6 +695,24 @@ func (s *S) TestCopyImageExample(c *C) {
c.Assert(resp.RequestId, Equals, "60bc441d-fa2c-494d-b155-5d6a3EXAMPLE")
}

func (s *S) TestDescribeKeyPairsExample(c *C) {
testServer.Response(200, nil, DescribeKeyPairsExample)

resp, err := s.ec2.DescribeKeyPairs()

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], DeepEquals, []string{"DescribeKeyPairs"})
c.Assert(err, IsNil)

k0 := resp.KeyPairs[0]
c.Assert(k0.Name, Equals, "my-key-pair")
c.Assert(k0.Fingerprint, Equals, "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f")

k1 := resp.KeyPairs[1]
c.Assert(k1.Name, Equals, "my-other-key-pair")
c.Assert(k1.Fingerprint, Equals, "some-fingerprint-value")
}

func (s *S) TestCreateKeyPairExample(c *C) {
testServer.Response(200, nil, CreateKeyPairExample)

Expand Down
16 changes: 16 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ var CopyImageExample = `
</CopyImageResponse>
`

var DescribeKeyPairsExample = `
<DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<keySet>
<item>
<keyName>my-key-pair</keyName>
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
</item>
<item>
<keyName>my-other-key-pair</keyName>
<keyFingerprint>some-fingerprint-value</keyFingerprint>
</item>
</keySet>
</DescribeKeyPairsResponse>
`

var CreateKeyPairExample = `
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
Expand Down