/*******************************************************************************
* 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.AppStream;
using Amazon.AppStream.Model;
namespace Amazon.PowerShell.Cmdlets.APS
{
///
/// Updates the specified application.
///
[Cmdlet("Update", "APSApplication", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.AppStream.Model.Application")]
[AWSCmdlet("Calls the Amazon AppStream UpdateApplication API operation.", Operation = new[] {"UpdateApplication"}, SelectReturnType = typeof(Amazon.AppStream.Model.UpdateApplicationResponse))]
[AWSCmdletOutput("Amazon.AppStream.Model.Application or Amazon.AppStream.Model.UpdateApplicationResponse",
"This cmdlet returns an Amazon.AppStream.Model.Application object.",
"The service call response (type Amazon.AppStream.Model.UpdateApplicationResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateAPSApplicationCmdlet : AmazonAppStreamClientCmdlet, IExecutor
{
#region Parameter AppBlockArn
///
///
/// The ARN of the app block.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AppBlockArn { get; set; }
#endregion
#region Parameter AttributesToDelete
///
///
/// The attributes to delete for an application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String[] AttributesToDelete { get; set; }
#endregion
#region Parameter Description
///
///
/// The description of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Description { get; set; }
#endregion
#region Parameter DisplayName
///
///
/// The display name of the application. This name is visible to users in the application
/// catalog.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DisplayName { get; set; }
#endregion
#region Parameter LaunchParameter
///
///
/// The launch parameters of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LaunchParameters")]
public System.String LaunchParameter { get; set; }
#endregion
#region Parameter LaunchPath
///
///
/// The launch path of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String LaunchPath { get; set; }
#endregion
#region Parameter Name
///
///
/// The name of the application. This name is visible to users when display name is not
/// specified.
///
///
#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 Name { get; set; }
#endregion
#region Parameter IconS3Location_S3Bucket
///
///
/// The S3 bucket of the S3 object.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String IconS3Location_S3Bucket { get; set; }
#endregion
#region Parameter IconS3Location_S3Key
///
///
/// The S3 key of the S3 object.This is required when used for the following:- IconS3Location (Actions: CreateApplication and UpdateApplication)
- SessionScriptS3Location (Actions: CreateFleet and UpdateFleet)
- ScriptDetails (Actions: CreateAppBlock)
- SourceS3Location when creating an app block with
CUSTOM
PackagingType
/// (Actions: CreateAppBlock) - SourceS3Location when creating an app block with
APPSTREAM2
PackagingType,
/// and using an existing application package (VHD file). In this case, S3Key
/// refers to the VHD file. If a new application package is required, then S3Key
/// is not required. (Actions: CreateAppBlock)
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String IconS3Location_S3Key { get; set; }
#endregion
#region Parameter WorkingDirectory
///
///
/// The working directory of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String WorkingDirectory { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'Application'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AppStream.Model.UpdateApplicationResponse).
/// Specifying the name of a property of type Amazon.AppStream.Model.UpdateApplicationResponse 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; } = "Application";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Name parameter.
/// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' 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.Name), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-APSApplication (UpdateApplication)"))
{
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.Name;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AppBlockArn = this.AppBlockArn;
if (this.AttributesToDelete != null)
{
context.AttributesToDelete = new List(this.AttributesToDelete);
}
context.Description = this.Description;
context.DisplayName = this.DisplayName;
context.IconS3Location_S3Bucket = this.IconS3Location_S3Bucket;
context.IconS3Location_S3Key = this.IconS3Location_S3Key;
context.LaunchParameter = this.LaunchParameter;
context.LaunchPath = this.LaunchPath;
context.Name = this.Name;
#if MODULAR
if (this.Name == null && ParameterWasBound(nameof(this.Name)))
{
WriteWarning("You are passing $null as a value for parameter Name 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.WorkingDirectory = this.WorkingDirectory;
// 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.AppStream.Model.UpdateApplicationRequest();
if (cmdletContext.AppBlockArn != null)
{
request.AppBlockArn = cmdletContext.AppBlockArn;
}
if (cmdletContext.AttributesToDelete != null)
{
request.AttributesToDelete = cmdletContext.AttributesToDelete;
}
if (cmdletContext.Description != null)
{
request.Description = cmdletContext.Description;
}
if (cmdletContext.DisplayName != null)
{
request.DisplayName = cmdletContext.DisplayName;
}
// populate IconS3Location
var requestIconS3LocationIsNull = true;
request.IconS3Location = new Amazon.AppStream.Model.S3Location();
System.String requestIconS3Location_iconS3Location_S3Bucket = null;
if (cmdletContext.IconS3Location_S3Bucket != null)
{
requestIconS3Location_iconS3Location_S3Bucket = cmdletContext.IconS3Location_S3Bucket;
}
if (requestIconS3Location_iconS3Location_S3Bucket != null)
{
request.IconS3Location.S3Bucket = requestIconS3Location_iconS3Location_S3Bucket;
requestIconS3LocationIsNull = false;
}
System.String requestIconS3Location_iconS3Location_S3Key = null;
if (cmdletContext.IconS3Location_S3Key != null)
{
requestIconS3Location_iconS3Location_S3Key = cmdletContext.IconS3Location_S3Key;
}
if (requestIconS3Location_iconS3Location_S3Key != null)
{
request.IconS3Location.S3Key = requestIconS3Location_iconS3Location_S3Key;
requestIconS3LocationIsNull = false;
}
// determine if request.IconS3Location should be set to null
if (requestIconS3LocationIsNull)
{
request.IconS3Location = null;
}
if (cmdletContext.LaunchParameter != null)
{
request.LaunchParameters = cmdletContext.LaunchParameter;
}
if (cmdletContext.LaunchPath != null)
{
request.LaunchPath = cmdletContext.LaunchPath;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
if (cmdletContext.WorkingDirectory != null)
{
request.WorkingDirectory = cmdletContext.WorkingDirectory;
}
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.AppStream.Model.UpdateApplicationResponse CallAWSServiceOperation(IAmazonAppStream client, Amazon.AppStream.Model.UpdateApplicationRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon AppStream", "UpdateApplication");
try
{
#if DESKTOP
return client.UpdateApplication(request);
#elif CORECLR
return client.UpdateApplicationAsync(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 AppBlockArn { get; set; }
public List AttributesToDelete { get; set; }
public System.String Description { get; set; }
public System.String DisplayName { get; set; }
public System.String IconS3Location_S3Bucket { get; set; }
public System.String IconS3Location_S3Key { get; set; }
public System.String LaunchParameter { get; set; }
public System.String LaunchPath { get; set; }
public System.String Name { get; set; }
public System.String WorkingDirectory { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.Application;
}
}
}