Skip to content

Commit

Permalink
generate project uri from send receive domain, fix some code that was…
Browse files Browse the repository at this point in the history
… broken due to old refactors
  • Loading branch information
hahn-kev committed Dec 7, 2023
1 parent d96a502 commit b0ef101
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
50 changes: 25 additions & 25 deletions backend/LexBoxApi/Controllers/IntegrationController.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
using LexBoxApi.Auth;
using LexBoxApi.Services;
using LexCore.Auth;
using LexCore.Config;
using LexCore.ServiceInterfaces;
using LexData;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

namespace LexBoxApi.Controllers;

[ApiController]
[Route("/api/integration")]
public class IntegrationController: ControllerBase
public class IntegrationController(
LexBoxDbContext lexBoxDbContext,
LexAuthService authService,
LoggedInContext loggedInContext,
IHgService hgService,
IPermissionService permissionService,
IOptions<HgConfig> hgConfigOptions,
IHostEnvironment hostEnvironment)
: ControllerBase
{
private readonly LexBoxDbContext _lexBoxDbContext;
private readonly LoggedInContext _loggedInContext;
private readonly LexAuthService _authService;
private readonly IHgService _hgService;

public IntegrationController(LexBoxDbContext lexBoxDbContext,
LexAuthService authService,
LoggedInContext loggedInContext,
IHgService hgService)
{
_lexBoxDbContext = lexBoxDbContext;
_authService = authService;
_loggedInContext = loggedInContext;
_hgService = hgService;
}
private readonly string _protocol = hostEnvironment.IsDevelopment() ? "http" : "https";
private readonly HgConfig _hgConfig = hgConfigOptions.Value;

[HttpGet("openWithFlex")]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status302Found)]
public async Task<ActionResult> OpenWithFlex(Guid projectId)
{
//todo requires more work, just a quick poc.
var user = _loggedInContext.User;
if (!user.CanAccessProject(projectId)) return Unauthorized();
var project = await _lexBoxDbContext.Projects.FirstOrDefaultAsync(p => p.Id == projectId);
if (project is null) return NotFound();
var repoId = await _hgService.GetRepositoryIdentifier(project);
var refreshUser = await _authService.RefreshUser(user.Id, false);
var user = loggedInContext.User;
if (!permissionService.CanAccessProject(projectId)) return Unauthorized();
var refreshUser = await authService.RefreshUser(user.Id, false);
if (refreshUser is null) return Unauthorized();
var (jwt, _) = _authService.GenerateJwt(refreshUser);
var projectUri = "https://hg-staging.languageforge.org/sena-3";
var project = await lexBoxDbContext.Projects.FirstOrDefaultAsync(p => p.Id == projectId);
if (project is null) return NotFound();
var repoId = await hgService.GetRepositoryIdentifier(project);
var (jwt, _) = authService.GenerateJwt(refreshUser, audience: LexboxAudience.SendAndReceive);
var projectUri = $"{_protocol}://{_hgConfig.SendReceiveDomain}/{project.Code}";
var queryString = new QueryString()
.Add("db", project.Code)
.Add("user", "bearer")
Expand Down
2 changes: 2 additions & 0 deletions backend/LexCore/Config/HgConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class HgConfig
{
[Required]
public required string RepoPath { get; init; }
[Required]
public required string SendReceiveDomain { get; init; }
[Required, Url, RegularExpression(@"^.+/$", ErrorMessage = "Must end with '/'")]
public required string HgWebUrl { get; init; }
[Required, Url]
Expand Down
1 change: 1 addition & 0 deletions deployment/base/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
data:
environment-name: "Development"
hg-otel-enabled: "ON"
hg-domain: "hg.localhost"

5 changes: 5 additions & 0 deletions deployment/base/lexbox-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ spec:
value: "10.42.0.0/16"
- name: HgConfig__RepoPath
value: /hg-repos
- name: HgConfig__SendReceiveDomain
valueFrom:
configMapKeyRef:
name: app-config
key: hg-domain
- name: HgConfig__HgWebUrl
value: http://hg:8088/hg/
- name: HgConfig__HgResumableUrl
Expand Down
1 change: 1 addition & 0 deletions deployment/production/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ metadata:
name: app-config
data:
environment-name: "Production"
hg-domain: "hg-public.languageforge.org"

1 change: 1 addition & 0 deletions deployment/staging/app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
data:
environment-name: "Staging"
hg-otel-enabled: "OFF"
hg-domain: "hg-staging.languageforge.org"

0 comments on commit b0ef101

Please sign in to comment.