Skip to content

Commit

Permalink
implement fetching required iam service related data
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrar-Ahmed7 committed Feb 1, 2023
1 parent ee8e5d4 commit 5c87910
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
76 changes: 76 additions & 0 deletions internal/aws/iam.go
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
}
6 changes: 0 additions & 6 deletions internal/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ func (b ByBucketName) Len() int { return len(b) }
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b ByBucketName) Less(i, j int) bool { return b[i].BucketName < b[j].BucketName }

type S3Service interface {
ListBuckets(sess session.Session) ([]BucketResp, error)
GetInfoAboutBucket(sess session.Session)
PutObjects(sess session.Session)
}

func ListBuckets(sess session.Session) ([]BucketResp, error) {
var bucketInfo []BucketResp
s3Serv := *s3.New(&sess)
Expand Down

0 comments on commit 5c87910

Please sign in to comment.