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

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

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

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

            return(response);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateAccessKeyResponse 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("AccessKey", targetDepth))
                    {
                        var unmarshaller = AccessKeyUnmarshaller.Instance;
                        response.AccessKey = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
            }

            return;
        }
Esempio n. 3
0
        public void TestCreateAccessKey()
        {
            string username = IAMUtil.CreateTestUser(Client);
            string keyId    = null;

            try
            {
                CreateAccessKeyResponse response =
                    Client.CreateAccessKey(new CreateAccessKeyRequest()
                {
                    UserName = username
                });
                keyId = response.AccessKey.AccessKeyId;
                Assert.IsTrue(response.AccessKey.CreateDate.Date.CompareTo(DateTime.Now.Date) == 0);
            }
            finally
            {
                if (keyId != null)
                {
                    Client.DeleteAccessKey(new DeleteAccessKeyRequest()
                    {
                        UserName = username, AccessKeyId = keyId
                    });
                }

                IAMUtil.DeleteTestUsers(Client, username);
            }
        }
Esempio n. 4
0
        public static async Task Main()
        {
            var iamClient = new AmazonIdentityManagementServiceClient();
            var s3Client  = new AmazonS3Client();

            // Clear the console screen before displaying any text.
            Console.Clear();

            // Create an IAM group.
            var createGroupResponse = await CreateNewGroupAsync(iamClient, GroupName);

            // Create a policy and add it to the group.
            var success = await AddGroupPermissionsAsync(iamClient, createGroupResponse.Group);

            // Now create a new user.
            User readOnlyUser;
            var  userRequest = new CreateUserRequest
            {
                UserName = UserName,
            };

            readOnlyUser = await CreateNewUserAsync(iamClient, userRequest);

            // Create access and secret keys for the user.
            CreateAccessKeyResponse createKeyResponse = await CreateNewAccessKeyAsync(iamClient, UserName);

            // Add the new user to the group.
            success = await AddNewUserToGroupAsync(iamClient, readOnlyUser.UserName, createGroupResponse.Group.GroupName);

            // Show that the user can access Amazon S3 by listing the buckets on
            // the account.
            Console.Write("Waiting for user status to be Active.");
            do
            {
                Console.Write(" .");
            }while (createKeyResponse.AccessKey.Status != StatusType.Active);

            await ListBucketsAsync(createKeyResponse.AccessKey);

            // Show that the user also has write access to Amazon S3 by creating
            // a new bucket.
            success = await CreateS3BucketAsync(createKeyResponse.AccessKey, BucketName);

            if (success)
            {
                Console.WriteLine($"Successfully created the bucket: {BucketName}.");
            }

            // Delete the user, the group, and the new bucket.
            await CleanUpResources(
                iamClient,
                s3Client,
                UserName,
                GroupName,
                BucketName,
                createKeyResponse.AccessKey.AccessKeyId);

            Console.WriteLine("Press <Enter> to close the program.");
            Console.ReadLine();
        }
Esempio n. 5
0
        public async Task TestCreateAccessKey()
        {
            using (var session = new IAMTestSession("TestCreateAccessKey", Client))
            {
                string username = session.CreateTestUser();
                string keyId    = null;
                try
                {
                    CreateAccessKeyResponse response =
                        await Client.CreateAccessKeyAsync(new CreateAccessKeyRequest()
                    {
                        UserName = username
                    });

                    keyId = response.AccessKey.AccessKeyId;
                    Assert.True(response.AccessKey.CreateDate.Date.CompareTo(DateTime.Now.Date) == 0);
                }
                finally
                {
                    if (keyId != null)
                    {
                        await Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                        {
                            UserName = username, AccessKeyId = keyId
                        });
                    }
                }
            }
        }
Esempio n. 6
0
        public void TestDeleteNonExistentAccessKeyException()
        {
            string username = IAMUtil.CreateTestUser(Client);

            try
            {
                CreateAccessKeyResponse response =
                    Client.CreateAccessKey(new CreateAccessKeyRequest()
                {
                    UserName = username
                });

                string keyId = response.AccessKey.AccessKeyId;

                Client.DeleteAccessKey(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                });
                Client.DeleteAccessKey(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                });
            }
            finally
            {
                IAMUtil.DeleteTestUsers(Client, username);
            }
        }
Esempio n. 7
0
        //[ExpectedException(typeof(NoSuchEntityException))]
        public void TestDeleteNonExistentAccessKeyException()
        {
            string username = IAMUtil.CreateTestUser(Client);

            try
            {
                CreateAccessKeyResponse response =
                    Client.CreateAccessKeyAsync(new CreateAccessKeyRequest()
                {
                    UserName = username
                }).Result;

                string keyId = response.AccessKey.AccessKeyId;

                Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                }).Wait();
                Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                }).Wait();
            }
            catch (AggregateException ae)
            {
                AssertExtensions.VerifyException <NoSuchEntityException>(ae);
            }
            finally
            {
                IAMUtil.DeleteTestUsers(Client, username);
            }
        }
Esempio n. 8
0
        private static void CreateAccessKey(String User)
        {
            if (String.IsNullOrEmpty(Token))
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, iamconfig);
            }
            else
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, Token, iamconfig);
            }

            try
            {
                CreateAccessKeyRequest accesskeyReq = new CreateAccessKeyRequest();
                if (!String.IsNullOrEmpty(User))
                {
                    accesskeyReq.UserName = User;
                }
                CreateAccessKeyResponse response = stsClient.CreateAccessKey(accesskeyReq);
                Console.WriteLine("Access keys :{0}, Secret Key: {1}", response.AccessKey.AccessKeyId,
                                  response.AccessKey.SecretAccessKey);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured while creating user. " + ex.ToString());
            }
        }
Esempio n. 9
0
        public static CreateAccessKeyResponse Unmarshall(UnmarshallerContext context)
        {
            CreateAccessKeyResponse createAccessKeyResponse = new CreateAccessKeyResponse();

            createAccessKeyResponse.HttpResponse = context.HttpResponse;
            createAccessKeyResponse.RequestId    = context.StringValue("CreateAccessKey.RequestId");

            CreateAccessKeyResponse.CreateAccessKey_AccessKey accessKey = new CreateAccessKeyResponse.CreateAccessKey_AccessKey();
            accessKey.AccessKeyId             = context.StringValue("CreateAccessKey.AccessKey.AccessKeyId");
            accessKey.AccessKeySecret         = context.StringValue("CreateAccessKey.AccessKey.AccessKeySecret");
            accessKey.Status                  = context.StringValue("CreateAccessKey.AccessKey.Status");
            accessKey.CreateDate              = context.StringValue("CreateAccessKey.AccessKey.CreateDate");
            createAccessKeyResponse.AccessKey = accessKey;

            return(createAccessKeyResponse);
        }
Esempio n. 10
0
        public void TestDeleteAccessKey()
        {
            string username = IAMUtil.CreateTestUser(Client);

            string[] keyIds = new string[2];
            try
            {
                for (int i = 0; i < 2; i++)
                {
                    CreateAccessKeyResponse response =
                        Client.CreateAccessKey(new CreateAccessKeyRequest()
                    {
                        UserName = username
                    });

                    keyIds[i] = response.AccessKey.AccessKeyId;
                }

                ListAccessKeysResponse lakRes =
                    Client.ListAccessKeys(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                Assert.AreEqual(2, lakRes.AccessKeyMetadata.Count());

                Client.DeleteAccessKey(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyIds[0]
                });

                lakRes = Client.ListAccessKeys(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                Assert.AreEqual(1, lakRes.AccessKeyMetadata.Count());
                Assert.AreEqual(keyIds[1], lakRes.AccessKeyMetadata[0].AccessKeyId);
            }
            finally
            {
                IAMUtil.DeleteTestUsers(Client, username);
            }
        }
Esempio n. 11
0
        public void TestListAccessKeys()
        {
            string username = IAMUtil.CreateTestUser(Client);

            string[] keyIds = new string[2];
            try
            {
                for (int i = 0; i < 2; i++)
                {
                    CreateAccessKeyResponse response =
                        Client.CreateAccessKey(new CreateAccessKeyRequest()
                    {
                        UserName = username
                    });

                    keyIds[i] = response.AccessKey.AccessKeyId;
                }

                ListAccessKeysResponse listRes =
                    Client.ListAccessKeys(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                int matches = 0;
                foreach (AccessKeyMetadata akm in listRes.AccessKeyMetadata)
                {
                    if (akm.AccessKeyId.Equals(keyIds[0]))
                    {
                        matches |= 1;
                    }
                    if (akm.AccessKeyId.Equals(keyIds[1]))
                    {
                        matches |= 2;
                    }
                }
                Assert.AreEqual(3, matches);
            }
            finally
            {
                IAMUtil.DeleteTestUsers(Client, username);
            }
        }
Esempio n. 12
0
        public async Task TestDeleteAccessKey()
        {
            using (var session = new IAMTestSession("TestDeleteAccessKey", Client))
            {
                string   username = session.CreateTestUser();
                string[] keyIds   = new string[2];

                for (int i = 0; i < 2; i++)
                {
                    CreateAccessKeyResponse response =
                        await Client.CreateAccessKeyAsync(new CreateAccessKeyRequest()
                    {
                        UserName = username
                    });

                    keyIds[i] = response.AccessKey.AccessKeyId;
                }

                ListAccessKeysResponse lakRes =
                    await Client.ListAccessKeysAsync(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                Assert.Equal(2, lakRes.AccessKeyMetadata.Count());

                await Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyIds[0]
                });

                lakRes = await Client.ListAccessKeysAsync(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                Assert.Equal(1, lakRes.AccessKeyMetadata.Count());
                Assert.Equal(keyIds[1], lakRes.AccessKeyMetadata[0].AccessKeyId);
            }
        }
Esempio n. 13
0
        public async Task TestListAccessKeys()
        {
            using (var session = new IAMTestSession("TestListAccessKeys", Client))
            {
                string   username = session.CreateTestUser();
                string[] keyIds   = new string[2];

                for (int i = 0; i < 2; i++)
                {
                    CreateAccessKeyResponse response =
                        await Client.CreateAccessKeyAsync(new CreateAccessKeyRequest()
                    {
                        UserName = username
                    });

                    keyIds[i] = response.AccessKey.AccessKeyId;
                }

                ListAccessKeysResponse listRes =
                    await Client.ListAccessKeysAsync(new ListAccessKeysRequest()
                {
                    UserName = username
                });

                int matches = 0;
                foreach (AccessKeyMetadata akm in listRes.AccessKeyMetadata)
                {
                    if (akm.AccessKeyId.Equals(keyIds[0]))
                    {
                        matches |= 1;
                    }
                    if (akm.AccessKeyId.Equals(keyIds[1]))
                    {
                        matches |= 2;
                    }
                }
                Assert.Equal(3, matches);
            }
        }
Esempio n. 14
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateAccessKeyResponse response = new CreateAccessKeyResponse();

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


            return(response);
        }
Esempio n. 15
0
        public async Task TestDeleteNonExistentAccessKeyException()
        {
            using (var session = new IAMTestSession("TestDeleteNonExistentAccessKeyException", Client))
            {
                string username = session.CreateTestUser();

                CreateAccessKeyResponse response = await Client.CreateAccessKeyAsync(new CreateAccessKeyRequest()
                {
                    UserName = username
                });

                string keyId = response.AccessKey.AccessKeyId;
                await Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                });

                await Assert.ThrowsAsync <NoSuchEntityException>(() => Client.DeleteAccessKeyAsync(new DeleteAccessKeyRequest()
                {
                    UserName = username, AccessKeyId = keyId
                }));
            }
        }