-
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 iam role, role policies related UI and its functionalities
- Loading branch information
1 parent
a26d3de
commit 1c6eaf5
Showing
11 changed files
with
228 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
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 IamRole struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (iamu *IamRole) Init(ctx context.Context) { | ||
iamu.ctx = ctx | ||
} | ||
|
||
func (iamu *IamRole) 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)) | ||
} | ||
usr := aws.GetIamRoles(*sess) | ||
objs := make([]Object, len(usr)) | ||
for i, obj := range usr { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (iamu *IamRole) 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 IamRolePloicy struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (irp *IamRolePloicy) Init(ctx context.Context) { | ||
irp.ctx = ctx | ||
} | ||
|
||
func (irp *IamRolePloicy) 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)) | ||
} | ||
rn := fmt.Sprintf("%v", ctx.Value(internal.RoleName)) | ||
rp := aws.GetPoliciesOfRoles(*sess, rn) | ||
objs := make([]Object, len(rp)) | ||
for i, obj := range rp { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (iamup *IamRolePloicy) 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
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,36 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/derailed/tview" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
) | ||
|
||
type IamRole struct { | ||
} | ||
|
||
func (ir IamRole) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "User-Id", SortIndicatorIdx: 5, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "User-Name", SortIndicatorIdx: 5, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "ARN", SortIndicatorIdx: -1, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Created-Date", SortIndicatorIdx: 8, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: true}, | ||
} | ||
} | ||
|
||
func (ir IamRole) Render(o interface{}, ns string, row *Row) error { | ||
irResp, ok := o.(aws.IamRoleResp) | ||
if !ok { | ||
return fmt.Errorf("expected iam role didn't receive, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
irResp.RoleId, | ||
irResp.RoleName, | ||
irResp.ARN, | ||
irResp.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,32 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/derailed/tview" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
) | ||
|
||
type IamRolePloicy struct { | ||
} | ||
|
||
func (irp IamRolePloicy) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "Policy-ARN", SortIndicatorIdx: 7, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Policy-Name", SortIndicatorIdx: 7, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
} | ||
} | ||
|
||
func (irp IamRolePloicy) Render(o interface{}, ns string, row *Row) error { | ||
usrPolicy, ok := o.(aws.IamRolePolicyResponse) | ||
if !ok { | ||
return fmt.Errorf("expected usrPolicy, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
usrPolicy.PolicyArn, | ||
usrPolicy.PolicyName, | ||
} | ||
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,43 @@ | ||
package view | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/one2nc/cloud-lens/internal" | ||
"github.com/one2nc/cloud-lens/internal/ui" | ||
) | ||
|
||
type IamRole struct { | ||
ResourceViewer | ||
} | ||
|
||
// NewSG returns a new viewer. | ||
func NewIamRole(resource string) ResourceViewer { | ||
var iamu IamRole | ||
iamu.ResourceViewer = NewBrowser(resource) | ||
iamu.AddBindKeysFn(iamu.bindKeys) | ||
return &iamu | ||
} | ||
|
||
func (ir IamRole) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
ui.KeyShiftI: ui.NewKeyAction("Sort Role-Id ", ir.GetTable().SortColCmd("Role-Id", true), true), | ||
ui.KeyShiftN: ui.NewKeyAction("Sort Role-Name", ir.GetTable().SortColCmd("Role-Name", true), true), | ||
ui.KeyShiftD: ui.NewKeyAction("Sort Created-Date", ir.GetTable().SortColCmd("Created-Date", true), true), | ||
tcell.KeyEscape: ui.NewKeyAction("Back", ir.App().PrevCmd, true), | ||
ui.KeyShiftP: ui.NewKeyAction("View", ir.enterCmd, true), | ||
}) | ||
} | ||
|
||
func (ir *IamRole) enterCmd(evt *tcell.EventKey) *tcell.EventKey { | ||
roleName := ir.GetTable().GetSecondColumn() | ||
if roleName != "" { | ||
irp := NewIamRolePloicy("Role Policy") | ||
ctx := context.WithValue(ir.App().GetContext(), internal.RoleName, roleName) | ||
ir.App().SetContext(ctx) | ||
ir.App().Flash().Info("Role Name: " + roleName) | ||
ir.App().inject(irp) | ||
} | ||
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,25 @@ | ||
package view | ||
|
||
import ( | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/one2nc/cloud-lens/internal/ui" | ||
) | ||
|
||
type IamRolePloicy struct { | ||
ResourceViewer | ||
} | ||
|
||
func NewIamRolePloicy(resource string) ResourceViewer { | ||
var irp IamRolePloicy | ||
irp.ResourceViewer = NewBrowser(resource) | ||
irp.AddBindKeysFn(irp.bindKeys) | ||
return &irp | ||
} | ||
|
||
func (up *IamRolePloicy) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
tcell.KeyEscape: ui.NewKeyAction("Back", up.App().PrevCmd, true), | ||
ui.KeyShiftA: ui.NewKeyAction("Policy-ARN", up.GetTable().SortColCmd("Policy-ARN", true), true), | ||
ui.KeyShiftN: ui.NewKeyAction("Policy-Name", up.GetTable().SortColCmd("Policy-Name", true), true), | ||
}) | ||
} |
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