mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
fix: updated erroneous console responses for Secrets Providers
refactor: updated method by which the Factories assess secret objects refactor: updated 'SecretsManager' console responses feat: added 'secretproviderlist' console command feat: added 'secretproviderinfo' console command feat: added 'CrestronGlobalSecretsProvider' feat: Added 'Description' property to 'ISecretProvider' feat: added 'TestSecret' method to 'ISecretProvider' docs: added xml comments to 'ISecretProvider' docs: added xml comments to 'ISecret' refactor: cleaned up crestron default secrets provider classes refactor: moved 'CrestronSecret' to its own class file refactor: overhauled all secrets-related console commands resolves #968
This commit is contained in:
@@ -338,7 +338,9 @@
|
|||||||
<Compile Include="Feedbacks\BoolFeedbackPulseExtender.cs" />
|
<Compile Include="Feedbacks\BoolFeedbackPulseExtender.cs" />
|
||||||
<Compile Include="Routing\RoutingPortNames.cs" />
|
<Compile Include="Routing\RoutingPortNames.cs" />
|
||||||
<Compile Include="Routing\TieLineConfig.cs" />
|
<Compile Include="Routing\TieLineConfig.cs" />
|
||||||
<Compile Include="Secrets\CrestronSecretsProvider.cs" />
|
<Compile Include="Secrets\CrestronGlobalSecretsProvider.cs" />
|
||||||
|
<Compile Include="Secrets\CrestronLocalSecretsProvider.cs" />
|
||||||
|
<Compile Include="Secrets\CrestronSecret.cs" />
|
||||||
<Compile Include="Secrets\Interfaces.cs" />
|
<Compile Include="Secrets\Interfaces.cs" />
|
||||||
<Compile Include="Secrets\SecretsManager.cs" />
|
<Compile Include="Secrets\SecretsManager.cs" />
|
||||||
<Compile Include="Secrets\SecretsPropertiesConfig.cs" />
|
<Compile Include="Secrets\SecretsPropertiesConfig.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronDataStore;
|
||||||
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
public class CrestronGlobalSecretsProvider : ISecretProvider
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
//Added for reference
|
||||||
|
public string Description { get; private set; }
|
||||||
|
|
||||||
|
public CrestronGlobalSecretsProvider(string key)
|
||||||
|
{
|
||||||
|
Key = key;
|
||||||
|
Description = String.Format("Default secret provider serving all local applications");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static CrestronGlobalSecretsProvider()
|
||||||
|
{
|
||||||
|
//Added for future encrypted reference
|
||||||
|
var secureSupported = CrestronSecureStorage.Supported;
|
||||||
|
|
||||||
|
CrestronDataStoreStatic.InitCrestronDataStore();
|
||||||
|
if (secureSupported)
|
||||||
|
{
|
||||||
|
//doThingsFuture
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set secret for item in the CrestronSecretsProvider
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Secret Key</param>
|
||||||
|
/// <param name="value">Secret Value</param>
|
||||||
|
public bool SetSecret(string key, object value)
|
||||||
|
{
|
||||||
|
var secret = value as string;
|
||||||
|
CrestronDataStore.CDS_ERROR returnCode;
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(secret))
|
||||||
|
{
|
||||||
|
returnCode = CrestronDataStoreStatic.clearGlobal(key);
|
||||||
|
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Successfully removed secret \"{0}\"", secret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnCode = CrestronDataStoreStatic.SetGlobalStringValue(key, secret);
|
||||||
|
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Successfully set secret \"{0}\"", secret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Unable to set secret for {0}:{1} - {2}", Key, key, returnCode.ToString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve secret for item in the CrestronSecretsProvider
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Secret Key</param>
|
||||||
|
/// <returns>ISecret Object containing key, provider, and value</returns>
|
||||||
|
public ISecret GetSecret(string key)
|
||||||
|
{
|
||||||
|
string mySecret;
|
||||||
|
var getErrorCode = CrestronDataStoreStatic.GetGlobalStringValue(key, out mySecret);
|
||||||
|
|
||||||
|
switch (getErrorCode)
|
||||||
|
{
|
||||||
|
case CrestronDataStore.CDS_ERROR.CDS_SUCCESS:
|
||||||
|
Debug.Console(2, this, "Secret Successfully retrieved for {0}:{1}", Key, key);
|
||||||
|
return new CrestronSecret(key, mySecret, this);
|
||||||
|
default:
|
||||||
|
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Unable to retrieve secret for {0}:{1} - {2}",
|
||||||
|
Key, key, getErrorCode.ToString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine if a secret is present within the provider without retrieving it
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">Secret Key</param>
|
||||||
|
/// <returns>bool if present</returns>
|
||||||
|
public bool TestSecret(string key)
|
||||||
|
{
|
||||||
|
string mySecret;
|
||||||
|
return CrestronDataStoreStatic.GetGlobalStringValue(key, out mySecret) == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,27 +2,31 @@
|
|||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronDataStore;
|
using Crestron.SimplSharp.CrestronDataStore;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
using Crestron.SimplSharpPro;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public class CrestronSecretsProvider : ISecretProvider
|
public class CrestronLocalSecretsProvider : ISecretProvider
|
||||||
{
|
{
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
//Added for reference
|
//Added for reference
|
||||||
private static readonly bool SecureSupported;
|
public string Description { get; private set; }
|
||||||
public CrestronSecretsProvider(string key)
|
|
||||||
|
|
||||||
|
public CrestronLocalSecretsProvider(string key)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
|
Description = String.Format("Default secret provider serving Essentials Application {0}", InitialParametersClass.ApplicationNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CrestronSecretsProvider()
|
static CrestronLocalSecretsProvider()
|
||||||
{
|
{
|
||||||
//Added for future encrypted reference
|
//Added for future encrypted reference
|
||||||
SecureSupported = CrestronSecureStorage.Supported;
|
var secureSupported = CrestronSecureStorage.Supported;
|
||||||
|
|
||||||
CrestronDataStoreStatic.InitCrestronDataStore();
|
CrestronDataStoreStatic.InitCrestronDataStore();
|
||||||
if (SecureSupported)
|
if (secureSupported)
|
||||||
{
|
{
|
||||||
//doThingsFuture
|
//doThingsFuture
|
||||||
}
|
}
|
||||||
@@ -41,13 +45,21 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (String.IsNullOrEmpty(secret))
|
if (String.IsNullOrEmpty(secret))
|
||||||
{
|
{
|
||||||
returnCode = CrestronDataStoreStatic.clearLocal(key);
|
returnCode = CrestronDataStoreStatic.clearLocal(key);
|
||||||
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS) return true;
|
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Successfully removed secret \"{0}\"", secret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
returnCode = CrestronDataStoreStatic.SetLocalStringValue(key, secret);
|
returnCode = CrestronDataStoreStatic.SetLocalStringValue(key, secret);
|
||||||
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS) return true;
|
if (returnCode == CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
|
{
|
||||||
|
Debug.Console(0, this, "Successfully set secret \"{0}\"", secret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Unable to set secret for {0}:{1} - {2}", Key, key, returnCode.ToString());
|
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Unable to set secret for {0}:{1} - {2}", Key, key, returnCode.ToString());
|
||||||
@@ -75,24 +87,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Special container class for CrestronSecret provider
|
/// Determine if a secret is present within the provider without retrieving it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CrestronSecret : ISecret
|
/// <param name="key">Secret Key</param>
|
||||||
{
|
/// <returns>bool if present</returns>
|
||||||
public ISecretProvider Provider { get; private set; }
|
public bool TestSecret(string key)
|
||||||
public string Key { get; private set; }
|
|
||||||
|
|
||||||
public object Value { get; private set; }
|
|
||||||
|
|
||||||
public CrestronSecret(string key, string value, ISecretProvider provider)
|
|
||||||
{
|
{
|
||||||
Key = key;
|
string mySecret;
|
||||||
Value = value;
|
return CrestronDataStoreStatic.GetLocalStringValue(key, out mySecret) == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
|
||||||
Provider = provider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Special container class for CrestronSecret provider
|
||||||
|
/// </summary>
|
||||||
|
public class CrestronSecret : ISecret
|
||||||
|
{
|
||||||
|
public ISecretProvider Provider { get; private set; }
|
||||||
|
public string Key { get; private set; }
|
||||||
|
|
||||||
|
public object Value { get; private set; }
|
||||||
|
|
||||||
|
public CrestronSecret(string key, string value, ISecretProvider provider)
|
||||||
|
{
|
||||||
|
Key = key;
|
||||||
|
Value = value;
|
||||||
|
Provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,9 +7,32 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ISecretProvider : IKeyed
|
public interface ISecretProvider : IKeyed
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Set secret value for provider by key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">key of secret to set</param>
|
||||||
|
/// <param name="value">value to set secret to</param>
|
||||||
|
/// <returns></returns>
|
||||||
bool SetSecret(string key, object value);
|
bool SetSecret(string key, object value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return object containing secret from provider
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">key of secret to retrieve</param>
|
||||||
|
/// <returns></returns>
|
||||||
ISecret GetSecret(string key);
|
ISecret GetSecret(string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies presence of secret
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">key of secret to chek</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool TestSecret(string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Description of the secrets provider
|
||||||
|
/// </summary>
|
||||||
|
string Description { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -17,8 +40,19 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ISecret
|
public interface ISecret
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instance of ISecretProvider that the secret belongs to
|
||||||
|
/// </summary>
|
||||||
ISecretProvider Provider { get; }
|
ISecretProvider Provider { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Key of the secret in the provider
|
||||||
|
/// </summary>
|
||||||
string Key { get; }
|
string Key { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value of the secret
|
||||||
|
/// </summary>
|
||||||
object Value { get; }
|
object Value { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public static class SecretsManager
|
public static class SecretsManager
|
||||||
@@ -16,18 +16,28 @@ namespace PepperDash.Essentials.Core
|
|||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
AddSecretProvider("default", new CrestronSecretsProvider("default"));
|
AddSecretProvider("default", new CrestronLocalSecretsProvider("default"));
|
||||||
|
|
||||||
|
AddSecretProvider("CrestronGlobalSecrets", new CrestronGlobalSecretsProvider("CrestronGlobalSecrets"));
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(SetSecretProcess, "setsecret",
|
CrestronConsole.AddNewConsoleCommand(SetSecretProcess, "setsecret",
|
||||||
"Adds secrets to secret provider",
|
"Adds secret to secrets provider",
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(UpdateSecretProcess, "updatesecret",
|
CrestronConsole.AddNewConsoleCommand(UpdateSecretProcess, "updatesecret",
|
||||||
"Updates secrets in secret provider",
|
"Updates secret in secrets provider",
|
||||||
ConsoleAccessLevelEnum.AccessAdministrator);
|
ConsoleAccessLevelEnum.AccessAdministrator);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(DeleteSecretProcess, "deletesecret",
|
CrestronConsole.AddNewConsoleCommand(DeleteSecretProcess, "deletesecret",
|
||||||
"Deletes secrets in secret provider",
|
"Deletes secret from secrest provider",
|
||||||
|
ConsoleAccessLevelEnum.AccessAdministrator);
|
||||||
|
|
||||||
|
CrestronConsole.AddNewConsoleCommand(ListProviders, "secretproviderlist",
|
||||||
|
"Return list of all valid secrets providers",
|
||||||
|
ConsoleAccessLevelEnum.AccessAdministrator);
|
||||||
|
|
||||||
|
CrestronConsole.AddNewConsoleCommand(GetProviderInfo, "secretproviderinfo",
|
||||||
|
"Return data about secrets provider",
|
||||||
ConsoleAccessLevelEnum.AccessAdministrator);
|
ConsoleAccessLevelEnum.AccessAdministrator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +64,79 @@ namespace PepperDash.Essentials.Core
|
|||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void GetProviderInfo(string cmd)
|
||||||
|
{
|
||||||
|
string response;
|
||||||
|
var args = cmd.Split(' ');
|
||||||
|
|
||||||
|
if (cmd.Length == 0 || (args.Length == 1 && args[0] == "?"))
|
||||||
|
{
|
||||||
|
response = "Returns data about secrets provider. Format 'secretproviderinfo <provider>'";
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
var provider = GetSecretProviderByKey(args[0]);
|
||||||
|
|
||||||
|
if (provider == null)
|
||||||
|
{
|
||||||
|
response = "Invalid secrets provider key";
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = String.Format("{0} : {1}", provider.Key, provider.Description);
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
response = "Improper number of arguments";
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Console Command that returns all valid secrets in the essentials program.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
public static void ListProviders(string cmd)
|
||||||
|
{
|
||||||
|
var response = String.Empty;
|
||||||
|
var args = cmd.Split(' ');
|
||||||
|
|
||||||
|
if (cmd.Length == 0)
|
||||||
|
{
|
||||||
|
if (Secrets != null && Secrets.Count > 0)
|
||||||
|
{
|
||||||
|
response = Secrets.Aggregate(response,
|
||||||
|
(current, secretProvider) => current + (secretProvider.Key + "\n\r"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response = "No Secrets Providers Available";
|
||||||
|
}
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Length == 1 && args[0] == "?")
|
||||||
|
{
|
||||||
|
response = "Reports all valid and preset Secret providers";
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
response = "Improper number of arguments";
|
||||||
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add secret provider to secrets dictionary
|
/// Add secret provider to secrets dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -100,14 +183,14 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
//some Instructional Text
|
//some Instructional Text
|
||||||
response = "Adds secrets to secret provider. Format 'setsecret <provider> <secretKey> <secret>";
|
response = "Adds secrets to secret provider. Format 'setsecret <provider> <secretKey> <secret>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Length == 1 && args[0] == "?")
|
if (args.Length == 1 && args[0] == "?")
|
||||||
{
|
{
|
||||||
response = "Adds secrets to secret provider. Format 'setsecret <provider> <secretKey> <secret>";
|
response = "Adds secrets to secret provider. Format 'setsecret <provider> <secretKey> <secret>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -134,23 +217,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
var key = args[1];
|
var key = args[1];
|
||||||
var secret = args[2];
|
var secret = args[2];
|
||||||
|
|
||||||
if (provider.GetSecret(key) == null)
|
CrestronConsole.ConsoleCommandResponse(SetSecret(provider, key, secret));
|
||||||
{
|
|
||||||
|
|
||||||
response = provider.SetSecret(key, secret)
|
|
||||||
? String.Format(
|
|
||||||
"Secret successfully set for {0}:{1}",
|
|
||||||
provider.Key, key)
|
|
||||||
: String.Format(
|
|
||||||
"Unable to set secret for {0}:{1}",
|
|
||||||
provider.Key, key);
|
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
response =
|
|
||||||
String.Format(
|
|
||||||
"Unable to set secret for {0}:{1} - Please use the 'UpdateSecret' command to modify it");
|
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateSecretProcess(string cmd)
|
private static void UpdateSecretProcess(string cmd)
|
||||||
@@ -161,7 +228,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
//some Instructional Text
|
//some Instructional Text
|
||||||
response = "Updates secrets in secret provider. Format 'updatesecret <provider> <secretKey> <secret>";
|
response = "Updates secrets in secret provider. Format 'updatesecret <provider> <secretKey> <secret>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -169,7 +236,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
if (args.Length == 1 && args[0] == "?")
|
if (args.Length == 1 && args[0] == "?")
|
||||||
{
|
{
|
||||||
response = "Updates secrets in secret provider. Format 'updatesecret <provider> <secretKey> <secret>";
|
response = "Updates secrets in secret provider. Format 'updatesecret <provider> <secretKey> <secret>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -198,23 +265,49 @@ namespace PepperDash.Essentials.Core
|
|||||||
var key = args[1];
|
var key = args[1];
|
||||||
var secret = args[2];
|
var secret = args[2];
|
||||||
|
|
||||||
if (provider.GetSecret(key) != null)
|
CrestronConsole.ConsoleCommandResponse(UpdateSecret(provider, key, secret));
|
||||||
{
|
|
||||||
response = provider.SetSecret(key, secret)
|
}
|
||||||
? String.Format(
|
|
||||||
"Secret successfully set for {0}:{1}",
|
private static string UpdateSecret(ISecretProvider provider, string key, string secret)
|
||||||
provider.Key, key)
|
{
|
||||||
: String.Format(
|
var secretPresent = provider.TestSecret(key);
|
||||||
"Unable to set secret for {0}:{1}",
|
|
||||||
provider.Key, key);
|
Debug.Console(2, provider, "SecretsProvider {0} {1} contain a secret entry for {2}", provider.Key, secretPresent ? "does" : "does not", key);
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
|
||||||
return;
|
if (!secretPresent)
|
||||||
}
|
return
|
||||||
|
String.Format(
|
||||||
|
"Unable to update secret for {0}:{1} - Please use the 'SetSecret' command to modify it");
|
||||||
|
var response = provider.SetSecret(key, secret)
|
||||||
|
? String.Format(
|
||||||
|
"Secret successfully set for {0}:{1}",
|
||||||
|
provider.Key, key)
|
||||||
|
: String.Format(
|
||||||
|
"Unable to set secret for {0}:{1}",
|
||||||
|
provider.Key, key);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string SetSecret(ISecretProvider provider, string key, string secret)
|
||||||
|
{
|
||||||
|
var secretPresent = provider.TestSecret(key);
|
||||||
|
|
||||||
|
Debug.Console(2, provider, "SecretsProvider {0} {1} contain a secret entry for {2}", provider.Key, secretPresent ? "does" : "does not", key);
|
||||||
|
|
||||||
|
if (secretPresent)
|
||||||
|
return
|
||||||
|
String.Format(
|
||||||
|
"Unable to set secret for {0}:{1} - Please use the 'UpdateSecret' command to modify it");
|
||||||
|
var response = provider.SetSecret(key, secret)
|
||||||
|
? String.Format(
|
||||||
|
"Secret successfully set for {0}:{1}",
|
||||||
|
provider.Key, key)
|
||||||
|
: String.Format(
|
||||||
|
"Unable to set secret for {0}:{1}",
|
||||||
|
provider.Key, key);
|
||||||
|
return response;
|
||||||
|
|
||||||
response =
|
|
||||||
String.Format(
|
|
||||||
"Unable to update secret for {0}:{1} - Please use the 'SetSecret' command to create a new secret");
|
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DeleteSecretProcess(string cmd)
|
private static void DeleteSecretProcess(string cmd)
|
||||||
@@ -225,14 +318,14 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
//some Instructional Text
|
//some Instructional Text
|
||||||
response = "Deletes secrets in secret provider. Format 'deletesecret <provider> <secretKey>";
|
response = "Deletes secrets in secret provider. Format 'deletesecret <provider> <secretKey>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (args.Length == 1 && args[0] == "?")
|
if (args.Length == 1 && args[0] == "?")
|
||||||
{
|
{
|
||||||
response = "Deletes secrets in secret provider. Format 'deletesecret <provider> <secretKey>";
|
response = "Deletes secrets in secret provider. Format 'deletesecret <provider> <secretKey>'";
|
||||||
CrestronConsole.ConsoleCommandResponse(response);
|
CrestronConsole.ConsoleCommandResponse(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user