Skip to content

[CognitiveServices] Support getting account types (kinds). #7519

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

Merged
merged 6 commits into from Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -70,6 +70,9 @@
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetAccounts.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetAccountType.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetUsages.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public void TestAccountSkus()
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountSkus");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetAccountType()
{
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountType");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestPipingToGetKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,36 @@ function Test-GetAzureRmCognitiveServicesAccountSkus
}
}

<#
.SYNOPSIS
Test Get-AzureRmCognitiveServicesAccountType
#>
function Test-GetAzureRmCognitiveServicesAccountType
{
try
{
$typeName = (Get-AzureRmCognitiveServicesAccountType -TypeName 'Face');
Assert-AreEqual 'Face' $typeName

$typeName = (Get-AzureRmCognitiveServicesAccountType -TypeName 'InvalidKind');
Assert-Null $typeName

$typeNames = (Get-AzureRmCognitiveServicesAccountType -Location 'westus');
Assert-True {$typeNames.Contains('Face')}

$typeNames = (Get-AzureRmCognitiveServicesAccountType);
Assert-True {$typeNames.Contains('Face')}

$typeNames = (Get-AzureRmCognitiveServicesAccountType -Location 'global');
Assert-False {$typeNames.Contains('Face')}
Assert-True {$typeNames.Contains('Bing.Search.v7')}
}
finally
{
}
}


<#
.SYNOPSIS
Test Get-AzureRmCognitiveServicesAccount | Get-AzureRmCognitiveServicesAccountKey
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ FunctionsToExport = @()
CmdletsToExport = 'Get-AzCognitiveServicesAccount',
'Get-AzCognitiveServicesAccountKey',
'Get-AzCognitiveServicesAccountSkus',
'Get-AzCognitiveServicesAccountUsage',
'Get-AzCognitiveServicesAccountType',
'Get-AzCognitiveServicesAccountUsage',
'New-AzCognitiveServicesAccount',
'New-AzCognitiveServicesAccountKey',
'Remove-AzCognitiveServicesAccount',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ FunctionsToExport = @()
CmdletsToExport = 'Get-AzureRmCognitiveServicesAccount',
'Get-AzureRmCognitiveServicesAccountKey',
'Get-AzureRmCognitiveServicesAccountSkus',
'Get-AzureRmCognitiveServicesAccountType',
'Get-AzureRmCognitiveServicesAccountUsage',
'New-AzureRmCognitiveServicesAccount',
'New-AzureRmCognitiveServicesAccountKey',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
-->
## Current Release

* Add Get-AzureRmCognitiveServicesAccountSkus operation.

## Version 0.9.11
* Support Get-AzureRmCognitiveServicesAccountSkus without an existing account.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public abstract class CognitiveServicesAccountBaseCmdlet : AzureRMCmdlet
{
private CognitiveServicesManagementClientWrapper cognitiveServicesClientWrapper;

protected const string CognitiveServicesAccountNounStr = "AzureRmCognitiveServicesAccount";
protected const string CognitiveServicesAccountNounStr = ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CognitiveServicesAccount";
protected const string CognitiveServicesAccountKeyNounStr = CognitiveServicesAccountNounStr + "Key";
protected const string CognitiveServicesAccountSkusNounStr = CognitiveServicesAccountNounStr + "Skus";
protected const string CognitiveServicesAccountTypeNounStr = CognitiveServicesAccountNounStr + "Type";
protected const string CognitiveServicesAccountUsagesNounStr = CognitiveServicesAccountNounStr + "Usage";

protected const string CognitiveServicesAccountNameAlias = "CognitiveServicesAccountName";
Expand All @@ -40,6 +41,9 @@ public abstract class CognitiveServicesAccountBaseCmdlet : AzureRMCmdlet
protected const string CognitiveServicesAccountTypeAlias = "CognitiveServicesAccountType";
protected const string AccountTypeAlias = "AccountType";
protected const string KindAlias = "Kind";
protected const string CognitiveServicesAccountTypeNameAlias = "CognitiveServicesAccountTypeName";
protected const string AccountTypeNameAlias = "AccountTypeName";
protected const string KindNameAlias = "KindName";

protected const string TagsAlias = "Tags";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ----------------------------------------------------------------------------------
//
// 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.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.CognitiveServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Management.CognitiveServices
{
/// <summary>
/// Get Account Types for Cognitive Services Account Type(s)
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CognitiveServicesAccountType", DefaultParameterSetName = GetAccountTypesParamSetName), OutputType(typeof(string[]), typeof(string))]
public class GetAzureCognitiveServicesAccountTypeCommand : CognitiveServicesAccountBaseCmdlet
{
protected const string GetAccountTypeWithNameParamSetName = "GetAccountTypeWithName";
protected const string GetAccountTypesParamSetName = "GetAccountTypes";


[Parameter(
ParameterSetName = GetAccountTypeWithNameParamSetName,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Cognitive Services Account Type Name.")]
[Alias(CognitiveServicesAccountTypeNameAlias, AccountTypeNameAlias, KindNameAlias)]
public string TypeName { get; set; }

[Parameter(
ParameterSetName = GetAccountTypesParamSetName,
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Cognitive Services Account Location.")]
[LocationCompleter("Microsoft.CognitiveServices/accounts")]
public string Location { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
RunCmdLet(() =>
{
switch (ParameterSetName)
{
case GetAccountTypeWithNameParamSetName:

if (GetAccountKinds(this.CognitiveServicesClient).Contains(TypeName))
{
WriteObject(TypeName);
}
else
{
WriteObject(null);
}
break;
case GetAccountTypesParamSetName:
var resourceSkuKinds = GetAccountKinds(this.CognitiveServicesClient, this.Location).OrderBy(x => x).ToArray();
WriteObject(resourceSkuKinds, true);
break;
}
});
}

/// <summary>
/// Get Cognitive Services Account Kinds.
/// </summary>
/// <param name="client">The ICognitiveServicesManagementClient instance.</param>
/// <param name="location">The location as filter, set to null to ignore.</param>
/// <returns>A set of available Kinds.</returns>
private static HashSet<string> GetAccountKinds(ICognitiveServicesManagementClient client, string location = null)
{
var resourceSkuKindList = client.ResourceSkus.List().Where(resourceSku => (string.IsNullOrWhiteSpace(location) || resourceSku.Locations.Any(x => string.Compare(x, location, StringComparison.OrdinalIgnoreCase) == 0))).Select(x => x.Kind).ToList();
return new HashSet<string>(resourceSkuKindList);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="CognitiveServicesAccount\GetAzureCognitiveServicesAccountType.cs" />
<Compile Include="CognitiveServicesAccount\GetAzureCognitiveServicesAccountUsage.cs" />
<Compile Include="Models\PSCognitiveServicesUsage.cs" />
<Compile Include="ObsoletedModels\ProvisioningState.cs" />
Expand Down Expand Up @@ -106,4 +107,4 @@
</ItemGroup>
<Copy SourceFiles="@(MarkdownFiles)" DestinationFolder="$(OutputPath)\help\" ContinueOnError="false" />
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Gets the API keys for an account.
### [Get-AzureRmCognitiveServicesAccountSkus](Get-AzureRmCognitiveServicesAccountSkus.md)
Gets the available SKUs for an account.

### [Get-AzureRmCognitiveServicesAccountType](Get-AzureRmCognitiveServicesAccountType.md)
Gets the available Cognitive Services Account Types.

### [Get-AzureRmCognitiveServicesAccountUsage](Get-AzureRmCognitiveServicesAccountUsage.md)
Get current usages for a Cognitive Services account.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
external help file: Microsoft.Azure.Commands.Management.CognitiveServices.dll-Help.xml
Module Name: AzureRM.CognitiveServices
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.cognitiveservices/get-azurermcognitiveservicesaccounttype
schema: 2.0.0
---

# Get-AzureRmCognitiveServicesAccountType

## SYNOPSIS
Gets the available Cognitive Services Account Types.

## SYNTAX

### GetAccountTypeWithName
```
Get-AzureRmCognitiveServicesAccountType -TypeName <String> [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```

### GetAccountTypes
```
Get-AzureRmCognitiveServicesAccountType [-Location <String>] [-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
```

## DESCRIPTION
The **Get-AzureRmCognitiveServicesAccountType** cmdlet gets the available Cognitive Services Account Types under this subscription.

## EXAMPLES

### Example 1
```powershell
PS C:\> Get-AzureRmCognitiveServicesAccountType
```

Get the list of available Types.

### Example 2
```powershell
PS C:\> Get-AzureRmCognitiveServicesAccountType -Location westus
```

Get the list of available Types in westus.

### Example 3
```powershell
PS C:\> Get-AzureRmCognitiveServicesAccountType -TypeName Face

Face
```

Check if `Face` is a valid Type name, the name will be returned if it is a valid name.

## PARAMETERS

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

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

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

### -Location
Cognitive Services Account Location.

```yaml
Type: System.String
Parameter Sets: GetAccountTypes
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -TypeName
Cognitive Services Account Type Name.

```yaml
Type: System.String
Parameter Sets: GetAccountTypeWithName
Aliases: CognitiveServicesAccountTypeName, AccountTypeName, KindName

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
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

### System.String

## OUTPUTS

### System.String[]

### System.String

## NOTES

## RELATED LINKS
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,7 @@ Accept wildcard characters: False
```

### -Type
Specifies the type of account to create. Current acceptable values for this parameter are:
- Bing.Autosuggest.v7
- Bing.CustomSearch
- Bing.Search.v7
- Bing.Speech
- Bing.SpellCheck.v7
- ComputerVision
- ContentModerator
- CustomSpeech
- CustomVision.Prediction
- CustomVision.Training
- Emotion
- Face
- LUIS
- QnAMaker
- SpeakerRecognition
- SpeechTranslation
- TextAnalytics
- TextTranslation
- WebLM
Specifies the type of account to create. Use `Get-AzureRmCognitiveServicesAccountType` cmdlet to get current acceptable values.

```yaml
Type: System.String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
"Get-AzCognitiveServicesAccount": "Get-AzureRmCognitiveServicesAccount",
"Get-AzCognitiveServicesAccountKey": "Get-AzureRmCognitiveServicesAccountKey",
"Get-AzCognitiveServicesAccountSkus": "Get-AzureRmCognitiveServicesAccountSkus",
"Get-AzCognitiveServicesAccountType": "Get-AzureRmCognitiveServicesAccountType",
"Get-AzCognitiveServicesAccountUsage": "Get-AzureRmCognitiveServicesAccountUsage",
"New-AzCognitiveServicesAccount": "New-AzureRmCognitiveServicesAccount",
"New-AzCognitiveServicesAccountKey": "New-AzureRmCognitiveServicesAccountKey",
Expand Down