-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/dpsRbacSupport' of https://github.com/Azure/azu…
…re-iot-sdk-csharp into feature/dpsRbacSupport
- Loading branch information
Showing
5 changed files
with
190 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
|
||
namespace Microsoft.Azure.Devices.E2ETests.Provisioning | ||
{ | ||
internal class ConnectionStringParser | ||
{ | ||
public string ProvisioningHostName { get; private set; } | ||
|
||
public string DeviceId { get; private set; } | ||
|
||
public string SharedAccessKey { get; private set; } | ||
|
||
public string SharedAccessKeyName { get; private set; } | ||
|
||
public ConnectionStringParser(string connectionString) | ||
{ | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
{ | ||
throw new ArgumentException(nameof(connectionString), "Parameter cannot be null, empty, or whitespace."); | ||
} | ||
|
||
string[] parts = connectionString.Split(';'); | ||
|
||
foreach (string part in parts) | ||
{ | ||
int separatorIndex = part.IndexOf('='); | ||
if (separatorIndex < 0) | ||
{ | ||
throw new ArgumentException($"Improperly formatted key/value pair: {part}."); | ||
} | ||
|
||
string key = part.Substring(0, separatorIndex); | ||
string value = part.Substring(separatorIndex + 1); | ||
|
||
switch (key.ToUpperInvariant()) | ||
{ | ||
case "HOSTNAME": | ||
ProvisioningHostName = value; | ||
break; | ||
|
||
case "SHAREDACCESSKEY": | ||
SharedAccessKey = value; | ||
break; | ||
|
||
case "DEVICEID": | ||
DeviceId = value; | ||
break; | ||
|
||
case "SHAREDACCESSKEYNAME": | ||
SharedAccessKeyName = value; | ||
break; | ||
|
||
default: | ||
throw new NotSupportedException($"Unrecognized tag found in parameter {nameof(connectionString)}."); | ||
} | ||
} | ||
} | ||
} | ||
} |
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