/*******************************************************************************
* 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.OAM;
using Amazon.OAM.Model;
namespace Amazon.PowerShell.Cmdlets.CWOAM
{
///
/// Creates a link between a source account and a sink that you have created in a monitoring
/// account.
///
///
///
/// Before you create a link, you must create a sink in the monitoring account and create
/// a sink policy in that account. The sink policy must permit the source account to link
/// to it. You can grant permission to source accounts by granting permission to an entire
/// organization or to individual accounts.
///
/// For more information, see CreateSink
/// and PutSinkPolicy.
///
/// Each monitoring account can be linked to as many as 100,000 source accounts.
///
/// Each source account can be linked to as many as five monitoring accounts.
///
///
[Cmdlet("New", "CWOAMLink", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.OAM.Model.CreateLinkResponse")]
[AWSCmdlet("Calls the CloudWatch Observability Access Manager CreateLink API operation.", Operation = new[] {"CreateLink"}, SelectReturnType = typeof(Amazon.OAM.Model.CreateLinkResponse))]
[AWSCmdletOutput("Amazon.OAM.Model.CreateLinkResponse",
"This cmdlet returns an Amazon.OAM.Model.CreateLinkResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewCWOAMLinkCmdlet : AmazonOAMClientCmdlet, IExecutor
{
#region Parameter LabelTemplate
///
///
/// Specify a friendly human-readable name to use to identify this source account when
/// you are viewing data from it in the monitoring account.You can use a custom label or use the following variables:$AccountName
is the name of the account$AccountEmail
is the globally unique email address of the account$AccountEmailNoDomain
is the email address of the account without the
/// domain name
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String LabelTemplate { get; set; }
#endregion
#region Parameter ResourceType
///
///
/// An array of strings that define which types of data that the source account shares
/// with the monitoring account.
///
///
#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("ResourceTypes")]
public System.String[] ResourceType { get; set; }
#endregion
#region Parameter SinkIdentifier
///
///
/// The ARN of the sink to use to create this link. You can use ListSinks
/// to find the ARNs of sinks.For more information about sinks, see CreateSink.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String SinkIdentifier { get; set; }
#endregion
#region Parameter Tag
///
///
/// Assigns one or more tags (key-value pairs) to the link. Tags can help you organize and categorize your resources. You can also use them to
/// scope user permissions by granting a user permission to access or change only resources
/// with certain tag values.For more information about using tags to control access, see Controlling
/// access to Amazon Web Services resources using tags.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public System.Collections.Hashtable Tag { 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.OAM.Model.CreateLinkResponse).
/// Specifying the name of a property of type Amazon.OAM.Model.CreateLinkResponse 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 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.SinkIdentifier), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-CWOAMLink (CreateLink)"))
{
return;
}
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));
}
context.LabelTemplate = this.LabelTemplate;
#if MODULAR
if (this.LabelTemplate == null && ParameterWasBound(nameof(this.LabelTemplate)))
{
WriteWarning("You are passing $null as a value for parameter LabelTemplate 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
if (this.ResourceType != null)
{
context.ResourceType = new List(this.ResourceType);
}
#if MODULAR
if (this.ResourceType == null && ParameterWasBound(nameof(this.ResourceType)))
{
WriteWarning("You are passing $null as a value for parameter ResourceType 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.SinkIdentifier = this.SinkIdentifier;
#if MODULAR
if (this.SinkIdentifier == null && ParameterWasBound(nameof(this.SinkIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter SinkIdentifier 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
if (this.Tag != null)
{
context.Tag = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.Tag.Keys)
{
context.Tag.Add((String)hashKey, (String)(this.Tag[hashKey]));
}
}
// 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.OAM.Model.CreateLinkRequest();
if (cmdletContext.LabelTemplate != null)
{
request.LabelTemplate = cmdletContext.LabelTemplate;
}
if (cmdletContext.ResourceType != null)
{
request.ResourceTypes = cmdletContext.ResourceType;
}
if (cmdletContext.SinkIdentifier != null)
{
request.SinkIdentifier = cmdletContext.SinkIdentifier;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
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.OAM.Model.CreateLinkResponse CallAWSServiceOperation(IAmazonOAM client, Amazon.OAM.Model.CreateLinkRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "CloudWatch Observability Access Manager", "CreateLink");
try
{
#if DESKTOP
return client.CreateLink(request);
#elif CORECLR
return client.CreateLinkAsync(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 LabelTemplate { get; set; }
public List ResourceType { get; set; }
public System.String SinkIdentifier { get; set; }
public Dictionary Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}