diff --git a/internal/aws/iam.go b/internal/aws/iam.go new file mode 100644 index 0000000..11ccb33 --- /dev/null +++ b/internal/aws/iam.go @@ -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 +} diff --git a/internal/aws/s3.go b/internal/aws/s3.go index 9bf6d1a..3212590 100644 --- a/internal/aws/s3.go +++ b/internal/aws/s3.go @@ -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)