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
32 changes: 32 additions & 0 deletions ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (ec2 *EC2) query(params map[string]string, resp interface{}) error {
if r.StatusCode != 200 {
return buildError(r)
}

err = xml.NewDecoder(r.Body).Decode(resp)
return err
}
Expand Down Expand Up @@ -906,6 +907,37 @@ func (ec2 *EC2) Instances(instIds []string, filter *Filter) (resp *InstancesResp
return
}

// Response to a GetPasswordData request.
//
// If PasswordData is empty, then one of two conditions is likely: either the
// instance is not running Windows, or the password is not yet available. The
// API documentation suggests that the password should be available within 15
// minutes of launch.
//
// See http://goo.gl/7Dppx0 for more details.
type PasswordDataResponse struct {
RequestId string `xml:"requestId"`
InstanceId string `xml:"instanceId"`
Timestamp time.Time `xml:"timestamp"`
PasswordData string `xml:"passwordData"`
}

// GetPasswordData retrieves the encrypted administrator password for an
// instance running Windows. The password is encrypted using the key pair,
// so must be decrypted with the corresponding key pair file.
//
// See http://goo.gl/7Dppx0 for more details.
func (ec2 *EC2) GetPasswordData(instId string) (resp *PasswordDataResponse, err error) {
params := makeParams("GetPasswordData")
addParamsList(params, "InstanceId", []string{instId})
resp = &PasswordDataResponse{}
ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}

// ----------------------------------------------------------------------------
// Volume management

Expand Down
17 changes: 17 additions & 0 deletions ec2/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ec2_test

import (
"testing"
"time"

"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
Expand Down Expand Up @@ -124,6 +125,22 @@ func (s *S) TestRequestSpotInstancesErrorWithoutXML(c *C) {
c.Assert(ec2err.RequestId, Equals, "")
}

func (s *S) TestGetPasswordDataExample(c *C) {
testServer.Response(200, nil, GetPasswordDataResponseExample)

resp, err := s.ec2.GetPasswordData("i-2574e22a")

req := testServer.WaitRequest()

c.Assert(req.Form["InstanceId.1"], DeepEquals, []string{"i-2574e22a"})

c.Assert(err, IsNil)
c.Assert(resp.RequestId, Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE")
c.Assert(resp.InstanceId, Equals, "i-2574e22a")
c.Assert(resp.Timestamp, Equals, time.Date(2009, 10, 24, 15, 0, 0, 0, time.UTC))
c.Assert(resp.PasswordData, Equals, "TGludXggdmVyc2lvbiAyLjYuMTYteGVuVSAoYnVpbGRlckBwYXRjaGJhdC5hbWF6b25zYSkgKGdj")
}

func (s *S) TestRunInstancesExample(c *C) {
testServer.Response(200, nil, RunInstancesExample)

Expand Down
8 changes: 8 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,3 +1261,11 @@ var DeleteCustomerGatewayResponseExample = `
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<return>true</return>
</DeleteCustomerGatewayResponse>`

var GetPasswordDataResponseExample = `
<GetPasswordDataResponse xmlns="http://ec2.amazonaws.com/doc/2014-10-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<instanceId>i-2574e22a</instanceId>
<timestamp>2009-10-24T15:00:00.000Z</timestamp>
<passwordData>TGludXggdmVyc2lvbiAyLjYuMTYteGVuVSAoYnVpbGRlckBwYXRjaGJhdC5hbWF6b25zYSkgKGdj</passwordData>
</GetPasswordDataResponse>`