Skip to content

Commit

Permalink
add HasApiBackend to services
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinzadehashraf committed Nov 21, 2023
1 parent 2ec42fc commit 9459c64
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
11 changes: 10 additions & 1 deletion Domain/Logic/Deserialize/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ internal static class Features

internal static void SetRepository(IFeatureRepository featureRepository) => Repository = featureRepository;

internal static async Task RefreshServiceFeatures()
internal static async Task<List<string>> RefreshServiceFeatures()
{
var errors = new ConcurrentList<string>();

if (Service.All?.Any() == true)
{
var throttler = new SemaphoreSlim(initialCount: 10);
Expand All @@ -26,6 +28,11 @@ internal static async Task RefreshServiceFeatures()
{
await service.GetAndSaveFeaturesJson().ConfigureAwait(false);
}
catch (Exception e)
{
Log.For(typeof(Feature)).Error(e);
errors.Add(e.ToString());
}
finally
{
throttler.Release();
Expand All @@ -35,6 +42,8 @@ internal static async Task RefreshServiceFeatures()
}

await RefreshFeatures();

return errors.ToList();
}

internal static async Task RefreshFeatures()
Expand Down
20 changes: 15 additions & 5 deletions Domain/Logic/Deserialize/StructureDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static void Load()
{
Task.Factory.RunSync(ViewModel.BoardComponents.SetBoardSources);
Task.Factory.RunSync(ViewModel.GlobalSearch.SetSearchSources);
}
}

}

public static async Task RefreshFeatures() => await Features.RefreshFeatures();

public static async Task RefreshServiceFeatures() => await Features.RefreshServiceFeatures();
public static async Task<List<string>> RefreshServiceFeatures() => await Features.RefreshServiceFeatures();

static void LoadServices()
{
Expand All @@ -46,7 +46,8 @@ static void LoadServices()
Name = x,
Icon = Config.Get("Microservice:" + x + ":Icon"),
UseIframe = Config.Get("Microservice:" + x + ":Iframe").ToLower() == "true",
BaseUrl = Config.Get("Microservice:" + x + ":Url"),
BaseUrl = GetServiceBaseUrl(Config.Get("Microservice:" + x + ":Url"), Config.Get<bool>("Microservice:" + x + ":HasApiBackend")),
HasApiBackend = Config.Get<bool>("Microservice:" + x + ":HasApiBackend", false),
InjectSingleSignon = Config.Get("Microservice:" + x + ":Sso").ToLower() == "true",
});
}
Expand All @@ -65,13 +66,22 @@ static async Task SetServicesFromXml()
{
Name = x.GetCleanName(),
UseIframe = x.GetValue<bool?>("@iframe") ?? false,
BaseUrl = (url.StartsWith("http") ? url : $"https://{url}.{envDomain}").ToLower(),
BaseUrl = GetServiceBaseUrl(url.StartsWith("http") ? url : $"https://{url}.{envDomain}", x.GetValue<bool?>("@hasapibackend") ?? false).ToLower(),
Icon = x.GetValue<string>("@icon"),
InjectSingleSignon = x.GetValue<bool?>("@sso") ?? false
InjectSingleSignon = x.GetValue<bool?>("@sso") ?? false,
HasApiBackend = x.GetValue<bool?>("@hasapibackend") ?? false

}).ToList();
}

static string GetServiceBaseUrl(string baseUrl, bool hasApiBackend)
{
if (!hasApiBackend) return baseUrl;
var domain = Config.Get("Authentication:Cookie:Domain").Trim('/');
baseUrl = baseUrl.Replace("." + domain, "api." + domain);
return baseUrl;
}

static void Run(string actionName, Func<bool> condition, Action action)
{
if (condition() == false) return;
Expand Down
3 changes: 3 additions & 0 deletions Domain/Structure/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public Service()

/// <summary>Gets or sets a value indicating whether this Service instance Inject single signon.</summary>
public bool InjectSingleSignon { get; set; }

/// <summary>Gets or sets a value indicating whether this Service instance Inject single signon.</summary>
public bool HasApiBackend { get; set; }

/// <summary>Gets or sets the value of Name on this Service instance.</summary>
[System.ComponentModel.DataAnnotations.StringLength(200)]
Expand Down
3 changes: 2 additions & 1 deletion Domain/Theme/ThemeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private string GetSidebarProfileUrl(SidebarProfileUrl? profile, string[] userRol
if (sidebarProfileUrl.IsEmpty())
sidebarProfileUrl = profile?.Default;

return RenderSidebarProfileUrl(sidebarProfileUrl.Or("https://hub.%DOMAIN%/person/%EMAIL%"), parameters);
return RenderSidebarProfileUrl(sidebarProfileUrl.Or(
$"https://hub.{Config.Get("Authentication:Cookie:Domain").EnsureEndsWith("/")}person/%EMAIL%"), parameters);
}

private string RenderSidebarProfileUrl(string sidebarProfileUrl, Dictionary<string, string> parameters)
Expand Down
2 changes: 1 addition & 1 deletion Olive.Microservices.Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>Geeks Ltd</Authors>
<RepositoryUrl>https://github.com/Geeksltd/Olive.Microservices.Hub/tree/master/Olive.Microservices.Hub</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<Version>1.5.31</Version>
<Version>1.5.32</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<Nullable>warnings</Nullable>
Expand Down

0 comments on commit 9459c64

Please sign in to comment.