/******************************************************************************* * 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.CloudTrail; using Amazon.CloudTrail.Model; namespace Amazon.PowerShell.Cmdlets.CT { /// /// Updates trail settings that control what events you are logging, and how to handle /// log files. Changes to a trail do not require stopping the CloudTrail service. Use /// this action to designate an existing bucket for log delivery. If the existing bucket /// has previously been a target for CloudTrail log files, an IAM policy exists for the /// bucket. UpdateTrail must be called from the Region in which the trail /// was created; otherwise, an InvalidHomeRegionException is thrown. /// [Cmdlet("Update", "CTTrail", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.CloudTrail.Model.UpdateTrailResponse")] [AWSCmdlet("Calls the AWS CloudTrail UpdateTrail API operation.", Operation = new[] {"UpdateTrail"}, SelectReturnType = typeof(Amazon.CloudTrail.Model.UpdateTrailResponse))] [AWSCmdletOutput("Amazon.CloudTrail.Model.UpdateTrailResponse", "This cmdlet returns an Amazon.CloudTrail.Model.UpdateTrailResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class UpdateCTTrailCmdlet : AmazonCloudTrailClientCmdlet, IExecutor { #region Parameter CloudWatchLogsLogGroupArn /// /// /// Specifies a log group name using an Amazon Resource Name (ARN), a unique identifier /// that represents the log group to which CloudTrail logs are delivered. You must use /// a log group that exists in your account.Not required unless you specify CloudWatchLogsRoleArn. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String CloudWatchLogsLogGroupArn { get; set; } #endregion #region Parameter CloudWatchLogsRoleArn /// /// /// Specifies the role for the CloudWatch Logs endpoint to assume to write to a user's /// log group. You must use a role that exists in your account. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String CloudWatchLogsRoleArn { get; set; } #endregion #region Parameter EnableLogFileValidation /// /// /// Specifies whether log file validation is enabled. The default is false.When you disable log file integrity validation, the chain of digest files is broken /// after one hour. CloudTrail does not create digest files for log files that were delivered /// during a period in which log file integrity validation was disabled. For example, /// if you enable log file integrity validation at noon on January 1, disable it at noon /// on January 2, and re-enable it at noon on January 10, digest files will not be created /// for the log files delivered from noon on January 2 to noon on January 10. The same /// applies whenever you stop CloudTrail logging or delete a trail. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? EnableLogFileValidation { get; set; } #endregion #region Parameter IncludeGlobalServiceEvent /// /// /// Specifies whether the trail is publishing events from global services such as IAM /// to the log files. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("IncludeGlobalServiceEvents")] public System.Boolean? IncludeGlobalServiceEvent { get; set; } #endregion #region Parameter IsMultiRegionTrail /// /// /// Specifies whether the trail applies only to the current Region or to all Regions. /// The default is false. If the trail exists only in the current Region and this value /// is set to true, shadow trails (replications of the trail) will be created in the other /// Regions. If the trail exists in all Regions and this value is set to false, the trail /// will remain in the Region where it was created, and its shadow trails in other Regions /// will be deleted. As a best practice, consider using trails that log events in all /// Regions. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? IsMultiRegionTrail { get; set; } #endregion #region Parameter IsOrganizationTrail /// /// /// Specifies whether the trail is applied to all accounts in an organization in Organizations, /// or only for the current Amazon Web Services account. The default is false, and cannot /// be true unless the call is made on behalf of an Amazon Web Services account that is /// the management account or delegated administrator account for an organization in Organizations. /// If the trail is not an organization trail and this is set to true, the /// trail will be created in all Amazon Web Services accounts that belong to the organization. /// If the trail is an organization trail and this is set to false, the trail /// will remain in the current Amazon Web Services account but be deleted from all member /// accounts in the organization. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? IsOrganizationTrail { get; set; } #endregion #region Parameter KmsKeyId /// /// /// Specifies the KMS key ID to use to encrypt the logs delivered by CloudTrail. The value /// can be an alias name prefixed by "alias/", a fully specified ARN to an alias, a fully /// specified ARN to a key, or a globally unique identifier.CloudTrail also supports KMS multi-Region keys. For more information about multi-Region /// keys, see Using /// multi-Region keys in the Key Management Service Developer Guide.Examples: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KmsKeyId { get; set; } #endregion #region Parameter Name /// /// /// Specifies the name of the trail or trail ARN. If Name is a trail name, /// the string must meet the following requirements:If Name is a trail ARN, it must be in the following format.arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail /// /// #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 S3BucketName /// /// /// Specifies the name of the Amazon S3 bucket designated for publishing log files. See /// Amazon /// S3 Bucket Naming Requirements. /// /// [System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)] public System.String S3BucketName { get; set; } #endregion #region Parameter S3KeyPrefix /// /// /// Specifies the Amazon S3 key prefix that comes after the name of the bucket you have /// designated for log file delivery. For more information, see Finding /// Your CloudTrail Log Files. The maximum length is 200 characters. /// /// [System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true)] public System.String S3KeyPrefix { get; set; } #endregion #region Parameter SnsTopicName /// /// /// Specifies the name of the Amazon SNS topic defined for notification of log file delivery. /// The maximum length is 256 characters. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnsTopicName { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is '*'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.CloudTrail.Model.UpdateTrailResponse). /// Specifying the name of a property of type Amazon.CloudTrail.Model.UpdateTrailResponse 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; } = "*"; #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-CTTrail (UpdateTrail)")) { 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.CloudWatchLogsLogGroupArn = this.CloudWatchLogsLogGroupArn; context.CloudWatchLogsRoleArn = this.CloudWatchLogsRoleArn; context.EnableLogFileValidation = this.EnableLogFileValidation; context.IncludeGlobalServiceEvent = this.IncludeGlobalServiceEvent; context.IsMultiRegionTrail = this.IsMultiRegionTrail; context.IsOrganizationTrail = this.IsOrganizationTrail; context.KmsKeyId = this.KmsKeyId; 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.S3BucketName = this.S3BucketName; context.S3KeyPrefix = this.S3KeyPrefix; context.SnsTopicName = this.SnsTopicName; // 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.CloudTrail.Model.UpdateTrailRequest(); if (cmdletContext.CloudWatchLogsLogGroupArn != null) { request.CloudWatchLogsLogGroupArn = cmdletContext.CloudWatchLogsLogGroupArn; } if (cmdletContext.CloudWatchLogsRoleArn != null) { request.CloudWatchLogsRoleArn = cmdletContext.CloudWatchLogsRoleArn; } if (cmdletContext.EnableLogFileValidation != null) { request.EnableLogFileValidation = cmdletContext.EnableLogFileValidation.Value; } if (cmdletContext.IncludeGlobalServiceEvent != null) { request.IncludeGlobalServiceEvents = cmdletContext.IncludeGlobalServiceEvent.Value; } if (cmdletContext.IsMultiRegionTrail != null) { request.IsMultiRegionTrail = cmdletContext.IsMultiRegionTrail.Value; } if (cmdletContext.IsOrganizationTrail != null) { request.IsOrganizationTrail = cmdletContext.IsOrganizationTrail.Value; } if (cmdletContext.KmsKeyId != null) { request.KmsKeyId = cmdletContext.KmsKeyId; } if (cmdletContext.Name != null) { request.Name = cmdletContext.Name; } if (cmdletContext.S3BucketName != null) { request.S3BucketName = cmdletContext.S3BucketName; } if (cmdletContext.S3KeyPrefix != null) { request.S3KeyPrefix = cmdletContext.S3KeyPrefix; } if (cmdletContext.SnsTopicName != null) { request.SnsTopicName = cmdletContext.SnsTopicName; } 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.CloudTrail.Model.UpdateTrailResponse CallAWSServiceOperation(IAmazonCloudTrail client, Amazon.CloudTrail.Model.UpdateTrailRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS CloudTrail", "UpdateTrail"); try { #if DESKTOP return client.UpdateTrail(request); #elif CORECLR return client.UpdateTrailAsync(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 CloudWatchLogsLogGroupArn { get; set; } public System.String CloudWatchLogsRoleArn { get; set; } public System.Boolean? EnableLogFileValidation { get; set; } public System.Boolean? IncludeGlobalServiceEvent { get; set; } public System.Boolean? IsMultiRegionTrail { get; set; } public System.Boolean? IsOrganizationTrail { get; set; } public System.String KmsKeyId { get; set; } public System.String Name { get; set; } public System.String S3BucketName { get; set; } public System.String S3KeyPrefix { get; set; } public System.String SnsTopicName { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }