-
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.
implement fetching required iam service related data
- Loading branch information
1 parent
ee8e5d4
commit 5c87910
Showing
2 changed files
with
76 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/iam" | ||
) | ||
|
||
func GetUsers(sess session.Session) []*iam.User { | ||
iamSrv := iam.New(&sess) | ||
result, err := iamSrv.ListUsers(&iam.ListUsersInput{}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam Users: ", " err: ", err) | ||
return nil | ||
} | ||
return result.Users | ||
} | ||
|
||
func GetUserGroups(sess session.Session) []*iam.Group { | ||
iamSrv := iam.New(&sess) | ||
result, err := iamSrv.ListGroups(&iam.ListGroupsInput{}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam Groups: ", " err: ", err) | ||
return nil | ||
} | ||
return result.Groups | ||
} | ||
|
||
func GetGroupUsers(sess session.Session, grpName string) []*iam.User { | ||
iamSrv := iam.New(&sess) | ||
result, err := iamSrv.GetGroup(&iam.GetGroupInput{ | ||
GroupName: &grpName, | ||
}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam users of the Group: ", grpName, " err: ", err) | ||
return nil | ||
} | ||
return result.Users | ||
} | ||
|
||
func GetPoliciesOfGrp(sess session.Session, grpName string) []*iam.AttachedPolicy { | ||
imaSrv := iam.New(&sess) | ||
result, err := imaSrv.ListAttachedGroupPolicies(&iam.ListAttachedGroupPoliciesInput{ | ||
GroupName: &grpName, | ||
}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam policies of the Group: ", grpName, " err: ", err) | ||
return nil | ||
} | ||
return result.AttachedPolicies | ||
} | ||
|
||
// If a user belong to a Group then we can't see the user's attached policy here, | ||
// their policies are governed on the top of the group | ||
func GetPoliciesOfUser(sess session.Session, usrName string) []*iam.AttachedPolicy { | ||
imaSrv := iam.New(&sess) | ||
result, err := imaSrv.ListAttachedUserPolicies(&iam.ListAttachedUserPoliciesInput{ | ||
UserName: &usrName, | ||
}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam policies of the User: ", usrName, " err: ", err) | ||
return nil | ||
} | ||
return result.AttachedPolicies | ||
} | ||
|
||
func GetIamRoles(sess session.Session) []*iam.Role { | ||
iamSrv := iam.New(&sess) | ||
result, err := iamSrv.ListRoles(&iam.ListRolesInput{}) | ||
if err != nil { | ||
fmt.Println("Error in fetching Iam Roles: ", " err: ", err) | ||
return nil | ||
} | ||
return result.Roles | ||
} |
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