mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 07:43:27 +00:00
dir type, preserve old values on config updates
This commit is contained in:
@@ -248,11 +248,27 @@ namespace Bit.Console
|
|||||||
|
|
||||||
private static Task ConfigDirectoryAsync()
|
private static Task ConfigDirectoryAsync()
|
||||||
{
|
{
|
||||||
var config = new ServerConfiguration();
|
var config = Core.Services.SettingsService.Instance.Server ?? new ServerConfiguration();
|
||||||
|
|
||||||
if(_usingArgs)
|
if(_usingArgs)
|
||||||
{
|
{
|
||||||
var parameters = ParseParameters();
|
var parameters = ParseParameters();
|
||||||
|
if(parameters.ContainsKey("t"))
|
||||||
|
{
|
||||||
|
Core.Enums.DirectoryType dirType;
|
||||||
|
if(Enum.TryParse(parameters["t"], out dirType))
|
||||||
|
{
|
||||||
|
config.Type = dirType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Con.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Con.WriteLine("Unable to parse type parameter.");
|
||||||
|
Con.ResetColor();
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(parameters.ContainsKey("a"))
|
if(parameters.ContainsKey("a"))
|
||||||
{
|
{
|
||||||
config.Address = parameters["a"];
|
config.Address = parameters["a"];
|
||||||
@@ -282,18 +298,61 @@ namespace Bit.Console
|
|||||||
{
|
{
|
||||||
string input;
|
string input;
|
||||||
|
|
||||||
Con.Write("Address: ");
|
Con.WriteLine("1. Active Directory");
|
||||||
config.Address = Con.ReadLine().Trim();
|
//Con.WriteLine("2. Azure Active Directory ");
|
||||||
|
Con.WriteLine("2. Other LDAP Directory");
|
||||||
|
|
||||||
|
string currentType;
|
||||||
|
switch(config.Type)
|
||||||
|
{
|
||||||
|
case Core.Enums.DirectoryType.ActiveDirectory:
|
||||||
|
currentType = "1";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
currentType = "2";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Con.Write("Type [{0}]: ", currentType);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
switch(input)
|
||||||
|
{
|
||||||
|
case "1":
|
||||||
|
config.Type = Core.Enums.DirectoryType.ActiveDirectory;
|
||||||
|
break;
|
||||||
|
//case "2":
|
||||||
|
// config.Type = Core.Enums.DirectoryType.AzureActiveCirectory;
|
||||||
|
default:
|
||||||
|
config.Type = Core.Enums.DirectoryType.Other;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Con.Write("Address [{0}]: ", config.Address);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
config.Address = input;
|
||||||
|
}
|
||||||
Con.Write("Port [{0}]: ", config.Port);
|
Con.Write("Port [{0}]: ", config.Port);
|
||||||
input = Con.ReadLine().Trim();
|
input = Con.ReadLine().Trim();
|
||||||
if(!string.IsNullOrWhiteSpace(input))
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
{
|
{
|
||||||
config.Port = input;
|
config.Port = input;
|
||||||
}
|
}
|
||||||
Con.Write("Path: ");
|
Con.Write("Path [{0}]: ", config.Path);
|
||||||
config.Path = Con.ReadLine().Trim();
|
input = Con.ReadLine().Trim();
|
||||||
Con.Write("Username: ");
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
config.Username = Con.ReadLine().Trim();
|
{
|
||||||
|
config.Path = input;
|
||||||
|
}
|
||||||
|
Con.Write("Username [{0}]: ", config.Username);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
config.Username = input;
|
||||||
|
}
|
||||||
Con.Write("Password: ");
|
Con.Write("Password: ");
|
||||||
input = ReadSecureLine();
|
input = ReadSecureLine();
|
||||||
if(!string.IsNullOrWhiteSpace(input))
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
@@ -326,7 +385,7 @@ namespace Bit.Console
|
|||||||
|
|
||||||
private static Task ConfigSyncAsync()
|
private static Task ConfigSyncAsync()
|
||||||
{
|
{
|
||||||
var config = new SyncConfiguration();
|
var config = Core.Services.SettingsService.Instance.Sync ?? new SyncConfiguration();
|
||||||
|
|
||||||
if(_usingArgs)
|
if(_usingArgs)
|
||||||
{
|
{
|
||||||
@@ -357,6 +416,18 @@ namespace Bit.Console
|
|||||||
config.MemberAttribute = parameters["m"];
|
config.MemberAttribute = parameters["m"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.EmailPrefixSuffix = parameters.ContainsKey("ps");
|
||||||
|
|
||||||
|
if(parameters.ContainsKey("ep"))
|
||||||
|
{
|
||||||
|
config.UserEmailPrefixAttribute = parameters["ep"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parameters.ContainsKey("es"))
|
||||||
|
{
|
||||||
|
config.UserEmailSuffix = parameters["es"];
|
||||||
|
}
|
||||||
|
|
||||||
if(parameters.ContainsKey("c"))
|
if(parameters.ContainsKey("c"))
|
||||||
{
|
{
|
||||||
config.CreationDateAttribute = parameters["c"];
|
config.CreationDateAttribute = parameters["c"];
|
||||||
@@ -371,7 +442,7 @@ namespace Bit.Console
|
|||||||
{
|
{
|
||||||
string input;
|
string input;
|
||||||
|
|
||||||
Con.Write("Sync groups? [y]: ");
|
Con.Write("Sync groups? [{0}]: ", config.SyncGroups ? "y" : "n");
|
||||||
input = Con.ReadLine().Trim().ToLower();
|
input = Con.ReadLine().Trim().ToLower();
|
||||||
config.SyncGroups = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
config.SyncGroups = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
||||||
if(config.SyncGroups)
|
if(config.SyncGroups)
|
||||||
@@ -389,7 +460,7 @@ namespace Bit.Console
|
|||||||
config.GroupNameAttribute = input;
|
config.GroupNameAttribute = input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Con.Write("Sync users? [y]: ");
|
Con.Write("Sync users? [{0}]: ", config.SyncUsers ? "y" : "n");
|
||||||
input = Con.ReadLine().Trim().ToLower();
|
input = Con.ReadLine().Trim().ToLower();
|
||||||
config.SyncUsers = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
config.SyncUsers = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
||||||
if(config.SyncUsers)
|
if(config.SyncUsers)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Enums\DirectoryType.cs" />
|
||||||
<Compile Include="Enums\OrganizationUserType.cs" />
|
<Compile Include="Enums\OrganizationUserType.cs" />
|
||||||
<Compile Include="Enums\OrganizationUserStatusType.cs" />
|
<Compile Include="Enums\OrganizationUserStatusType.cs" />
|
||||||
<Compile Include="Models\ApiError.cs" />
|
<Compile Include="Models\ApiError.cs" />
|
||||||
|
|||||||
15
src/Core/Enums/DirectoryType.cs
Normal file
15
src/Core/Enums/DirectoryType.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.Core.Enums
|
||||||
|
{
|
||||||
|
public enum DirectoryType : byte
|
||||||
|
{
|
||||||
|
ActiveDirectory = 0,
|
||||||
|
AzureActiveCirectory = 1,
|
||||||
|
Other = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ namespace Bit.Core.Models
|
|||||||
public EncryptedData Password { get; set; }
|
public EncryptedData Password { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string ServerPath => $"LDAP://{Address}:{Port}/{Path}";
|
public string ServerPath => $"LDAP://{Address}:{Port}/{Path}";
|
||||||
public string Type { get; set; } = "Active Directory";
|
public Enums.DirectoryType Type { get; set; } = Enums.DirectoryType.ActiveDirectory;
|
||||||
|
|
||||||
public DirectoryEntry GetDirectoryEntry()
|
public DirectoryEntry GetDirectoryEntry()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user