/******************************************************************************* * 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.Macie2; using Amazon.Macie2.Model; namespace Amazon.PowerShell.Cmdlets.MAC2 { /// /// Retrieves the details of one or more findings. /// [Cmdlet("Get", "MAC2Finding")] [OutputType("Amazon.Macie2.Model.Finding")] [AWSCmdlet("Calls the Amazon Macie 2 GetFindings API operation.", Operation = new[] {"GetFindings"}, SelectReturnType = typeof(Amazon.Macie2.Model.GetFindingsResponse))] [AWSCmdletOutput("Amazon.Macie2.Model.Finding or Amazon.Macie2.Model.GetFindingsResponse", "This cmdlet returns a collection of Amazon.Macie2.Model.Finding objects.", "The service call response (type Amazon.Macie2.Model.GetFindingsResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class GetMAC2FindingCmdlet : AmazonMacie2ClientCmdlet, IExecutor { #region Parameter SortCriteria_AttributeName /// /// /// The name of the property to sort the results by. Valid values are: count, createdAt, /// policyDetails.action.apiCallDetails.firstSeen, policyDetails.action.apiCallDetails.lastSeen, /// resourcesAffected, severity.score, type, and updatedAt. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SortCriteria_AttributeName { get; set; } #endregion #region Parameter FindingId /// /// /// An array of strings that lists the unique identifiers for the findings to retrieve. /// You can specify as many as 50 unique identifiers in this array. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyCollection] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [Alias("FindingIds")] public System.String[] FindingId { get; set; } #endregion #region Parameter SortCriteria_OrderBy /// /// /// The sort order to apply to the results, based on the value for the property specified /// by the attributeName property. Valid values are: ASC, sort the results in ascending /// order; and, DESC, sort the results in descending order. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.Macie2.OrderBy")] public Amazon.Macie2.OrderBy SortCriteria_OrderBy { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Findings'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Macie2.Model.GetFindingsResponse). /// Specifying the name of a property of type Amazon.Macie2.Model.GetFindingsResponse 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; } = "Findings"; #endregion protected override void ProcessRecord() { this._AWSSignerType = "v4"; base.ProcessRecord(); var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); } if (this.FindingId != null) { context.FindingId = new List(this.FindingId); } #if MODULAR if (this.FindingId == null && ParameterWasBound(nameof(this.FindingId))) { WriteWarning("You are passing $null as a value for parameter FindingId 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.SortCriteria_AttributeName = this.SortCriteria_AttributeName; context.SortCriteria_OrderBy = this.SortCriteria_OrderBy; // 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.Macie2.Model.GetFindingsRequest(); if (cmdletContext.FindingId != null) { request.FindingIds = cmdletContext.FindingId; } // populate SortCriteria var requestSortCriteriaIsNull = true; request.SortCriteria = new Amazon.Macie2.Model.SortCriteria(); System.String requestSortCriteria_sortCriteria_AttributeName = null; if (cmdletContext.SortCriteria_AttributeName != null) { requestSortCriteria_sortCriteria_AttributeName = cmdletContext.SortCriteria_AttributeName; } if (requestSortCriteria_sortCriteria_AttributeName != null) { request.SortCriteria.AttributeName = requestSortCriteria_sortCriteria_AttributeName; requestSortCriteriaIsNull = false; } Amazon.Macie2.OrderBy requestSortCriteria_sortCriteria_OrderBy = null; if (cmdletContext.SortCriteria_OrderBy != null) { requestSortCriteria_sortCriteria_OrderBy = cmdletContext.SortCriteria_OrderBy; } if (requestSortCriteria_sortCriteria_OrderBy != null) { request.SortCriteria.OrderBy = requestSortCriteria_sortCriteria_OrderBy; requestSortCriteriaIsNull = false; } // determine if request.SortCriteria should be set to null if (requestSortCriteriaIsNull) { request.SortCriteria = null; } 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.Macie2.Model.GetFindingsResponse CallAWSServiceOperation(IAmazonMacie2 client, Amazon.Macie2.Model.GetFindingsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Macie 2", "GetFindings"); try { #if DESKTOP return client.GetFindings(request); #elif CORECLR return client.GetFindingsAsync(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 List FindingId { get; set; } public System.String SortCriteria_AttributeName { get; set; } public Amazon.Macie2.OrderBy SortCriteria_OrderBy { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Findings; } } }