Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann authored Aug 25, 2023
2 parents bd90c7e + ab396a4 commit 49973c6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pkg/types/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ func (p Properties) SetTagWithPrefix(prefix string, tagKey *string, tagValue int
return p.Set(keyStr, tagValue)
}

func (p Properties) SetPropertyWithPrefix(prefix string, propertyKey string, propertyValue interface{}) Properties {
keyStr := strings.TrimSpace(propertyKey)
prefix = strings.TrimSpace(prefix)

if keyStr == "" {
return p
}

if prefix != "" {
keyStr = fmt.Sprintf("%s:%s", prefix, keyStr)
}

return p.Set(keyStr, propertyValue)
}

func (p Properties) Get(key string) string {
value, ok := p[key]
if !ok {
Expand Down
38 changes: 38 additions & 0 deletions pkg/types/properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,41 @@ func TestPropertiesSetTagWithPrefix(t *testing.T) {
})
}
}

func TestPropertiesSetPropertiesWithPrefix(t *testing.T) {
cases := []struct {
name string
prefix string
key string
value interface{}
want string
}{
{
name: "empty",
prefix: "",
key: "OwnerID",
value: aws.String("123456789012"),
want: `[OwnerID: "123456789012"]`,
},
{
name: "nonempty",
prefix: "igw",
key: "OwnerID",
value: aws.String("123456789012"),
want: `[igw:OwnerID: "123456789012"]`,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
p := types.NewProperties()

p.SetPropertyWithPrefix(tc.prefix, tc.key, tc.value)
have := p.String()

if tc.want != have {
t.Errorf("'%s' != '%s'", tc.want, have)
}
})
}
}
3 changes: 3 additions & 0 deletions resources/ec2-dhcp-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type EC2DHCPOption struct {
id *string
tags []*ec2.Tag
defaultVPC bool
ownerID *string
}

func init() {
Expand All @@ -37,6 +38,7 @@ func ListEC2DHCPOptions(sess *session.Session) ([]Resource, error) {
id: out.DhcpOptionsId,
tags: out.Tags,
defaultVPC: defVpcDhcpOptsId == *out.DhcpOptionsId,
ownerID: out.OwnerId,
})
}

Expand All @@ -62,6 +64,7 @@ func (e *EC2DHCPOption) Properties() types.Properties {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("DefaultVPC", e.defaultVPC)
properties.Set("OwnerID", e.ownerID)
return properties
}

Expand Down
6 changes: 6 additions & 0 deletions resources/ec2-internet-gateway-attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
type EC2InternetGatewayAttachment struct {
svc *ec2.EC2
vpcId *string
vpcOwnerID *string
vpcTags []*ec2.Tag
igwId *string
igwOwnerID *string
igwTags []*ec2.Tag
defaultVPC bool
}
Expand Down Expand Up @@ -50,8 +52,10 @@ func ListEC2InternetGatewayAttachments(sess *session.Session) ([]Resource, error
resources = append(resources, &EC2InternetGatewayAttachment{
svc: svc,
vpcId: vpc.VpcId,
vpcOwnerID: vpc.OwnerId,
vpcTags: vpc.Tags,
igwId: igw.InternetGatewayId,
igwOwnerID: igw.OwnerId,
igwTags: igw.Tags,
defaultVPC: *vpc.IsDefault,
})
Expand Down Expand Up @@ -84,6 +88,8 @@ func (e *EC2InternetGatewayAttachment) Properties() types.Properties {
properties.SetTagWithPrefix("vpc", tagValue.Key, tagValue.Value)
}
properties.Set("DefaultVPC", e.defaultVPC)
properties.SetPropertyWithPrefix("vpc", "OwnerID", e.vpcOwnerID)
properties.SetPropertyWithPrefix("igw", "OwnerID", e.igwOwnerID)
return properties
}

Expand Down
3 changes: 3 additions & 0 deletions resources/ec2-route-tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type EC2RouteTable struct {
svc *ec2.EC2
routeTable *ec2.RouteTable
defaultVPC bool
ownerID *string
}

func init() {
Expand All @@ -37,6 +38,7 @@ func ListEC2RouteTables(sess *session.Session) ([]Resource, error) {
svc: svc,
routeTable: out,
defaultVPC: defVpcId == *out.VpcId,
ownerID: out.OwnerId,
})
}

Expand Down Expand Up @@ -72,6 +74,7 @@ func (e *EC2RouteTable) Properties() types.Properties {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("DefaultVPC", e.defaultVPC)
properties.Set("OwnerID", e.ownerID)
return properties
}

Expand Down
2 changes: 1 addition & 1 deletion resources/iam-instance-profile-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (e *IAMInstanceProfileRole) Remove() error {
}

func (e *IAMInstanceProfileRole) String() string {
return fmt.Sprintf("%s -> %s", *e.profile.InstanceProfileName, e.role)
return fmt.Sprintf("%s -> %s", *e.profile.InstanceProfileName, *e.role.RoleName)
}

func (e *IAMInstanceProfileRole) Properties() types.Properties {
Expand Down

0 comments on commit 49973c6

Please sign in to comment.