Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ApiProperties support for Cognitive Services #12870

Merged
merged 5 commits into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,12 @@ public void TestCapabilities()
{
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-Capabilities");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestApiProperties()
{
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-ApiProperties");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1303,4 +1303,41 @@ function Test-Capabilities
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test ApiProperties
#>
function Test-ApiProperties
{
# Setup
$rgname = Get-CognitiveServicesManagementTestResourceName;

try
{
# Test
$accountname = 'csa' + $rgname;
$skuname = 'S0';
$accounttype = 'QnAMaker';
$loc = "West US";

New-AzResourceGroup -Name $rgname -Location $loc;
$apiProperties = New-AzCognitiveServicesAccountApiProperties
$apiProperties.QnaRuntimeEndpoint = "https://sdk-test-qna-maker.azurewebsites.net"
$createdAccount = New-AzCognitiveServicesAccount -ResourceGroupName $rgname -Name $accountname -Type $accounttype -SkuName $skuname -Location $loc -CustomSubdomainName $accountname -ApiProperties $apiProperties -Force;
Assert-NotNull $createdAccount;
Assert-True {$createdAccount.ApiProperties.QnaRuntimeEndpoint -eq "https://sdk-test-qna-maker.azurewebsites.net"}

$apiProperties.QnaRuntimeEndpoint = "https://qnamaker.azurewebsites.net"

$updatedAccount = Set-AzCognitiveServicesAccount -ResourceGroupName $rgname -Name $accountname -ApiProperties $apiProperties -Force;
Assert-NotNull $updatedAccount;
Assert-True {$updatedAccount.ApiProperties.QnaRuntimeEndpoint -eq "https://qnamaker.azurewebsites.net"}
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ CmdletsToExport = 'Get-AzCognitiveServicesAccount',
'Get-AzCognitiveServicesAccountNetworkRuleSet',
'Update-AzCognitiveServicesAccountNetworkRuleSet',
'Add-AzCognitiveServicesAccountNetworkRule',
'Remove-AzCognitiveServicesAccountNetworkRule'
'Remove-AzCognitiveServicesAccountNetworkRule',
'New-AzCognitiveServicesAccountApiProperties'
yangyuan marked this conversation as resolved.
Show resolved Hide resolved

# Variables to export from this module
# VariablesToExport = @()
Expand Down
2 changes: 2 additions & 0 deletions src/CognitiveServices/CognitiveServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
-->
## Upcoming Release
* Show additional legal terms for certain APIs.
* Add `New-AzCognitiveServicesAccountApiProperties` command.
* Support "ApiProperties" parameter for `New-AzCognitiveServicesAccount` and `Set-AzCognitiveServicesAccount`

## Version 1.5.1
* Used `Deny` specifically as NetworkRules default action.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public string KeyVaultUri
[ValidateSet("Enabled", "Disabled", IgnoreCase = true)]
public string PublicNetworkAccess { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The ApiProperties of Cognitive Services Account. Required by specific account types.")]
public CognitiveServicesAccountApiProperties ApiProperties { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
public SwitchParameter Force { get; set; }

Expand All @@ -181,6 +186,11 @@ public override void ExecuteCmdlet()
properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet();
}

if (ApiProperties != null)
{
properties.ApiProperties = ApiProperties;
}

CognitiveServicesAccount createParameters = new CognitiveServicesAccount()
{
Location = Location,
Expand Down Expand Up @@ -270,10 +280,19 @@ public override void ExecuteCmdlet()
Name,
createParameters);
}
catch (ErrorException ex)
{
// If the Exception is ErrorException, clone the exception with modified message.
var newEx = new ErrorException($"Failed to create Cognitive Services account. {ex.Message}", ex);
newEx.Body = ex.Body;
newEx.Request = ex.Request;
newEx.Response = ex.Response;
throw newEx;
}
catch (Exception ex)
{
// Give users a specific message says `Failed to create Cognitive Services account.`
// Details should able be found in the exception.
// Details should able be found in the inner exception.
throw new Exception("Failed to create Cognitive Services account.", ex);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.CognitiveServices.Models;
using System.Management.Automation;
using CognitiveServicesModels = Microsoft.Azure.Management.CognitiveServices.Models;

namespace Microsoft.Azure.Commands.Management.CognitiveServices
{
/// <summary>
/// Generate Cognitive Services Account ApiProperties class
/// </summary>
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CognitiveServicesAccountApiProperties", SupportsShouldProcess = true), OutputType(typeof(CognitiveServicesModels.CognitiveServicesAccountApiProperties))]
public class NewAzureCognitiveServicesAccountApiPropertiesCommand : CognitiveServicesAccountBaseCmdlet
{
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

WriteObject(new CognitiveServicesAccountApiProperties());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public string KeyVaultUri
[ValidateSet("Enabled", "Disabled", IgnoreCase = true)]
public string PublicNetworkAccess { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The ApiProperties of Cognitive Services Account. Required by specific account types.")]
public CognitiveServicesAccountApiProperties ApiProperties { get; set; }
yangyuan marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")]
public SwitchParameter Force { get; set; }

Expand All @@ -164,6 +169,11 @@ public override void ExecuteCmdlet()
hasPropertiesChange = true;
properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet();
}
if (ApiProperties != null)
{
hasPropertiesChange = true;
properties.ApiProperties = ApiProperties;
}

Sku sku = null;
if (!string.IsNullOrWhiteSpace(this.SkuName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public PSVirtualNetworkRule[] VirtualNetworkRule
private bool isIpRuleSet = false;
private bool isNetworkRuleSet = false;


public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.CognitiveServices.dll-Help.xml
Module Name: Az.CognitiveServices
online version: https://docs.microsoft.com/en-us/powershell/module/az.cognitiveservices/new-azcognitiveservicesaccountapiproperties
schema: 2.0.0
---

# New-AzCognitiveServicesAccountApiProperties

## SYNOPSIS
Generate a new instance of Cognitive Services Account ApiProperties

## SYNTAX

```
New-AzCognitiveServicesAccountApiProperties [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
Generate a new instance of Cognitive Services Account ApiProperties.
ApiProperties can be used when creating a new account or updating an existing account.
ApiProperties is required by certain account types.

## EXAMPLES

### Example 1
```powershell
PS C:\> $apiProperties = New-AzCognitiveServicesAccountApiProperties
PS C:\> $apiProperties.QnaRuntimeEndpoint = "https://qnamaker.azurewebsites.net"
PS C:\> New-AzCognitiveServicesAccount -ResourceGroupName cognitive-services-resource-group -name qnamaker -Type QnAMaker -SkuName S0 -Locatio WestUS -ApiProperties $apiProperties
```

Above example will create an QnAMaker account, with API property "QnaRuntimeEndpoint".

## PARAMETERS

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### Microsoft.Azure.Management.CognitiveServices.Models.CognitiveServicesAccountApiProperties

## NOTES

## RELATED LINKS