Skip to content

Commit

Permalink
work on displaying json for ec2 image and ec2 snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
aanamshaikh committed Feb 14, 2023
1 parent 346045a commit 3afe039
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
9 changes: 9 additions & 0 deletions internal/dao/ec2_image.go
Expand Up @@ -35,3 +35,12 @@ func (ei *EC2I) List(ctx context.Context) ([]Object, error) {
func (ei *EC2I) Get(ctx context.Context, path string) (Object, error) {
return nil, nil
}

func (ei *EC2I) Describe(imageId string) (string, error) {
sess, ok := ei.ctx.Value(internal.KeySession).(*session.Session)
if !ok {
log.Err(fmt.Errorf("conversion err: Expected session.session but got %v", sess))
}
res := aws.GetSingleAMI(*sess, imageId).GoString()
return res, nil
}
9 changes: 9 additions & 0 deletions internal/dao/ec2_snapshot.go
Expand Up @@ -35,3 +35,12 @@ func (es *EC2S) List(ctx context.Context) ([]Object, error) {
func (es *EC2S) Get(ctx context.Context, path string) (Object, error) {
return nil, nil
}

func (es *EC2S) Describe(snapshotId string) (string, error) {
sess, ok := es.ctx.Value(internal.KeySession).(*session.Session)
if !ok {
log.Err(fmt.Errorf("conversion err: Expected session.session but got %v", sess))
}
res := aws.GetSingleSnapshot(*sess, snapshotId).GoString()
return res, nil
}
16 changes: 15 additions & 1 deletion internal/view/ec2_image.go
Expand Up @@ -20,5 +20,19 @@ func (ei *EC2I) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort Image-Id", ei.GetTable().SortColCmd("Image-Id", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", ei.App().PrevCmd, true),
tcell.KeyEnter: ui.NewKeyAction("View", ei.enterCmd, true),
})
}
}

func (ei *EC2I) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
imageId := ei.GetTable().GetSelectedItem()
if imageId != "" {
f := describeResource
if ei.GetTable().enterFn != nil {
f = ei.GetTable().enterFn
}
f(ei.App(), ei.GetTable().GetModel(), ei.Resource(), imageId)
ei.App().Flash().Info("Image-Id: " + imageId)
}
return nil
}
16 changes: 15 additions & 1 deletion internal/view/ec2_snapshot.go
Expand Up @@ -19,8 +19,22 @@ func NewEC2S(resource string) ResourceViewer {
func (es *EC2S) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort Snapshot-Id", es.GetTable().SortColCmd("Snapshot-Id", true), true),
ui.KeyShiftV: ui.NewKeyAction("Sort Volume-Size", es.GetTable().SortColCmd("Volume-Size", true), true),
ui.KeyShiftS: ui.NewKeyAction("Sort Volume-Size", es.GetTable().SortColCmd("Volume-Size", true), true),
ui.KeyShiftT: ui.NewKeyAction("Sort Start-Time", es.GetTable().SortColCmd("Start-Time", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", es.App().PrevCmd, true),
tcell.KeyEnter: ui.NewKeyAction("View", es.enterCmd, true),
})
}

func (es *EC2S) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
snapshotId := es.GetTable().GetSelectedItem()
if snapshotId != "" {
f := describeResource
if es.GetTable().enterFn != nil {
f = es.GetTable().enterFn
}
f(es.App(), es.GetTable().GetModel(), es.Resource(), snapshotId)
es.App().Flash().Info("Snapshot-Id: " + snapshotId)
}
return nil
}

0 comments on commit 3afe039

Please sign in to comment.