mirror of
https://github.com/bitwarden/mobile
synced 2025-12-23 19:53:50 +00:00
[PM-2671] Update mobile client to use regions (#2798)
* [PM-2671] Update mobile client to use regions * [PM-2671] Refactor * [PM-2671] Move migration of region to migration service. * [PM-2671] Move comment * [PM-2671] Change method name * [PM-2671] Change method name on usages --------- Co-authored-by: Federico Maccaroni <fedemkr@gmail.com>
This commit is contained in:
@@ -1,9 +1,34 @@
|
||||
namespace Bit.Core.Models.Data
|
||||
using System.Text.RegularExpressions;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Models.Data
|
||||
{
|
||||
public class EnvironmentUrlData
|
||||
{
|
||||
public static EnvironmentUrlData DefaultUS = new EnvironmentUrlData { Base = "https://vault.bitwarden.com" };
|
||||
public static EnvironmentUrlData DefaultEU = new EnvironmentUrlData { Base = "https://vault.bitwarden.eu" };
|
||||
public static EnvironmentUrlData DefaultUS = new EnvironmentUrlData
|
||||
{
|
||||
Base = "https://vault.bitwarden.com",
|
||||
Api = "https://api.bitwarden.com",
|
||||
Identity = "https://identity.bitwarden.com",
|
||||
Icons = "https://icons.bitwarden.net",
|
||||
WebVault = "https://vault.bitwarden.com",
|
||||
Notifications = "https://notifications.bitwarden.com",
|
||||
Events = "https://events.bitwarden.com",
|
||||
Domain = "bitwarden.com"
|
||||
};
|
||||
|
||||
public static EnvironmentUrlData DefaultEU = new EnvironmentUrlData
|
||||
{
|
||||
Base = "https://vault.bitwarden.eu",
|
||||
Api = "https://api.bitwarden.eu",
|
||||
Identity = "https://identity.bitwarden.eu",
|
||||
Icons = "https://icons.bitwarden.eu",
|
||||
WebVault = "https://vault.bitwarden.eu",
|
||||
Notifications = "https://notifications.bitwarden.eu",
|
||||
Events = "https://events.bitwarden.eu",
|
||||
Domain = "bitwarden.eu"
|
||||
};
|
||||
|
||||
public string Base { get; set; }
|
||||
public string Api { get; set; }
|
||||
@@ -12,6 +37,7 @@
|
||||
public string Notifications { get; set; }
|
||||
public string WebVault { get; set; }
|
||||
public string Events { get; set; }
|
||||
public string Domain { get; set; }
|
||||
|
||||
public bool IsEmpty => string.IsNullOrEmpty(Base)
|
||||
&& string.IsNullOrEmpty(Api)
|
||||
@@ -20,5 +46,63 @@
|
||||
&& string.IsNullOrEmpty(Notifications)
|
||||
&& string.IsNullOrEmpty(WebVault)
|
||||
&& string.IsNullOrEmpty(Events);
|
||||
|
||||
public Region Region
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Base == Region.US.BaseUrl())
|
||||
{
|
||||
return Region.US;
|
||||
}
|
||||
if (Base == Region.EU.BaseUrl())
|
||||
{
|
||||
return Region.EU;
|
||||
}
|
||||
return Region.SelfHosted;
|
||||
}
|
||||
}
|
||||
|
||||
public EnvironmentUrlData FormatUrls()
|
||||
{
|
||||
return new EnvironmentUrlData
|
||||
{
|
||||
Base = FormatUrl(Base),
|
||||
Api = FormatUrl(Api),
|
||||
Identity = FormatUrl(Identity),
|
||||
Icons = FormatUrl(Icons),
|
||||
Notifications = FormatUrl(Notifications),
|
||||
WebVault = FormatUrl(WebVault),
|
||||
Events = FormatUrl(Events)
|
||||
};
|
||||
}
|
||||
|
||||
private string FormatUrl(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
url = Regex.Replace(url, "\\/+$", string.Empty);
|
||||
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
|
||||
{
|
||||
url = string.Concat("https://", url);
|
||||
}
|
||||
return url.Trim();
|
||||
}
|
||||
|
||||
public string GetDomainOrHostname()
|
||||
{
|
||||
var url = WebVault ?? Base ?? Api ?? Identity;
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (url.Contains(Region.US.Domain()) || url.Contains(Region.EU.Domain()))
|
||||
{
|
||||
return CoreHelpers.GetDomain(url);
|
||||
}
|
||||
return CoreHelpers.GetHostname(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,12 +102,14 @@ namespace Bit.Core.Models.Domain
|
||||
return;
|
||||
}
|
||||
|
||||
Region = copy.Region;
|
||||
EnvironmentUrls = copy.EnvironmentUrls;
|
||||
VaultTimeout = copy.VaultTimeout;
|
||||
VaultTimeoutAction = copy.VaultTimeoutAction;
|
||||
ScreenCaptureAllowed = copy.ScreenCaptureAllowed;
|
||||
}
|
||||
|
||||
public Region? Region;
|
||||
public EnvironmentUrlData EnvironmentUrls;
|
||||
[Obsolete("Feb 10 2023: VaultTimeout has been deprecated in favor of stored prefs to retain value after logout. It remains here to allow for migration during app upgrade.")]
|
||||
public int? VaultTimeout;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Bit.Core.Models.Domain
|
||||
{
|
||||
public class EnvironmentUrls
|
||||
{
|
||||
public string Base { get; set; }
|
||||
public string Api { get; set; }
|
||||
public string Identity { get; set; }
|
||||
public string Events { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -22,21 +22,7 @@ namespace Bit.Core.Models.View
|
||||
Email = a.Profile?.Email;
|
||||
Name = a.Profile?.Name;
|
||||
AvatarColor = a.Profile?.AvatarColor;
|
||||
Hostname = ParseEndpoint(a.Settings?.EnvironmentUrls);
|
||||
}
|
||||
|
||||
private string ParseEndpoint(EnvironmentUrlData urls)
|
||||
{
|
||||
var url = urls?.WebVault ?? urls?.Base;
|
||||
if (!string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
if (url.Contains("bitwarden.com") || url.Contains("bitwarden.eu"))
|
||||
{
|
||||
return CoreHelpers.GetDomain(url);
|
||||
}
|
||||
return CoreHelpers.GetHostname(url);
|
||||
}
|
||||
return string.Empty;
|
||||
Hostname = a.Settings?.EnvironmentUrls?.GetDomainOrHostname();
|
||||
}
|
||||
|
||||
public bool IsAccount { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user