Skip to content

Commit

Permalink
Consolidate EBS and VPC tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bporter816 committed Jan 12, 2024
1 parent bca1cf6 commit 5a733b0
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 272 deletions.
52 changes: 52 additions & 0 deletions ebs_tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"github.com/bporter816/aws-tui/repo"
"github.com/bporter816/aws-tui/ui"
"github.com/bporter816/aws-tui/view"
)

type EBSTags struct {
*ui.Table
view.EBS
resourceId string
repo *repo.EC2
app *Application
}

func NewEBSTags(resourceId string, repo *repo.EC2, app *Application) *EBSTags {
e := &EBSTags{
Table: ui.NewTable([]string{
"KEY",
"VALUE",
}, 1, 0),
resourceId: resourceId,
repo: repo,
app: app,
}
return e
}

func (e EBSTags) GetLabels() []string {
return []string{e.resourceId, "Tags"}
}

func (e EBSTags) GetKeyActions() []KeyAction {
return []KeyAction{}
}

func (e EBSTags) Render() {
model, err := e.repo.ListTags(e.resourceId)
if err != nil {
panic(err)
}

var data [][]string
for _, v := range model {
data = append(data, []string{
v.Key,
v.Value,
})
}
e.SetData(data)
}
52 changes: 0 additions & 52 deletions ebs_volume_tags.go

This file was deleted.

2 changes: 1 addition & 1 deletion ebs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (e EBSVolumes) tagsHandler() {
if err != nil {
return
}
tagsView := NewEBSVolumeTags(id, e.repo, e.app)
tagsView := NewEBSTags(id, e.repo, e.app)
e.app.AddAndSwitch(tagsView)
}

Expand Down
60 changes: 0 additions & 60 deletions repo/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,46 +220,6 @@ func (e EC2) ListReservedInstances(filters []ec2Types.Filter) ([]model.EC2Reserv
return reservedInstances, nil
}

func (e EC2) ListVPCTags(vpcId string) (model.Tags, error) {
out, err := e.ec2Client.DescribeVpcs(
context.TODO(),
&ec2.DescribeVpcsInput{
VpcIds: []string{vpcId},
},
)
if err != nil {
return model.Tags{}, err
}
if len(out.Vpcs) != 1 {
return model.Tags{}, errors.New("should get exactly 1 vpc")
}
var tags model.Tags
for _, v := range out.Vpcs[0].Tags {
tags = append(tags, model.Tag{Key: *v.Key, Value: *v.Value})
}
return tags, nil
}

func (e EC2) ListSubnetTags(subnetId string) (model.Tags, error) {
out, err := e.ec2Client.DescribeSubnets(
context.TODO(),
&ec2.DescribeSubnetsInput{
SubnetIds: []string{subnetId},
},
)
if err != nil {
return model.Tags{}, err
}
if len(out.Subnets) != 1 {
return model.Tags{}, errors.New("should get exactly 1 subnet")
}
var tags model.Tags
for _, v := range out.Subnets[0].Tags {
tags = append(tags, model.Tag{Key: *v.Key, Value: *v.Value})
}
return tags, nil
}

func (e EC2) ListInternetGateways() ([]model.EC2InternetGateway, error) {
pg := ec2.NewDescribeInternetGatewaysPaginator(
e.ec2Client,
Expand Down Expand Up @@ -298,26 +258,6 @@ func (e EC2) ListInternetGatewayAttachments(internetGatewayId string) ([]model.E
return attachments, nil
}

func (e EC2) ListInternetGatewayTags(internetGatewayId string) (model.Tags, error) {
out, err := e.ec2Client.DescribeInternetGateways(
context.TODO(),
&ec2.DescribeInternetGatewaysInput{
InternetGatewayIds: []string{internetGatewayId},
},
)
if err != nil {
return model.Tags{}, err
}
if len(out.InternetGateways) != 1 {
return model.Tags{}, errors.New("should get exactly 1 internet gateway")
}
var tags model.Tags
for _, v := range out.InternetGateways[0].Tags {
tags = append(tags, model.Tag{Key: *v.Key, Value: *v.Value})
}
return tags, nil
}

func (e EC2) ListVolumes(filters []ec2Types.Filter) ([]model.EC2Volume, error) {
pg := ec2.NewDescribeVolumesPaginator(
e.ec2Client,
Expand Down
52 changes: 0 additions & 52 deletions vpc_internet_gateway_tags.go

This file was deleted.

2 changes: 1 addition & 1 deletion vpc_internet_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (e VPCInternetGateways) tagsHandler() {
if err != nil {
return
}
tagsView := NewVPCInternetGatewayTags(e.repo, internetGatewayId, e.app)
tagsView := NewVPCTags(e.repo, internetGatewayId, e.app)
e.app.AddAndSwitch(tagsView)
}

Expand Down
52 changes: 0 additions & 52 deletions vpc_subnet_tags.go

This file was deleted.

2 changes: 1 addition & 1 deletion vpc_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (e VPCSubnets) tagsHandler() {
if err != nil {
return
}
tagsView := NewVPCSubnetTags(e.repo, subnetId, e.app)
tagsView := NewVPCTags(e.repo, subnetId, e.app)
e.app.AddAndSwitch(tagsView)
}

Expand Down
52 changes: 52 additions & 0 deletions vpc_tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"github.com/bporter816/aws-tui/repo"
"github.com/bporter816/aws-tui/ui"
"github.com/bporter816/aws-tui/view"
)

type VPCTags struct {
*ui.Table
view.VPC
repo *repo.EC2
resourceId string
app *Application
}

func NewVPCTags(repo *repo.EC2, resourceId string, app *Application) *VPCTags {
e := &VPCTags{
Table: ui.NewTable([]string{
"KEY",
"VALUE",
}, 1, 0),
repo: repo,
resourceId: resourceId,
app: app,
}
return e
}

func (e VPCTags) GetLabels() []string {
return []string{e.resourceId, "Tags"}
}

func (e VPCTags) GetKeyActions() []KeyAction {
return []KeyAction{}
}

func (e VPCTags) Render() {
model, err := e.repo.ListTags(e.resourceId)
if err != nil {
panic(err)
}

var data [][]string
for _, v := range model {
data = append(data, []string{
v.Key,
v.Value,
})
}
e.SetData(data)
}
Loading

0 comments on commit 5a733b0

Please sign in to comment.