aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/DataStore/Tango.DataStore.CLI
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-19 01:46:41 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-19 01:46:41 +0200
commit466340a97f8a158570f84fc12238101ca9c124ec (patch)
tree5400eb9aeeac9571079b4d80fb4eeac5abf103fa /Software/Visual_Studio/DataStore/Tango.DataStore.CLI
parentcd5006f765c65482033d671095f34453acfc416b (diff)
downloadTango-466340a97f8a158570f84fc12238101ca9c124ec.tar.gz
Tango-466340a97f8a158570f84fc12238101ca9c124ec.zip
Data store improvements.
Added line number to logs viewer. Added DataStore Create Write Global permission. Added FSE application path to "Path" environment variable for dsUtil. Completed dsUtil.
Diffstat (limited to 'Software/Visual_Studio/DataStore/Tango.DataStore.CLI')
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs131
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs15
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs21
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs66
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj6
5 files changed, 176 insertions, 63 deletions
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs
new file mode 100644
index 000000000..b18476e3f
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtil.cs
@@ -0,0 +1,131 @@
+using ConsoleTables;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Cryptography;
+using Tango.DataStore.Web;
+using Tango.Settings;
+using Tango.Web;
+
+namespace Tango.DataStore.CLI
+{
+ public class DataStoreConsole
+ {
+ public void Get(GetOptions options)
+ {
+ try
+ {
+ ApplyAutoLogin(options);
+
+ if (options.MachineSerialNumber != null)
+ {
+ Console.WriteLine($"Retrieving data store values for '{options.MachineSerialNumber}'...");
+ }
+ else
+ {
+ Console.WriteLine("Retrieving global data store values...");
+ }
+
+ var client = CreateClient(options.Email, options.Password, options.Environment);
+
+ var items = client.Get(options.MachineSerialNumber, options.Collection, options.Key).ToList();
+
+ ConsoleTable table = new ConsoleTable("COLLECTION", "KEY", "DATA TYPE", "PROTO TYPE", "STATE", "GLOBAL", "LOCAL");
+
+ foreach (var item in items)
+ {
+ table.AddRow(item.Collection, item.Key, item.DataType, item.ProtoMessageType != MessageType.None ? item.ProtoMessageType.ToString() : null, item.Type, item.GlobalValue.ToStringSafe().ToOneLine(), item.LocalValue.ToStringSafe().ToOneLine());
+ }
+
+ Console.WriteLine();
+ Console.WriteLine("DATA STORE RESULTS:");
+ Console.WriteLine();
+
+ table.Write();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.FlattenMessage());
+ }
+ }
+
+ public void Put(PutOptions options)
+ {
+ try
+ {
+ ApplyAutoLogin(options);
+
+ if (options.MachineSerialNumber != null)
+ {
+ Console.WriteLine($"Storing data store value for '{options.MachineSerialNumber}'...");
+ }
+ else
+ {
+ Console.WriteLine("Storing global data store value...");
+ }
+
+ var client = CreateClient(options.Email, options.Password, options.Environment);
+
+ if (options.DataType == Web.DataType.Proto)
+ {
+ options.Value = options.Value.ToStringOrEmpty().Replace("'", "\"");
+ }
+
+ client.Put(new DataStoreWebPutItem()
+ {
+ Collection = options.Collection,
+ Key = options.Key,
+ DataType = options.DataType,
+ MachineSerialNumber = options.MachineSerialNumber,
+ ProtoMessageType = options.ProtoMessageType,
+ Value = options.Value
+ });
+
+ Console.WriteLine($"Item '{options.Key}' stored successfully.");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.FlattenMessage());
+ }
+ }
+
+ public void AutoLogin(LoginConfig options)
+ {
+ MachineLevelCryptographer crypt = new MachineLevelCryptographer();
+ var settings = SettingsManager.Default.GetOrCreate<DataStoreUtilSettings>();
+ settings.Email = options.Email;
+ settings.Password = crypt.Encrypt(options.Password);
+ settings.Save();
+ }
+
+ private void ApplyAutoLogin(OptionsBase options)
+ {
+ if (options.Email == null && options.Password == null)
+ {
+ MachineLevelCryptographer crypt = new MachineLevelCryptographer();
+ var settings = SettingsManager.Default.GetOrCreate<DataStoreUtilSettings>();
+ options.Email = settings.Email;
+ options.Password = crypt.Decrypt(settings.Password);
+ }
+ }
+
+ private DataStoreClient CreateClient(String email, String password, DeploymentSlot slot)
+ {
+ String token = String.Empty;
+
+ HttpClient http = new HttpClient();
+ DataStoreClient dsClient = new DataStoreClient(slot.ToAddress(), http);
+ var response = dsClient.Login(new LoginRequest()
+ {
+ Email = email,
+ Password = password,
+ });
+ http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.Token);
+
+ return dsClient;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs
new file mode 100644
index 000000000..58380d231
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/DataStoreUtilSettings.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Settings;
+
+namespace Tango.DataStore.CLI
+{
+ public class DataStoreUtilSettings : SettingsBase
+ {
+ public String Email { get; set; }
+ public String Password { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs
index 150756671..fd91a5722 100644
--- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Options.cs
@@ -4,16 +4,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Tango.DataStore.Web;
using Tango.Web;
namespace Tango.DataStore.CLI
{
public class OptionsBase
{
- [Option(longName: "email", HelpText = "Email address.", Required = true)]
+ [Option(longName: "email", HelpText = "Email address.")]
public String Email { get; set; }
- [Option(longName: "password", HelpText = "Password.", Required = true)]
+ [Option(longName: "password", HelpText = "Password.")]
public String Password { get; set; }
[Option(longName: "env", HelpText = "The target environment.", Required = true)]
@@ -45,7 +46,23 @@ namespace Tango.DataStore.CLI
[Option(longName: "key", HelpText = "New or existing item key", Required = true)]
public String Key { get; set; }
+ [Option(longName: "data-type", HelpText = "Item data type", Required = true)]
+ public Web.DataType DataType { get; set; }
+
+ [Option(longName: "proto-type", HelpText = "Protobuf message type when data-type is 'Proto'.")]
+ public MessageType ProtoMessageType { get; set; }
+
[Option(longName: "value", HelpText = "Item value", Required = true)]
public String Value { get; set; }
}
+
+ [Verb("login-config", HelpText = "Stores the specified credentials for use with the --auto-login flag.")]
+ public class LoginConfig
+ {
+ [Option(longName: "email", HelpText = "Email address.")]
+ public String Email { get; set; }
+
+ [Option(longName: "password", HelpText = "Password.")]
+ public String Password { get; set; }
+ }
}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs
index db4f54620..85dfbb0bb 100644
--- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Program.cs
@@ -19,7 +19,7 @@ namespace Tango.DataStore.CLI
{
var console = new DataStoreConsole();
- var result = Parser.Default.ParseArguments<GetOptions, PutOptions>(args)
+ var result = Parser.Default.ParseArguments<GetOptions, PutOptions, LoginConfig>(args)
.WithParsed<GetOptions>((options) =>
{
console.Get(options);
@@ -28,6 +28,10 @@ namespace Tango.DataStore.CLI
{
console.Put(options);
})
+ .WithParsed<LoginConfig>((options) =>
+ {
+ console.AutoLogin(options);
+ })
.WithNotParsed((errors) =>
{
@@ -41,64 +45,4 @@ namespace Tango.DataStore.CLI
}
}
}
-
- public class DataStoreConsole
- {
- public void Get(GetOptions options)
- {
- try
- {
- if (options.MachineSerialNumber != null)
- {
- Console.WriteLine($"Retrieving data store values for '{options.MachineSerialNumber}'...");
- }
- else
- {
- Console.WriteLine("Retrieving global data store values...");
- }
-
- var client = CreateClient(options.Email, options.Password, options.Environment);
-
- var items = client.Get(options.MachineSerialNumber, options.Collection, options.Key).ToList();
-
- ConsoleTable table = new ConsoleTable("COLLECTION", "KEY", "DATA TYPE", "STATE", "GLOBAL", "LOCAL");
-
- foreach (var item in items)
- {
- table.AddRow(item.Collection, item.Key, item.DataType, item.Type, item.GlobalValue.ToStringSafe().ToOneLine(), item.LocalValue.ToStringSafe().ToOneLine());
- }
-
- Console.WriteLine();
- Console.WriteLine("DATA STORE RESULTS:");
- Console.WriteLine();
-
- table.Write();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.FlattenMessage());
- }
- }
-
- public void Put(PutOptions options)
- {
-
- }
-
- private DataStoreClient CreateClient(String email, String password, DeploymentSlot slot)
- {
- String token = String.Empty;
-
- HttpClient http = new HttpClient();
- DataStoreClient dsClient = new DataStoreClient(slot.ToAddress(), http);
- var response = dsClient.Login(new LoginRequest()
- {
- Email = "roy@twine-s.com",
- Password = "1Creativity",
- });
- http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.Token);
-
- return dsClient;
- }
- }
}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj
index 28aab4ef7..42b0b95dc 100644
--- a/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.CLI/Tango.DataStore.CLI.csproj
@@ -63,6 +63,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="DataStoreUtil.cs" />
+ <Compile Include="DataStoreUtilSettings.cs" />
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -85,6 +87,10 @@
<Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project>
<Name>Tango.PMR</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Tango.Settings\Tango.Settings.csproj">
+ <Project>{d8f1ad85-526a-4f50-b6dc-d437af63d8d8}</Project>
+ <Name>Tango.Settings</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\Tango.Web\Tango.Web.csproj">
<Project>{5001990f-977b-48ff-b217-0236a5022ad8}</Project>
<Name>Tango.Web</Name>