}//EndIamUserScan
/// <summary>
/// Given a profile and user, collect additional information.
/// </summary>
/// <param name="aprofile">An AWS Profile name stored in Windows Credential Store</param>
/// <param name="auser">The Name of a User</param>
/// <returns>Dictionary containing keys for each type of data[AccessKeys], [Groups], [Policies]</returns>
public Dictionary<string, string> GetUserDetails(string aprofile, string username)
{
var credential = new Amazon.Runtime.StoredProfileAWSCredentials(aprofile);
var iam = new AmazonIdentityManagementServiceClient(credential);
Dictionary<string, string> ToReturn = new Dictionary<string, string>();
string policylist = "";
string aklist = "";
string groups = "";
try
{
ListAccessKeysRequest LAKREQ = new ListAccessKeysRequest();
LAKREQ.UserName = username;
var LAKRES = iam.ListAccessKeys(LAKREQ);
foreach (var blivet in LAKRES.AccessKeyMetadata)
{
if (aklist.Length > 1) aklist += "\n";
aklist += blivet.AccessKeyId + " : " + blivet.Status;
}
}
catch { aklist = ""; }
try
{
ListAttachedUserPoliciesRequest LAUPREQ = new ListAttachedUserPoliciesRequest();
LAUPREQ.UserName = username;
var LAUPRES = iam.ListAttachedUserPolicies(LAUPREQ);
foreach (var apol in LAUPRES.AttachedPolicies)
{
if (policylist.Length > 1) policylist += "\n";
policylist += apol.PolicyName;
}
}
catch { policylist = ""; }
try
{
var groopsreq = new ListGroupsForUserRequest();
groopsreq.UserName = username;
var LG = iam.ListGroupsForUser(groopsreq);
foreach (var agroup in LG.Groups)
{
if (groups.Length > 1) groups += "\n";
groups += agroup.GroupName;
}
}
catch { groups = ""; }
ToReturn.Add("Groups", groups);
ToReturn.Add("Policies", policylist);
ToReturn.Add("AccessKeys", aklist);
return ToReturn;
}