Exemple #1
0
        private static void DeleteAccessKey(String DelAccessKeyid, String User = "")
        {
            if (String.IsNullOrEmpty(Token))
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, iamconfig);
            }
            else
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, Token, iamconfig);
            }

            try
            {
                DeleteAccessKeyRequest accesskeyReq = new DeleteAccessKeyRequest(DelAccessKeyid);
                if (!String.IsNullOrEmpty(User))
                {
                    accesskeyReq.UserName = User;
                }
                DeleteAccessKeyResponse response = stsClient.DeleteAccessKey(accesskeyReq);
                Console.WriteLine("Access Key deleted successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured while creating user. " + ex.ToString());
            }
        }
        /// <summary>
        /// Deletes the User, Group, and AccessKey which were created for the purposes of
        /// this example.
        /// </summary>
        /// <param name="client">The IAM client used to delete the other
        /// resources.</param>
        /// <param name="userName">The name of the user that will be deleted.</param>
        /// <param name="groupName">The name of the group that will be deleted.</param>
        /// <param name="accessKeyId">The AccessKeyId that represents the
        /// AccessKey that was created for use with the ListBucketsAsync
        /// method.</param>
        public static async Task CleanUpResources(AmazonIdentityManagementServiceClient client, string userName, string groupName, string accessKeyId)
        {
            // Remove the user from the group.
            var removeUserRequest = new RemoveUserFromGroupRequest()
            {
                UserName  = userName,
                GroupName = groupName,
            };

            await client.RemoveUserFromGroupAsync(removeUserRequest);

            // Delete the client access keys before deleting the user.
            var deleteAccessKeyRequest = new DeleteAccessKeyRequest()
            {
                AccessKeyId = accessKeyId,
                UserName    = userName,
            };

            await client.DeleteAccessKeyAsync(deleteAccessKeyRequest);

            // Now we can safely delete the user.
            var deleteUserRequest = new DeleteUserRequest()
            {
                UserName = userName,
            };

            await client.DeleteUserAsync(deleteUserRequest);

            // We have to delete the policy attached to the group first.
            var deleteGroupPolicyRequest = new DeleteGroupPolicyRequest()
            {
                GroupName  = groupName,
                PolicyName = PolicyName,
            };

            await client.DeleteGroupPolicyAsync(deleteGroupPolicyRequest);

            // Now delete the group.
            var deleteGroupRequest = new DeleteGroupRequest()
            {
                GroupName = groupName,
            };

            await client.DeleteGroupAsync(deleteGroupRequest);

            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("Deleted the user and group created for this example.");
        }
        public static void DeleteUser(this AmazonIdentityManagementServiceClient client, string userName)
        {
            try
            {
                var userPolicies =
                    client.ListUserPolicies(new ListUserPoliciesRequest {
                    UserName = userName
                }).PolicyNames;

                foreach (var policy in userPolicies)
                {
                    var request = new DeleteUserPolicyRequest {
                        UserName = userName, PolicyName = policy
                    };
                    IgnoringNoSuchEntity(() => { client.DeleteUserPolicy(request); });
                }
            }
            catch (NoSuchEntityException)
            {
                return;
            }

            var keys = client.ListAccessKeys(new ListAccessKeysRequest {
                UserName = userName
            });

            foreach (var key in keys.AccessKeyMetadata)
            {
                var request = new DeleteAccessKeyRequest {
                    UserName = userName, AccessKeyId = key.AccessKeyId
                };
                IgnoringNoSuchEntity(() => { client.DeleteAccessKey(request); });
            }

            IgnoringNoSuchEntity(() => client.DeleteUser(new DeleteUserRequest {
                UserName = userName
            }));
        }
 public Task <DeleteAccessKeyResponse> DeleteAccessKeyAsync(DeleteAccessKeyRequest request,
                                                            CancellationToken cancellationToken = new CancellationToken())
 {
     throw new System.NotImplementedException();
 }