Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page for uploading json files from tenor to configure persons and orgs #61

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions loadbalancer/templates/nginx.conf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http {

sendfile on;

upstream localtest {
upstream localtest {
server host.docker.internal:5101;
}

Expand All @@ -58,7 +58,7 @@ http {
}

server {
listen 80 default_server;
listen 80 default_server;
server_name ${TEST_DOMAIN};

proxy_redirect off;
Expand All @@ -68,50 +68,50 @@ http {

error_page 502 /502LocalTest.html;

location = / {
location = / {
proxy_pass http://localtest/Home/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}
}

location / {
location / {
#Support using Local js, when a cookie value is set
sub_filter_once off;
sub_filter 'https://altinncdn.no/toolkits/altinn-app-frontend/3/' $LOCAL_SUB_FILTER;
proxy_pass http://app/;
error_page 502 /502App.html;
proxy_cookie_domain altinn3local.no local.altinn.cloud;
}
}

location /Home/_framework/ {
proxy_pass http://localtest/_framework/;
proxy_pass http://localtest/_framework/;
}

location /Home/ {
proxy_pass http://localtest/Home/;
location /Home/ {
proxy_pass http://localtest/Home/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}
}

location /receipt/ {
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}

location /accessmanagement/ {
proxy_pass http://accessmanagementcomp/accessmanagement/;
proxy_pass http://accessmanagementcomp/accessmanagement/;
error_page 502 /502Accessmanagement.html;
}
}

location /storage/ {
proxy_pass http://localtest/storage/;
}
proxy_pass http://localtest/storage/;
}

location /pdfservice/ {
proxy_pass http://pdfservice/;
}

location /localtestresources/ {
proxy_pass http://localtest/localtestresources/;
}
proxy_pass http://localtest/localtestresources/;
}
location /LocalPlatformStorage/ {
proxy_pass http://localtest/LocalPlatformStorage/;
}
Expand All @@ -128,5 +128,5 @@ http {
root /www;
}

}
}
}
2 changes: 2 additions & 0 deletions src/Configuration/LocalPlatformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ public string LocalTestingStaticTestDataPath {
public string RolesFolder { get; set; } = "roles/";

public string ClaimsFolder { get; set; } = "claims/";

public string TenorDataFolder { get; set; } = "tenorUsers";
}
}
74 changes: 74 additions & 0 deletions src/Controllers/DebugUsersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class DebugUsersController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly ILocalApp _localApp;
ivarne marked this conversation as resolved.
Show resolved Hide resolved

public DebugUsersController(
TenorDataRepository tenorDataRepository,
IOptions<LocalPlatformSettings> localPlatformSettings,
ILocalApp localApp)
{
_tenorDataRepository = tenorDataRepository;
_localPlatformSettings = localPlatformSettings.Value;
_localApp = localApp;
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRaw()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);

return Json(localData);
}

//Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsers()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData);
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRoundTrip()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData.GetTestDataModel());
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> ShowTenorUsers([FromServices] TenorDataRepository tenorDataRepository)
{
var localData = await tenorDataRepository.GetAppTestDataModel();

return Json(localData);
}


}
103 changes: 103 additions & 0 deletions src/Controllers/FrontendVersionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class FrontendVersionController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly ILocalApp _localApp;
ivarne marked this conversation as resolved.
Show resolved Hide resolved

public FrontendVersionController(
TenorDataRepository tenorDataRepository,
IOptions<LocalPlatformSettings> localPlatformSettings,
ILocalApp localApp)
{
_tenorDataRepository = tenorDataRepository;
_localPlatformSettings = localPlatformSettings.Value;
_localApp = localApp;
}
/// <summary>
/// See src\development\loadbalancer\nginx.conf
/// </summary>
public static readonly string FRONTEND_URL_COOKIE_NAME = "frontendVersion";

[HttpGet]
public async Task<ActionResult> Index([FromServices] HttpClient client)
{
var versionFromCookie = HttpContext.Request.Cookies[FRONTEND_URL_COOKIE_NAME];

var frontendVersion = new FrontendVersion()
{
Version = versionFromCookie,
Versions = new List<SelectListItem>()
{
new ()
{
Text = "Keep as is",
Value = "",
},
new ()
{
Text = "localhost:8080 (local dev)",
Value = "http://localhost:8080/"
}
}
};
var cdnVersionsString = await client.GetStringAsync("https://altinncdn.no/toolkits/altinn-app-frontend/index.json");
var groupCdnVersions = new SelectListGroup() { Name = "Specific version from cdn" };
var versions = JsonSerializer.Deserialize<List<string>>(cdnVersionsString)!;
versions.Reverse();
versions.ForEach(version =>
{
frontendVersion.Versions.Add(new()
{
Text = version,
Value = $"https://altinncdn.no/toolkits/altinn-app-frontend/{version}/",
Group = groupCdnVersions
});
});

return View(frontendVersion);
}
public ActionResult Index(FrontendVersion frontendVersion)
{
var options = new CookieOptions
{
Expires = DateTime.MaxValue,
HttpOnly = true,
};
ICookieManager cookieManager = new ChunkingCookieManager();
if (string.IsNullOrWhiteSpace(frontendVersion.Version))
{
cookieManager.DeleteCookie(HttpContext, FRONTEND_URL_COOKIE_NAME, options);
}
else
{
cookieManager.AppendResponseCookie(
HttpContext,
FRONTEND_URL_COOKIE_NAME,
frontendVersion.Version,
options
);
}

return RedirectToAction("Index", "Home");
}
}
Loading