Skip to content

Commit

Permalink
Bring pnp updates to preview (#2301)
Browse files Browse the repository at this point in the history
* feat(shared): Add common resources for convention-based operations

* feat(iot-device): Add support for convention-based telemetry operation

* feat(iot-device): Add support for convention-based command operations

* * feat(iot-device): Add support for convention-based properties operations

* feat(iot-device): Add support for convention-based properties operations

Co-authored-by: James Davis ⛺️🏔 <jamdavi@microsoft.com>

* feat(e2e-tests): Add telemetry E2E tests

* feat(e2e-tests): Add command E2E tests

* fix(iot-device): Updating client property collection to handle no convention

* feat(samples): Add thermostat and temperature controller sample

* fix(doc, samples): Update API design doc and move SystemTextJson helper to samples

* fix(iot-device): Separate out root-level and component-level property addition operations

* feat(tests): Add unit tests for ClientPropertyCollection

feat(tests): Add unit tests for ClientPropertyCollection

Co-authored-by: Abhipsa Misra <abhipsa.misra@microsoft.com>

* feat(e2e-tests): Add properties E2E tests

Co-authored-by: Abhipsa Misra <abhipsa.misra@microsoft.com>

* feat(e2e-tests): Add fault injection tests for properties operations (#2001)

* fix(iot-device, shared, samples): Rename StatusCodes to CommonClientResponseCodes and add a comment to highlight ClientOptions behavior

* fix(iot-device): Fix enumerator implementation to return key-value pairs

* fix(iot-device): Make ClientOptions.PayloadConvention readonly

* fix(shared): Fix from merge conflict

* fix(samples): Update the pnp samples readme (#2025)

* refactor(samples): Move preview samples to samples repository (#2057)

* fix(e2e-tests): Fix file renaming Configutaion to TestConfiguration

* refactor(iot-device): Rename property add method

* * fix(iot-device): TryGetValue methods should check for the component identifier when applicable and should not throw any exceptions (#2111)

* refactor(iot-device): Separate client reported properties into a separate accessor

* fix(iot-device): Add checks to verify that client property update response has version and requestId (#2115)

* refactor(iot-device): Update the internal method names as per functionality

* feat(iot-device): Add convenience method for acknowledging writable property update requests

* fix(iot-device): Update PayloadCollection to accept dictionary of values (#2171)

* refactor(iot-device): Merge flows for twin and client property operations (#2180)

* fix(e2e-tests): Update E2E tests to initialize and dispose resources correctly

* doc(client, service): Update documents about the Proxy property for various clients (#2248)

Update our code docs to better explain proxy settings

* Cleanup IDE warnings. From 442 down to 31. (#2254)

* Fix documented exception types thrown by methods in device client. (#2256)

* (Fix: DeviceClient): Fix the concurrency issue in MQTT stack (#2234)

* Update RegistryManager bulk API unit tests (#2258)

* feat(hub-svc): add support and tests for configurations export (#2250)

* Temporarily disable import devices/configs test (#2263)

* fix(iot-svc): update debug assert (#2264)

* fix(iot-svc): update debug assert

* Temporarily disable import devices/configs test (#2263)

* fix(iot-svc): update debug assert

* Reduce modules in ModulesClient_GetModulesOnDevice to 2

* Consolidate keyvault writes, and fix error about null (#2266)

* Cleanup code in Hub RTAC (#2268)

* fix(deviceClient): Fix issue with AMQP connection pool and TokenReferesher disposal. (#2260)

* Fix issue with AMQP connection pool

* Dispose the connection holder appropriately

* Add unit testing capability to connection pool

* Move more LA steps under conditional (#2270)

* Disable import/export of config until bug fix (#2273)

* Adding RBAC support for provisioning SDK (#2262)

* Added types for different credentials

* Altered code to work with new types

* Fixed Managers

* removed unneeded #if !NET451

* Filled in method summaries

* refactored GetHeaderProvider

* Added documentation

* Formatting fixes to address comments

* Adding Common 0.7.1 (#2272)

* Fix doc comment list bullets (#2275)

* Fix doc comment list bullets

* Change to use description tag

* sdl(all): Create SBOM for net packages  (#2261)

* Streamline an RBAC test (#2274)

* Exclude low pri .net targets in PR builds (#2277)

* fix(tests): Fix device client test to use updated API

* Update IDeviceIdentity interface to add doc comments. (#2282)

* PnP doc comment updates (#2278)

* Fix remaining doc comment bullets (#2285)

* Give e2e appId permission on the DPS instance (#2283)

* fix(DeviceClient): Avoid NRE after client dispose (#2286)

* refactor(iot-device): Update API surface for property callback API

* refactor(iot-device): Update API surface for command callback API

* fix(e2e-tests): Update E2E tests to use fluent assertions

* fix(iot-device): Update API surface to remove redundant private setters

* Revert "Adding RBAC support for provisioning SDK (#2262)" (#2289)

This reverts commit 7a26eda.

* Version bump for 2021-01-26 release (#2291)

* Update service clients instantiation doc comments (#2290)

* Update RegistryManager instantiation doc comments

* Update other service client doc comments.

* Fix class field constants casing (#2292)

* Disable checks for config in import e2e test (#2293)

* Update iteration path in vsts.yaml (#2296)

Co-authored-by: James Davis ⛺️🏔 <jamdavi@microsoft.com>
Co-authored-by: jamdavi <73593426+jamdavi@users.noreply.github.com>
Co-authored-by: Azad Abbasi <azabbasi@microsoft.com>
Co-authored-by: David R. Williamson <drwill@microsoft.com>
Co-authored-by: dylanbulfinMS <95251881+dylanbulfinMS@users.noreply.github.com>
  • Loading branch information
6 people authored Feb 14, 2022
1 parent b583f4b commit 1749f7c
Show file tree
Hide file tree
Showing 195 changed files with 3,016 additions and 1,761 deletions.
1 change: 0 additions & 1 deletion common/src/Logging.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int off
/// <param name="count">The number of bytes to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "Parameters 'thisOrContextObject' and 'memberName' used in NET451; remove when no longer supported.")]
public static unsafe void DumpBuffer(object thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string memberName = null)
{
Debug.Assert(bufferPtr != IntPtr.Zero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static string BuildSasSignature(string keyName, string key, string target

public static string BuildExpiresOn(TimeSpan timeToLive)
{
DateTime epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime expiresOn = DateTime.UtcNow.Add(timeToLive);
TimeSpan secondsFromBaseTime = expiresOn.Subtract(epochTime);
long seconds = Convert.ToInt64(secondsFromBaseTime.TotalSeconds, CultureInfo.InvariantCulture);
Expand Down
4 changes: 2 additions & 2 deletions common/src/service/HttpClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,10 @@ internal static HttpMessageHandler CreateDefaultHttpMessageHandler(IWebProxy web
#pragma warning disable CA2000 // Dispose objects before losing scope (object is returned by this method, so the caller is responsible for disposing it)
#if NETCOREAPP && !NETCOREAPP2_0 && !NETCOREAPP1_0 && !NETCOREAPP1_1
// SocketsHttpHandler is only available in netcoreapp2.1 and onwards
SocketsHttpHandler httpMessageHandler = new SocketsHttpHandler();
var httpMessageHandler = new SocketsHttpHandler();
httpMessageHandler.SslOptions.EnabledSslProtocols = TlsVersions.Instance.Preferred;
#else
HttpClientHandler httpMessageHandler = new HttpClientHandler();
var httpMessageHandler = new HttpClientHandler();
#if !NET451
httpMessageHandler.SslProtocols = TlsVersions.Instance.Preferred;
httpMessageHandler.CheckCertificateRevocationList = TlsVersions.Instance.CertificateRevocationCheck;
Expand Down
5 changes: 4 additions & 1 deletion common/src/service/IAuthorizationHeaderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

namespace Microsoft.Azure.Devices
{
interface IAuthorizationHeaderProvider
/// <summary>
/// Gets the authorization header for authenticated requests, regardless of choice of authentication.
/// </summary>
internal interface IAuthorizationHeaderProvider
{
string GetAuthorizationHeader();
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/service/StringValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public static bool IsBase64String(string value)
return false;
}

var lengthNoPadding = value.Length;
int lengthNoPadding = value.Length;
value = value.TrimEnd(Base64Padding);
var lengthPadding = value.Length;
int lengthPadding = value.Length;

if ((lengthNoPadding - lengthPadding) > 2)
{
Expand Down
17 changes: 17 additions & 0 deletions e2e/test/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
"Style",
"IDE1006:Naming Styles",
Justification = "Missing Async suffix on test method names. Test method names may be misleading when they have the Async suffix. Additionally, not changing test names help to maintain ADO history.",
Scope = "module")]
[assembly: SuppressMessage(
"CodeQuality",
"IDE0079:Remove unnecessary suppression",
Justification = "Each frameworks consider certain suppressions required by other frameworks unnecessary.",
Scope = "module")]
12 changes: 6 additions & 6 deletions e2e/test/config/TestConfiguration.IoTHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,39 @@ public static string GetIotHubSharedAccessSignature(TimeSpan timeToLive)
public static X509Certificate2 GetCertificateWithPrivateKey()
{
const string hubPfxCert = "IOTHUB_X509_PFX_CERTIFICATE";
var cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
X509Certificate2 cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubPfxCert} has expired.");
return cert;
}

public static X509Certificate2 GetChainDeviceCertificateWithPrivateKey()
{
const string hubPfxCert = "HUB_CHAIN_DEVICE_PFX_CERTIFICATE";
var cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
X509Certificate2 cert = GetBase64EncodedCertificate(hubPfxCert, defaultValue: string.Empty);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubPfxCert} has expired.");
return cert;
}

public static X509Certificate2 GetRootCACertificate()
{
const string hubCert = "HUB_CHAIN_ROOT_CA_CERTIFICATE";
var cert = GetBase64EncodedCertificate(hubCert);
X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}

public static X509Certificate2 GetIntermediate1Certificate()
{
const string hubCert = "HUB_CHAIN_INTERMEDIATE1_CERTIFICATE";
var cert = GetBase64EncodedCertificate(hubCert);
X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}

public static X509Certificate2 GetIntermediate2Certificate()
{
const string hubCert = "HUB_CHAIN_INTERMEDIATE2_CERTIFICATE";
var cert = GetBase64EncodedCertificate(hubCert);
X509Certificate2 cert = GetBase64EncodedCertificate(hubCert);
Assert.IsTrue(cert.NotAfter > DateTime.UtcNow, $"The X509 cert from {hubCert} has expired.");
return cert;
}
Expand All @@ -111,7 +111,7 @@ public static X509Certificate2 GetIntermediate2Certificate()

private static string GenerateSasToken(string resourceUri, string sharedAccessKey, TimeSpan timeToLive, string policyName = default)
{
DateTime epochTime = new DateTime(1970, 1, 1);
var epochTime = new DateTime(1970, 1, 1);
DateTime expiresOn = DateTime.UtcNow.Add(timeToLive);
TimeSpan secondsFromEpochTime = expiresOn.Subtract(epochTime);
long seconds = Convert.ToInt64(secondsFromEpochTime.TotalSeconds, CultureInfo.InvariantCulture);
Expand Down
29 changes: 0 additions & 29 deletions e2e/test/helpers/ImportExportDevicesHelpers.cs

This file was deleted.

30 changes: 30 additions & 0 deletions e2e/test/helpers/ImportExportHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;

namespace Microsoft.Azure.Devices.E2ETests.Helpers
{
internal static class ImportExportHelpers
{
/// <summary>
/// Makes a stream compatible for writing to a storage blob of serialized, newline-delimited rows of the specified objects.
/// </summary>
/// <param name="items">The objects to serialize.</param>
public static Stream BuildImportStream<T>(IReadOnlyList<T> items)
{
var itemsFileSb = new StringBuilder();

foreach (T item in items)
{
itemsFileSb.AppendLine(JsonConvert.SerializeObject(item));
}

byte[] itemsFileInBytes = Encoding.Default.GetBytes(itemsFileSb.ToString());
return new MemoryStream(itemsFileInBytes);
}
}
}
2 changes: 1 addition & 1 deletion e2e/test/helpers/StorageContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected virtual void Dispose(bool disposing)

private async Task InitializeAsync()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(TestConfiguration.Storage.ConnectionString);
var storageAccount = CloudStorageAccount.Parse(TestConfiguration.Storage.ConnectionString);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer = cloudBlobClient.GetContainerReference(ContainerName);
await CloudBlobContainer.CreateIfNotExistsAsync().ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion e2e/test/helpers/TestDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static async Task<TestDevice> CreateDeviceAsync(TestDeviceType type, str
string deviceName = "E2E_" + prefix + Guid.NewGuid();

// Delete existing devices named this way and create a new one.
using RegistryManager rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
using var rm = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
s_logger.Trace($"{nameof(GetTestDeviceAsync)}: Creating device {deviceName} with type {type}.");

Client.IAuthenticationMethod auth = null;
Expand Down
10 changes: 3 additions & 7 deletions e2e/test/helpers/TestDeviceCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,11 @@ public async Task WaitForReceiveMessageCallbackAsync(CancellationToken ct)

public async Task SetClientPropertyUpdateCallbackHandlerAsync<T>(string expectedPropName, string componentName = default)
{
string userContext = "myContext";

await _deviceClient
.SubscribeToWritablePropertyUpdateRequestsAsync(
(patch, context) =>
patch =>
{
_logger.Trace($"{nameof(SetClientPropertyUpdateCallbackHandlerAsync)}: DeviceClient {_testDevice.Id} callback property: WritableProperty: {patch}, {context}");
_logger.Trace($"{nameof(SetClientPropertyUpdateCallbackHandlerAsync)}: DeviceClient {_testDevice.Id} callback property: WritableProperty: {patch}.");

try
{
Expand All @@ -193,7 +191,6 @@ await _deviceClient

isPropertyPresent.Should().BeTrue();
propertyFromCollection.Should().BeEquivalentTo((T)ExpectedClientPropertyValue);
context.Should().Be(userContext);
}
catch (Exception ex)
{
Expand All @@ -206,8 +203,7 @@ await _deviceClient
}

return Task.FromResult(true);
},
userContext)
})
.ConfigureAwait(false);
}

Expand Down
Loading

0 comments on commit 1749f7c

Please sign in to comment.