/*******************************************************************************
* 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.TranscribeService;
using Amazon.TranscribeService.Model;
namespace Amazon.PowerShell.Cmdlets.TRS
{
///
/// Creates a new custom vocabulary.
///
///
///
/// When creating a new custom vocabulary, you can either upload a text file that contains
/// your new entries, phrases, and terms into an Amazon S3 bucket and include the URI
/// in your request. Or you can include a list of terms directly in your request using
/// the Phrases
flag.
///
/// Each language has a character set that contains all allowed characters for that specific
/// language. If you use unsupported characters, your custom vocabulary request fails.
/// Refer to Character
/// Sets for Custom Vocabularies to get the character set for your language.
///
/// For more information, see Custom
/// vocabularies.
///
///
[Cmdlet("New", "TRSVocabulary", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.TranscribeService.Model.CreateVocabularyResponse")]
[AWSCmdlet("Calls the Amazon Transcribe Service CreateVocabulary API operation.", Operation = new[] {"CreateVocabulary"}, SelectReturnType = typeof(Amazon.TranscribeService.Model.CreateVocabularyResponse))]
[AWSCmdletOutput("Amazon.TranscribeService.Model.CreateVocabularyResponse",
"This cmdlet returns an Amazon.TranscribeService.Model.CreateVocabularyResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewTRSVocabularyCmdlet : AmazonTranscribeServiceClientCmdlet, IExecutor
{
#region Parameter DataAccessRoleArn
///
///
/// The Amazon Resource Name (ARN) of an IAM role that has permissions to access the Amazon
/// S3 bucket that contains your input files (in this case, your custom vocabulary). If
/// the role that you specify doesn’t have the appropriate permissions to access the specified
/// Amazon S3 location, your request fails.IAM role ARNs have the format arn:partition:iam::account:role/role-name-with-path
.
/// For example: arn:aws:iam::111122223333:role/Admin
.For more information, see IAM
/// ARNs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DataAccessRoleArn { get; set; }
#endregion
#region Parameter LanguageCode
///
///
/// The language code that represents the language of the entries in your custom vocabulary.
/// Each custom vocabulary must contain terms in only one language.A custom vocabulary can only be used to transcribe files in the same language as the
/// custom vocabulary. For example, if you create a custom vocabulary using US English
/// (en-US
), you can only apply this custom vocabulary to files that contain
/// English audio.For a list of supported languages and their associated language codes, refer to the
/// Supported
/// languages table.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
[AWSConstantClassSource("Amazon.TranscribeService.LanguageCode")]
public Amazon.TranscribeService.LanguageCode LanguageCode { get; set; }
#endregion
#region Parameter Phrase
///
///
/// Use this parameter if you want to create your custom vocabulary by including all desired
/// terms, as comma-separated values, within your request. The other option for creating
/// your custom vocabulary is to save your entries in a text file and upload them to an
/// Amazon S3 bucket, then specify the location of your file using the VocabularyFileUri
/// parameter.Note that if you include Phrases
in your request, you cannot use VocabularyFileUri
;
/// you must choose one or the other.Each language has a character set that contains all allowed characters for that specific
/// language. If you use unsupported characters, your custom vocabulary filter request
/// fails. Refer to Character
/// Sets for Custom Vocabularies to get the character set for your language.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Phrases")]
public System.String[] Phrase { get; set; }
#endregion
#region Parameter Tag
///
///
/// Adds one or more custom tags, each in the form of a key:value pair, to a new custom
/// vocabulary at the time you create this new custom vocabulary.To learn more about using tags with Amazon Transcribe, refer to Tagging
/// resources.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.TranscribeService.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter VocabularyFileUri
///
///
/// The Amazon S3 location of the text file that contains your custom vocabulary. The
/// URI must be located in the same Amazon Web Services Region as the resource you're
/// calling.Here's an example URI path: s3://DOC-EXAMPLE-BUCKET/my-vocab-file.txt
Note that if you include VocabularyFileUri
in your request, you cannot
/// use the Phrases
flag; you must choose one or the other.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String VocabularyFileUri { get; set; }
#endregion
#region Parameter VocabularyName
///
///
/// A unique name, chosen by you, for your new custom vocabulary.This name is case sensitive, cannot contain spaces, and must be unique within an Amazon
/// Web Services account. If you try to create a new custom vocabulary with the same name
/// as an existing custom vocabulary, you get a ConflictException
error.
///
///
#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 VocabularyName { 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.TranscribeService.Model.CreateVocabularyResponse).
/// Specifying the name of a property of type Amazon.TranscribeService.Model.CreateVocabularyResponse 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 PassThru
///
/// Changes the cmdlet behavior to return the value passed to the VocabularyName parameter.
/// The -PassThru parameter is deprecated, use -Select '^VocabularyName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^VocabularyName' 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.VocabularyName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-TRSVocabulary (CreateVocabulary)"))
{
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.VocabularyName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.DataAccessRoleArn = this.DataAccessRoleArn;
context.LanguageCode = this.LanguageCode;
#if MODULAR
if (this.LanguageCode == null && ParameterWasBound(nameof(this.LanguageCode)))
{
WriteWarning("You are passing $null as a value for parameter LanguageCode 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.Phrase != null)
{
context.Phrase = new List(this.Phrase);
}
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
context.VocabularyFileUri = this.VocabularyFileUri;
context.VocabularyName = this.VocabularyName;
#if MODULAR
if (this.VocabularyName == null && ParameterWasBound(nameof(this.VocabularyName)))
{
WriteWarning("You are passing $null as a value for parameter VocabularyName 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
// 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.TranscribeService.Model.CreateVocabularyRequest();
if (cmdletContext.DataAccessRoleArn != null)
{
request.DataAccessRoleArn = cmdletContext.DataAccessRoleArn;
}
if (cmdletContext.LanguageCode != null)
{
request.LanguageCode = cmdletContext.LanguageCode;
}
if (cmdletContext.Phrase != null)
{
request.Phrases = cmdletContext.Phrase;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.VocabularyFileUri != null)
{
request.VocabularyFileUri = cmdletContext.VocabularyFileUri;
}
if (cmdletContext.VocabularyName != null)
{
request.VocabularyName = cmdletContext.VocabularyName;
}
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.TranscribeService.Model.CreateVocabularyResponse CallAWSServiceOperation(IAmazonTranscribeService client, Amazon.TranscribeService.Model.CreateVocabularyRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Transcribe Service", "CreateVocabulary");
try
{
#if DESKTOP
return client.CreateVocabulary(request);
#elif CORECLR
return client.CreateVocabularyAsync(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 DataAccessRoleArn { get; set; }
public Amazon.TranscribeService.LanguageCode LanguageCode { get; set; }
public List Phrase { get; set; }
public List Tag { get; set; }
public System.String VocabularyFileUri { get; set; }
public System.String VocabularyName { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}