Skip to content

Commit

Permalink
feat(ec2-key-pair): add key type and create time properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Aug 28, 2024
1 parent e64fc94 commit 25d9ffa
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions resources/ec2-key-pairs.go → resources/ec2-key-pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"time"

"github.com/aws/aws-sdk-go/service/ec2"

Expand Down Expand Up @@ -37,45 +38,42 @@ 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,
})
}

return resources, nil
}

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
}

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
}

0 comments on commit 25d9ffa

Please sign in to comment.