Exemple #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListGroupPoliciesResponse response = new ListGroupPoliciesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ListGroupPoliciesResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Exemple #2
0
        public void TestDeleteGroupPolicy()
        {
            string groupname = "sdk-testgroup-" + DateTime.Now.Ticks;
            string pName     = "test-policy-" + DateTime.Now.Ticks;

            try
            {
                Client.CreateGroup(new CreateGroupRequest()
                {
                    GroupName = groupname, Path = IAMUtil.TEST_PATH
                });

                Client.PutGroupPolicy(new PutGroupPolicyRequest()
                {
                    GroupName      = groupname,
                    PolicyName     = pName,
                    PolicyDocument = TEST_ALLOW_POLICY
                });

                ListGroupPoliciesResponse response =
                    Client.ListGroupPolicies(new ListGroupPoliciesRequest()
                {
                    GroupName = groupname
                });

                Assert.AreEqual(1, response.PolicyNames.Count());

                Client.DeleteGroupPolicy(new DeleteGroupPolicyRequest()
                {
                    GroupName = groupname, PolicyName = pName
                });

                response = Client.ListGroupPolicies(new ListGroupPoliciesRequest()
                {
                    GroupName = groupname
                });

                Assert.AreEqual(0, response.PolicyNames.Count());
            }
            finally
            {
                Client.DeleteGroup(new DeleteGroupRequest()
                {
                    GroupName = groupname
                });
            }
        }
Exemple #3
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListGroupPoliciesResponse 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;
        }
Exemple #4
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListGroupPoliciesResponse 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;
        }
Exemple #5
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListGroupPoliciesResponse response = new ListGroupPoliciesResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ListGroupPoliciesResult", 2))
                    {
                        response.ListGroupPoliciesResult = ListGroupPoliciesResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
Exemple #6
0
        public void TestListGroupPoliciesPaging()
        {
            string grpname   = "sdk-testgroup-" + DateTime.Now.Ticks;
            int    nPolicies = 3;

            string[] policyNames = new string[nPolicies];

            try
            {
                Client.CreateGroup(new CreateGroupRequest()
                {
                    GroupName = grpname, Path = IAMUtil.TEST_PATH
                });

                for (int i = 0; i < nPolicies; i++)
                {
                    policyNames[i] = "test-policy-" + DateTime.Now.Ticks + i;
                    Client.PutGroupPolicy(new PutGroupPolicyRequest()
                    {
                        GroupName      = grpname,
                        PolicyName     = policyNames[i],
                        PolicyDocument = TEST_ALLOW_POLICY
                    });
                }

                ListGroupPoliciesResponse response =
                    Client.ListGroupPolicies(new ListGroupPoliciesRequest()
                {
                    GroupName = grpname, 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.ListGroupPolicies(new ListGroupPoliciesRequest()
                {
                    GroupName = grpname, 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
            {
                for (int i = 0; i < nPolicies; i++)
                {
                    Client.DeleteGroupPolicy(new DeleteGroupPolicyRequest()
                    {
                        GroupName = grpname, PolicyName = policyNames[i]
                    });
                }

                Client.DeleteGroup(new DeleteGroupRequest()
                {
                    GroupName = grpname
                });
            }
        }
Exemple #7
0
        public void TestListGroupPolicies()
        {
            string grpname = "sdk-testgroup-" + DateTime.Now.Ticks;

            string[] policyNames = new string[3];
            int      nPolicies   = 3;

            try
            {
                Client.CreateGroupAsync(new CreateGroupRequest()
                {
                    GroupName = grpname, Path = IAMUtil.TEST_PATH
                }).Wait();

                for (int i = 0; i < nPolicies; i++)
                {
                    policyNames[i] = "test-policy-" + DateTime.Now.Ticks + i;
                    Client.PutGroupPolicyAsync(new PutGroupPolicyRequest()
                    {
                        GroupName      = grpname,
                        PolicyName     = policyNames[i],
                        PolicyDocument = TEST_ALLOW_POLICY
                    }).Wait();
                }

                ListGroupPoliciesResponse response =
                    Client.ListGroupPoliciesAsync(new ListGroupPoliciesRequest()
                {
                    GroupName = grpname
                }).Result;

                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
            {
                for (int i = 0; i < nPolicies; i++)
                {
                    Client.DeleteGroupPolicyAsync(new DeleteGroupPolicyRequest()
                    {
                        GroupName = grpname, PolicyName = policyNames[i]
                    }).Wait();
                }

                Client.DeleteGroupAsync(new DeleteGroupRequest()
                {
                    GroupName = grpname
                }).Wait();
            }
        }