Skip to content
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
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>CognitiveServices</PsModuleName>
Expand All @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="6.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="7.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.18.0-preview" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public void TestGetAccounts()
{
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureCognitiveServiceAccount");
}

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

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


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

try
{
# Test
$accountname = 'csa' + $rgname;
$skuname = 'S0';
$accounttype = 'Personalizer';
$loc = Get-Location -providerNamespace "Microsoft.CognitiveServices" -resourceType "accounts" -preferredLocation "West US 2";

New-AzResourceGroup -Name $rgname -Location $loc;

$createdAccount = New-AzCognitiveServicesAccount -ResourceGroupName $rgname -Name $accountname -Type $accounttype -SkuName $skuname -Location $loc -Force;
Remove-AzCognitiveServicesAccount -ResourceGroupName $rgname -Name $accountname -Force;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Remove-AzCognitiveServicesAccount
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/CognitiveServices/CognitiveServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Update SDK to 7.0
* Improve error message when server responses empty body

## Version 1.2.2
* Update references in .psd1 to use relative path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="6.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="7.0.0-preview" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void ExecuteCmdlet()
var account = this.CognitiveServicesClient.Accounts.GetProperties(
this.ResourceGroupName,
this.Name);
NetworkRuleSet accountACL = account.NetworkAcls;
NetworkRuleSet accountACL = account.Properties.NetworkAcls;

if (accountACL == null)
{
Expand Down Expand Up @@ -156,21 +156,28 @@ public override void ExecuteCmdlet()
break;
}

var properties = new JObject();
properties["networkAcls"] = JToken.FromObject(accountACL);
this.CognitiveServicesClient.Accounts.Update(this.ResourceGroupName, this.Name, null, null, properties);
var properties = new CognitiveServicesAccountProperties();
properties.NetworkAcls = accountACL;
this.CognitiveServicesClient.Accounts.Update(
this.ResourceGroupName,
this.Name,
new CognitiveServicesAccount()
{
Properties = properties
}
);

account = this.CognitiveServicesClient.Accounts.GetProperties(this.ResourceGroupName, this.Name);

switch (ParameterSetName)
{
case NetWorkRuleStringParameterSet:
case NetworkRuleObjectParameterSet:
WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls).VirtualNetworkRules);
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).VirtualNetworkRules);
break;
case IpRuleStringParameterSet:
case IpRuleObjectParameterSet:
WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls).IpRules);
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).IpRules);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ protected void RunCmdLet(Action action)
}
catch (ErrorException ex)
{
if (ex.Body == null)
{
throw new PSInvalidOperationException(ex.Message, ex);
}

throw new PSInvalidOperationException(ex.Body.ErrorProperty.Message, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public override void ExecuteCmdlet()
this.ResourceGroupName,
this.Name);

if (account != null && account.NetworkAcls != null)
if (account != null && account.Properties.NetworkAcls != null)
{
WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls));
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ public override void ExecuteCmdlet()

RunCmdLet(() =>
{
var properties = new JObject();
var properties = new CognitiveServicesAccountProperties();
if (!string.IsNullOrWhiteSpace(CustomSubdomainName))
{
properties["customSubDomainName"] = CustomSubdomainName;
properties.CustomSubDomainName = CustomSubdomainName;
}
if (NetworkRuleSet != null)
{
properties["networkAcls"] = JToken.FromObject(NetworkRuleSet);
properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet();
}

CognitiveServicesAccountCreateParameters createParameters = new CognitiveServicesAccountCreateParameters()
CognitiveServicesAccount createParameters = new CognitiveServicesAccount()
{
Location = Location,
Kind = Type, // must have value, mandatory parameter
Sku = new Sku(SkuName),
Sku = new Sku(SkuName, null),
Tags = TagsConversionHelper.CreateTagDictionary(Tag),
Properties = properties
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public override void ExecuteCmdlet()
var account = this.CognitiveServicesClient.Accounts.GetProperties(
this.ResourceGroupName,
this.Name);
NetworkRuleSet accountACL = account.NetworkAcls;
NetworkRuleSet accountACL = account.Properties.NetworkAcls;

if (accountACL == null)
{
Expand Down Expand Up @@ -152,21 +152,28 @@ public override void ExecuteCmdlet()
}


var properties = new JObject();
properties["networkAcls"] = JToken.FromObject(accountACL);
this.CognitiveServicesClient.Accounts.Update(this.ResourceGroupName, this.Name, null, null, properties);
var properties = new CognitiveServicesAccountProperties();
properties.NetworkAcls = accountACL;
this.CognitiveServicesClient.Accounts.Update(
this.ResourceGroupName,
this.Name,
new CognitiveServicesAccount()
{
Properties = properties
}
);

account = this.CognitiveServicesClient.Accounts.GetProperties(this.ResourceGroupName, this.Name);

switch (ParameterSetName)
{
case NetWorkRuleStringParameterSet:
case NetworkRuleObjectParameterSet:
WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls).VirtualNetworkRules);
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).VirtualNetworkRules);
break;
case IpRuleStringParameterSet:
case IpRuleObjectParameterSet:
WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls).IpRules);
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls).IpRules);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ public override void ExecuteCmdlet()
base.ExecuteCmdlet();

bool hasPropertiesChange = false;
var properties = new JObject();
var properties = new CognitiveServicesAccountProperties();
if (!string.IsNullOrWhiteSpace(CustomSubdomainName))
{
hasPropertiesChange = true;
properties["customSubDomainName"] = CustomSubdomainName;
properties.CustomSubDomainName = CustomSubdomainName;
}
if (NetworkRuleSet != null)
{
hasPropertiesChange = true;
properties["networkAcls"] = JToken.FromObject(NetworkRuleSet);
properties.NetworkAcls = NetworkRuleSet.ToNetworkRuleSet();
}

Sku sku = null;
Expand Down Expand Up @@ -152,9 +152,13 @@ public override void ExecuteCmdlet()
var updatedAccount = this.CognitiveServicesClient.Accounts.Update(
this.ResourceGroupName,
this.Name,
sku,
tags,
properties);
new CognitiveServicesAccount()
{
Sku = sku,
Tags = tags,
Properties = properties
}
);

WriteCognitiveServicesAccount(updatedAccount);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override void ExecuteCmdlet()
var account = this.CognitiveServicesClient.Accounts.GetProperties(
this.ResourceGroupName,
this.Name);
NetworkRuleSet accountACL = account.NetworkAcls;
NetworkRuleSet accountACL = account.Properties.NetworkAcls;

if (accountACL == null)
{
Expand All @@ -138,13 +138,20 @@ public override void ExecuteCmdlet()
psNetworkRule.DefaultAction = defaultAction.Value;
}

var properties = new JObject();
properties["networkAcls"] = JToken.FromObject(psNetworkRule.ToNetworkRuleSet());
this.CognitiveServicesClient.Accounts.Update(this.ResourceGroupName, this.Name, null, null, properties);
var properties = new CognitiveServicesAccountProperties();
properties.NetworkAcls = psNetworkRule.ToNetworkRuleSet();
this.CognitiveServicesClient.Accounts.Update(
this.ResourceGroupName,
this.Name,
new CognitiveServicesAccount()
{
Properties = properties
}
);

account = this.CognitiveServicesClient.Accounts.GetProperties(this.ResourceGroupName, this.Name);

WriteObject(PSNetworkRuleSet.Create(account.NetworkAcls));
WriteObject(PSNetworkRuleSet.Create(account.Properties.NetworkAcls));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public PSCognitiveServicesAccount(CognitiveServicesModels.CognitiveServicesAccou
this.ResourceGroupName = ParseResourceGroupFromId(cognitiveServicesAccount.Id);
this.AccountName = cognitiveServicesAccount.Name;
this.Id = cognitiveServicesAccount.Id;
this.Endpoint = cognitiveServicesAccount.Endpoint;
this.Endpoint = cognitiveServicesAccount.Properties.Endpoint;
this.Location = cognitiveServicesAccount.Location;
this.Sku = cognitiveServicesAccount.Sku;
this.AccountType = cognitiveServicesAccount.Kind;
this.Etag = cognitiveServicesAccount.Etag;
this.ResourceType = cognitiveServicesAccount.Type;
this.ProvisioningState = cognitiveServicesAccount.ProvisioningState;
this.ProvisioningState = cognitiveServicesAccount.Properties.ProvisioningState;
this.Tags = cognitiveServicesAccount.Tags;
this.CustomSubDomainName = cognitiveServicesAccount.CustomSubDomainName;
this.CustomSubDomainName = cognitiveServicesAccount.Properties.CustomSubDomainName;

if (cognitiveServicesAccount.NetworkAcls != null)
if (cognitiveServicesAccount.Properties.NetworkAcls != null)
{
this.NetworkRuleSet = PSNetworkRuleSet.Create(cognitiveServicesAccount.NetworkAcls);
this.NetworkRuleSet = PSNetworkRuleSet.Create(cognitiveServicesAccount.Properties.NetworkAcls);
}
}

Expand Down