-
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.
- Loading branch information
1 parent
a7353f7
commit 9666649
Showing
8 changed files
with
178 additions
and
9 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,49 @@ | ||
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 EBS struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (ebs *EBS) Init(ctx context.Context) { | ||
ebs.ctx = ctx | ||
} | ||
|
||
func (ebs *EBS) 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)) | ||
} | ||
vols, err := aws.GetVolumes(*sess) | ||
if err != nil { | ||
return nil, err | ||
} | ||
objs := make([]Object, len(vols)) | ||
for i, obj := range vols { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (ebs *EBS) Get(ctx context.Context, path string) (Object, error) { | ||
return nil, nil | ||
} | ||
|
||
func (ebs *EBS) Describe(volId string) (string, error) { | ||
sess, ok := ebs.ctx.Value(internal.KeySession).(*session.Session) | ||
if !ok { | ||
log.Err(fmt.Errorf("conversion err: Expected session.session but got %v", sess)) | ||
} | ||
res := aws.GetSingleVolume(*sess, volId) | ||
return res.GoString(), 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,45 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/derailed/tview" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
) | ||
|
||
type EBS struct { | ||
} | ||
|
||
// Header returns a header row. | ||
func (ebs EBS) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "Volume-Id", SortIndicatorIdx: 7, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Size", SortIndicatorIdx: 0, Align: tview.AlignRight, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Volume-Type", SortIndicatorIdx: 0, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "State", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Availability-Zone", SortIndicatorIdx: 13, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Snapshot", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: true}, | ||
HeaderColumn{Name: "Creation-Time", SortIndicatorIdx: 9, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
} | ||
} | ||
|
||
func (ebs EBS) Render(o interface{}, ns string, row *Row) error { | ||
ebsResp, ok := o.(aws.EBSResp) | ||
|
||
if !ok { | ||
return fmt.Errorf("Expected EBS response, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
ebsResp.VolumeId, | ||
ebsResp.Size, | ||
ebsResp.VolumeType, | ||
ebsResp.State, | ||
ebsResp.AvailabilityZone, | ||
ebsResp.Snapshot, | ||
ebsResp.CreationTime, | ||
} | ||
|
||
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
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 EBS struct { | ||
ResourceViewer | ||
} | ||
|
||
func NewEBS(resource string) ResourceViewer { | ||
var ebs EBS | ||
ebs.ResourceViewer = NewBrowser(resource) | ||
ebs.AddBindKeysFn(ebs.bindKeys) | ||
// s3.GetTable().SetEnterFn(s3.describeInstace) | ||
return &ebs | ||
} | ||
func (ebs *EBS) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
ui.KeyShiftI: ui.NewKeyAction("Sort Volume-Id", ebs.GetTable().SortColCmd("Volume-Id", true), true), | ||
ui.KeyShiftS: ui.NewKeyAction("Sort Size", ebs.GetTable().SortColCmd("Size", true), true), | ||
ui.KeyShiftV: ui.NewKeyAction("Sort Volume-Type", ebs.GetTable().SortColCmd("Volume-Type", true), true), | ||
ui.KeyShiftZ: ui.NewKeyAction("Sort Availability-Zone", ebs.GetTable().SortColCmd("Availability-Zone", true), true), | ||
ui.KeyShiftT: ui.NewKeyAction("Sort Creation-Time", ebs.GetTable().SortColCmd("Creation-Time", true), true), | ||
tcell.KeyEscape: ui.NewKeyAction("Back", ebs.App().PrevCmd, true), | ||
tcell.KeyEnter: ui.NewKeyAction("View", ebs.enterCmd, true), | ||
}) | ||
} | ||
|
||
func (ebs *EBS) enterCmd(evt *tcell.EventKey) *tcell.EventKey { | ||
volId := ebs.GetTable().GetSelectedItem() | ||
ebs.App().Flash().Info("volume id: " + volId) | ||
|
||
f := describeResource | ||
if ebs.GetTable().enterFn != nil { | ||
f = ebs.GetTable().enterFn | ||
} | ||
f(ebs.App(), ebs.GetTable().GetModel(), ebs.Resource(), volId) | ||
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