Skip to content

Commit

Permalink
aws-dump: Added ec2:key-pairs report
Browse files Browse the repository at this point in the history
  • Loading branch information
hamstah committed Jul 28, 2019
1 parent 0b9fe3b commit 2ac56f7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aws/dump/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
"images": EC2ListImages,
"instances": EC2ListInstances,
"nat-gateways": EC2ListNATGateways,
"key-pairs": EC2ListKeyPairs,
},
}
)
Expand Down Expand Up @@ -208,3 +209,27 @@ func EC2ListNATGateways(session *Session) *ReportResult {

return &ReportResult{resources, err}
}

func EC2ListKeyPairs(session *Session) *ReportResult {
client := ec2.New(session.Session, session.Config)

keypairs := []Resource{}

res, err := client.DescribeKeyPairs(&ec2.DescribeKeyPairsInput{})
if err != nil {
return &ReportResult{nil, err}
}

for _, keypair := range res.KeyPairs {
keypairs = append(keypairs, Resource{
ID: *keypair.KeyName,
Service: "ec2",
Type: "key-pair",
AccountID: session.AccountID,
Region: *session.Config.Region,
Metadata: structs.Map(keypair),
})
}

return &ReportResult{keypairs, err}
}

0 comments on commit 2ac56f7

Please sign in to comment.