fix:console commands for Secrets Management Modified

This commit is contained in:
Trevor Payne
2022-07-15 17:40:48 -05:00
parent c3818b8bf2
commit 5a4cc2fd39
3 changed files with 79 additions and 75 deletions

View File

@@ -1,35 +1,35 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Config namespace PepperDash.Essentials.Core.Config
{ {
public class DeviceConfig public class DeviceConfig
{ {
[JsonProperty("key")] [JsonProperty("key")]
public string Key { get; set; } public string Key { get; set; }
[JsonProperty("uid")] [JsonProperty("uid")]
public int Uid { get; set; } public int Uid { get; set; }
[JsonProperty("name")] [JsonProperty("name")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("group")] [JsonProperty("group")]
public string Group { get; set; } public string Group { get; set; }
[JsonProperty("type")] [JsonProperty("type")]
public string Type { get; set; } public string Type { get; set; }
[JsonProperty("properties")] [JsonProperty("properties")]
[JsonConverter(typeof(DevicePropertiesConverter))] [JsonConverter(typeof(DevicePropertiesConverter))]
public JToken Properties { get; set; } public JToken Properties { get; set; }
public DeviceConfig(DeviceConfig dc) public DeviceConfig(DeviceConfig dc)
@@ -39,39 +39,42 @@ namespace PepperDash.Essentials.Core.Config
Name = dc.Name; Name = dc.Name;
Group = dc.Group; Group = dc.Group;
Type = dc.Type; Type = dc.Type;
Properties = JToken.FromObject(dc.Properties);
Properties = JToken.Parse(dc.Properties.ToString());
//Properties = JToken.FromObject(dc.Properties);
} }
public DeviceConfig() {} public DeviceConfig() {}
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class DevicePropertiesConverter : JsonConverter public class DevicePropertiesConverter : JsonConverter
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)
{ {
return objectType == typeof(JToken); return objectType == typeof(JToken);
} }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
return JToken.ReadFrom(reader); return JToken.ReadFrom(reader);
} }
public override bool CanWrite public override bool CanWrite
{ {
get get
{ {
return false; return false;
} }
} }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
throw new NotImplementedException("SOD OFF HOSER"); throw new NotImplementedException("SOD OFF HOSER");
} }
} }
} }

View File

@@ -59,7 +59,7 @@ namespace PepperDash.Essentials.Core.Devices
/// <summary> /// <summary>
/// Used by the extending class to allow for any custom actions to be taken (tell the ConfigWriter to write config, etc) /// Used by the extending class to allow for any custom actions to be taken (tell the ConfigWriter to write config, etc)
/// </summary> /// </summary>
/// <param name="Config"></param> /// <param name="config"></param>
protected virtual void CustomSetConfig(DeviceConfig config) protected virtual void CustomSetConfig(DeviceConfig config)
{ {
ConfigWriter.UpdateDeviceConfig(config); ConfigWriter.UpdateDeviceConfig(config);

View File

@@ -36,21 +36,22 @@ namespace PepperDash.Essentials.Core
public bool SetSecret(string key, object value) public bool SetSecret(string key, object value)
{ {
var secret = value as string; var secret = value as string;
CrestronDataStore.CDS_ERROR returnCode;
if (String.IsNullOrEmpty(secret)) if (String.IsNullOrEmpty(secret))
{ {
Debug.Console(2, this, "Unable to set secret for {0}:{1} - value is empty.", Key, key); returnCode = CrestronDataStoreStatic.clearLocal(key);
return false; if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS) return true;
} }
var setErrorCode = CrestronDataStoreStatic.SetLocalStringValue(key, secret);
switch (setErrorCode) else
{ {
case CrestronDataStore.CDS_ERROR.CDS_SUCCESS: returnCode = CrestronDataStoreStatic.SetLocalStringValue(key, secret);
Debug.Console(1, this,"Secret Successfully Set for {0}:{1}", Key, key); if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS) return true;
return true;
default:
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Unable to set secret for {0}:{1} - {2}", Key, key, setErrorCode.ToString());
return false;
} }
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Unable to set secret for {0}:{1} - {2}", Key, key, returnCode.ToString());
return false;
} }
/// <summary> /// <summary>