mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 12:15:01 +00:00
fixed minor registration error
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
public static class JsonExtensions
|
||||||
|
{
|
||||||
|
public static List<JToken> FindTokens(this JToken containerToken, string name)
|
||||||
|
{
|
||||||
|
List<JToken> matches = new List<JToken>();
|
||||||
|
FindTokens(containerToken, name, matches);
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FindTokens(JToken containerToken, string name, List<JToken> matches)
|
||||||
|
{
|
||||||
|
if (containerToken.Type == JTokenType.Object)
|
||||||
|
{
|
||||||
|
foreach (JProperty child in containerToken.Children<JProperty>())
|
||||||
|
{
|
||||||
|
if (child.Name == name)
|
||||||
|
{
|
||||||
|
matches.Add(child.Value);
|
||||||
|
}
|
||||||
|
FindTokens(child.Value, name, matches);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (containerToken.Type == JTokenType.Array)
|
||||||
|
{
|
||||||
|
foreach (JToken child in containerToken.Children())
|
||||||
|
{
|
||||||
|
FindTokens(child, name, matches);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,65 +105,68 @@ namespace PepperDash.Essentials.Core
|
|||||||
var name = localDc.Name;
|
var name = localDc.Name;
|
||||||
var type = localDc.Type;
|
var type = localDc.Type;
|
||||||
var properties = localDc.Properties;
|
var properties = localDc.Properties;
|
||||||
|
//var propRecurse = properties;
|
||||||
|
|
||||||
|
|
||||||
var typeName = localDc.Type.ToLower();
|
var typeName = localDc.Type.ToLower();
|
||||||
|
|
||||||
Debug.Console(2, "typeName = {0}", typeName);
|
Debug.Console(2, "typeName = {0}", typeName);
|
||||||
// Check for types that have been added by plugin dlls.
|
// Check for types that have been added by plugin dlls.
|
||||||
if (FactoryMethods.ContainsKey(typeName))
|
if (!FactoryMethods.ContainsKey(typeName)) return null;
|
||||||
|
|
||||||
|
/*foreach (var obj in (propRecurse as JObject).FindTokens("secret").OfType<JObject>())
|
||||||
|
{
|
||||||
|
Debug.Console(2, obj.ToString());
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
//look for secret in username
|
||||||
|
var userSecretToken = properties["control"]["tcpSshProperties"]["username"]["secret"];
|
||||||
|
|
||||||
|
if (userSecretToken != null)
|
||||||
{
|
{
|
||||||
//look for secret in username
|
Debug.Console(2, "Found a secret for {0} - attempting to retrieve it!", name);
|
||||||
var userSecretToken = properties["control"]["tcpSshProperties"]["username"]["secret"];
|
var userSecretResult =
|
||||||
|
JsonConvert.DeserializeObject<SecretsPropertiesConfig>(userSecretToken.ToString());
|
||||||
if (userSecretToken != null)
|
var userProvider = SecretsManager.GetSecretProviderByKey(userSecretResult.Provider);
|
||||||
|
if (userProvider != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, "Found a secret for {0} - attempting to retrieve it!", name);
|
var user = userProvider.GetSecret(userSecretResult.Key);
|
||||||
var userSecretResult =
|
if (user == null)
|
||||||
JsonConvert.DeserializeObject<SecretsPropertiesConfig>(userSecretToken.ToString());
|
|
||||||
var userProvider = SecretsManager.GetSecretProviderByKey(userSecretResult.Provider);
|
|
||||||
if (userProvider != null)
|
|
||||||
{
|
{
|
||||||
var user = userProvider.GetSecret(userSecretResult.Key);
|
Debug.Console(1,
|
||||||
if (user == null)
|
"Unable to retrieve secret for {0} - Make sure you've added it to the secrets provider");
|
||||||
{
|
return null;
|
||||||
Debug.Console(1,
|
|
||||||
"Unable to retrieve secret for {0} - Make sure you've added it to the secrets provider");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
properties["control"]["tcpSshProperties"]["username"] = (string) user.Value;
|
|
||||||
}
|
}
|
||||||
|
properties["control"]["tcpSshProperties"]["username"] = (string) user.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//look for secret in password
|
|
||||||
var passwordSecretToken = properties["control"]["tcpSshProperties"]["password"]["secret"];
|
|
||||||
|
|
||||||
if (passwordSecretToken != null)
|
|
||||||
{
|
|
||||||
Debug.Console(2, "Found a secret for {0} - attempting to retrieve it!", name);
|
|
||||||
|
|
||||||
var passwordSecretResult =
|
|
||||||
JsonConvert.DeserializeObject<SecretsPropertiesConfig>(passwordSecretToken.ToString());
|
|
||||||
var passwordProvider = SecretsManager.GetSecretProviderByKey(passwordSecretResult.Provider);
|
|
||||||
if (passwordProvider != null)
|
|
||||||
{
|
|
||||||
var password = passwordProvider.GetSecret(passwordSecretResult.Key);
|
|
||||||
if (password == null)
|
|
||||||
{
|
|
||||||
Debug.Console(1,
|
|
||||||
"Unable to retrieve secret for {0} - Make sure you've added it to the secrets provider");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
properties["control"]["tcpSshProperties"]["password"] = (string) password.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Console(0, "{0}", localDc.Properties.ToString());
|
|
||||||
|
|
||||||
return FactoryMethods[typeName].FactoryMethod(localDc);
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
//look for secret in password
|
||||||
|
var passwordSecretToken = properties["control"]["tcpSshProperties"]["password"]["secret"];
|
||||||
|
|
||||||
|
if (passwordSecretToken != null)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "Found a secret for {0} - attempting to retrieve it!", name);
|
||||||
|
|
||||||
|
var passwordSecretResult =
|
||||||
|
JsonConvert.DeserializeObject<SecretsPropertiesConfig>(passwordSecretToken.ToString());
|
||||||
|
var passwordProvider = SecretsManager.GetSecretProviderByKey(passwordSecretResult.Provider);
|
||||||
|
if (passwordProvider != null)
|
||||||
|
{
|
||||||
|
var password = passwordProvider.GetSecret(passwordSecretResult.Key);
|
||||||
|
if (password == null)
|
||||||
|
{
|
||||||
|
Debug.Console(1,
|
||||||
|
"Unable to retrieve secret for {0} - Make sure you've added it to the secrets provider");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
properties["control"]["tcpSshProperties"]["password"] = (string)password.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Console(0, "{0}", localDc.Properties.ToString());
|
||||||
|
|
||||||
|
return FactoryMethods[typeName].FactoryMethod(localDc);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -209,6 +209,7 @@
|
|||||||
<Compile Include="DeviceTypeInterfaces\IHasFarEndContentStatus.cs" />
|
<Compile Include="DeviceTypeInterfaces\IHasFarEndContentStatus.cs" />
|
||||||
<Compile Include="DeviceTypeInterfaces\IHasPhoneDialing.cs" />
|
<Compile Include="DeviceTypeInterfaces\IHasPhoneDialing.cs" />
|
||||||
<Compile Include="DeviceTypeInterfaces\IMobileControl.cs" />
|
<Compile Include="DeviceTypeInterfaces\IMobileControl.cs" />
|
||||||
|
<Compile Include="Extensions\JsonExtensions.cs" />
|
||||||
<Compile Include="Factory\DeviceFactory.cs" />
|
<Compile Include="Factory\DeviceFactory.cs" />
|
||||||
<Compile Include="Factory\IDeviceFactory.cs" />
|
<Compile Include="Factory\IDeviceFactory.cs" />
|
||||||
<Compile Include="Factory\ReadyEventArgs.cs" />
|
<Compile Include="Factory\ReadyEventArgs.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user