Skip to content

[CosmosDB] [Breaking Change] Update ListConnectionStrings Response #22829

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

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ function Test-AccountRelatedCmdlets
$cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -Type "ConnectionStrings"
Assert-NotNull $cosmosDBAccountConnectionStrings

for (($i = 0); $i -lt $cosmosDBAccountConnectionStrings.Count; $i++) {
Assert-NotNull $cosmosDBAccountConnectionStrings[$i].KeyKind
Assert-NotNull $cosmosDBAccountConnectionStrings[$i].Type
}

$cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -Type "ReadOnlyKeys"
Assert-NotNull $cosmosDBAccountReadOnlyKeys
Assert-NotNull $cosmosDBAccountReadOnlyKeys["PrimaryReadonlyMasterKey"]
Assert-NotNull $cosmosDBAccountReadOnlyKeys["SecondaryReadonlyMasterKey"]

$RegeneratedKey = New-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -KeyKind "primary"
Assert-NotNull $RegeneratedKey
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/CosmosDB/CosmosDB/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* ListConnectionStrings response now includes keyKind and type properties

## Version 1.12.0
* Added PublicNetworkAccess parameter to `Restore-AzCosmosDBAccount`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;

namespace Microsoft.Azure.Commands.CosmosDB
{
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBAccountKey", DefaultParameterSetName = NameParameterSet), OutputType(typeof(Hashtable))]
[GenericBreakingChangeWithVersionAttribute("Output type for -Type ConnectionStrings has been changed to List<DatabaseAccountConnectionString>", Constants.deprecateByAzVersion11, Constants.deprecateByVersion8)]
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBAccountKey", DefaultParameterSetName = NameParameterSet), OutputType(typeof(Hashtable), typeof(IList<DatabaseAccountConnectionString>))]
public class GetAzCosmosDBAccountKey : AzureCosmosDBCmdletBase
{
[Parameter(Mandatory = true, ParameterSetName = NameParameterSet, HelpMessage = Constants.ResourceGroupNameHelpMessage)]
Expand Down
3 changes: 3 additions & 0 deletions src/CosmosDB/CosmosDB/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace Microsoft.Azure.Commands.CosmosDB.Helpers
{
internal static class Constants
{
public const string deprecateByAzVersion11 = "11.0.0";
public const string deprecateByVersion8 = "8.0.0";

public const string ResourceGroupNameHelpMessage = "Name of resource group.";
public const string ResourceIdHelpMessage = "ResourceId of the resource.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.Azure.Commands.CosmosDB.Models
{
using System.Collections;
using System.Collections.Generic;
using Microsoft.Azure.Management.CosmosDB.Models;

public class PSDatabaseAccountListKeys
Expand Down Expand Up @@ -43,7 +44,7 @@ public PSDatabaseAccountListKeys(DatabaseAccountListConnectionStringsResult data

foreach (DatabaseAccountConnectionString connectionString in databaseAccountConnectionString.ConnectionStrings)
{
Keys.Add(connectionString.Description, connectionString.ConnectionString);
ConnectionStrings.Add(connectionString);
}
}

Expand All @@ -61,5 +62,7 @@ public PSDatabaseAccountListKeys(DatabaseAccountListKeysResult databaseAccountLi
}

public Hashtable Keys { get; set; } = new Hashtable();

public IList<DatabaseAccountConnectionString> ConnectionStrings { get; set; } = new List<DatabaseAccountConnectionString>();
}
}
16 changes: 16 additions & 0 deletions src/CosmosDB/CosmosDB/help/Get-AzCosmosDBAccountKey.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ SecondaryReadonlyMasterKey 9YRcTABuOHcKyHAKf0lmCeHsrcXu02aeID1g3wjXjlX8SU4s2

Lists the keys for CosmosDB Account. The Key Type can be value from : ConnectionStrings, Keys and ReadOnlyKeys. Default is Keys.

### Example 2
```powershell
Get-AzCosmosDBAccountKey -ResourceGroupName rg1 -Name dbname -Type "ConnectionStrings"
```

```output
ConnectionString Description KeyKind Type
---------------- ----------- ------- ----
AccountEndpoint=https://cosmosdbaccount.documents.azure.com:443/;AccountKey=qjw0ISW1WNN0BIVPeaI7Tm3H8uZ1h7ESQjxaUendxHmIUNQowVvcL84fTqeXoC2HFgyu8Zo1mCFEcg0jZJHPjA==; Primary SQL Connection String Primary Sql
AccountEndpoint=https://cosmosdbaccount.documents.azure.com:443/;AccountKey=qjw0ISW1WNN0BIVPeaI7Tm3H8uZ1h7ESQjxaUendxHmIUNQowVvcL84fTqeXoC2HFgyu8Zo1mCFEcg0jZJHPjA==; Secondary SQL Connection String Secondary Sql
AccountEndpoint=https://cosmosdbaccount.documents.azure.com:443/;AccountKey=qjw0ISW1WNN0BIVPeaI7Tm3H8uZ1h7ESQjxaUendxHmIUNQowVvcL84fTqeXoC2HFgyu8Zo1mCFEcg0jZJHPjA==; Primary Read-Only SQL Connection String PrimaryReadonly Sql
AccountEndpoint=https://cosmosdbaccount.documents.azure.com:443/;AccountKey=qjw0ISW1WNN0BIVPeaI7Tm3H8uZ1h7ESQjxaUendxHmIUNQowVvcL84fTqeXoC2HFgyu8Zo1mCFEcg0jZJHPjA==; Secondary Read-Only SQL Connection String SecondaryReadonly Sql
```

Lists the ConnectionStrings for CosmosDB Account by specifying Key Type ConnectionStrings.

## PARAMETERS

### -DefaultProfile
Expand Down