/*******************************************************************************
* 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.ManagedGrafana;
using Amazon.ManagedGrafana.Model;
namespace Amazon.PowerShell.Cmdlets.MGRF
{
///
/// Modifies an existing Amazon Managed Grafana workspace. If you use this operation and
/// omit any optional parameters, the existing values of those parameters are not changed.
///
///
///
/// To modify the user authentication methods that the workspace uses, such as SAML or
/// IAM Identity Center, use UpdateWorkspaceAuthentication.
///
/// To modify which users in the workspace have the Admin
and Editor
/// Grafana roles, use UpdatePermissions.
///
///
[Cmdlet("Update", "MGRFWorkspace", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.ManagedGrafana.Model.WorkspaceDescription")]
[AWSCmdlet("Calls the Amazon Managed Grafana UpdateWorkspace API operation.", Operation = new[] {"UpdateWorkspace"}, SelectReturnType = typeof(Amazon.ManagedGrafana.Model.UpdateWorkspaceResponse))]
[AWSCmdletOutput("Amazon.ManagedGrafana.Model.WorkspaceDescription or Amazon.ManagedGrafana.Model.UpdateWorkspaceResponse",
"This cmdlet returns an Amazon.ManagedGrafana.Model.WorkspaceDescription object.",
"The service call response (type Amazon.ManagedGrafana.Model.UpdateWorkspaceResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateMGRFWorkspaceCmdlet : AmazonManagedGrafanaClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
protected override bool IsSensitiveResponse { get; set; } = true;
#region Parameter AccountAccessType
///
///
/// Specifies whether the workspace can access Amazon Web Services resources in this Amazon
/// Web Services account only, or whether it can also access Amazon Web Services resources
/// in other accounts in the same organization. If you specify ORGANIZATION
,
/// you must specify which organizational units the workspace can access in the workspaceOrganizationalUnits
/// parameter.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.ManagedGrafana.AccountAccessType")]
public Amazon.ManagedGrafana.AccountAccessType AccountAccessType { get; set; }
#endregion
#region Parameter OrganizationRoleName
///
///
/// The name of an IAM role that already exists to use to access resources through Organizations.
/// This can only be used with a workspace that has the permissionType
set
/// to CUSTOMER_MANAGED
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String OrganizationRoleName { get; set; }
#endregion
#region Parameter PermissionType
///
///
/// Use this parameter if you want to change a workspace from SERVICE_MANAGED
/// to CUSTOMER_MANAGED
. This allows you to manage the permissions that the
/// workspace uses to access datasources and notification channels. If the workspace is
/// in a member Amazon Web Services account of an organization, and that account is not
/// a delegated administrator account, and you want the workspace to access data sources
/// in other Amazon Web Services accounts in the organization, you must choose CUSTOMER_MANAGED
.If you specify this as CUSTOMER_MANAGED
, you must also specify a workspaceRoleArn
/// that the workspace will use for accessing Amazon Web Services resources.For more information on the role and permissions needed, see Amazon
/// Managed Grafana permissions and policies for Amazon Web Services data sources and
/// notification channelsDo not use this to convert a CUSTOMER_MANAGED
workspace to SERVICE_MANAGED
.
/// Do not include this parameter if you want to leave the workspace as SERVICE_MANAGED
.You can convert a CUSTOMER_MANAGED
workspace to SERVICE_MANAGED
/// using the Amazon Managed Grafana console. For more information, see Managing
/// permissions for data sources and notification channels.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.ManagedGrafana.PermissionType")]
public Amazon.ManagedGrafana.PermissionType PermissionType { get; set; }
#endregion
#region Parameter NetworkAccessControl_PrefixListId
///
///
/// An array of prefix list IDs. A prefix list is a list of CIDR ranges of IP addresses.
/// The IP addresses specified are allowed to access your workspace. If the list is not
/// included in the configuration (passed an empty array) then no IP addresses are allowed
/// to access the workspace. You create a prefix list using the Amazon VPC console.Prefix list IDs have the format pl-1a2b3c4d
.For more information about prefix lists, see Group
/// CIDR blocks using managed prefix listsin the Amazon Virtual Private Cloud User
/// Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkAccessControl_PrefixListIds")]
public System.String[] NetworkAccessControl_PrefixListId { get; set; }
#endregion
#region Parameter RemoveNetworkAccessConfiguration
///
///
/// Whether to remove the network access configuration from the workspace.Setting this to true
and providing a networkAccessControl
/// to set will return an error.If you remove this configuration by setting this to true
, then all IP
/// addresses and VPC endpoints will be allowed. Standard Grafana authentication and authorization
/// will still be required.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? RemoveNetworkAccessConfiguration { get; set; }
#endregion
#region Parameter RemoveVpcConfiguration
///
///
/// Whether to remove the VPC configuration from the workspace.Setting this to true
and providing a vpcConfiguration
to
/// set will return an error.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? RemoveVpcConfiguration { get; set; }
#endregion
#region Parameter VpcConfiguration_SecurityGroupId
///
///
/// The list of Amazon EC2 security group IDs attached to the Amazon VPC for your Grafana
/// workspace to connect. Duplicates not allowed.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("VpcConfiguration_SecurityGroupIds")]
public System.String[] VpcConfiguration_SecurityGroupId { get; set; }
#endregion
#region Parameter StackSetName
///
///
/// The name of the CloudFormation stack set to use to generate IAM roles to be used for
/// this workspace.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String StackSetName { get; set; }
#endregion
#region Parameter VpcConfiguration_SubnetId
///
///
/// The list of Amazon EC2 subnet IDs created in the Amazon VPC for your Grafana workspace
/// to connect. Duplicates not allowed.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("VpcConfiguration_SubnetIds")]
public System.String[] VpcConfiguration_SubnetId { get; set; }
#endregion
#region Parameter NetworkAccessControl_VpceId
///
///
/// An array of Amazon VPC endpoint IDs for the workspace. You can create VPC endpoints
/// to your Amazon Managed Grafana workspace for access from within a VPC. If a NetworkAccessConfiguration
/// is specified then only VPC endpoints specified here are allowed to access the workspace.
/// If you pass in an empty array of strings, then no VPCs are allowed to access the workspace.VPC endpoint IDs have the format vpce-1a2b3c4d
.For more information about creating an interface VPC endpoint, see Interface
/// VPC endpoints in the Amazon Managed Grafana User Guide.The only VPC endpoints that can be specified here are interface VPC endpoints for
/// Grafana workspaces (using the com.amazonaws.[region].grafana-workspace
/// service endpoint). Other VPC endpoints are ignored.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NetworkAccessControl_VpceIds")]
public System.String[] NetworkAccessControl_VpceId { get; set; }
#endregion
#region Parameter WorkspaceDataSource
///
///
/// This parameter is for internal use only, and should not be used.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("WorkspaceDataSources")]
public System.String[] WorkspaceDataSource { get; set; }
#endregion
#region Parameter WorkspaceDescription
///
///
/// A description for the workspace. This is used only to help you identify this workspace.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String WorkspaceDescription { get; set; }
#endregion
#region Parameter WorkspaceId
///
///
/// The ID of the workspace to update.
///
///
#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 WorkspaceId { get; set; }
#endregion
#region Parameter WorkspaceName
///
///
/// A new name for the workspace to update.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String WorkspaceName { get; set; }
#endregion
#region Parameter WorkspaceNotificationDestination
///
///
/// Specify the Amazon Web Services notification channels that you plan to use in this
/// workspace. Specifying these data sources here enables Amazon Managed Grafana to create
/// IAM roles and permissions that allow Amazon Managed Grafana to use these channels.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("WorkspaceNotificationDestinations")]
public System.String[] WorkspaceNotificationDestination { get; set; }
#endregion
#region Parameter WorkspaceOrganizationalUnit
///
///
/// Specifies the organizational units that this workspace is allowed to use data sources
/// from, if this workspace is in an account that is part of an organization.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("WorkspaceOrganizationalUnits")]
public System.String[] WorkspaceOrganizationalUnit { get; set; }
#endregion
#region Parameter WorkspaceRoleArn
///
///
/// Specifies an IAM role that grants permissions to Amazon Web Services resources that
/// the workspace accesses, such as data sources and notification channels. If this workspace
/// has permissionType
CUSTOMER_MANAGED
, then this role is required.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String WorkspaceRoleArn { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'Workspace'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.ManagedGrafana.Model.UpdateWorkspaceResponse).
/// Specifying the name of a property of type Amazon.ManagedGrafana.Model.UpdateWorkspaceResponse 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; } = "Workspace";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the WorkspaceId parameter.
/// The -PassThru parameter is deprecated, use -Select '^WorkspaceId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^WorkspaceId' 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.WorkspaceId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-MGRFWorkspace (UpdateWorkspace)"))
{
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.WorkspaceId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AccountAccessType = this.AccountAccessType;
if (this.NetworkAccessControl_PrefixListId != null)
{
context.NetworkAccessControl_PrefixListId = new List(this.NetworkAccessControl_PrefixListId);
}
if (this.NetworkAccessControl_VpceId != null)
{
context.NetworkAccessControl_VpceId = new List(this.NetworkAccessControl_VpceId);
}
context.OrganizationRoleName = this.OrganizationRoleName;
context.PermissionType = this.PermissionType;
context.RemoveNetworkAccessConfiguration = this.RemoveNetworkAccessConfiguration;
context.RemoveVpcConfiguration = this.RemoveVpcConfiguration;
context.StackSetName = this.StackSetName;
if (this.VpcConfiguration_SecurityGroupId != null)
{
context.VpcConfiguration_SecurityGroupId = new List(this.VpcConfiguration_SecurityGroupId);
}
if (this.VpcConfiguration_SubnetId != null)
{
context.VpcConfiguration_SubnetId = new List(this.VpcConfiguration_SubnetId);
}
if (this.WorkspaceDataSource != null)
{
context.WorkspaceDataSource = new List(this.WorkspaceDataSource);
}
context.WorkspaceDescription = this.WorkspaceDescription;
context.WorkspaceId = this.WorkspaceId;
#if MODULAR
if (this.WorkspaceId == null && ParameterWasBound(nameof(this.WorkspaceId)))
{
WriteWarning("You are passing $null as a value for parameter WorkspaceId 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.WorkspaceName = this.WorkspaceName;
if (this.WorkspaceNotificationDestination != null)
{
context.WorkspaceNotificationDestination = new List(this.WorkspaceNotificationDestination);
}
if (this.WorkspaceOrganizationalUnit != null)
{
context.WorkspaceOrganizationalUnit = new List(this.WorkspaceOrganizationalUnit);
}
context.WorkspaceRoleArn = this.WorkspaceRoleArn;
// 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.ManagedGrafana.Model.UpdateWorkspaceRequest();
if (cmdletContext.AccountAccessType != null)
{
request.AccountAccessType = cmdletContext.AccountAccessType;
}
// populate NetworkAccessControl
var requestNetworkAccessControlIsNull = true;
request.NetworkAccessControl = new Amazon.ManagedGrafana.Model.NetworkAccessConfiguration();
List requestNetworkAccessControl_networkAccessControl_PrefixListId = null;
if (cmdletContext.NetworkAccessControl_PrefixListId != null)
{
requestNetworkAccessControl_networkAccessControl_PrefixListId = cmdletContext.NetworkAccessControl_PrefixListId;
}
if (requestNetworkAccessControl_networkAccessControl_PrefixListId != null)
{
request.NetworkAccessControl.PrefixListIds = requestNetworkAccessControl_networkAccessControl_PrefixListId;
requestNetworkAccessControlIsNull = false;
}
List requestNetworkAccessControl_networkAccessControl_VpceId = null;
if (cmdletContext.NetworkAccessControl_VpceId != null)
{
requestNetworkAccessControl_networkAccessControl_VpceId = cmdletContext.NetworkAccessControl_VpceId;
}
if (requestNetworkAccessControl_networkAccessControl_VpceId != null)
{
request.NetworkAccessControl.VpceIds = requestNetworkAccessControl_networkAccessControl_VpceId;
requestNetworkAccessControlIsNull = false;
}
// determine if request.NetworkAccessControl should be set to null
if (requestNetworkAccessControlIsNull)
{
request.NetworkAccessControl = null;
}
if (cmdletContext.OrganizationRoleName != null)
{
request.OrganizationRoleName = cmdletContext.OrganizationRoleName;
}
if (cmdletContext.PermissionType != null)
{
request.PermissionType = cmdletContext.PermissionType;
}
if (cmdletContext.RemoveNetworkAccessConfiguration != null)
{
request.RemoveNetworkAccessConfiguration = cmdletContext.RemoveNetworkAccessConfiguration.Value;
}
if (cmdletContext.RemoveVpcConfiguration != null)
{
request.RemoveVpcConfiguration = cmdletContext.RemoveVpcConfiguration.Value;
}
if (cmdletContext.StackSetName != null)
{
request.StackSetName = cmdletContext.StackSetName;
}
// populate VpcConfiguration
var requestVpcConfigurationIsNull = true;
request.VpcConfiguration = new Amazon.ManagedGrafana.Model.VpcConfiguration();
List requestVpcConfiguration_vpcConfiguration_SecurityGroupId = null;
if (cmdletContext.VpcConfiguration_SecurityGroupId != null)
{
requestVpcConfiguration_vpcConfiguration_SecurityGroupId = cmdletContext.VpcConfiguration_SecurityGroupId;
}
if (requestVpcConfiguration_vpcConfiguration_SecurityGroupId != null)
{
request.VpcConfiguration.SecurityGroupIds = requestVpcConfiguration_vpcConfiguration_SecurityGroupId;
requestVpcConfigurationIsNull = false;
}
List requestVpcConfiguration_vpcConfiguration_SubnetId = null;
if (cmdletContext.VpcConfiguration_SubnetId != null)
{
requestVpcConfiguration_vpcConfiguration_SubnetId = cmdletContext.VpcConfiguration_SubnetId;
}
if (requestVpcConfiguration_vpcConfiguration_SubnetId != null)
{
request.VpcConfiguration.SubnetIds = requestVpcConfiguration_vpcConfiguration_SubnetId;
requestVpcConfigurationIsNull = false;
}
// determine if request.VpcConfiguration should be set to null
if (requestVpcConfigurationIsNull)
{
request.VpcConfiguration = null;
}
if (cmdletContext.WorkspaceDataSource != null)
{
request.WorkspaceDataSources = cmdletContext.WorkspaceDataSource;
}
if (cmdletContext.WorkspaceDescription != null)
{
request.WorkspaceDescription = cmdletContext.WorkspaceDescription;
}
if (cmdletContext.WorkspaceId != null)
{
request.WorkspaceId = cmdletContext.WorkspaceId;
}
if (cmdletContext.WorkspaceName != null)
{
request.WorkspaceName = cmdletContext.WorkspaceName;
}
if (cmdletContext.WorkspaceNotificationDestination != null)
{
request.WorkspaceNotificationDestinations = cmdletContext.WorkspaceNotificationDestination;
}
if (cmdletContext.WorkspaceOrganizationalUnit != null)
{
request.WorkspaceOrganizationalUnits = cmdletContext.WorkspaceOrganizationalUnit;
}
if (cmdletContext.WorkspaceRoleArn != null)
{
request.WorkspaceRoleArn = cmdletContext.WorkspaceRoleArn;
}
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.ManagedGrafana.Model.UpdateWorkspaceResponse CallAWSServiceOperation(IAmazonManagedGrafana client, Amazon.ManagedGrafana.Model.UpdateWorkspaceRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Managed Grafana", "UpdateWorkspace");
try
{
#if DESKTOP
return client.UpdateWorkspace(request);
#elif CORECLR
return client.UpdateWorkspaceAsync(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 Amazon.ManagedGrafana.AccountAccessType AccountAccessType { get; set; }
public List NetworkAccessControl_PrefixListId { get; set; }
public List NetworkAccessControl_VpceId { get; set; }
public System.String OrganizationRoleName { get; set; }
public Amazon.ManagedGrafana.PermissionType PermissionType { get; set; }
public System.Boolean? RemoveNetworkAccessConfiguration { get; set; }
public System.Boolean? RemoveVpcConfiguration { get; set; }
public System.String StackSetName { get; set; }
public List VpcConfiguration_SecurityGroupId { get; set; }
public List VpcConfiguration_SubnetId { get; set; }
public List WorkspaceDataSource { get; set; }
public System.String WorkspaceDescription { get; set; }
public System.String WorkspaceId { get; set; }
public System.String WorkspaceName { get; set; }
public List WorkspaceNotificationDestination { get; set; }
public List WorkspaceOrganizationalUnit { get; set; }
public System.String WorkspaceRoleArn { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.Workspace;
}
}
}