-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into varunpuranik/Tokupdfix1
- Loading branch information
Showing
26 changed files
with
1,822 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/DeviceScopeApiException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy | ||
{ | ||
using System; | ||
using System.Net; | ||
|
||
public class DeviceScopeApiException : Exception | ||
{ | ||
public DeviceScopeApiException(string message, HttpStatusCode statusCode, string content) | ||
: base(message) | ||
{ | ||
this.StatusCode = statusCode; | ||
this.Content = content; | ||
} | ||
|
||
public HttpStatusCode StatusCode { get; } | ||
|
||
public string Content { get; } | ||
|
||
public override string Message => $"Message: {base.Message}, HttpStatusCode: {this.StatusCode}, Content: {this.Content}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/authenticators/CloudTokenAuthenticator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Authenticators | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Cloud; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Identity; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public class CloudTokenAuthenticator : IAuthenticator | ||
{ | ||
readonly IConnectionManager connectionManager; | ||
|
||
public CloudTokenAuthenticator(IConnectionManager connectionManager) | ||
{ | ||
this.connectionManager = Preconditions.CheckNotNull(connectionManager, nameof(connectionManager)); | ||
} | ||
|
||
public async Task<bool> AuthenticateAsync(IClientCredentials clientCredentials) | ||
{ | ||
if (!(clientCredentials is ITokenCredentials)) | ||
{ | ||
return false; | ||
} | ||
|
||
Try<ICloudProxy> cloudProxyTry = await this.connectionManager.CreateCloudConnectionAsync(clientCredentials); | ||
if (cloudProxyTry.Success) | ||
{ | ||
try | ||
{ | ||
await cloudProxyTry.Value.OpenAsync(); | ||
Events.AuthenticatedWithIotHub(clientCredentials.Identity); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Events.ErrorValidatingTokenWithIoTHub(clientCredentials.Identity, ex); | ||
} | ||
} | ||
else | ||
{ | ||
Events.ErrorGettingCloudProxy(clientCredentials.Identity, cloudProxyTry.Exception); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
static class Events | ||
{ | ||
static readonly ILogger Log = Logger.Factory.CreateLogger<CloudTokenAuthenticator>(); | ||
const int IdStart = CloudProxyEventIds.CloudTokenAuthenticator; | ||
|
||
enum EventIds | ||
{ | ||
AuthenticatedWithCloud = IdStart, | ||
ErrorValidatingToken, | ||
ErrorGettingCloudProxy | ||
} | ||
|
||
public static void AuthenticatedWithIotHub(IIdentity identity) | ||
{ | ||
Log.LogDebug((int)EventIds.AuthenticatedWithCloud, $"Authenticated {identity.Id} with IotHub"); | ||
} | ||
|
||
public static void ErrorValidatingTokenWithIoTHub(IIdentity identity, Exception ex) | ||
{ | ||
Log.LogWarning((int)EventIds.ErrorValidatingToken, ex, $"Error validating token for {identity.Id} with IoTHub"); | ||
} | ||
|
||
public static void ErrorGettingCloudProxy(IIdentity identity, Exception ex) | ||
{ | ||
Log.LogWarning((int)EventIds.ErrorGettingCloudProxy, ex, $"Error getting cloud proxy for {identity.Id}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.