/******************************************************************************* * 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.CodeArtifact; using Amazon.CodeArtifact.Model; namespace Amazon.PowerShell.Cmdlets.CA { /// /// Creates a domain. CodeArtifact domains make it easier to manage multiple repositories /// across an organization. You can use a domain to apply permissions across many repositories /// owned by different Amazon Web Services accounts. An asset is stored only once in a /// domain, even if it's in multiple repositories. /// /// /// /// Although you can have multiple domains, we recommend a single production domain that /// contains all published artifacts so that your development teams can find and share /// packages. You can use a second pre-production domain to test changes to the production /// domain configuration. /// /// [Cmdlet("New", "CADomain", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.CodeArtifact.Model.DomainDescription")] [AWSCmdlet("Calls the AWS CodeArtifact CreateDomain API operation.", Operation = new[] {"CreateDomain"}, SelectReturnType = typeof(Amazon.CodeArtifact.Model.CreateDomainResponse))] [AWSCmdletOutput("Amazon.CodeArtifact.Model.DomainDescription or Amazon.CodeArtifact.Model.CreateDomainResponse", "This cmdlet returns an Amazon.CodeArtifact.Model.DomainDescription object.", "The service call response (type Amazon.CodeArtifact.Model.CreateDomainResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewCADomainCmdlet : AmazonCodeArtifactClientCmdlet, IExecutor { #region Parameter Domain /// /// /// The name of the domain to create. All domain names in an Amazon Web Services Region /// that are in the same Amazon Web Services account must be unique. The domain name is /// used as the prefix in DNS hostnames. Do not use sensitive information in a domain /// name because it is publicly discoverable. /// /// #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 Domain { get; set; } #endregion #region Parameter EncryptionKey /// /// /// The encryption key for the domain. This is used to encrypt content stored in a domain. /// An encryption key can be a key ID, a key Amazon Resource Name (ARN), a key alias, /// or a key alias ARN. To specify an encryptionKey, your IAM role must have /// kms:DescribeKey and kms:CreateGrant permissions on the encryption /// key that is used. For more information, see DescribeKey /// in the Key Management Service API Reference and Key /// Management Service API Permissions Reference in the Key Management Service /// Developer Guide. CodeArtifact supports only symmetric CMKs. Do not associate an asymmetric CMK with /// your domain. For more information, see Using /// symmetric and asymmetric keys in the Key Management Service Developer Guide. /// /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String EncryptionKey { get; set; } #endregion #region Parameter Tag /// /// /// One or more tag key-value pairs for the domain. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.CodeArtifact.Model.Tag[] Tag { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Domain'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.CodeArtifact.Model.CreateDomainResponse). /// Specifying the name of a property of type Amazon.CodeArtifact.Model.CreateDomainResponse 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; } = "Domain"; #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.Domain), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-CADomain (CreateDomain)")) { 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.Domain = this.Domain; #if MODULAR if (this.Domain == null && ParameterWasBound(nameof(this.Domain))) { WriteWarning("You are passing $null as a value for parameter Domain 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.EncryptionKey = this.EncryptionKey; if (this.Tag != null) { context.Tag = new List(this.Tag); } // 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.CodeArtifact.Model.CreateDomainRequest(); if (cmdletContext.Domain != null) { request.Domain = cmdletContext.Domain; } if (cmdletContext.EncryptionKey != null) { request.EncryptionKey = cmdletContext.EncryptionKey; } 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.CodeArtifact.Model.CreateDomainResponse CallAWSServiceOperation(IAmazonCodeArtifact client, Amazon.CodeArtifact.Model.CreateDomainRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS CodeArtifact", "CreateDomain"); try { #if DESKTOP return client.CreateDomain(request); #elif CORECLR return client.CreateDomainAsync(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 Domain { get; set; } public System.String EncryptionKey { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Domain; } } }