/*******************************************************************************
* 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.Rekognition;
using Amazon.Rekognition.Model;
namespace Amazon.PowerShell.Cmdlets.REK
{
///
/// Attaches a project policy to a Amazon Rekognition Custom Labels project in a trusting
/// AWS account. A project policy specifies that a trusted AWS account can copy a model
/// version from a trusting AWS account to a project in the trusted AWS account. To copy
/// a model version you use the CopyProjectVersion operation.
///
///
///
/// For more information about the format of a project policy document, see Attaching
/// a project policy (SDK) in the Amazon Rekognition Custom Labels Developer Guide.
///
///
/// The response from PutProjectPolicy
is a revision ID for the project policy.
/// You can attach multiple project policies to a project. You can also update an existing
/// project policy by specifying the policy revision ID of the existing policy.
///
/// To remove a project policy from a project, call DeleteProjectPolicy. To get
/// a list of project policies attached to a project, call ListProjectPolicies.
///
///
/// You copy a model version by calling CopyProjectVersion.
///
/// This operation requires permissions to perform the rekognition:PutProjectPolicy
/// action.
///
///
[Cmdlet("Write", "REKProjectPolicy", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the Amazon Rekognition PutProjectPolicy API operation.", Operation = new[] {"PutProjectPolicy"}, SelectReturnType = typeof(Amazon.Rekognition.Model.PutProjectPolicyResponse))]
[AWSCmdletOutput("System.String or Amazon.Rekognition.Model.PutProjectPolicyResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.Rekognition.Model.PutProjectPolicyResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class WriteREKProjectPolicyCmdlet : AmazonRekognitionClientCmdlet, IExecutor
{
#region Parameter PolicyDocument
///
///
/// A resource policy to add to the model. The policy is a JSON structure that contains
/// one or more statements that define the policy. The policy must follow the IAM syntax.
/// For more information about the contents of a JSON policy document, see IAM
/// JSON policy reference.
///
///
#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 PolicyDocument { get; set; }
#endregion
#region Parameter PolicyName
///
///
/// A name for the policy.
///
///
#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 PolicyName { get; set; }
#endregion
#region Parameter PolicyRevisionId
///
///
/// The revision ID for the Project Policy. Each time you modify a policy, Amazon Rekognition
/// Custom Labels generates and assigns a new PolicyRevisionId
and then deletes
/// the previous version of the policy.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PolicyRevisionId { get; set; }
#endregion
#region Parameter ProjectArn
///
///
/// The Amazon Resource Name (ARN) of the project that the project policy is attached
/// to.
///
///
#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 ProjectArn { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'PolicyRevisionId'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Rekognition.Model.PutProjectPolicyResponse).
/// Specifying the name of a property of type Amazon.Rekognition.Model.PutProjectPolicyResponse 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; } = "PolicyRevisionId";
#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 = string.Empty;
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Write-REKProjectPolicy (PutProjectPolicy)"))
{
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.PolicyDocument = this.PolicyDocument;
#if MODULAR
if (this.PolicyDocument == null && ParameterWasBound(nameof(this.PolicyDocument)))
{
WriteWarning("You are passing $null as a value for parameter PolicyDocument 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.PolicyName = this.PolicyName;
#if MODULAR
if (this.PolicyName == null && ParameterWasBound(nameof(this.PolicyName)))
{
WriteWarning("You are passing $null as a value for parameter PolicyName 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.PolicyRevisionId = this.PolicyRevisionId;
context.ProjectArn = this.ProjectArn;
#if MODULAR
if (this.ProjectArn == null && ParameterWasBound(nameof(this.ProjectArn)))
{
WriteWarning("You are passing $null as a value for parameter ProjectArn 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.Rekognition.Model.PutProjectPolicyRequest();
if (cmdletContext.PolicyDocument != null)
{
request.PolicyDocument = cmdletContext.PolicyDocument;
}
if (cmdletContext.PolicyName != null)
{
request.PolicyName = cmdletContext.PolicyName;
}
if (cmdletContext.PolicyRevisionId != null)
{
request.PolicyRevisionId = cmdletContext.PolicyRevisionId;
}
if (cmdletContext.ProjectArn != null)
{
request.ProjectArn = cmdletContext.ProjectArn;
}
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.Rekognition.Model.PutProjectPolicyResponse CallAWSServiceOperation(IAmazonRekognition client, Amazon.Rekognition.Model.PutProjectPolicyRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Rekognition", "PutProjectPolicy");
try
{
#if DESKTOP
return client.PutProjectPolicy(request);
#elif CORECLR
return client.PutProjectPolicyAsync(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 PolicyDocument { get; set; }
public System.String PolicyName { get; set; }
public System.String PolicyRevisionId { get; set; }
public System.String ProjectArn { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.PolicyRevisionId;
}
}
}