Skip to content
Snippets Groups Projects
Commit 73be9bd9 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Initial commit

parents
Branches
Tags
No related merge requests found
Pipeline #815168 waiting for manual action
Showing
with 1350 additions and 0 deletions
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
\ No newline at end of file
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
Resharper
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
#cake
tools/*
!tools/packages.config
dist/
#linq2db
src/.tools/*
# Dotnet Tool Manifest
.config/*
include:
- project: coscine/tools/gitlab-ci-templates
file:
- /dotnet.yml
stages:
- build
- test
- publish
- container
variables:
DOTNET_MAIN_PROJECT_FOLDER: RdmStandardsWrapper
build-branch:
extends: .build-branch
test:
extends: .test
publish-gitlab-release:
extends: .publish-gitlab-release
publish:
extends: .publish-artifact-release
container:
stage: container
tags:
- runner:docker
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
variables:
# variables can be overridden by extending the task
# name of the container, uses project name (+path) by default
CONTAINER_LABEL: latest
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY/$CI_PROJECT_PATH:$CONTAINER_LABEL
rules:
- when: manual
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["src/RdmStandardsWrapper/RdmStandardsWrapper.csproj", "RdmStandardsWrapper/"]
RUN dotnet restore "RdmStandardsWrapper/RdmStandardsWrapper.csproj"
COPY src .
WORKDIR "/src/RdmStandardsWrapper"
RUN dotnet build "RdmStandardsWrapper.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "RdmStandardsWrapper.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RdmStandardsWrapper.dll"]
mode: ContinuousDeployment
next-version: 1.0.0
major-version-bump-message: 'Breaking:'
minor-version-bump-message: '(Update|New):'
patch-version-bump-message: 'Fix:'
no-bump-message: '.*'
commit-message-incrementing: Enabled
\ No newline at end of file
LICENSE 0 → 100644
MIT License
Copyright (c) 2021 RWTH Aachen University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
# RDM Standards Wrapper
This application wraps a service like Trellis and adds additional things like versioning and Coscine User Token support.
## Usage
Make sure that [Trellis](https://git.rwth-aachen.de/coscine/backend/trellis-coscine) runs at the same time.
<?xml version="1.0" encoding="utf-8"?>
<!--
Taken from: https://github.com/nunit/nunit-transforms/tree/master/nunit3-junit
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/test-run">
<testsuites tests="{@testcasecount}" failures="{@failed}" disabled="{@skipped}" time="{@duration}">
<xsl:apply-templates/>
</testsuites>
</xsl:template>
<xsl:template match="test-suite">
<xsl:if test="test-case">
<testsuite tests="{@testcasecount}" time="{@duration}" errors="{@testcasecount - @passed - @skipped - @failed}" failures="{@failed}" skipped="{@skipped}" timestamp="{@start-time}">
<xsl:attribute name="name">
<xsl:for-each select="ancestor-or-self::test-suite/@name">
<xsl:value-of select="concat(., '.')"/>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates select="test-case"/>
</testsuite>
<xsl:apply-templates select="test-suite"/>
</xsl:if>
<xsl:if test="not(test-case)">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
<xsl:template match="test-case">
<testcase name="{@name}" assertions="{@asserts}" time="{@duration}" status="{@result}" classname="{@classname}">
<xsl:if test="@runstate = 'Skipped' or @runstate = 'Ignored'">
<skipped/>
</xsl:if>
<xsl:apply-templates/>
</testcase>
</xsl:template>
<xsl:template match="command-line"/>
<xsl:template match="settings"/>
<xsl:template match="output">
<system-out>
<xsl:value-of select="."/>
</system-out>
</xsl:template>
<xsl:template match="stack-trace">
</xsl:template>
<xsl:template match="test-case/failure">
<failure message="{./message}">
<xsl:value-of select="./stack-trace"/>
</failure>
</xsl:template>
<xsl:template match="test-suite/failure"/>
<xsl:template match="test-case/reason">
<skipped message="{./message}"/>
</xsl:template>
<xsl:template match="test-case/assertions">
</xsl:template>
<xsl:template match="test-suite/reason"/>
<xsl:template match="properties"/>
</xsl:stylesheet>
\ No newline at end of file
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
\ No newline at end of file
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
Resharper
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
#cake
tools/*
!tools/packages.config
dist/
#linq2db
src/.tools/*
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RdmStandardsWrapper", "RdmStandardsWrapper\RdmStandardsWrapper.csproj", "{0EEF91F5-AA49-48DF-8902-9410D22C287D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0EEF91F5-AA49-48DF-8902-9410D22C287D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EEF91F5-AA49-48DF-8902-9410D22C287D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EEF91F5-AA49-48DF-8902-9410D22C287D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EEF91F5-AA49-48DF-8902-9410D22C287D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AE05BEF1-5D6D-41CB-A8E6-932AC7E7396C}
EndGlobalSection
EndGlobal
using Coscine.ApiCommons;
using Coscine.Configuration;
using Coscine.JwtHandler;
using MetadataTracker.MetadataStore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using RdmStandardsWrapper.Util;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
namespace RdmStandardsWrapper.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExtendedLDPController : ControllerBase
{
private static readonly HttpClientHandler clientHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }
};
private static readonly HttpClient HttpClient = new(clientHandler);
private readonly ILogger<ExtendedLDPController> _logger;
private readonly static Coscine.Configuration.IConfiguration _configuration = new ConsulConfiguration();
private readonly IMetadataStore _metaStore = new CoscineMetadataStore(_configuration);
private readonly Uri _trellis = new(_configuration.GetString("coscine/local/trellis/url", "http://localhost:8253"));
private readonly JwtGenerator _jwtGenerator;
private readonly JWTHandler _jwtHandler;
public ExtendedLDPController(ILogger<ExtendedLDPController> logger)
{
_logger = logger;
_jwtGenerator = new JwtGenerator(_configuration);
_jwtHandler = new JWTHandler(_configuration);
}
[HttpGet("{*path}")]
public async Task Get(string? path)
{
await ForwardRequestAsync(HttpMethod.Get, path);
}
[HttpPut("{*path}")]
public async Task Put(string? path)
{
await ForwardRequestAsync(HttpMethod.Put, path);
}
[HttpPost("{*path}")]
public async Task Post(string? path)
{
await ForwardRequestAsync(HttpMethod.Post, path);
}
[HttpPatch("{*path}")]
public async Task Patch(string? path)
{
await ForwardRequestAsync(HttpMethod.Patch, path);
}
[HttpDelete("{*path}")]
public async Task Delete(string? path)
{
await ForwardRequestAsync(HttpMethod.Delete, path);
}
[HttpOptions("{*path}")]
public async Task Options(string? path)
{
await ForwardRequestAsync(HttpMethod.Options, path);
}
private async Task ForwardRequestAsync(HttpMethod method, string? path)
{
if (path == null)
{
path = "";
}
var pathSplit = path.Split('/');
var identiferPart = "";
if (pathSplit.Length > 1)
{
identiferPart = string.Join('/', pathSplit[1..]);
}
var workingOnEntity = pathSplit.Length > 1 && (identiferPart.IndexOf("/") != identiferPart.LastIndexOf("/") || (identiferPart.Contains("/") && !identiferPart.EndsWith("/")));
var headers = Request.Headers;
var noFilter = headers.ContainsKey("No-Filter");
var additionalParameter = "";
// Deal with missing type
if (path.Contains("@type="))
{
// Type already defined
}
else if (workingOnEntity && !noFilter)
{
if (!path.EndsWith("/"))
{
path += "/";
}
// Default to Metadata
additionalParameter += "@type=metadata";
}
// Deal with versions
if (path.Contains("&version"))
{
// Version already set, nothing to do here
}
else if (headers.ContainsKey("Accept-Datetime"))
{
var givenVersion = long.Parse(Convert.ToString((int)DateTime.Parse(headers["Accept-Datetime"]).Subtract(new DateTime(1970, 1, 1)).TotalSeconds));
var graphs = _metaStore.ListGraphs($"https://purl.org/coscine/resources/{path}");
var closestVersionGraph = VersionUtil.GetClosestVersion(graphs, givenVersion,
path.Contains("type=metadata") ? "metadata"
: (path.Contains("type=data") ? "data"
: null),
path.Contains("&extracted")
);
if (closestVersionGraph != null)
{
var queryDictionary = System.Web.HttpUtility.ParseQueryString(
new Uri(closestVersionGraph.ToString().Replace("@", "?")).Query);
var version = queryDictionary["version"];
additionalParameter += "&version=" + version;
}
}
else if (method == HttpMethod.Post)
{
if (headers.ContainsKey("slug") && !noFilter)
{
if (headers["slug"].ToString().Contains("@type"))
{
headers["slug"] = headers["slug"].ToString() + "&version=" + long.Parse(Convert.ToString((int)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds));
}
}
}
else if (
(method == HttpMethod.Get || method == HttpMethod.Patch || method == HttpMethod.Put || method == HttpMethod.Options || method == HttpMethod.Delete)
&& workingOnEntity && !noFilter
)
{
var graphs = _metaStore.ListGraphs($"https://purl.org/coscine/{path}");
var recentVersionGraph = VersionUtil.GetRecentVersion(graphs,
path.Contains("type=metadata") ? "metadata"
: (path.Contains("type=data") ? "data"
: null),
path.Contains("&extracted")
);
if (recentVersionGraph != null)
{
var queryDictionary = System.Web.HttpUtility.ParseQueryString(
new Uri(recentVersionGraph.ToString().Replace("@", "?")).Query);
var version = queryDictionary["version"];
if (version != null)
{
additionalParameter += "&version=" + version;
}
}
}
var message = CreateRequestMessage(method, path, headers, additionalParameter);
var response = await HttpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, HttpContext.RequestAborted);
// If 401 is returned, you sometimes need to try again and then it works
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
message = CreateRequestMessage(method, path, headers, additionalParameter);
response = await HttpClient.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, HttpContext.RequestAborted);
}
Response.StatusCode = (int)response.StatusCode;
foreach (var header in response.Headers)
{
Response.Headers[header.Key] = header.Value.ToArray();
}
foreach (var header in response.Content.Headers)
{
Response.Headers[header.Key] = header.Value.ToArray();
}
// SendAsync removes chunking from the response. This removes the header so it doesn't expect a chunked response.
Response.Headers.Remove("transfer-encoding");
using (var responseStream = await response.Content.ReadAsStreamAsync())
{
await responseStream.CopyToAsync(Response.Body, 81920, HttpContext.RequestAborted);
}
}
private HttpRequestMessage CreateRequestMessage(HttpMethod method, string? path, IHeaderDictionary headers, string additionalParameter)
{
var message = new HttpRequestMessage()
{
Method = method,
RequestUri = new Uri(_trellis.ToString() + path + Request.QueryString.ToString() + additionalParameter)
};
if (Request.ContentLength > 0 || Request.Headers.ContainsKey("Transfer-Encoding"))
{
var streamContent = new StreamContent(Request.Body);
message.Content = streamContent;
}
foreach (var header in headers)
{
try
{
var headerName = header.Key;
var value = header.Value;
if (headerName.ToLower() == "Authorization".ToLower())
{
// Parse JWT Token and try to see if its a Coscine one
var securityKey = _jwtHandler.GetSecurityKey();
var tokenValidationParameters = new TokenValidationParameters
{
ValidAudience = "https://coscine.rwth-aachen.de",
ValidIssuer = "https://coscine.rwth-aachen.de",
ValidateIssuerSigningKey = true,
IssuerSigningKey = securityKey,
ValidateIssuer = false,
ValidateAudience = true
};
var token = value.ToString().Replace("Bearer ", "");
try
{
// If valid, create a one with WebId
new JwtSecurityTokenHandler().ValidateToken(token, tokenValidationParameters, out _);
var userId = Authenticator.GetUserId(_jwtHandler.GetContents(token));
message.Headers.Add(header.Key,
"Bearer " + _jwtGenerator.GenerateJwtToken(
new JwtPayload(
new List<Claim>()
{
new Claim("webid", $"https://purl.org/coscine/users/{userId}")
}
),
"https://purl.org/coscine/users/",
userId,
DateTime.UtcNow.AddMinutes(-1440),
DateTime.UtcNow.AddMinutes(1440)
)
);
continue;
}
catch (Exception)
{
// If not valid, just forward it
}
}
if (header.Key.ToLower() != "Accept-Datetime".ToLower())
{
// From https://github.com/ProxyKit/ProxyKit
if (value.Count == 1)
{
string headerValue = value;
if (!message.Headers.TryAddWithoutValidation(headerName, headerValue))
{
message.Content?.Headers.TryAddWithoutValidation(headerName, headerValue);
}
}
else
{
string[] headerValues = value;
if (!message.Headers.TryAddWithoutValidation(headerName, headerValues))
{
message.Content?.Headers.TryAddWithoutValidation(headerName, headerValues);
}
}
}
}
catch
{
// Filter weird headers
}
}
message.Headers.Host = message.RequestUri.Authority;
return message;
}
}
}
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RdmStandardsWrapper/RdmStandardsWrapper.csproj", "RdmStandardsWrapper/"]
RUN dotnet restore "RdmStandardsWrapper/RdmStandardsWrapper.csproj"
COPY . .
WORKDIR "/src/RdmStandardsWrapper"
RUN dotnet build "RdmStandardsWrapper.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "RdmStandardsWrapper.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RdmStandardsWrapper.dll"]
\ No newline at end of file
using Coscine.Metadata;
using VDS.RDF;
using VDS.RDF.Query;
namespace MetadataTracker.MetadataStore
{
public class CoscineMetadataStore : IMetadataStore
{
private readonly RdfStoreConnector _rdfStoreConnector;
public CoscineMetadataStore()
{
_rdfStoreConnector = new RdfStoreConnector();
}
public CoscineMetadataStore(Coscine.Configuration.IConfiguration configuration)
{
_rdfStoreConnector = new RdfStoreConnector(configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
}
public void AddGraph(IGraph graph)
{
_rdfStoreConnector.AddGraph(graph);
}
public void AddTripleStore(ITripleStore tripleStore)
{
foreach (var entryGraph in tripleStore.Graphs)
{
AddGraph(entryGraph);
}
}
public IGraph GetGraph(Uri uri)
{
return _rdfStoreConnector.GetGraph(uri);
}
public IGraph GetGraphOrEmpty(Uri uri)
{
if (uri != null && HasGraph(uri))
{
return GetGraph(uri);
}
return new Graph()
{
BaseUri = uri
};
}
public bool HasGraph(Uri uri)
{
return HasGraph(uri.AbsoluteUri);
}
public bool HasGraph(string absoluteUri)
{
return _rdfStoreConnector.HasGraph(absoluteUri);
}
public IEnumerable<Uri> ListGraphs(string id)
{
var cmdString = new SparqlParameterizedString
{
CommandText = @"SELECT DISTINCT ?g
WHERE { GRAPH ?g { ?s ?p ?o }
FILTER(contains(str(?g), @graph)) }"
};
cmdString.SetLiteral("graph", id);
var resultSet = _rdfStoreConnector.QueryEndpoint.QueryWithResultSet(cmdString.ToString());
var graphs = new List<Uri>();
foreach (SparqlResult r in resultSet)
{
graphs.Add((r.Value("g") as UriNode)?.Uri);
}
return graphs;
}
public void UpdateGraph(IGraph graph)
{
_rdfStoreConnector.ClearGraph(graph.BaseUri);
AddGraph(graph);
}
}
}
using System;
using System.Collections.Generic;
using VDS.RDF;
namespace MetadataTracker.MetadataStore
{
public interface IMetadataStore
{
void AddGraph(IGraph graph);
void AddTripleStore(ITripleStore tripleStore);
bool HasGraph(Uri uri);
bool HasGraph(string absoluteUri);
IGraph GetGraph(Uri uri);
IGraph GetGraphOrEmpty(Uri uri);
IEnumerable<Uri> ListGraphs(string id);
void UpdateGraph(IGraph graph);
}
}
using System;
using System.Collections.Generic;
using VDS.RDF;
namespace MetadataTracker.MetadataStore
{
public class MockupMetadataStore : IMetadataStore
{
public void AddGraph(IGraph graph)
{
return;
}
public void AddTripleStore(ITripleStore tripleStore)
{
return;
}
public IGraph GetGraph(Uri uri)
{
return null;
}
public IGraph GetGraphOrEmpty(Uri uri)
{
return new Graph()
{
BaseUri = uri
};
}
public bool HasGraph(Uri uri)
{
return false;
}
public bool HasGraph(string absoluteUri)
{
return false;
}
public IEnumerable<Uri> ListGraphs(string id)
{
return new List<Uri>();
}
public void UpdateGraph(IGraph graph)
{
return;
}
}
}
using Swashbuckle.AspNetCore.Swagger;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger((SwaggerOptions options) =>
{
});
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:42358",
"sslPort": 44363
}
},
"profiles": {
"RdmStandardsWrapper": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7192;http://localhost:5192",
"dotnetRunMessages": true
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true
}
}
}
\ No newline at end of file
{
"dependencies": {
"mssql1": {
"type": "mssql",
"connectionId": "ConnectionStrings:RdmStandardsWrapperContext"
}
}
}
\ No newline at end of file
{
"dependencies": {
"mssql1": {
"type": "mssql.local",
"connectionId": "ConnectionStrings:RdmStandardsWrapperContext"
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment