forked from Azure/iotedge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 797501: Set env variables to edgelet uri and use DeviceClie…
…ntFactory in EdgeHub - Set env variables to edgelet details - Use DeviceClientFactory to create EdgeHub connection
- Loading branch information
1 parent
1ebb45f
commit a9b99dd
Showing
50 changed files
with
749 additions
and
379 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/ConnectionStringCredentials.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,17 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
public class ConnectionStringCredentials : ICredentials | ||
{ | ||
public ConnectionStringCredentials(string connectionString) | ||
{ | ||
this.CredentialsType = CredentialType.ConnectionString; | ||
this.ConnectionString = connectionString; | ||
} | ||
|
||
public string ConnectionString { get; } | ||
|
||
public CredentialType CredentialsType { get; } | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/CredentialType.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,11 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
public enum CredentialType | ||
{ | ||
None, | ||
ConnectionString, | ||
IdentityProviderService | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/ICredentials.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,9 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
public interface ICredentials | ||
{ | ||
CredentialType CredentialsType { get; } | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/IdentityProviderServiceCredentials.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,35 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
|
||
public class IdentityProviderServiceCredentials : ICredentials | ||
{ | ||
const string DefaultAuthScheme = "sasToken"; | ||
|
||
public IdentityProviderServiceCredentials(string providerUri) : this(providerUri, DefaultAuthScheme) | ||
{ | ||
} | ||
|
||
public IdentityProviderServiceCredentials(string providerUri, string authScheme) : this(providerUri, authScheme, Option.None<string>()) | ||
{ | ||
} | ||
|
||
public IdentityProviderServiceCredentials(string providerUri, string authScheme, Option<string> providerVersion) | ||
{ | ||
this.CredentialsType = CredentialType.IdentityProviderService; | ||
this.ProviderUri = Preconditions.CheckNonWhiteSpace(providerUri, nameof(providerUri)); | ||
this.AuthScheme = Preconditions.CheckNonWhiteSpace(authScheme, nameof(authScheme)); | ||
this.Version = Preconditions.CheckNotNull(providerVersion, nameof(providerVersion)); | ||
} | ||
|
||
public string ProviderUri { get; } | ||
|
||
public Option<string> Version { get; } | ||
|
||
public string AuthScheme { get; } | ||
|
||
public CredentialType CredentialsType { get; } | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/ModuleConnectionString.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,103 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
using System; | ||
using System.Text; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
|
||
public class ModuleConnectionString | ||
{ | ||
const string HostNamePropertyName = "HostName"; | ||
const string GatewayHostNamePropertyName = "GatewayHostName"; | ||
const string DeviceIdPropertyName = "DeviceId"; | ||
const string ModuleIdPropertyname = "ModuleId"; | ||
const string SharedAccessKeyPropertyName = "SharedAccessKey"; | ||
const char ValuePairDelimiter = ';'; | ||
|
||
readonly string sasKey; | ||
|
||
ModuleConnectionString(string iotHubHostName, string gatewayHostName, string deviceId, string moduleId, string sasKey) | ||
{ | ||
this.IotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); | ||
this.GatewayHostName = gatewayHostName; | ||
this.DeviceId = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId)); | ||
this.ModuleId = Preconditions.CheckNonWhiteSpace(moduleId, nameof(moduleId)); | ||
this.sasKey = sasKey; | ||
} | ||
|
||
public string IotHubHostName { get; } | ||
|
||
public string DeviceId { get; } | ||
|
||
public string ModuleId { get; } | ||
|
||
public string GatewayHostName { get; } | ||
|
||
public override string ToString() | ||
{ | ||
if (string.IsNullOrEmpty(this.ModuleId)) | ||
{ | ||
throw new ArgumentException("Required parameter moduleId has not been set"); | ||
} | ||
|
||
var connectionString = new StringBuilder(); | ||
this.AppendIfNotEmpty(connectionString, HostNamePropertyName, this.IotHubHostName); | ||
this.AppendIfNotEmpty(connectionString, DeviceIdPropertyName, this.DeviceId); | ||
this.AppendIfNotEmpty(connectionString, ModuleIdPropertyname, this.ModuleId); | ||
this.AppendIfNotEmpty(connectionString, SharedAccessKeyPropertyName, this.sasKey); | ||
this.AppendIfNotEmpty(connectionString, GatewayHostNamePropertyName, this.GatewayHostName); | ||
return connectionString.ToString(); | ||
} | ||
|
||
void AppendIfNotEmpty(StringBuilder stringBuilder, string propertyName, string propertyValue) | ||
{ | ||
if (!string.IsNullOrEmpty(propertyValue)) | ||
{ | ||
if (stringBuilder.Length > 0) | ||
{ | ||
stringBuilder.Append(ValuePairDelimiter); | ||
} | ||
|
||
stringBuilder.Append($"{propertyName}={propertyValue}"); | ||
} | ||
} | ||
|
||
public static implicit operator string(ModuleConnectionString moduleConnectionStringBuilder) => moduleConnectionStringBuilder.ToString(); | ||
|
||
public class ModuleConnectionStringBuilder | ||
{ | ||
readonly string iotHubHostName; | ||
readonly string deviceId; | ||
string moduleId; | ||
string gatewayHostname; | ||
string sasKey; | ||
|
||
public ModuleConnectionStringBuilder(string iotHubHostName, string deviceId) | ||
{ | ||
this.iotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); | ||
this.deviceId = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId)); | ||
} | ||
|
||
public ModuleConnectionStringBuilder WithModuleId(string moduleId) | ||
{ | ||
this.moduleId = Preconditions.CheckNonWhiteSpace(moduleId, nameof(moduleId)); | ||
return this; | ||
} | ||
|
||
public ModuleConnectionStringBuilder WithGatewayHostName(string gatewayHostName) | ||
{ | ||
this.gatewayHostname = Preconditions.CheckNonWhiteSpace(gatewayHostName, nameof(gatewayHostName)); | ||
return this; | ||
} | ||
|
||
public ModuleConnectionStringBuilder WithSharedAccessKey(string sasKey) | ||
{ | ||
this.sasKey = Preconditions.CheckNonWhiteSpace(sasKey, nameof(sasKey)); | ||
return this; | ||
} | ||
|
||
public ModuleConnectionString Build() => new ModuleConnectionString(this.iotHubHostName, this.gatewayHostname, this.deviceId, this.moduleId, this.sasKey); | ||
} | ||
} | ||
} |
87 changes: 0 additions & 87 deletions
87
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/ModuleConnectionStringBuilder.cs
This file was deleted.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
...agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/ModuleIdentityProviderServiceBuilder.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,39 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.Azure.Devices.Edge.Agent.Core | ||
{ | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
|
||
public class ModuleIdentityProviderServiceBuilder | ||
{ | ||
readonly string iotHubHostName; | ||
readonly string deviceId; | ||
readonly string gatewayHostname; | ||
|
||
public ModuleIdentityProviderServiceBuilder(string iotHubHostName, string deviceId, string gatewayHostname) | ||
{ | ||
this.iotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); | ||
this.deviceId = Preconditions.CheckNonWhiteSpace(deviceId, nameof(deviceId)); | ||
this.gatewayHostname = gatewayHostname; | ||
} | ||
|
||
public IModuleIdentity Create(string moduleId, string providerUri) | ||
{ | ||
Preconditions.CheckNonWhiteSpace(moduleId, nameof(moduleId)); | ||
Preconditions.CheckNonWhiteSpace(providerUri, nameof(providerUri)); | ||
|
||
ICredentials credentials = new IdentityProviderServiceCredentials(providerUri); | ||
return new ModuleIdentity(this.iotHubHostName, this.gatewayHostname, this.deviceId, moduleId, credentials); | ||
} | ||
|
||
public IModuleIdentity Create(string moduleId, string providerUri, string authScheme) | ||
{ | ||
Preconditions.CheckNonWhiteSpace(moduleId, nameof(moduleId)); | ||
Preconditions.CheckNonWhiteSpace(providerUri, nameof(providerUri)); | ||
Preconditions.CheckNonWhiteSpace(authScheme, nameof(authScheme)); | ||
|
||
ICredentials credentials = new IdentityProviderServiceCredentials(providerUri, authScheme); | ||
return new ModuleIdentity(this.iotHubHostName, this.gatewayHostname, this.deviceId, moduleId, credentials); | ||
} | ||
} | ||
} |
Oops, something went wrong.