From 25d9ffae816bec572d15c630b0a7fe0114c28562 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Wed, 28 Aug 2024 14:08:09 -0600 Subject: [PATCH] feat(ec2-key-pair): add key type and create time properties --- .../{ec2-key-pairs.go => ec2-key-pair.go} | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) rename resources/{ec2-key-pairs.go => ec2-key-pair.go} (66%) diff --git a/resources/ec2-key-pairs.go b/resources/ec2-key-pair.go similarity index 66% rename from resources/ec2-key-pairs.go rename to resources/ec2-key-pair.go index cdf71565..3d46c0c2 100644 --- a/resources/ec2-key-pairs.go +++ b/resources/ec2-key-pair.go @@ -2,6 +2,7 @@ package resources import ( "context" + "time" "github.com/aws/aws-sdk-go/service/ec2" @@ -37,9 +38,11 @@ func (l *EC2KeyPairLister) List(_ context.Context, o interface{}) ([]resource.Re resources := make([]resource.Resource, 0) for _, out := range resp.KeyPairs { resources = append(resources, &EC2KeyPair{ - svc: svc, - name: *out.KeyName, - tags: out.Tags, + svc: svc, + Name: out.KeyName, + Tags: out.Tags, + KeyType: out.KeyType, + CreateTime: out.CreateTime, }) } @@ -47,17 +50,19 @@ func (l *EC2KeyPairLister) List(_ context.Context, o interface{}) ([]resource.Re } type EC2KeyPair struct { - svc *ec2.EC2 - name string - tags []*ec2.Tag + svc *ec2.EC2 + Name *string + Tags []*ec2.Tag + KeyType *string + CreateTime *time.Time } -func (e *EC2KeyPair) Remove(_ context.Context) error { +func (r *EC2KeyPair) Remove(_ context.Context) error { params := &ec2.DeleteKeyPairInput{ - KeyName: &e.name, + KeyName: r.Name, } - _, err := e.svc.DeleteKeyPair(params) + _, err := r.svc.DeleteKeyPair(params) if err != nil { return err } @@ -65,17 +70,10 @@ func (e *EC2KeyPair) Remove(_ context.Context) error { return nil } -func (e *EC2KeyPair) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("Name", e.name) - - for _, tag := range e.tags { - properties.SetTag(tag.Key, tag.Value) - } - - return properties +func (r *EC2KeyPair) Properties() types.Properties { + return types.NewPropertiesFromStruct(r) } -func (e *EC2KeyPair) String() string { - return e.name +func (r *EC2KeyPair) String() string { + return *r.Name }