Skip to content
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

Cleanup DPS service enrollment samples and SDK code #3077

Merged
merged 3 commits into from
Jan 18, 2023
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
1 change: 1 addition & 0 deletions SDK v2 migration guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ What was a loose affiliation of separate clients is now a consolidated client wi
| `ProvisioningServiceClient.CreateEnrollmentGroupRegistrationStateQuery(...)` | `ProvisioningServiceClient.DeviceRegistrationStates.CreateEnrollmentGroupQuery(...)` | |
| `DeviceRegistrationState.CreatedDateTimeUtc` | `DeviceRegistrationState.CreatedOnUtc` | Conforming to the naming guidelines by the Azure SDK team, where DateTime/Offset types have an "On" suffix (and "Utc" suffix when explicitly in UTC).¹ |
| `DeviceRegistrationState.LastUpdatedDateTimeUtc` | `DeviceRegistrationState.LastUpdatedOnUtc` | See¹ |
| `EnrollmentGroup.EnrollmentGroupId` | `EnrollmentGroup.Id` | Simplify property name. |
| `EnrollmentGroup.CreatedDateTimeUtc` | `EnrollmentGroup.CreatedOnUtc` | See¹ |
| `EnrollmentGroup.LastUpdatedDateTimeUtc` | `EnrollmentGroup.LastUpdatedOnUtc` | See¹ |
| `IndividualEnrollment.CreatedDateTimeUtc` | `IndividualEnrollment.CreatedOnUtc` | See¹ |
Expand Down
11 changes: 2 additions & 9 deletions azureiot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SymmetricKeySample", "provi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InvokeDeviceMethod", "iothub\service\samples\getting started\InvokeDeviceMethod\InvokeDeviceMethod.csproj", "{A9058CEC-E0EB-4461-A1B0-4C6CB83A8AAC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnrollmentGroupX509Sample", "provisioning\service\samples\getting started\EnrollmentGroupX509Sample\EnrollmentGroupX509Sample.csproj", "{83170B36-375E-40A9-B25D-999072362626}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnrollmentGroupSample", "provisioning\service\samples\getting started\EnrollmentGroupSample\EnrollmentGroupSample.csproj", "{83170B36-375E-40A9-B25D-999072362626}"
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndividualEnrollmentX509Sample", "provisioning\service\samples\getting started\IndividualEnrollmentX509Sample\IndividualEnrollmentX509Sample.csproj", "{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndividualEnrollmentTpmSample", "provisioning\service\samples\getting started\IndividualEnrollmentTpmSample\IndividualEnrollmentTpmSample.csproj", "{705C5B5A-6166-4566-B167-4401491D7650}"
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndividualEnrollmentSample", "provisioning\service\samples\getting started\IndividualEnrollmentSample\IndividualEnrollmentSample.csproj", "{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimulatedDevice", "iothub\device\samples\getting started\SimulatedDevice\SimulatedDevice.csproj", "{D3A771DC-1763-4A14-952C-CD69433FEC74}"
EndProject
Expand Down Expand Up @@ -365,10 +363,6 @@ Global
{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255}.Release|Any CPU.Build.0 = Release|Any CPU
{705C5B5A-6166-4566-B167-4401491D7650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{705C5B5A-6166-4566-B167-4401491D7650}.Debug|Any CPU.Build.0 = Debug|Any CPU
{705C5B5A-6166-4566-B167-4401491D7650}.Release|Any CPU.ActiveCfg = Release|Any CPU
{705C5B5A-6166-4566-B167-4401491D7650}.Release|Any CPU.Build.0 = Release|Any CPU
{D3A771DC-1763-4A14-952C-CD69433FEC74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3A771DC-1763-4A14-952C-CD69433FEC74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3A771DC-1763-4A14-952C-CD69433FEC74}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -456,7 +450,6 @@ Global
{A9058CEC-E0EB-4461-A1B0-4C6CB83A8AAC} = {E94FE5CB-3D5E-4E2E-97F6-73D27E1F6491}
{83170B36-375E-40A9-B25D-999072362626} = {01ED1C8E-E1FC-46B9-A05D-DFF217F20F9D}
{8F8EF9CB-EF6A-4E39-9CE1-8CD06C1AB255} = {01ED1C8E-E1FC-46B9-A05D-DFF217F20F9D}
{705C5B5A-6166-4566-B167-4401491D7650} = {01ED1C8E-E1FC-46B9-A05D-DFF217F20F9D}
{D3A771DC-1763-4A14-952C-CD69433FEC74} = {9BEF9B8B-7800-4C14-819F-F736DB4F1426}
{0C078DE2-1785-44A3-8235-C990FA680F76} = {9BEF9B8B-7800-4C14-819F-F736DB4F1426}
{F4DA6FA4-7655-4116-994B-9B2E3D3522C0} = {E94FE5CB-3D5E-4E2E-97F6-73D27E1F6491}
Expand Down
12 changes: 6 additions & 6 deletions e2e/test/provisioning/ProvisioningServiceClientE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ await RetryOperationHelper
.RunWithProvisioningServiceRetryAsync(
async () =>
{
attestationMechanism = await provisioningServiceClient.EnrollmentGroups.GetAttestationAsync(enrollmentGroup.EnrollmentGroupId);
attestationMechanism = await provisioningServiceClient.EnrollmentGroups.GetAttestationAsync(enrollmentGroup.Id);
},
s_provisioningServiceRetryPolicy,
CancellationToken.None)
.ConfigureAwait(false);

if (attestationMechanism == null)
{
throw new ArgumentException($"The attestation mechanism for enrollment with group Id {enrollmentGroup.EnrollmentGroupId} could not retrieved, exiting test.");
throw new ArgumentException($"The attestation mechanism for enrollment with group Id {enrollmentGroup.Id} could not retrieved, exiting test.");
}

if (attestationType == AttestationMechanismType.SymmetricKey)
Expand Down Expand Up @@ -261,7 +261,7 @@ await RetryOperationHelper
{
if (enrollmentGroup != null)
{
await DeleteCreatedEnrollmentAsync(EnrollmentType.Group, null, enrollmentGroup.EnrollmentGroupId);
await DeleteCreatedEnrollmentAsync(EnrollmentType.Group, null, enrollmentGroup.Id);
}
}
}
Expand Down Expand Up @@ -398,15 +398,15 @@ await RetryOperationHelper
.RunWithProvisioningServiceRetryAsync(
async () =>
{
enrollmentGroupResult = await provisioningServiceClient.EnrollmentGroups.GetAsync(enrollmentGroup.EnrollmentGroupId).ConfigureAwait(false);
enrollmentGroupResult = await provisioningServiceClient.EnrollmentGroups.GetAsync(enrollmentGroup.Id).ConfigureAwait(false);
},
s_provisioningServiceRetryPolicy,
CancellationToken.None)
.ConfigureAwait(false);

if (enrollmentGroupResult == null)
{
throw new ArgumentException($"The enrollment group with group Id {enrollmentGroup.EnrollmentGroupId} could not retrieved, exiting test.");
throw new ArgumentException($"The enrollment group with group Id {enrollmentGroup.Id} could not retrieved, exiting test.");
}

Assert.AreEqual(enrollmentGroupResult.ProvisioningStatus, ProvisioningStatus.Enabled);
Expand All @@ -429,7 +429,7 @@ await RetryOperationHelper
{
if (enrollmentGroup != null)
{
await DeleteCreatedEnrollmentAsync(EnrollmentType.Group, "", enrollmentGroup.EnrollmentGroupId).ConfigureAwait(false);
await DeleteCreatedEnrollmentAsync(EnrollmentType.Group, "", enrollmentGroup.Id).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ private async Task QueryAndDeleteEnrollmentGroupsAsync()
IEnumerable<object> items = queryResult.Items;
foreach (EnrollmentGroup enrollment in items.Cast<EnrollmentGroup>())
{
if (!_groupEnrollmentsToBeRetained.Contains(enrollment.EnrollmentGroupId, StringComparer.OrdinalIgnoreCase))
if (!_groupEnrollmentsToBeRetained.Contains(enrollment.Id, StringComparer.OrdinalIgnoreCase))
{
Console.WriteLine($"Enrollment group to be deleted: {enrollment.EnrollmentGroupId}");
Console.WriteLine($"Enrollment group to be deleted: {enrollment.Id}");
s_enrollmentGroupsDeleted++;
await _provisioningServiceClient.EnrollmentGroups.DeleteAsync(enrollment.EnrollmentGroupId);
await _provisioningServiceClient.EnrollmentGroups.DeleteAsync(enrollment.Id);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.Provisioning.Service.Samples
{
internal class EnrollmentGroupSample
{
private static readonly string s_enrollmentGroupId = $"enrollmentgrouptest-{Guid.NewGuid()}";
private readonly ProvisioningServiceClient _provisioningServiceClient;

public EnrollmentGroupSample(ProvisioningServiceClient provisioningServiceClient)
{
_provisioningServiceClient = provisioningServiceClient;
}

public async Task RunSampleAsync()
{
await CreateEnrollmentGroupAsync().ConfigureAwait(false);
await GetEnrollmentGroupInfoAsync().ConfigureAwait(false);
await QueryEnrollmentGroupAsync().ConfigureAwait(false);
await DeleteEnrollmentGroupAsync().ConfigureAwait(false);
}

public async Task CreateEnrollmentGroupAsync()
{
Attestation attestation = new SymmetricKeyAttestation();
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
var enrollmentGroup = new EnrollmentGroup(s_enrollmentGroupId, attestation);
Console.WriteLine($"Creating an enrollment group: {JsonConvert.SerializeObject(enrollmentGroup)}");

EnrollmentGroup group = await _provisioningServiceClient.EnrollmentGroups.CreateOrUpdateAsync(enrollmentGroup);
Console.WriteLine($"Created {group.Id}: {JsonConvert.SerializeObject(group)}");
}

public async Task GetEnrollmentGroupInfoAsync()
{
Console.WriteLine("Getting the enrollment group information...");
EnrollmentGroup group = await _provisioningServiceClient.EnrollmentGroups.GetAsync(s_enrollmentGroupId);
Console.WriteLine($"Got {group.Id}: {JsonConvert.SerializeObject(group)}");
}

public async Task QueryEnrollmentGroupAsync()
{
string queryText = "SELECT * FROM enrollmentGroups";
Console.WriteLine($"Running a query for enrollment groups: {queryText}");
Query query = _provisioningServiceClient.EnrollmentGroups.CreateQuery(queryText);

while (query.HasNext())
{
QueryResult queryResult = await query.NextAsync();

foreach (EnrollmentGroup group in queryResult.Items.Cast<EnrollmentGroup>())
{
Console.WriteLine($"Found enrollment group {group.Id} is {group.ProvisioningStatus}.");
await EnumerateRegistrationsInGroupAsync(queryText, group);
}
}
}

private async Task EnumerateRegistrationsInGroupAsync(string queryText, EnrollmentGroup group)
{
Console.WriteLine($"Registrations within group {group.Id}:");
Query registrationQuery = _provisioningServiceClient.DeviceRegistrationStates.CreateEnrollmentGroupQuery(queryText, group.Id);

while (registrationQuery.HasNext())
{
QueryResult registrationQueryResult = await registrationQuery.NextAsync();

foreach (DeviceRegistrationState registration in registrationQueryResult.Items.Cast<DeviceRegistrationState>())
{
Console.WriteLine($"\t{registration.RegistrationId} for {registration.DeviceId} is {registration.Status}.");
if (registration.ErrorCode.HasValue)
{
Console.WriteLine($"\t\tWith error ({registration.ErrorCode.Value}): {registration.ErrorMessage}");
}
}
}
}

public async Task DeleteEnrollmentGroupAsync()
{
Console.WriteLine($"Deleting the enrollment group {s_enrollmentGroupId}...");
await _provisioningServiceClient.EnrollmentGroups.DeleteAsync(s_enrollmentGroupId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ namespace Microsoft.Azure.Devices.Provisioning.Service.Samples
/// </summary>
internal class Parameters
{
[Option(
'p',
"CertificatePath",
Required = true,
HelpText = "The path to X509 certificate.")]
public string CertificatePath { get; set; }

[Option(
'c',
"ProvisioningConnectionString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using CommandLine;

Expand Down Expand Up @@ -36,10 +35,8 @@ public static async Task<int> Main(string[] args)
Environment.Exit(1);
}

using var certificate = new X509Certificate2(parameters.CertificatePath);

using var provisioningServiceClient = new ProvisioningServiceClient(parameters.ProvisioningConnectionString);
var sample = new EnrollmentGroupX509Sample(provisioningServiceClient, certificate);
var sample = new EnrollmentGroupSample(provisioningServiceClient);
await sample.RunSampleAsync();

Console.WriteLine("Done.\n");
Expand Down

This file was deleted.

Loading