mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 15:53:41 +00:00
save directory server config/settings
This commit is contained in:
@@ -40,10 +40,10 @@ namespace Bit.Console
|
||||
Con.WriteLine("=================================");
|
||||
Con.WriteLine("1. Log in to bitwarden");
|
||||
Con.WriteLine("2. Log out");
|
||||
Con.WriteLine("2. Configure directory connection");
|
||||
Con.WriteLine("3. Sync directory");
|
||||
Con.WriteLine("4. Start/stop background service");
|
||||
Con.WriteLine("5. Exit");
|
||||
Con.WriteLine("3. Configure directory connection");
|
||||
Con.WriteLine("4. Sync directory");
|
||||
Con.WriteLine("5. Start/stop background service");
|
||||
Con.WriteLine("6. Exit");
|
||||
Con.WriteLine();
|
||||
Con.Write("What would you like to do? ");
|
||||
selection = Con.ReadLine();
|
||||
@@ -62,6 +62,7 @@ namespace Bit.Console
|
||||
case "signout":
|
||||
await LogOutAsync();
|
||||
break;
|
||||
case "3":
|
||||
case "dir":
|
||||
case "directory":
|
||||
await DirectoryAsync();
|
||||
@@ -193,8 +194,74 @@ namespace Bit.Console
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
private static async Task DirectoryAsync()
|
||||
private static Task DirectoryAsync()
|
||||
{
|
||||
var config = new ServerConfiguration();
|
||||
|
||||
if(_usingArgs)
|
||||
{
|
||||
var parameters = ParseParameters();
|
||||
if(parameters.ContainsKey("a"))
|
||||
{
|
||||
config.Address = parameters["a"];
|
||||
}
|
||||
|
||||
if(parameters.ContainsKey("port"))
|
||||
{
|
||||
config.Port = parameters["port"];
|
||||
}
|
||||
|
||||
if(parameters.ContainsKey("path"))
|
||||
{
|
||||
config.Password = parameters["path"];
|
||||
}
|
||||
|
||||
if(parameters.ContainsKey("u"))
|
||||
{
|
||||
config.Username = parameters["u"];
|
||||
}
|
||||
|
||||
if(parameters.ContainsKey("p"))
|
||||
{
|
||||
config.Password = parameters["p"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Con.Write("Address: ");
|
||||
config.Address = Con.ReadLine().Trim();
|
||||
Con.Write("Port (389): ");
|
||||
var portInput = Con.ReadLine().Trim();
|
||||
if(!string.IsNullOrWhiteSpace(portInput))
|
||||
{
|
||||
config.Port = portInput;
|
||||
}
|
||||
Con.Write("Path: ");
|
||||
config.Path = Con.ReadLine().Trim();
|
||||
Con.Write("Username: ");
|
||||
config.Username = Con.ReadLine().Trim();
|
||||
Con.Write("Password: ");
|
||||
config.Password = ReadSecureLine();
|
||||
}
|
||||
|
||||
Con.WriteLine();
|
||||
Con.WriteLine();
|
||||
if(string.IsNullOrWhiteSpace(config.Address))
|
||||
{
|
||||
Con.ForegroundColor = ConsoleColor.Red;
|
||||
Con.WriteLine("Invalid input parameters.");
|
||||
Con.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Core.Services.SettingsService.Instance.Server = config;
|
||||
Con.ForegroundColor = ConsoleColor.Green;
|
||||
Con.WriteLine("Saved directory server configuration.");
|
||||
Con.ResetColor();
|
||||
}
|
||||
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
private static string ReadSecureLine()
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\ApiError.cs" />
|
||||
<Compile Include="Models\ApiResult.cs" />
|
||||
<Compile Include="Models\ServerConfiguration.cs" />
|
||||
<Compile Include="Models\LoginResult.cs" />
|
||||
<Compile Include="Models\ErrorResponse.cs" />
|
||||
<Compile Include="Models\EncryptedData.cs" />
|
||||
|
||||
17
src/Core/Models/ServerConfiguration.cs
Normal file
17
src/Core/Models/ServerConfiguration.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Models
|
||||
{
|
||||
public class ServerConfiguration
|
||||
{
|
||||
public string Address { get; set; }
|
||||
public string Port { get; set; } = "389";
|
||||
public string Path { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsModel Settings
|
||||
private SettingsModel Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -101,10 +101,24 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public ServerConfiguration Server
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Server;
|
||||
}
|
||||
set
|
||||
{
|
||||
Settings.Server = value;
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public class SettingsModel
|
||||
{
|
||||
public EncryptedData AccessToken { get; set; }
|
||||
public EncryptedData RefreshToken { get; set; }
|
||||
public ServerConfiguration Server { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user