Deletes the specified policy associated with the specified role.
public static void DeleteRole(this AmazonIdentityManagementServiceClient client, string roleName) { try { client.GetRole(new GetRoleRequest { RoleName = roleName }); } catch (NoSuchEntityException) { return; } var rolePoliciesResponse = client.ListRolePolicies(new ListRolePoliciesRequest { RoleName = roleName }); foreach (var p in rolePoliciesResponse.PolicyNames) { var request = new DeleteRolePolicyRequest { PolicyName = p, RoleName = roleName }; IgnoringNoSuchEntity(() => client.DeleteRolePolicy(request)); } IgnoringNoSuchEntity(() => client.DeleteRole(new DeleteRoleRequest { RoleName = roleName })); }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.IdentityManagement.Model.DeleteRolePolicyRequest(); if (cmdletContext.PolicyName != null) { request.PolicyName = cmdletContext.PolicyName; } if (cmdletContext.RoleName != null) { request.RoleName = cmdletContext.RoleName; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
internal DeleteRolePolicyResponse DeleteRolePolicy(DeleteRolePolicyRequest request) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance; return Invoke<DeleteRolePolicyRequest,DeleteRolePolicyResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the DeleteRolePolicy operation. /// <seealso cref="Amazon.IdentityManagement.IAmazonIdentityManagementService"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteRolePolicy operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<DeleteRolePolicyResponse> DeleteRolePolicyAsync(DeleteRolePolicyRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance; return InvokeAsync<DeleteRolePolicyRequest,DeleteRolePolicyResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Initiates the asynchronous execution of the DeleteRolePolicy operation. /// <seealso cref="Amazon.IdentityManagement.AmazonIdentityManagementService.DeleteRolePolicy"/> /// </summary> /// /// <param name="deleteRolePolicyRequest">Container for the necessary parameters to execute the DeleteRolePolicy operation on /// AmazonIdentityManagementService.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public IAsyncResult BeginDeleteRolePolicy(DeleteRolePolicyRequest deleteRolePolicyRequest, AsyncCallback callback, object state) { return invokeDeleteRolePolicy(deleteRolePolicyRequest, callback, state, false); }
IAsyncResult invokeDeleteRolePolicy(DeleteRolePolicyRequest deleteRolePolicyRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new DeleteRolePolicyRequestMarshaller().Marshall(deleteRolePolicyRequest); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// <para>Deletes the specified policy associated with the specified role.</para> /// </summary> /// /// <param name="deleteRolePolicyRequest">Container for the necessary parameters to execute the DeleteRolePolicy service method on /// AmazonIdentityManagementService.</param> /// /// <exception cref="NoSuchEntityException"/> public DeleteRolePolicyResponse DeleteRolePolicy(DeleteRolePolicyRequest deleteRolePolicyRequest) { IAsyncResult asyncResult = invokeDeleteRolePolicy(deleteRolePolicyRequest, null, null, true); return EndDeleteRolePolicy(asyncResult); }
/// <summary> /// Initiates the asynchronous execution of the DeleteRolePolicy operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteRolePolicy operation on AmazonIdentityManagementServiceClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteRolePolicy /// operation.</returns> public IAsyncResult BeginDeleteRolePolicy(DeleteRolePolicyRequest request, AsyncCallback callback, object state) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance; return BeginInvoke<DeleteRolePolicyRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Initiates the asynchronous execution of the DeleteRolePolicy operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteRolePolicy operation on AmazonIdentityManagementServiceClient.</param> /// <param name="callback">An Action delegate that is invoked when the operation completes.</param> /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public void DeleteRolePolicyAsync(DeleteRolePolicyRequest request, AmazonServiceCallback<DeleteRolePolicyRequest, DeleteRolePolicyResponse> callback, AsyncOptions options = null) { options = options == null?new AsyncOptions():options; var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<DeleteRolePolicyRequest,DeleteRolePolicyResponse> responseObject = new AmazonServiceResult<DeleteRolePolicyRequest,DeleteRolePolicyResponse>((DeleteRolePolicyRequest)req, (DeleteRolePolicyResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<DeleteRolePolicyRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Initiates the asynchronous execution of the DeleteRolePolicy operation. /// <seealso cref="Amazon.IdentityManagement.IAmazonIdentityManagementService.DeleteRolePolicy"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteRolePolicy operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<DeleteRolePolicyResponse> DeleteRolePolicyAsync(DeleteRolePolicyRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, DeleteRolePolicyRequest, DeleteRolePolicyResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para>Deletes the specified policy associated with the specified role.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteRolePolicy service method on /// AmazonIdentityManagementService.</param> /// /// <exception cref="T:Amazon.IdentityManagement.Model.NoSuchEntityException" /> /// <exception cref="T:Amazon.IdentityManagement.Model.LimitExceededException" /> public DeleteRolePolicyResponse DeleteRolePolicy(DeleteRolePolicyRequest request) { var task = DeleteRolePolicyAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// <para>Deletes the specified policy associated with the specified role.</para> /// </summary> /// /// <param name="deleteRolePolicyRequest">Container for the necessary parameters to execute the DeleteRolePolicy service method on /// AmazonIdentityManagementService.</param> /// /// <exception cref="T:Amazon.IdentityManagement.Model.NoSuchEntityException" /> /// <exception cref="T:Amazon.IdentityManagement.Model.LimitExceededException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<DeleteRolePolicyResponse> DeleteRolePolicyAsync(DeleteRolePolicyRequest deleteRolePolicyRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.GetInstance(); return Invoke<IRequest, DeleteRolePolicyRequest, DeleteRolePolicyResponse>(deleteRolePolicyRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal DeleteRolePolicyResponse DeleteRolePolicy(DeleteRolePolicyRequest request) { var task = DeleteRolePolicyAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
public virtual void PrepMode_RemoveRoles(AmazonIdentityManagementServiceClient iamClient, params string[] roles) { foreach (var roleName in roles) { try { iamClient.GetRole(new GetRoleRequest {RoleName = roleName}); Console.WriteLine("Removing old role {0}.", roleName); // Remove existing policies var listRolePoliciesResponse = iamClient.ListRolePolicies(new ListRolePoliciesRequest {RoleName = roleName}); foreach (var policyName in listRolePoliciesResponse.PolicyNames) { var deleteRolePolicyRequest = new DeleteRolePolicyRequest { PolicyName = policyName, RoleName = roleName }; iamClient.DeleteRolePolicy(deleteRolePolicyRequest); } iamClient.DeleteRole(new DeleteRoleRequest {RoleName = roleName}); } catch (NoSuchEntityException) { // Role doesn't exist, so don't do anything. // Gobble the exception and loop. break; } } }
private Amazon.IdentityManagement.Model.DeleteRolePolicyResponse CallAWSServiceOperation(IAmazonIdentityManagementService client, Amazon.IdentityManagement.Model.DeleteRolePolicyRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Identity and Access Management", "DeleteRolePolicy"); try { #if DESKTOP return(client.DeleteRolePolicy(request)); #elif CORECLR return(client.DeleteRolePolicyAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
IAsyncResult invokeDeleteRolePolicy(DeleteRolePolicyRequest request, AsyncCallback callback, object state, bool synchronized) { var marshaller = new DeleteRolePolicyRequestMarshaller(); var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance; return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer); }