Skip to content

Commit 7da9b9e

Browse files
authored
Adding non-identity to .NET SDK (#24301)
* Adding non-identity to .NET SDK * Add recordings * Update recordings * Update PR * Update PR * Update tests * Update * Update .NET PR * Update recordings * Add recordings for tests * Update recordings, updating names of tests so they don't repeat * Update PR * Remove unused snippet * Update CHANGELOG, readme and samples * Update changelog
1 parent ae99a7c commit 7da9b9e

File tree

36 files changed

+1244
-438
lines changed

36 files changed

+1244
-438
lines changed

sdk/communication/Azure.Communication.NetworkTraversal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.0.0-beta.3 (Unreleased)
44

55
### Features Added
6+
- Making user identity an optional argument when calling GetRelayConfiguration and GetRelayConfigurationAsync
67

78
### Breaking Changes
89

sdk/communication/Azure.Communication.NetworkTraversal/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ foreach (CommunicationIceServer iceServer in iceServers)
8383
}
8484
```
8585

86+
## Getting a Relay Configuration for a user without identity async
87+
88+
```C# Snippet:GetRelayConfigurationAsyncWithoutIdentity
89+
Response<CommunicationRelayConfiguration> relayConfiguration = await client.GetRelayConfigurationAsync();
90+
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
91+
IReadOnlyList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
92+
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
93+
foreach (CommunicationIceServer iceServer in iceServers)
94+
{
95+
foreach (string url in iceServer.Urls)
96+
{
97+
Console.WriteLine($"ICE Server Url: {url}");
98+
}
99+
Console.WriteLine($"ICE Server Username: {iceServer.Username}");
100+
Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
101+
}
102+
```
103+
86104
## Troubleshooting
87105

88106
> TODO

sdk/communication/Azure.Communication.NetworkTraversal/api/Azure.Communication.NetworkTraversal.netstandard2.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public CommunicationRelayClient(string connectionString) { }
1414
public CommunicationRelayClient(string connectionString, Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions options) { }
1515
public CommunicationRelayClient(System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions options = null) { }
1616
public CommunicationRelayClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions options = null) { }
17-
public virtual Azure.Response<Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration> GetRelayConfiguration(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
18-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration>> GetRelayConfigurationAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
17+
public virtual Azure.Response<Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration> GetRelayConfiguration(Azure.Communication.CommunicationUserIdentifier communicationUser = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
18+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration>> GetRelayConfigurationAsync(Azure.Communication.CommunicationUserIdentifier communicationUser = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1919
}
2020
public partial class CommunicationRelayClientOptions : Azure.Core.ClientOptions
2121
{

sdk/communication/Azure.Communication.NetworkTraversal/src/CommunicationRelayClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ protected CommunicationRelayClient()
9494
/// <param name="communicationUser">The <see cref="CommunicationUserIdentifier"/> for whom to issue a token.</param>
9595
/// <param name="cancellationToken">The cancellation token to use.</param>
9696
/// <exception cref="RequestFailedException">The server returned an error.</exception>
97-
public virtual Response<CommunicationRelayConfiguration> GetRelayConfiguration(CommunicationUserIdentifier communicationUser, CancellationToken cancellationToken = default)
97+
public virtual Response<CommunicationRelayConfiguration> GetRelayConfiguration(CommunicationUserIdentifier communicationUser = null, CancellationToken cancellationToken = default)
9898
{
9999
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationRelayClient)}.{nameof(GetRelayConfiguration)}");
100100
scope.Start();
101101
try
102102
{
103-
return RestClient.IssueRelayConfiguration(communicationUser.Id, cancellationToken);
103+
return RestClient.IssueRelayConfiguration(communicationUser?.Id, cancellationToken);
104104
}
105105
catch (Exception ex)
106106
{
@@ -112,13 +112,13 @@ public virtual Response<CommunicationRelayConfiguration> GetRelayConfiguration(C
112112
/// <summary>Asynchronously gets a Relay Configuration for a <see cref="CommunicationUserIdentifier"/>.</summary>
113113
/// <param name="communicationUser">The <see cref="CommunicationUserIdentifier"/> for whom to issue a token.</param>
114114
/// <param name="cancellationToken">The cancellation token to use.</param>
115-
public virtual async Task<Response<CommunicationRelayConfiguration>> GetRelayConfigurationAsync(CommunicationUserIdentifier communicationUser, CancellationToken cancellationToken = default)
115+
public virtual async Task<Response<CommunicationRelayConfiguration>> GetRelayConfigurationAsync(CommunicationUserIdentifier communicationUser = null, CancellationToken cancellationToken = default)
116116
{
117117
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationRelayClient)}.{nameof(GetRelayConfiguration)}");
118118
scope.Start();
119119
try
120120
{
121-
return await RestClient.IssueRelayConfigurationAsync(communicationUser.Id, cancellationToken).ConfigureAwait(false);
121+
return await RestClient.IssueRelayConfigurationAsync(communicationUser?.Id, cancellationToken).ConfigureAwait(false);
122122
}
123123
catch (Exception ex)
124124
{

sdk/communication/Azure.Communication.NetworkTraversal/src/Generated/CommunicationNetworkTraversalRestClient.cs

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.NetworkTraversal/src/Generated/Models/CommunicationRelayConfigurationRequest.Serialization.cs

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.NetworkTraversal/src/Generated/Models/CommunicationRelayConfigurationRequest.cs

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.NetworkTraversal/src/autorest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ title: Network traversal
1010
tag: package-2021-06-21-preview
1111
model-namespace: false
1212
require:
13-
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/a59747e42da9d74654106f16c5410620b5941fe0/specification/communication/data-plane/Turn/readme.md
13+
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/4c8162b0a1f7bbd46e9aedc0e19bbe181e549c4c/specification/communication/data-plane/NetworkTraversal/readme.md
1414
payload-flattening-threshold: 3
1515
```

sdk/communication/Azure.Communication.NetworkTraversal/tests/CommunicationRelayClient/CommunicationRelayClientLiveTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,35 @@ public async Task GettingTurnCredentialsGeneratesTurnCredentials(AuthMethod auth
5858
Assert.IsFalse(string.IsNullOrWhiteSpace(serverCredential.Credential));
5959
}
6060
}
61+
62+
[Test]
63+
[TestCase(AuthMethod.ConnectionString, TestName = "GettingTurnCredentialsWithConnectionStringWithoutIdentity")]
64+
[TestCase(AuthMethod.KeyCredential, TestName = "GettingTurnCredentialsWithKeyCredentialWithoutIdentity")]
65+
[TestCase(AuthMethod.TokenCredential, TestName = "GettingTurnCredentialsWithTokenCredentialWithoutIdentity")]
66+
public async Task GettingTurnCredentialsGeneratesTurnCredentialsWithoutIdentity(AuthMethod authMethod, params string[] scopes)
67+
{
68+
CommunicationRelayClient client = authMethod switch
69+
{
70+
AuthMethod.ConnectionString => CreateClientWithConnectionString(),
71+
AuthMethod.KeyCredential => CreateClientWithAzureKeyCredential(),
72+
AuthMethod.TokenCredential => CreateClientWithTokenCredential(),
73+
_ => throw new ArgumentOutOfRangeException(nameof(authMethod)),
74+
};
75+
76+
Response<CommunicationRelayConfiguration> turnCredentialsResponse = await client.GetRelayConfigurationAsync();
77+
78+
Assert.IsNotNull(turnCredentialsResponse.Value);
79+
Assert.IsNotNull(turnCredentialsResponse.Value.ExpiresOn);
80+
Assert.IsNotNull(turnCredentialsResponse.Value.IceServers);
81+
foreach (CommunicationIceServer serverCredential in turnCredentialsResponse.Value.IceServers)
82+
{
83+
foreach (string url in serverCredential.Urls)
84+
{
85+
Assert.IsFalse(string.IsNullOrWhiteSpace(url));
86+
}
87+
Assert.IsFalse(string.IsNullOrWhiteSpace(serverCredential.Username));
88+
Assert.IsFalse(string.IsNullOrWhiteSpace(serverCredential.Credential));
89+
}
90+
}
6191
}
6292
}

sdk/communication/Azure.Communication.NetworkTraversal/tests/SessionRecords/CommunicationRelayClientLiveTests/GettingTurnCredentialsWithConnectionString.json

Lines changed: 29 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)