/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.AuditManager;
using Amazon.AuditManager.Model;
namespace Amazon.PowerShell.Cmdlets.AUDM
{
///
/// Creates a share request for a custom framework in Audit Manager.
///
///
///
/// The share request specifies a recipient and notifies them that a custom framework
/// is available. Recipients have 120 days to accept or decline the request. If no action
/// is taken, the share request expires.
///
/// When you create a share request, Audit Manager stores a snapshot of your custom framework
/// in the US East (N. Virginia) Amazon Web Services Region. Audit Manager also stores
/// a backup of the same snapshot in the US West (Oregon) Amazon Web Services Region.
///
/// Audit Manager deletes the snapshot and the backup snapshot when one of the following
/// events occurs:
/// -
/// The sender revokes the share request.
///
-
/// The recipient declines the share request.
///
-
/// The recipient encounters an error and doesn't successfully accept the share request.
///
-
/// The share request expires before the recipient responds to the request.
///
/// When a sender resends
/// a share request, the snapshot is replaced with an updated version that corresponds
/// with the latest version of the custom framework.
///
/// When a recipient accepts a share request, the snapshot is replicated into their Amazon
/// Web Services account under the Amazon Web Services Region that was specified in the
/// share request.
///
/// When you invoke the StartAssessmentFrameworkShare
API, you are about
/// to share a custom framework with another Amazon Web Services account. You may not
/// share a custom framework that is derived from a standard framework if the standard
/// framework is designated as not eligible for sharing by Amazon Web Services, unless
/// you have obtained permission to do so from the owner of the standard framework. To
/// learn more about which standard frameworks are eligible for sharing, see Framework
/// sharing eligibility in the Audit Manager User Guide.
///
///
[Cmdlet("Start", "AUDMAssessmentFrameworkShare", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.AuditManager.Model.AssessmentFrameworkShareRequest")]
[AWSCmdlet("Calls the AWS Audit Manager StartAssessmentFrameworkShare API operation.", Operation = new[] {"StartAssessmentFrameworkShare"}, SelectReturnType = typeof(Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse))]
[AWSCmdletOutput("Amazon.AuditManager.Model.AssessmentFrameworkShareRequest or Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse",
"This cmdlet returns an Amazon.AuditManager.Model.AssessmentFrameworkShareRequest object.",
"The service call response (type Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class StartAUDMAssessmentFrameworkShareCmdlet : AmazonAuditManagerClientCmdlet, IExecutor
{
#region Parameter Comment
///
///
/// An optional comment from the sender about the share request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Comment { get; set; }
#endregion
#region Parameter DestinationAccount
///
///
/// The Amazon Web Services account of the recipient.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String DestinationAccount { get; set; }
#endregion
#region Parameter DestinationRegion
///
///
/// The Amazon Web Services Region of the recipient.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String DestinationRegion { get; set; }
#endregion
#region Parameter FrameworkId
///
///
/// The unique identifier for the custom framework to be shared.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String FrameworkId { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'AssessmentFrameworkShareRequest'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse).
/// Specifying the name of a property of type Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "AssessmentFrameworkShareRequest";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the FrameworkId parameter.
/// The -PassThru parameter is deprecated, use -Select '^FrameworkId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^FrameworkId' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.FrameworkId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Start-AUDMAssessmentFrameworkShare (StartAssessmentFrameworkShare)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.FrameworkId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Comment = this.Comment;
context.DestinationAccount = this.DestinationAccount;
#if MODULAR
if (this.DestinationAccount == null && ParameterWasBound(nameof(this.DestinationAccount)))
{
WriteWarning("You are passing $null as a value for parameter DestinationAccount which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.DestinationRegion = this.DestinationRegion;
#if MODULAR
if (this.DestinationRegion == null && ParameterWasBound(nameof(this.DestinationRegion)))
{
WriteWarning("You are passing $null as a value for parameter DestinationRegion which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.FrameworkId = this.FrameworkId;
#if MODULAR
if (this.FrameworkId == null && ParameterWasBound(nameof(this.FrameworkId)))
{
WriteWarning("You are passing $null as a value for parameter FrameworkId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.AuditManager.Model.StartAssessmentFrameworkShareRequest();
if (cmdletContext.Comment != null)
{
request.Comment = cmdletContext.Comment;
}
if (cmdletContext.DestinationAccount != null)
{
request.DestinationAccount = cmdletContext.DestinationAccount;
}
if (cmdletContext.DestinationRegion != null)
{
request.DestinationRegion = cmdletContext.DestinationRegion;
}
if (cmdletContext.FrameworkId != null)
{
request.FrameworkId = cmdletContext.FrameworkId;
}
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;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.AuditManager.Model.StartAssessmentFrameworkShareResponse CallAWSServiceOperation(IAmazonAuditManager client, Amazon.AuditManager.Model.StartAssessmentFrameworkShareRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Audit Manager", "StartAssessmentFrameworkShare");
try
{
#if DESKTOP
return client.StartAssessmentFrameworkShare(request);
#elif CORECLR
return client.StartAssessmentFrameworkShareAsync(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;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String Comment { get; set; }
public System.String DestinationAccount { get; set; }
public System.String DestinationRegion { get; set; }
public System.String FrameworkId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.AssessmentFrameworkShareRequest;
}
}
}