-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display all VPCs according to the region in the UI
- Loading branch information
1 parent
11579e9
commit d2ba54d
Showing
8 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dao | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/one2nc/cloud-lens/internal" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
type VPC struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (v *VPC) Init(ctx context.Context) { | ||
v.ctx = ctx | ||
} | ||
|
||
func (v *VPC) List(ctx context.Context) ([]Object, error) { | ||
sess, ok := ctx.Value(internal.KeySession).(*session.Session) | ||
if !ok { | ||
log.Err(fmt.Errorf("conversion err: Expected session.session but got %v", sess)) | ||
} | ||
vpcs := aws.GetVPCs(*sess) | ||
objs := make([]Object, len(vpcs)) | ||
for i, obj := range vpcs { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (ei *VPC) Get(ctx context.Context, path string) (Object, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/derailed/tview" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
) | ||
|
||
type VPC struct { | ||
} | ||
|
||
func (v VPC) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "VPC-Id", SortIndicatorIdx: 4, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Owner-Id", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Cidr Block", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Instance Tenancy", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "VPC-State", SortIndicatorIdx: 4, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
} | ||
} | ||
|
||
func (v VPC) Render(o interface{}, ns string, row *Row) error { | ||
vpcResp, ok := o.(aws.VpcResp) | ||
if !ok { | ||
return fmt.Errorf("expected vpc, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
vpcResp.VpcId, | ||
vpcResp.OwnerId, | ||
vpcResp.CidrBlock, | ||
vpcResp.InstanceTenancy, | ||
vpcResp.State, | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package view | ||
|
||
import ( | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/one2nc/cloud-lens/internal/ui" | ||
) | ||
|
||
type VPC struct { | ||
ResourceViewer | ||
} | ||
|
||
// NewPod returns a new viewer. | ||
func NewVPC(resource string) ResourceViewer { | ||
var v VPC | ||
v.ResourceViewer = NewBrowser(resource) | ||
v.AddBindKeysFn(v.bindKeys) | ||
return &v | ||
} | ||
|
||
func (v *VPC) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
ui.KeyShiftI: ui.NewKeyAction("Sort VPC-Id", v.GetTable().SortColCmd("VPC-Id", true), true), | ||
ui.KeyShiftS: ui.NewKeyAction("Sort VPC-State", v.GetTable().SortColCmd("VPC-State", true), true), | ||
tcell.KeyEscape: ui.NewKeyAction("Back", v.App().PrevCmd, false), | ||
}) | ||
} |