-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add user group and user group policy for iam resource
- Loading branch information
1 parent
801143c
commit d922e6f
Showing
14 changed files
with
267 additions
and
10 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 IAMUG struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (iamug *IAMUG) Init(ctx context.Context) { | ||
iamug.ctx = ctx | ||
} | ||
|
||
func (iamug *IAMUG) 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)) | ||
} | ||
usrGroup := aws.GetUserGroups(*sess) | ||
objs := make([]Object, len(usrGroup)) | ||
for i, obj := range usrGroup { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (iamug *IAMUG) 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 IAMUGP struct { | ||
Accessor | ||
ctx context.Context | ||
} | ||
|
||
func (iamugp *IAMUGP) Init(ctx context.Context) { | ||
iamugp.ctx = ctx | ||
} | ||
|
||
func (iamugp *IAMUGP) 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)) | ||
} | ||
grpName := fmt.Sprintf("%v", ctx.Value(internal.GroupName)) | ||
grpPolicy := aws.GetPoliciesOfGrp(*sess, grpName) | ||
objs := make([]Object, len(grpPolicy)) | ||
for i, obj := range grpPolicy { | ||
objs[i] = obj | ||
} | ||
return objs, nil | ||
} | ||
|
||
func (iamugp *IAMUGP) 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
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 IAMUG struct { | ||
} | ||
|
||
func (iamug IAMUG) Header() Header { | ||
return Header{ | ||
HeaderColumn{Name: "Group-Id", SortIndicatorIdx: 5, Align: tview.AlignLeft, Hide: false, Wide: false, MX: false, Time: false}, | ||
HeaderColumn{Name: "Group-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 (iamug IAMUG) Render(o interface{}, ns string, row *Row) error { | ||
iamugResp, ok := o.(aws.IAMUSerGroupResp) | ||
if !ok { | ||
return fmt.Errorf("Expected iamugResp, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
iamugResp.GroupId, | ||
iamugResp.GroupName, | ||
iamugResp.ARN, | ||
iamugResp.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,33 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/derailed/tview" | ||
"github.com/one2nc/cloud-lens/internal/aws" | ||
) | ||
|
||
type IamUserGroupPloicy struct { | ||
} | ||
|
||
func (iugp IamUserGroupPloicy) 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 (iugp IamUserGroupPloicy) Render(o interface{}, ns string, row *Row) error { | ||
usrGroupPolicy, ok := o.(aws.IAMUSerGroupPolicyResponse) | ||
if !ok { | ||
return fmt.Errorf("expected usrGroupPolicy, but got %T", o) | ||
} | ||
|
||
row.ID = ns | ||
row.Fields = Fields{ | ||
usrGroupPolicy.PolicyArn, | ||
usrGroupPolicy.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 IAMUG struct { | ||
ResourceViewer | ||
} | ||
|
||
// NewUG returns a new viewer. | ||
func NewIAMUG(resource string) ResourceViewer { | ||
var iamug IAMUG | ||
iamug.ResourceViewer = NewBrowser(resource) | ||
iamug.AddBindKeysFn(iamug.bindKeys) | ||
return &iamug | ||
} | ||
|
||
func (iamug IAMUG) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
ui.KeyShiftI: ui.NewKeyAction("Sort Group-Id ", iamug.GetTable().SortColCmd("Group-Id", true), true), | ||
ui.KeyShiftN: ui.NewKeyAction("Sort Group-Name", iamug.GetTable().SortColCmd("Group-Name", true), true), | ||
ui.KeyShiftD: ui.NewKeyAction("Sort Created-Date", iamug.GetTable().SortColCmd("Created-Date", true), true), | ||
tcell.KeyEscape: ui.NewKeyAction("Back", iamug.App().PrevCmd, true), | ||
ui.KeyShiftP: ui.NewKeyAction("View", iamug.enterCmd, true), | ||
}) | ||
} | ||
|
||
func (iamug *IAMUG) enterCmd(evt *tcell.EventKey) *tcell.EventKey { | ||
grpName := iamug.GetTable().GetSecondColumn() | ||
if grpName != "" { | ||
up := NewIamUserGroupPloicy("User Group Policy") | ||
ctx := context.WithValue(iamug.App().GetContext(), internal.GroupName, grpName) | ||
iamug.App().SetContext(ctx) | ||
iamug.App().Flash().Info("userName: " + grpName) | ||
iamug.App().inject(up) | ||
} | ||
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 iamUserGroupPloicy struct { | ||
ResourceViewer | ||
} | ||
|
||
func NewIamUserGroupPloicy(resource string) ResourceViewer { | ||
var ugp iamUserGroupPloicy | ||
ugp.ResourceViewer = NewBrowser(resource) | ||
ugp.AddBindKeysFn(ugp.bindKeys) | ||
return &ugp | ||
} | ||
|
||
func (ugp *iamUserGroupPloicy) bindKeys(aa ui.KeyActions) { | ||
aa.Add(ui.KeyActions{ | ||
tcell.KeyEscape: ui.NewKeyAction("Back", ugp.App().PrevCmd, true), | ||
ui.KeyShiftA: ui.NewKeyAction("Policy-ARN", ugp.GetTable().SortColCmd("Policy-ARN", true), true), | ||
ui.KeyShiftN: ui.NewKeyAction("Policy-Name", ugp.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