-
Notifications
You must be signed in to change notification settings - Fork 22
/
key_pair.go
48 lines (38 loc) · 833 Bytes
/
key_pair.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ec2
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
awsec2 "github.com/aws/aws-sdk-go/service/ec2"
)
type KeyPair struct {
client keyPairsClient
name *string
identifier string
rtype string
}
func NewKeyPair(client keyPairsClient, name *string) KeyPair {
return KeyPair{
client: client,
name: name,
identifier: *name,
rtype: "EC2 Key Pair",
}
}
func (k KeyPair) Delete() error {
input := &awsec2.DeleteKeyPairInput{KeyName: k.name}
_, err := k.client.DeleteKeyPair(input)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "InvalidKeyPair.NotFound" {
return nil
}
return fmt.Errorf("Delete: %s", err)
}
return nil
}
func (k KeyPair) Name() string {
return k.identifier
}
func (k KeyPair) Type() string {
return k.rtype
}