Skip to content

Commit 185b706

Browse files
authored
Merge pull request Azure#7519 from yuanyang-microsoft/yuanyang/types
[CognitiveServices] Support getting account types (kinds).
2 parents f4adacf + 15d9a3d commit 185b706

File tree

14 files changed

+570
-23
lines changed

14 files changed

+570
-23
lines changed

src/ResourceManager/CognitiveServices/CognitiveServices.Test/Commands.Management.CognitiveServices.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetAccounts.json">
7171
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7272
</None>
73+
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetAccountType.json">
74+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
75+
</None>
7376
<None Include="SessionRecords\CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests\TestGetUsages.json">
7477
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7578
</None>

src/ResourceManager/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesAccountTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public void TestAccountSkus()
9898
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountSkus");
9999
}
100100

101+
[Fact]
102+
[Trait(Category.AcceptanceType, Category.CheckIn)]
103+
public void TestGetAccountType()
104+
{
105+
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountType");
106+
}
107+
101108
[Fact]
102109
[Trait(Category.AcceptanceType, Category.CheckIn)]
103110
public void TestPipingToGetKey()

src/ResourceManager/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesAccountTests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,36 @@ function Test-GetAzureRmCognitiveServicesAccountSkus
362362
}
363363
}
364364

365+
<#
366+
.SYNOPSIS
367+
Test Get-AzureRmCognitiveServicesAccountType
368+
#>
369+
function Test-GetAzureRmCognitiveServicesAccountType
370+
{
371+
try
372+
{
373+
$typeName = (Get-AzureRmCognitiveServicesAccountType -TypeName 'Face');
374+
Assert-AreEqual 'Face' $typeName
375+
376+
$typeName = (Get-AzureRmCognitiveServicesAccountType -TypeName 'InvalidKind');
377+
Assert-Null $typeName
378+
379+
$typeNames = (Get-AzureRmCognitiveServicesAccountType -Location 'westus');
380+
Assert-True {$typeNames.Contains('Face')}
381+
382+
$typeNames = (Get-AzureRmCognitiveServicesAccountType);
383+
Assert-True {$typeNames.Contains('Face')}
384+
385+
$typeNames = (Get-AzureRmCognitiveServicesAccountType -Location 'global');
386+
Assert-False {$typeNames.Contains('Face')}
387+
Assert-True {$typeNames.Contains('Bing.Search.v7')}
388+
}
389+
finally
390+
{
391+
}
392+
}
393+
394+
365395
<#
366396
.SYNOPSIS
367397
Test Get-AzureRmCognitiveServicesAccount | Get-AzureRmCognitiveServicesAccountKey

src/ResourceManager/CognitiveServices/CognitiveServices.Test/SessionRecords/CognitiveServices.Test.ScenarioTests.CognitiveServicesAccountTests/TestGetAccountType.json

Lines changed: 308 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/Az.CognitiveServices.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ FunctionsToExport = @()
7575
CmdletsToExport = 'Get-AzCognitiveServicesAccount',
7676
'Get-AzCognitiveServicesAccountKey',
7777
'Get-AzCognitiveServicesAccountSkus',
78-
'Get-AzCognitiveServicesAccountUsage',
78+
'Get-AzCognitiveServicesAccountType',
79+
'Get-AzCognitiveServicesAccountUsage',
7980
'New-AzCognitiveServicesAccount',
8081
'New-AzCognitiveServicesAccountKey',
8182
'Remove-AzCognitiveServicesAccount',

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/AzureRM.CognitiveServices.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ FunctionsToExport = @()
7575
CmdletsToExport = 'Get-AzureRmCognitiveServicesAccount',
7676
'Get-AzureRmCognitiveServicesAccountKey',
7777
'Get-AzureRmCognitiveServicesAccountSkus',
78+
'Get-AzureRmCognitiveServicesAccountType',
7879
'Get-AzureRmCognitiveServicesAccountUsage',
7980
'New-AzureRmCognitiveServicesAccount',
8081
'New-AzureRmCognitiveServicesAccountKey',

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-->
2020
## Current Release
2121

22+
* Add Get-AzureRmCognitiveServicesAccountSkus operation.
23+
2224
## Version 0.9.11
2325
* Support Get-AzureRmCognitiveServicesAccountSkus without an existing account.
2426

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/CognitiveServicesAccount/CognitiveServicesAccountBaseCmdlet.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ public abstract class CognitiveServicesAccountBaseCmdlet : AzureRMCmdlet
2929
{
3030
private CognitiveServicesManagementClientWrapper cognitiveServicesClientWrapper;
3131

32-
protected const string CognitiveServicesAccountNounStr = "AzureRmCognitiveServicesAccount";
32+
protected const string CognitiveServicesAccountNounStr = ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CognitiveServicesAccount";
3333
protected const string CognitiveServicesAccountKeyNounStr = CognitiveServicesAccountNounStr + "Key";
3434
protected const string CognitiveServicesAccountSkusNounStr = CognitiveServicesAccountNounStr + "Skus";
35+
protected const string CognitiveServicesAccountTypeNounStr = CognitiveServicesAccountNounStr + "Type";
3536
protected const string CognitiveServicesAccountUsagesNounStr = CognitiveServicesAccountNounStr + "Usage";
3637

3738
protected const string CognitiveServicesAccountNameAlias = "CognitiveServicesAccountName";
@@ -40,6 +41,9 @@ public abstract class CognitiveServicesAccountBaseCmdlet : AzureRMCmdlet
4041
protected const string CognitiveServicesAccountTypeAlias = "CognitiveServicesAccountType";
4142
protected const string AccountTypeAlias = "AccountType";
4243
protected const string KindAlias = "Kind";
44+
protected const string CognitiveServicesAccountTypeNameAlias = "CognitiveServicesAccountTypeName";
45+
protected const string AccountTypeNameAlias = "AccountTypeName";
46+
protected const string KindNameAlias = "KindName";
4347

4448
protected const string TagsAlias = "Tags";
4549

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
16+
using Microsoft.Azure.Management.CognitiveServices;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Management.CognitiveServices
23+
{
24+
/// <summary>
25+
/// Get Account Types for Cognitive Services Account Type(s)
26+
/// </summary>
27+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CognitiveServicesAccountType", DefaultParameterSetName = GetAccountTypesParamSetName), OutputType(typeof(string[]), typeof(string))]
28+
public class GetAzureCognitiveServicesAccountTypeCommand : CognitiveServicesAccountBaseCmdlet
29+
{
30+
protected const string GetAccountTypeWithNameParamSetName = "GetAccountTypeWithName";
31+
protected const string GetAccountTypesParamSetName = "GetAccountTypes";
32+
33+
34+
[Parameter(
35+
ParameterSetName = GetAccountTypeWithNameParamSetName,
36+
Mandatory = true,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "Cognitive Services Account Type Name.")]
39+
[Alias(CognitiveServicesAccountTypeNameAlias, AccountTypeNameAlias, KindNameAlias)]
40+
public string TypeName { get; set; }
41+
42+
[Parameter(
43+
ParameterSetName = GetAccountTypesParamSetName,
44+
Mandatory = false,
45+
ValueFromPipelineByPropertyName = true,
46+
HelpMessage = "Cognitive Services Account Location.")]
47+
[LocationCompleter("Microsoft.CognitiveServices/accounts")]
48+
public string Location { get; set; }
49+
50+
public override void ExecuteCmdlet()
51+
{
52+
base.ExecuteCmdlet();
53+
RunCmdLet(() =>
54+
{
55+
switch (ParameterSetName)
56+
{
57+
case GetAccountTypeWithNameParamSetName:
58+
59+
if (GetAccountKinds(this.CognitiveServicesClient).Contains(TypeName))
60+
{
61+
WriteObject(TypeName);
62+
}
63+
else
64+
{
65+
WriteObject(null);
66+
}
67+
break;
68+
case GetAccountTypesParamSetName:
69+
var resourceSkuKinds = GetAccountKinds(this.CognitiveServicesClient, this.Location).OrderBy(x => x).ToArray();
70+
WriteObject(resourceSkuKinds, true);
71+
break;
72+
}
73+
});
74+
}
75+
76+
/// <summary>
77+
/// Get Cognitive Services Account Kinds.
78+
/// </summary>
79+
/// <param name="client">The ICognitiveServicesManagementClient instance.</param>
80+
/// <param name="location">The location as filter, set to null to ignore.</param>
81+
/// <returns>A set of available Kinds.</returns>
82+
private static HashSet<string> GetAccountKinds(ICognitiveServicesManagementClient client, string location = null)
83+
{
84+
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();
85+
return new HashSet<string>(resourceSkuKindList);
86+
}
87+
}
88+
}

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/Commands.Management.CognitiveServices.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Prefer32Bit>false</Prefer32Bit>
5050
</PropertyGroup>
5151
<ItemGroup>
52+
<Compile Include="CognitiveServicesAccount\GetAzureCognitiveServicesAccountType.cs" />
5253
<Compile Include="CognitiveServicesAccount\GetAzureCognitiveServicesAccountUsage.cs" />
5354
<Compile Include="Models\PSCognitiveServicesUsage.cs" />
5455
<Compile Include="ObsoletedModels\ProvisioningState.cs" />
@@ -106,4 +107,4 @@
106107
</ItemGroup>
107108
<Copy SourceFiles="@(MarkdownFiles)" DestinationFolder="$(OutputPath)\help\" ContinueOnError="false" />
108109
</Target>
109-
</Project>
110+
</Project>

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/help/AzureRM.CognitiveServices.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Gets the API keys for an account.
2020
### [Get-AzureRmCognitiveServicesAccountSkus](Get-AzureRmCognitiveServicesAccountSkus.md)
2121
Gets the available SKUs for an account.
2222

23+
### [Get-AzureRmCognitiveServicesAccountType](Get-AzureRmCognitiveServicesAccountType.md)
24+
Gets the available Cognitive Services Account Types.
25+
2326
### [Get-AzureRmCognitiveServicesAccountUsage](Get-AzureRmCognitiveServicesAccountUsage.md)
2427
Get current usages for a Cognitive Services account.
2528

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
external help file: Microsoft.Azure.Commands.Management.CognitiveServices.dll-Help.xml
3+
Module Name: AzureRM.CognitiveServices
4+
online version: https://docs.microsoft.com/en-us/powershell/module/azurerm.cognitiveservices/get-azurermcognitiveservicesaccounttype
5+
schema: 2.0.0
6+
---
7+
8+
# Get-AzureRmCognitiveServicesAccountType
9+
10+
## SYNOPSIS
11+
Gets the available Cognitive Services Account Types.
12+
13+
## SYNTAX
14+
15+
### GetAccountTypeWithName
16+
```
17+
Get-AzureRmCognitiveServicesAccountType -TypeName <String> [-DefaultProfile <IAzureContextContainer>]
18+
[<CommonParameters>]
19+
```
20+
21+
### GetAccountTypes
22+
```
23+
Get-AzureRmCognitiveServicesAccountType [-Location <String>] [-DefaultProfile <IAzureContextContainer>]
24+
[<CommonParameters>]
25+
```
26+
27+
## DESCRIPTION
28+
The **Get-AzureRmCognitiveServicesAccountType** cmdlet gets the available Cognitive Services Account Types under this subscription.
29+
30+
## EXAMPLES
31+
32+
### Example 1
33+
```powershell
34+
PS C:\> Get-AzureRmCognitiveServicesAccountType
35+
```
36+
37+
Get the list of available Types.
38+
39+
### Example 2
40+
```powershell
41+
PS C:\> Get-AzureRmCognitiveServicesAccountType -Location westus
42+
```
43+
44+
Get the list of available Types in westus.
45+
46+
### Example 3
47+
```powershell
48+
PS C:\> Get-AzureRmCognitiveServicesAccountType -TypeName Face
49+
50+
Face
51+
```
52+
53+
Check if `Face` is a valid Type name, the name will be returned if it is a valid name.
54+
55+
## PARAMETERS
56+
57+
### -DefaultProfile
58+
The credentials, account, tenant, and subscription used for communication with Azure.
59+
60+
```yaml
61+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer
62+
Parameter Sets: (All)
63+
Aliases: AzureRmContext, AzureCredential
64+
65+
Required: False
66+
Position: Named
67+
Default value: None
68+
Accept pipeline input: False
69+
Accept wildcard characters: False
70+
```
71+
72+
### -Location
73+
Cognitive Services Account Location.
74+
75+
```yaml
76+
Type: System.String
77+
Parameter Sets: GetAccountTypes
78+
Aliases:
79+
80+
Required: False
81+
Position: Named
82+
Default value: None
83+
Accept pipeline input: True (ByPropertyName)
84+
Accept wildcard characters: False
85+
```
86+
87+
### -TypeName
88+
Cognitive Services Account Type Name.
89+
90+
```yaml
91+
Type: System.String
92+
Parameter Sets: GetAccountTypeWithName
93+
Aliases: CognitiveServicesAccountTypeName, AccountTypeName, KindName
94+
95+
Required: True
96+
Position: Named
97+
Default value: None
98+
Accept pipeline input: True (ByPropertyName)
99+
Accept wildcard characters: False
100+
```
101+
102+
### CommonParameters
103+
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).
104+
105+
## INPUTS
106+
107+
### System.String
108+
109+
## OUTPUTS
110+
111+
### System.String[]
112+
113+
### System.String
114+
115+
## NOTES
116+
117+
## RELATED LINKS

src/ResourceManager/CognitiveServices/Commands.Management.CognitiveServices/help/New-AzureRmCognitiveServicesAccount.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,7 @@ Accept wildcard characters: False
162162
```
163163
164164
### -Type
165-
Specifies the type of account to create. Current acceptable values for this parameter are:
166-
- Bing.Autosuggest.v7
167-
- Bing.CustomSearch
168-
- Bing.Search.v7
169-
- Bing.Speech
170-
- Bing.SpellCheck.v7
171-
- ComputerVision
172-
- ContentModerator
173-
- CustomSpeech
174-
- CustomVision.Prediction
175-
- CustomVision.Training
176-
- Emotion
177-
- Face
178-
- LUIS
179-
- QnAMaker
180-
- SpeakerRecognition
181-
- SpeechTranslation
182-
- TextAnalytics
183-
- TextTranslation
184-
- WebLM
165+
Specifies the type of account to create. Use `Get-AzureRmCognitiveServicesAccountType` cmdlet to get current acceptable values.
185166

186167
```yaml
187168
Type: System.String

src/ResourceManager/Profile/Commands.Profile/AzureRmAlias/Mappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
"Get-AzCognitiveServicesAccount": "Get-AzureRmCognitiveServicesAccount",
369369
"Get-AzCognitiveServicesAccountKey": "Get-AzureRmCognitiveServicesAccountKey",
370370
"Get-AzCognitiveServicesAccountSkus": "Get-AzureRmCognitiveServicesAccountSkus",
371+
"Get-AzCognitiveServicesAccountType": "Get-AzureRmCognitiveServicesAccountType",
371372
"Get-AzCognitiveServicesAccountUsage": "Get-AzureRmCognitiveServicesAccountUsage",
372373
"New-AzCognitiveServicesAccount": "New-AzureRmCognitiveServicesAccount",
373374
"New-AzCognitiveServicesAccountKey": "New-AzureRmCognitiveServicesAccountKey",

0 commit comments

Comments
 (0)