public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { ListUserPoliciesResponse response = new ListUserPoliciesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("ListUserPoliciesResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
public static void DeleteUserPoliciesForUser(AmazonIdentityManagementServiceClient client, string username) { ListUserPoliciesResponse response = client.ListUserPoliciesAsync(new ListUserPoliciesRequest() { UserName = username }).Result; foreach (string pName in response.PolicyNames) { client.DeleteUserPolicyAsync(new DeleteUserPolicyRequest() { UserName = username, PolicyName = pName }).Wait(); } }
public void TestListUserPolicies() { string username = IAMUtil.CreateTestUser(Client); string[] policyNames = new string[3]; int nPolicies = 3; try { for (int i = 0; i < nPolicies; i++) { policyNames[i] = "test-policy-" + DateTime.Now.Ticks + i; Client.PutUserPolicy(new PutUserPolicyRequest() { UserName = username, PolicyName = policyNames[i], PolicyDocument = TEST_ALLOW_POLICY }); } ListUserPoliciesResponse response = Client.ListUserPolicies(new ListUserPoliciesRequest() { UserName = username }); Assert.AreEqual(nPolicies, response.PolicyNames.Count()); int matches = 0; foreach (string name in response.PolicyNames) { for (int i = 0; i < nPolicies; i++) { if (name.Equals(policyNames[i])) { matches |= (1 << i); } } } Assert.AreEqual((1 << nPolicies) - 1, matches); } finally { IAMUtil.DeleteTestUsers(Client, username); } }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListUserPoliciesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("PolicyNames/member", targetDepth)) { response.PolicyNames.Add(StringUnmarshaller.GetInstance().Unmarshall(context)); continue; } if (context.TestExpression("IsTruncated", targetDepth)) { response.IsTruncated = BoolUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("Marker", targetDepth)) { response.Marker = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
public void TestDeleteUserPolicy() { string username = IAMUtil.CreateTestUser(Client); string pName = "sdk-policy-" + DateTime.Now.Ticks; try { Client.PutUserPolicy(new PutUserPolicyRequest() { UserName = username, PolicyName = pName, PolicyDocument = TEST_ALLOW_POLICY }); ListUserPoliciesResponse response = Client.ListUserPolicies(new ListUserPoliciesRequest() { UserName = username }); Assert.AreEqual(1, response.PolicyNames.Count()); Client.DeleteUserPolicy(new DeleteUserPolicyRequest() { UserName = username, PolicyName = pName }); response = Client.ListUserPolicies(new ListUserPoliciesRequest() { UserName = username }); Assert.AreEqual(0, response.PolicyNames.Count()); } finally { IAMUtil.DeleteTestUsers(Client, username); } }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListUserPoliciesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("IsTruncated", targetDepth)) { var unmarshaller = BoolUnmarshaller.Instance; response.IsTruncated = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Marker", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Marker = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("PolicyNames/member", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; var item = unmarshaller.Unmarshall(context); response.PolicyNames.Add(item); continue; } } } return; }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { ListUserPoliciesResponse response = new ListUserPoliciesResponse(); while (context.Read()) { if (context.IsStartElement) { if (context.TestExpression("ListUserPoliciesResult", 2)) { response.ListUserPoliciesResult = ListUserPoliciesResultUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context); } } } return(response); }
public void TestListUserPoliciesPaging() { string username = IAMUtil.CreateTestUser(Client); int nPolicies = 4; string[] policyNames = new string[nPolicies]; try { for (int i = 0; i < nPolicies; i++) { policyNames[i] = "test-policy-" + DateTime.Now.Ticks + i; Client.PutUserPolicy(new PutUserPolicyRequest() { UserName = username, PolicyName = policyNames[i], PolicyDocument = TEST_ALLOW_POLICY }); } ListUserPoliciesResponse response = Client.ListUserPolicies(new ListUserPoliciesRequest() { UserName = username, MaxItems = 2 }); Assert.AreEqual(2, response.PolicyNames.Count()); Assert.AreEqual(true, response.IsTruncated); string marker = response.Marker; int matches = 0; foreach (string name in response.PolicyNames) { for (int i = 0; i < nPolicies; i++) { if (name.Equals(policyNames[i])) { matches |= (1 << i); } } } response = Client.ListUserPolicies(new ListUserPoliciesRequest() { UserName = username, Marker = marker }); Assert.AreEqual(nPolicies - 2, response.PolicyNames.Count()); Assert.AreEqual(false, response.IsTruncated); foreach (string name in response.PolicyNames) { for (int i = 0; i < nPolicies; i++) { if (name.Equals(policyNames[i])) { matches |= (1 << i); } } } Assert.AreEqual((1 << nPolicies) - 1, matches); } finally { IAMUtil.DeleteTestUsers(Client, username); } }