/******************************************************************************* * 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.IdentityManagement; using Amazon.IdentityManagement.Model; namespace Amazon.PowerShell.Cmdlets.IAM { /// /// Generates a report for service last accessed data for Organizations. You can generate /// a report for any entities (organization root, organizational unit, or account) or /// policies in your organization. /// /// /// /// To call this operation, you must be signed in using your Organizations management /// account credentials. You can use your long-term IAM user or root user credentials, /// or temporary credentials from assuming an IAM role. SCPs must be enabled for your /// organization root. You must have the required IAM and Organizations permissions. For /// more information, see Refining /// permissions using service last accessed data in the IAM User Guide. /// /// You can generate a service last accessed data report for entities by specifying only /// the entity's path. This data includes a list of services that are allowed by any service /// control policies (SCPs) that apply to the entity. /// /// You can generate a service last accessed data report for a policy by specifying an /// entity's path and an optional Organizations policy ID. This data includes a list of /// services that are allowed by the specified SCP. /// /// For each service in both report types, the data includes the most recent account activity /// that the policy allows to account principals in the entity or the entity's children. /// For important information about the data, reporting period, permissions required, /// troubleshooting, and supported Regions see Reducing /// permissions using service last accessed data in the IAM User Guide. /// /// The data includes all attempts to access Amazon Web Services, not just the successful /// ones. This includes all attempts that were made using the Amazon Web Services Management /// Console, the Amazon Web Services API through any of the SDKs, or any of the command /// line tools. An unexpected entry in the service last accessed data does not mean that /// an account has been compromised, because the request might have been denied. Refer /// to your CloudTrail logs as the authoritative source for information about all API /// calls and whether they were successful or denied access. For more information, see Logging /// IAM events with CloudTrail in the IAM User Guide. /// /// This operation returns a JobId. Use this parameter in the GetOrganizationsAccessReport operation to check the status of the report generation. To check the status /// of this request, use the JobId parameter in the GetOrganizationsAccessReport operation and test the JobStatus response parameter. When the /// job is complete, you can retrieve the report. /// /// To generate a service last accessed data report for entities, specify an entity path /// without specifying the optional Organizations policy ID. The type of entity that you /// specify determines the data returned in the report. /// /// To generate a service last accessed data report for policies, specify an entity path /// and the optional Organizations policy ID. The type of entity that you specify determines /// the data returned for each service. /// /// Service last accessed data does not use other policy types when determining whether /// a principal could access a service. These other policy types include identity-based /// policies, resource-based policies, access control lists, IAM permissions boundaries, /// and STS assume role policies. It only applies SCP logic. For more about the evaluation /// of policy types, see Evaluating /// policies in the IAM User Guide. /// /// For more information about service last accessed data, see Reducing /// policy scope by viewing user activity in the IAM User Guide. /// /// [Cmdlet("New", "IAMOrganizationsAccessReport", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS Identity and Access Management GenerateOrganizationsAccessReport API operation.", Operation = new[] {"GenerateOrganizationsAccessReport"}, SelectReturnType = typeof(Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse))] [AWSCmdletOutput("System.String or Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewIAMOrganizationsAccessReportCmdlet : AmazonIdentityManagementServiceClientCmdlet, IExecutor { #region Parameter EntityPath /// /// /// The path of the Organizations entity (root, OU, or account). You can build an entity /// path using the known structure of your organization. For example, assume that your /// account ID is 123456789012 and its parent OU ID is ou-rge0-awsabcde. /// The organization root ID is r-f6g7h8i9j0example and your organization /// ID is o-a1b2c3d4e5. Your entity path is o-a1b2c3d4e5/r-f6g7h8i9j0example/ou-rge0-awsabcde/123456789012. /// /// #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 EntityPath { get; set; } #endregion #region Parameter OrganizationsPolicyId /// /// /// The identifier of the Organizations service control policy (SCP). This parameter is /// optional.This ID is used to generate information about when an account principal that is limited /// by the SCP attempted to access an Amazon Web Services service. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String OrganizationsPolicyId { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'JobId'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse). /// Specifying the name of a property of type Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse 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; } = "JobId"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the EntityPath parameter. /// The -PassThru parameter is deprecated, use -Select '^EntityPath' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^EntityPath' 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.EntityPath), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-IAMOrganizationsAccessReport (GenerateOrganizationsAccessReport)")) { 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.EntityPath; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.EntityPath = this.EntityPath; #if MODULAR if (this.EntityPath == null && ParameterWasBound(nameof(this.EntityPath))) { WriteWarning("You are passing $null as a value for parameter EntityPath 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.OrganizationsPolicyId = this.OrganizationsPolicyId; // 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.IdentityManagement.Model.GenerateOrganizationsAccessReportRequest(); if (cmdletContext.EntityPath != null) { request.EntityPath = cmdletContext.EntityPath; } if (cmdletContext.OrganizationsPolicyId != null) { request.OrganizationsPolicyId = cmdletContext.OrganizationsPolicyId; } 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.IdentityManagement.Model.GenerateOrganizationsAccessReportResponse CallAWSServiceOperation(IAmazonIdentityManagementService client, Amazon.IdentityManagement.Model.GenerateOrganizationsAccessReportRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Identity and Access Management", "GenerateOrganizationsAccessReport"); try { #if DESKTOP return client.GenerateOrganizationsAccessReport(request); #elif CORECLR return client.GenerateOrganizationsAccessReportAsync(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 EntityPath { get; set; } public System.String OrganizationsPolicyId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.JobId; } } }