/*******************************************************************************
* 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.AWSSupport;
using Amazon.AWSSupport.Model;
namespace Amazon.PowerShell.Cmdlets.ASA
{
///
/// Creates a case in the Amazon Web Services Support Center. This operation is similar
/// to how you create a case in the Amazon Web Services Support Center Create
/// Case page.
///
///
///
/// The Amazon Web Services Support API doesn't support requesting service limit increases.
/// You can submit a service limit increase in the following ways:
///
/// A successful CreateCase
request returns an Amazon Web Services Support
/// case number. You can use the DescribeCases operation and specify the case number
/// to get existing Amazon Web Services Support cases. After you create a case, use the
/// AddCommunicationToCase operation to add additional communication or attachments
/// to an existing case.
///
/// The caseId
is separate from the displayId
that appears in
/// the Amazon Web Services Support Center.
/// Use the DescribeCases operation to get the displayId
.
/// -
/// You must have a Business, Enterprise On-Ramp, or Enterprise Support plan to use the
/// Amazon Web Services Support API.
///
-
/// If you call the Amazon Web Services Support API from an account that doesn't have
/// a Business, Enterprise On-Ramp, or Enterprise Support plan, the
SubscriptionRequiredException
/// error message appears. For information about changing your support plan, see Amazon
/// Web Services Support.
///
///
[Cmdlet("New", "ASACase", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the AWS Support CreateCase API operation.", Operation = new[] {"CreateCase"}, SelectReturnType = typeof(Amazon.AWSSupport.Model.CreateCaseResponse))]
[AWSCmdletOutput("System.String or Amazon.AWSSupport.Model.CreateCaseResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.AWSSupport.Model.CreateCaseResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewASACaseCmdlet : AmazonAWSSupportClientCmdlet, IExecutor
{
#region Parameter AttachmentSetId
///
///
/// The ID of a set of one or more attachments for the case. Create the set by using the
/// AddAttachmentsToSet operation.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AttachmentSetId { get; set; }
#endregion
#region Parameter CategoryCode
///
///
/// The category of problem for the support case. You also use the DescribeServices
/// operation to get the category code for a service. Each Amazon Web Services service
/// defines its own set of category codes.
///
///
[System.Management.Automation.Parameter(Position = 3, ValueFromPipelineByPropertyName = true)]
public System.String CategoryCode { get; set; }
#endregion
#region Parameter CcEmailAddress
///
///
/// A list of email addresses that Amazon Web Services Support copies on case correspondence.
/// Amazon Web Services Support identifies the account that creates the case when you
/// specify your Amazon Web Services credentials in an HTTP POST method or use the Amazon Web Services SDKs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("CcEmailAddresses")]
public System.String[] CcEmailAddress { get; set; }
#endregion
#region Parameter CommunicationBody
///
///
/// The communication body text that describes the issue. This text appears in the Description
/// field on the Amazon Web Services Support Center Create
/// Case page.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 4, ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(Position = 4, ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String CommunicationBody { get; set; }
#endregion
#region Parameter IssueType
///
///
/// The type of issue for the case. You can specify customer-service
or technical
.
/// If you don't specify a value, the default is technical
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String IssueType { get; set; }
#endregion
#region Parameter Language
///
///
/// The language in which Amazon Web Services Support handles the case. Amazon Web Services
/// Support currently supports Chinese (“zh”), English ("en"), Japanese ("ja") and Korean
/// (“ko”). You must specify the ISO 639-1 code for the language
parameter
/// if you want support in that language.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Language { get; set; }
#endregion
#region Parameter ServiceCode
///
///
/// The code for the Amazon Web Services service. You can use the DescribeServices
/// operation to get the possible serviceCode
values.
///
///
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)]
public System.String ServiceCode { get; set; }
#endregion
#region Parameter SeverityCode
///
///
/// A value that indicates the urgency of the case. This value determines the response
/// time according to your service level agreement with Amazon Web Services Support. You
/// can use the DescribeSeverityLevels operation to get the possible values for
/// severityCode
. For more information, see SeverityLevel and Choosing
/// a Severity in the Amazon Web Services Support User Guide.The availability of severity levels depends on the support plan for the Amazon Web
/// Services account.
///
///
[System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true)]
public System.String SeverityCode { get; set; }
#endregion
#region Parameter Subject
///
///
/// The title of the support case. The title appears in the Subject field on the
/// Amazon Web Services Support Center Create
/// Case page.
///
///
#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 Subject { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'CaseId'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AWSSupport.Model.CreateCaseResponse).
/// Specifying the name of a property of type Amazon.AWSSupport.Model.CreateCaseResponse 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; } = "CaseId";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Subject parameter.
/// The -PassThru parameter is deprecated, use -Select '^Subject' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Subject' 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.AttachmentSetId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-ASACase (CreateCase)"))
{
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.Subject;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AttachmentSetId = this.AttachmentSetId;
context.CategoryCode = this.CategoryCode;
if (this.CcEmailAddress != null)
{
context.CcEmailAddress = new List(this.CcEmailAddress);
}
context.CommunicationBody = this.CommunicationBody;
#if MODULAR
if (this.CommunicationBody == null && ParameterWasBound(nameof(this.CommunicationBody)))
{
WriteWarning("You are passing $null as a value for parameter CommunicationBody 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.IssueType = this.IssueType;
context.Language = this.Language;
context.ServiceCode = this.ServiceCode;
context.SeverityCode = this.SeverityCode;
context.Subject = this.Subject;
#if MODULAR
if (this.Subject == null && ParameterWasBound(nameof(this.Subject)))
{
WriteWarning("You are passing $null as a value for parameter Subject 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.AWSSupport.Model.CreateCaseRequest();
if (cmdletContext.AttachmentSetId != null)
{
request.AttachmentSetId = cmdletContext.AttachmentSetId;
}
if (cmdletContext.CategoryCode != null)
{
request.CategoryCode = cmdletContext.CategoryCode;
}
if (cmdletContext.CcEmailAddress != null)
{
request.CcEmailAddresses = cmdletContext.CcEmailAddress;
}
if (cmdletContext.CommunicationBody != null)
{
request.CommunicationBody = cmdletContext.CommunicationBody;
}
if (cmdletContext.IssueType != null)
{
request.IssueType = cmdletContext.IssueType;
}
if (cmdletContext.Language != null)
{
request.Language = cmdletContext.Language;
}
if (cmdletContext.ServiceCode != null)
{
request.ServiceCode = cmdletContext.ServiceCode;
}
if (cmdletContext.SeverityCode != null)
{
request.SeverityCode = cmdletContext.SeverityCode;
}
if (cmdletContext.Subject != null)
{
request.Subject = cmdletContext.Subject;
}
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.AWSSupport.Model.CreateCaseResponse CallAWSServiceOperation(IAmazonAWSSupport client, Amazon.AWSSupport.Model.CreateCaseRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Support", "CreateCase");
try
{
#if DESKTOP
return client.CreateCase(request);
#elif CORECLR
return client.CreateCaseAsync(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 AttachmentSetId { get; set; }
public System.String CategoryCode { get; set; }
public List CcEmailAddress { get; set; }
public System.String CommunicationBody { get; set; }
public System.String IssueType { get; set; }
public System.String Language { get; set; }
public System.String ServiceCode { get; set; }
public System.String SeverityCode { get; set; }
public System.String Subject { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.CaseId;
}
}
}