-
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.
add show subnets belong to a VPC and describe subnet functionality
- Loading branch information
1 parent
ecc0646
commit ca8c8d3
Showing
11 changed files
with
185 additions
and
5 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,47 @@ | ||
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 Subnet struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (sn *Subnet) Init(ctx context.Context) { | ||
sn.ctx = ctx | ||
} | ||
|
||
func (sn *Subnet) 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)) | ||
} | ||
vpcId := fmt.Sprintf("%v", ctx.Value(internal.VpcId)) | ||
subnets := aws.GetSubnets(*sess, vpcId) | ||
objs := make([]Object, len(subnets)) | ||
for i, obj := range subnets { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (sn *Subnet) Get(ctx context.Context, path string) (Object, error) { | ||
return nil, nil | ||
} | ||
|
||
func (sn *Subnet) Describe(vpcId string) (string, error) { | ||
sess, ok := sn.ctx.Value(internal.KeySession).(*session.Session) | ||
if !ok { | ||
log.Err(fmt.Errorf("conversion err: Expected session.session but got %v", sess)) | ||
} | ||
res := aws.GetSingleSubnet(*sess, vpcId).GoString() | ||
return res, 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
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 Subnet struct { | ||
} | ||
|
||
func (sn Subnet) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "Subnet-Id", SortIndicatorIdx: 7, 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: "Availability Zone", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Subnet-State", SortIndicatorIdx: 7, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
} | ||
} | ||
|
||
func (sn Subnet) Render(o interface{}, ns string, row *Row) error { | ||
snResp, ok := o.(aws.SubnetResp) | ||
if !ok { | ||
return fmt.Errorf("expected vpc, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
snResp.SubnetId, | ||
snResp.OwnerId, | ||
snResp.CidrBlock, | ||
snResp.AvailabilityZone, | ||
snResp.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,41 @@ | ||
package view | ||
|
||
import ( | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/one2nc/cloud-lens/internal/ui" | ||
) | ||
|
||
type Subnet struct { | ||
ResourceViewer | ||
} | ||
|
||
// NewPod returns a new viewer. | ||
func NewSubnet(resource string) ResourceViewer { | ||
var sn Subnet | ||
sn.ResourceViewer = NewBrowser(resource) | ||
sn.AddBindKeysFn(sn.bindKeys) | ||
return &sn | ||
} | ||
|
||
func (sn *Subnet) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
ui.KeyShiftI: ui.NewKeyAction("Sort Subnet-Id", sn.GetTable().SortColCmd("Subnet-Id", true), true), | ||
ui.KeyShiftS: ui.NewKeyAction("Sort Subnet-State", sn.GetTable().SortColCmd("Subnet-State", true), true), | ||
tcell.KeyEscape: ui.NewKeyAction("Back", sn.App().PrevCmd, false), | ||
tcell.KeyEnter: ui.NewKeyAction("View", sn.enterCmd, true), | ||
}) | ||
} | ||
|
||
func (sn *Subnet) enterCmd(evt *tcell.EventKey) *tcell.EventKey { | ||
subnetId := sn.GetTable().GetSelectedItem() | ||
if subnetId != "" { | ||
f := describeResource | ||
if sn.GetTable().enterFn != nil { | ||
f = sn.GetTable().enterFn | ||
} | ||
f(sn.App(), sn.GetTable().GetModel(), sn.Resource(), subnetId) | ||
sn.App().Flash().Info("Subnet Id: " + subnetId) | ||
} | ||
|
||
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