mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds bundled plugin trust and cross-platform native deployment
- embeds the append-only historical and deny trust lists in the API and marks matching bundled plugins as Official without blocking loading - builds and records the current plugin manifest only for official release builds - deploys the PDF native libraries for the supported Linux, macOS and Windows runtimes from the plugin dependency manifest - records release hashes by appending only missing entries to master's manifest and rejects any diff that removes a line - documents the release flow, the supported runtimes and the plugin installer limits
This commit is contained in:
1 parent
3fb8912c7f
commit
b30cbd6b9e
114 files changed
+2701
-236
No files matched your search
@@ -1,39 +1,41 @@
|
|||||||
**/.classpath
|
**/.classpath
|
||||||
**/.dockerignore
|
**/.dockerignore
|
||||||
**/.env
|
**/.env
|
||||||
**/.git
|
**/.git/
|
||||||
**/.gitignore
|
**/.gitignore
|
||||||
|
**/.idea/
|
||||||
|
**/.opencode/
|
||||||
**/.project
|
**/.project
|
||||||
**/.settings
|
**/.settings
|
||||||
**/.toolstarget
|
**/.toolstarget
|
||||||
**/.vs
|
**/.dsh/
|
||||||
**/.vscode
|
**/.vs/
|
||||||
|
**/.vscode/
|
||||||
**/*.*proj.user
|
**/*.*proj.user
|
||||||
**/*.dbmdl
|
**/*.dbmdl
|
||||||
**/*.jfm
|
**/*.jfm
|
||||||
|
**/*.suo
|
||||||
|
**/*.user
|
||||||
**/azds.yaml
|
**/azds.yaml
|
||||||
**/bin
|
**/bin/
|
||||||
**/charts
|
**/charts/
|
||||||
**/docker-compose*
|
**/docker-compose*
|
||||||
**/Dockerfile*
|
**/Dockerfile*
|
||||||
**/node_modules
|
**/node_modules/
|
||||||
**/npm-debug.log
|
**/npm-debug.log
|
||||||
**/obj
|
**/obj/
|
||||||
**/secrets.dev.yaml
|
**/secrets.dev.yaml
|
||||||
**/values.dev.yaml
|
**/values.dev.yaml
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
!**/.gitignore
|
docs/
|
||||||
!.git/HEAD
|
tests/
|
||||||
!.git/config
|
|
||||||
!.git/packed-refs
|
|
||||||
!.git/refs/heads/**
|
|
||||||
|
|
||||||
# AI
|
# AI instruction files.
|
||||||
**/AGENTS.[Mm][Dd]
|
**/AGENTS.[Mm][Dd]
|
||||||
**/agents.[Mm][Dd]
|
**/agents.[Mm][Dd]
|
||||||
**/SKILL.[Mm][Dd]
|
**/SKILL.[Mm][Dd]
|
||||||
**/skill.[Mm][Dd]
|
**/skill.[Mm][Dd]
|
||||||
|
|
||||||
# Six Labors license key file: must always be present for build-time license validation
|
# Six Labors license key file: must always be present for build-time license validation.
|
||||||
!**/sixlabors.lic
|
!**/sixlabors.lic
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
name: Publish Release
|
||||||
|
|
||||||
|
# Runs only when the repository owner creates a release/x.y.z branch. The protected "release" environment supplies the Six Labors license and the pull request token, and requires approval.
|
||||||
|
# The repository ruleset restricts who can create release branches.
|
||||||
|
|
||||||
|
on:
|
||||||
|
create:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
if: github.event.ref_type == 'branch' && startsWith(github.ref_name, 'release/') && github.actor == github.repository_owner
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 90
|
||||||
|
environment: release
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Validate release branch name
|
||||||
|
env:
|
||||||
|
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
if [[ ! "$RELEASE_BRANCH" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "Invalid release branch name. Use release/x.y.z." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Fetch master for the recording guard
|
||||||
|
run: git fetch --no-tags origin master:refs/remotes/origin/master
|
||||||
|
- name: Set up .NET
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: '10.0.100'
|
||||||
|
- name: Restore Six Labors license
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
SIXLABORS_LICENSE_KEY: ${{ secrets.SIXLABORS_LICENSE_KEY }}
|
||||||
|
run: printf '%s\n' "$SIXLABORS_LICENSE_KEY" > src/Nemera.Domain/sixlabors.lic
|
||||||
|
- name: Publish, verify, and record official release
|
||||||
|
env:
|
||||||
|
SixLaborsLicenseKey: ${{ secrets.SIXLABORS_LICENSE_KEY }}
|
||||||
|
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||||
|
run: dotnet msbuild build/build.proj -t:RecordBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:AllowBundledPluginsRecording=true -p:ReleaseBranch="$RELEASE_BRANCH"
|
||||||
|
# Reuse the verified publish output, so the images contain exactly the plugin binaries whose hashes were recorded.
|
||||||
|
- name: Build release images
|
||||||
|
env:
|
||||||
|
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
release_version="${RELEASE_BRANCH#release/}"
|
||||||
|
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:ReusePublishedBundledPlugins=true -p:Version="$release_version"
|
||||||
|
- name: Upload release server files
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-api
|
||||||
|
path: bin/api/publish
|
||||||
|
if-no-files-found: error
|
||||||
|
- name: Upload release web files
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-web
|
||||||
|
path: bin/web/publish
|
||||||
|
if-no-files-found: error
|
||||||
|
- name: Upload bundled plugin manifest
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: bundled-plugins-manifest
|
||||||
|
path: build/BundledPlugins.manifest
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
# The record job runs separately because it needs the pull request token to write to master, while the publish job stays read-only.
|
||||||
|
record-manifest:
|
||||||
|
needs: publish
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: release
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
# Use the PAT rather than GITHUB_TOKEN, so the pull request opened below triggers the normal CI workflows.
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: master
|
||||||
|
fetch-depth: 0
|
||||||
|
token: ${{ secrets.RELEASE_PR_TOKEN }}
|
||||||
|
- name: Validate release branch name
|
||||||
|
env:
|
||||||
|
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
if [[ ! "$RELEASE_BRANCH" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "Invalid release branch name. Use release/x.y.z." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Download bundled plugin manifest
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: bundled-plugins-manifest
|
||||||
|
path: recorded-manifest
|
||||||
|
# Merge into master's current file instead of overwriting it, so hashes recorded by earlier releases survive when master advanced after this branch was cut.
|
||||||
|
- name: Merge the released manifest into master
|
||||||
|
run: |
|
||||||
|
python3 - <<'PY'
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
master_path = Path("build/BundledPlugins.manifest")
|
||||||
|
artifact_path = Path("recorded-manifest/BundledPlugins.manifest")
|
||||||
|
master_text = master_path.read_text()
|
||||||
|
existing_entries = {
|
||||||
|
line.strip().lower()
|
||||||
|
for line in master_text.splitlines()
|
||||||
|
if line.strip() and not line.strip().startswith("#")
|
||||||
|
}
|
||||||
|
new_entries = []
|
||||||
|
for line in artifact_path.read_text().splitlines():
|
||||||
|
entry = line.strip()
|
||||||
|
if not entry or entry.startswith("#") or entry.lower() in existing_entries:
|
||||||
|
continue
|
||||||
|
existing_entries.add(entry.lower())
|
||||||
|
new_entries.append(entry)
|
||||||
|
if new_entries:
|
||||||
|
separator = "" if master_text.endswith("\n") else "\n"
|
||||||
|
master_path.write_text(master_text + separator + "\n".join(new_entries) + "\n")
|
||||||
|
PY
|
||||||
|
- name: Create record-release pull request
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.RELEASE_PR_TOKEN }}
|
||||||
|
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
release_version="${RELEASE_BRANCH#release/}"
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
branch="other/record-release-$release_version"
|
||||||
|
git checkout -b "$branch"
|
||||||
|
git add build/BundledPlugins.manifest
|
||||||
|
# The list is append-only. Fail loudly if a merge or a rerun staged a deletion instead of relying on review to catch it.
|
||||||
|
if [[ -n "$(git diff --cached --numstat -- build/BundledPlugins.manifest | awk '$2 != 0')" ]]; then
|
||||||
|
echo "The bundled plugin trust manifest diff removes lines. The list is append-only." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
echo "The bundled plugin manifest is already up to date."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
git commit -m "Records bundled plugin hashes for $release_version"
|
||||||
|
git push --force-with-lease --set-upstream origin "$branch"
|
||||||
|
gh pr create \
|
||||||
|
--base master \
|
||||||
|
--head "$branch" \
|
||||||
|
--title "Records bundled plugin hashes for $release_version" \
|
||||||
|
--body "This pull request records the published plugin hashes of the $release_version release in the bundled plugin trust list. The release artifacts already embed the current release's official plugin manifest. Merge this pull request to keep the $release_version plugin binaries Official in future releases. Run All Tests and the branch validators should pass before merging."
|
||||||
@@ -14,11 +14,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Set up .NET
|
- name: Set up .NET
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: '10.0.x'
|
dotnet-version: '10.0.100'
|
||||||
- name: Raise file watcher limits
|
- name: Raise file watcher limits
|
||||||
# The test hosts create a Razor file watcher per static asset, and the default limit of 128 inotify instances
|
# The test hosts create a Razor file watcher per static asset, and the default limit of 128 inotify instances
|
||||||
# is reached when several hosts run in parallel.
|
# is reached when several hosts run in parallel.
|
||||||
@@ -26,7 +26,9 @@ jobs:
|
|||||||
run: sudo sysctl -w fs.inotify.max_user_instances=1024 fs.inotify.max_user_watches=524288
|
run: sudo sysctl -w fs.inotify.max_user_instances=1024 fs.inotify.max_user_watches=524288
|
||||||
- name: Restore Six Labors license
|
- name: Restore Six Labors license
|
||||||
shell: bash
|
shell: bash
|
||||||
run: printf '%s\n' "${{ secrets.SIXLABORS_LICENSE_KEY }}" > src/Nemera.Domain/sixlabors.lic
|
env:
|
||||||
|
SIXLABORS_LICENSE_KEY: ${{ secrets.SIXLABORS_LICENSE_KEY }}
|
||||||
|
run: printf '%s\n' "$SIXLABORS_LICENSE_KEY" > src/Nemera.Domain/sixlabors.lic
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
run: dotnet restore src/Nemera.slnx
|
run: dotnet restore src/Nemera.slnx
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -10,15 +10,21 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check branch name
|
- name: Check branch name
|
||||||
|
env:
|
||||||
|
BRANCH_NAME: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
branch_name=${{ github.ref_name }}
|
branch_name="$BRANCH_NAME"
|
||||||
if [[ $branch_name == "master" ]]; then
|
if [[ "$branch_name" == "master" ]]; then
|
||||||
echo "Branch is master, skipping check."
|
echo "Branch is master, skipping check."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if ! [[ $branch_name =~ ^(feature|bugfix|hotfix|documentation|refactor|other)/ ]]; then
|
if [[ "$branch_name" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "Branch name '$branch_name' follows the release naming convention."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if ! [[ "$branch_name" =~ ^(feature|bugfix|hotfix|documentation|refactor|other)/ ]]; then
|
||||||
echo "Branch name '$branch_name' does not follow the naming convention."
|
echo "Branch name '$branch_name' does not follow the naming convention."
|
||||||
echo "It should start with one of: feature/, bugfix/, hotfix/, documentation/, refactor/, or other/"
|
echo "It should start with one of: feature/, bugfix/, hotfix/, documentation/, refactor/, other/, or be a release/x.y.z branch."
|
||||||
echo "Example: feature/my-feature-name or bugfix/fix-issue-123"
|
echo "Example: feature/my-feature-name, bugfix/fix-issue-123, or release/1.2.3"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -10,11 +10,17 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check source branch name
|
- name: Check source branch name
|
||||||
|
env:
|
||||||
|
BRANCH_NAME: ${{ github.head_ref }}
|
||||||
run: |
|
run: |
|
||||||
branch_name=${{ github.head_ref }}
|
branch_name="$BRANCH_NAME"
|
||||||
if ! [[ $branch_name =~ ^(feature|bugfix|hotfix|documentation|refactor|other)/ ]]; then
|
if [[ "$branch_name" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "Branch name '$branch_name' follows the release naming convention."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if ! [[ "$branch_name" =~ ^(feature|bugfix|hotfix|documentation|refactor|other)/ ]]; then
|
||||||
echo "Error: Branch name '$branch_name' does not follow the naming convention."
|
echo "Error: Branch name '$branch_name' does not follow the naming convention."
|
||||||
echo "It should start with one of: feature/, bugfix/, hotfix/, documentation/, refactor/, or other/"
|
echo "It should start with one of: feature/, bugfix/, hotfix/, documentation/, refactor/, other/, or be a release/x.y.z branch."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Branch name '$branch_name' follows the correct naming convention."
|
echo "Branch name '$branch_name' follows the correct naming convention."
|
||||||
@@ -32,6 +32,7 @@ These rules apply to every agent, on every task, in this repository. For C# code
|
|||||||
|
|
||||||
## Completing the work
|
## Completing the work
|
||||||
|
|
||||||
|
- Test scope: decide once whether the change needs targeted tests or the full test suite. If the full suite is needed, run it once. If only targeted tests are needed, run only those. Never run targeted tests and then rerun the full suite for the same change, because that doubles the wait without adding coverage.
|
||||||
- Never deliver an incomplete job while presenting it as done. A task is only done when every part of it is implemented, wired up, and verified to the same standard as the rest of the repository.
|
- Never deliver an incomplete job while presenting it as done. A task is only done when every part of it is implemented, wired up, and verified to the same standard as the rest of the repository.
|
||||||
- If a task is genuinely larger than what can be completed in a single pass, do not silently do a fraction of it and call it finished. Choose one of these, explicitly:
|
- If a task is genuinely larger than what can be completed in a single pass, do not silently do a fraction of it and call it finished. Choose one of these, explicitly:
|
||||||
- Delegate to subagents, one per subtask or workstream, and act as the coordinator/orchestrator: keep your own context for planning, dispatch, integration and verification, and let the subagents produce the bulk of the work.
|
- Delegate to subagents, one per subtask or workstream, and act as the coordinator/orchestrator: keep your own context for planning, dispatch, integration and verification, and let the subagents produce the bulk of the work.
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<Project>
|
||||||
|
<!-- The repository root, used to keep every build output under the shared bin directory. -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -36,6 +36,7 @@ For those with technical curiosities, here are some goodies to browse through:
|
|||||||
7. [4.3 Code scheduled jobs diagram](./docs/technical/architecture/4.3%20code-scheduler-diagram.svg)
|
7. [4.3 Code scheduled jobs diagram](./docs/technical/architecture/4.3%20code-scheduler-diagram.svg)
|
||||||
- To regenerate the diagrams after editing a `.puml` file, follow the [diagram rendering instructions](./docs/technical/architecture/README.md).
|
- To regenerate the diagrams after editing a `.puml` file, follow the [diagram rendering instructions](./docs/technical/architecture/README.md).
|
||||||
- Also for Software Architects, you might want to take a look at the Architecture Decision Log, where you may find important stories from the past of Nemera's development, like [this one](./docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md), and others like it.
|
- Also for Software Architects, you might want to take a look at the Architecture Decision Log, where you may find important stories from the past of Nemera's development, like [this one](./docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md), and others like it.
|
||||||
|
- The release process, required GitHub environment, secrets and credential rotation are documented in [Releasing](./docs/technical/RELEASING.md).
|
||||||
|
|
||||||
## Telemetry and Observability
|
## Telemetry and Observability
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Bundled plugin revocation list.
|
||||||
|
# Each line revokes one plugin binary: <assembly file name>|<SHA-256>.
|
||||||
|
# The reader removes these hashes from the historical and current trust lists, so a revoked binary is no longer marked Official.
|
||||||
|
# Remove an entry to restore trust in that hash. The historical trust list remains append-only.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Bundled plugin trust list.
|
||||||
|
# Each line identifies one shipped plugin binary: <assembly file name>|<SHA-256>.
|
||||||
|
# The release workflow appends a line for every released plugin binary. Never remove an existing line, so older bundled versions remain Official.
|
||||||
|
# Use BundledPlugins.deny.manifest to revoke a hash without removing its trust-list entry.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<Project>
|
||||||
|
<!-- The append-only list of bundled plugin binaries that are trusted as Official. -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<BundledPluginsManifest>$(MSBuildThisFileDirectory)BundledPlugins.manifest</BundledPluginsManifest>
|
||||||
|
<BundledPluginsDenyManifest>$(MSBuildThisFileDirectory)BundledPlugins.deny.manifest</BundledPluginsDenyManifest>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- The plugin projects that ship with the application. -->
|
||||||
|
<ItemGroup>
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.Calibre/Nemera.Plugins.Calibre.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.CoverArtArchive/Nemera.Plugins.CoverArtArchive.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.Epub/Nemera.Plugins.Epub.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.ID3/Nemera.Plugins.ID3.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.LocalMusicArtwork/Nemera.Plugins.LocalMusicArtwork.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.MusicBrainz/Nemera.Plugins.MusicBrainz.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.OpenLibrary/Nemera.Plugins.OpenLibrary.csproj" />
|
||||||
|
<BundledPluginProject Include="$(MSBuildThisFileDirectory)../plugins/Nemera.Plugins.Pdf/Nemera.Plugins.Pdf.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
<Project DefaultTargets="CI">
|
||||||
|
<Import Project="$(MSBuildThisFileDirectory)BundledPlugins.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..'))</RepoRoot>
|
||||||
|
<Solution>$(RepoRoot)/src/Nemera.slnx</Solution>
|
||||||
|
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
|
||||||
|
<ApiPublishDirectory>$(RepoRoot)/bin/api/publish</ApiPublishDirectory>
|
||||||
|
<WebPublishDirectory>$(RepoRoot)/bin/web/publish</WebPublishDirectory>
|
||||||
|
<BundledPluginsCurrentManifest Condition="'$(BundledPluginsCurrentManifest)' == ''">$(RepoRoot)/bin/api/BundledPlugins.current.manifest</BundledPluginsCurrentManifest>
|
||||||
|
<BundledPluginsSolution Condition="'$(BundledPluginsSolution)' == ''">$(MSBuildThisFileDirectory)obj/BundledPlugins.slnx</BundledPluginsSolution>
|
||||||
|
<_OfficialReleaseBuild Condition="'$(OfficialReleaseBuild)' == ''">false</_OfficialReleaseBuild>
|
||||||
|
<_OfficialReleaseBuild Condition="'$(OfficialReleaseBuild)' != ''">$(OfficialReleaseBuild)</_OfficialReleaseBuild>
|
||||||
|
<_DockerDependsOn>Build</_DockerDependsOn>
|
||||||
|
<_DockerDependsOn Condition="'$(_OfficialReleaseBuild)' == 'true'">ValidateDockerRelease;VerifyPublishedBundledPlugins</_DockerDependsOn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Target Name="Restore">
|
||||||
|
<Exec Command="dotnet restore "$(Solution)"" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<BundledPluginsAlreadyRestored>true</BundledPluginsAlreadyRestored>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="Build" DependsOnTargets="Restore;CompileSolution;FinalizeOfficialBundledPluginManifest" />
|
||||||
|
|
||||||
|
<Target Name="CompileSolution" DependsOnTargets="PrepareOfficialBundledPluginManifest">
|
||||||
|
<Exec Condition="'$(_OfficialReleaseBuild)' == 'true'" Command="dotnet build "$(Solution)" -c $(Configuration) --no-restore -p:OfficialReleaseBuild=$(_OfficialReleaseBuild) -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)"" />
|
||||||
|
<Exec Condition="'$(_OfficialReleaseBuild)' != 'true'" Command="dotnet build "$(Solution)" -c $(Configuration) --no-restore -p:OfficialReleaseBuild=$(_OfficialReleaseBuild)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="Test" DependsOnTargets="Build">
|
||||||
|
<Exec Command="dotnet test "$(Solution)" -c $(Configuration) --no-build --blame-hang --blame-hang-timeout 10m" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- The generated solution lets dotnet restore and dotnet build handle the plugin projects as separate supported invocations. -->
|
||||||
|
<Target Name="PrepareBundledPluginsSolution">
|
||||||
|
<ItemGroup>
|
||||||
|
<_BundledPluginSolutionLine Include="<Solution>" />
|
||||||
|
<_BundledPluginSolutionLine Include="@(BundledPluginProject->' <Project Path="%(FullPath)" />')" />
|
||||||
|
<_BundledPluginSolutionLine Include="</Solution>" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Error Condition="'@(BundledPluginProject)' == ''" Text="The bundled plugin catalog is empty." />
|
||||||
|
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(BundledPluginsSolution)'))" />
|
||||||
|
<WriteLinesToFile File="$(BundledPluginsSolution)" Lines="@(_BundledPluginSolutionLine)" Overwrite="true" WriteOnlyWhenDifferent="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="RestoreBundledPlugins" Condition="'$(BundledPluginsAlreadyRestored)' != 'true'" DependsOnTargets="PrepareBundledPluginsSolution">
|
||||||
|
<Exec Command="dotnet restore "$(BundledPluginsSolution)"" WorkingDirectory="$(RepoRoot)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="BuildBundledPlugins" DependsOnTargets="PrepareBundledPluginsSolution;RestoreBundledPlugins">
|
||||||
|
<Exec Command="dotnet build "$(BundledPluginsSolution)" -c $(Configuration) --no-restore -p:NemeraPluginsOutputDirectory="$(NemeraPluginsOutputDirectory)"" WorkingDirectory="$(RepoRoot)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- The first official build needs a current manifest file to embed. The real manifest is generated from the deployed plugins after the solution build. -->
|
||||||
|
<Target Name="PrepareOfficialBundledPluginManifest" Condition="'$(_OfficialReleaseBuild)' == 'true'">
|
||||||
|
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(BundledPluginsCurrentManifest)'))" />
|
||||||
|
<WriteLinesToFile File="$(BundledPluginsCurrentManifest)" Lines="# The current manifest is generated after the solution build." Overwrite="true" WriteOnlyWhenDifferent="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- The official manifest is generated from the plugins that the solution build actually deployed, so the embedded hashes and the deployed binaries cannot diverge. -->
|
||||||
|
<Target Name="FinalizeOfficialBundledPluginManifest" Condition="'$(_OfficialReleaseBuild)' == 'true'" DependsOnTargets="CompileSolution">
|
||||||
|
<MSBuild Projects="$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" Targets="GetTargetPath" Properties="Configuration=$(Configuration)">
|
||||||
|
<Output TaskParameter="TargetOutputs" ItemName="_BundledPluginApiTargetPath" />
|
||||||
|
</MSBuild>
|
||||||
|
<Error Condition="'@(_BundledPluginApiTargetPath)' == ''" Text="The API target path could not be determined." />
|
||||||
|
<ItemGroup>
|
||||||
|
<_BundledPluginApiTargetDirectory Include="@(_BundledPluginApiTargetPath->'%(RootDir)%(Directory)')" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<_DeployedBundledPluginsDirectory>@(_BundledPluginApiTargetDirectory)plugins</_DeployedBundledPluginsDirectory>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<_DeployedBundledPluginAssembly Include="$(_DeployedBundledPluginsDirectory)/Nemera.Plugins.*.dll" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Error Condition="'@(_DeployedBundledPluginAssembly)' == ''" Text="No bundled plugin binaries were deployed to '$(_DeployedBundledPluginsDirectory)'." />
|
||||||
|
<GetFileHash Files="@(_DeployedBundledPluginAssembly)" Algorithm="SHA256">
|
||||||
|
<Output TaskParameter="Items" ItemName="_FinalizedBundledPluginHash" />
|
||||||
|
</GetFileHash>
|
||||||
|
<WriteLinesToFile File="$(BundledPluginsCurrentManifest)" Lines="@(_FinalizedBundledPluginHash->'%(Filename)%(Extension)|%(FileHash)')" Overwrite="true" WriteOnlyWhenDifferent="true" />
|
||||||
|
<Exec Command="dotnet build "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" -c $(Configuration) --no-restore -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)"" />
|
||||||
|
<Exec Command="dotnet build "$(RepoRoot)/tests/UnitTests/Nemera.Presentation.Api.UnitTests/Nemera.Presentation.Api.UnitTests.csproj" -c $(Configuration) --no-restore -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)"" />
|
||||||
|
<Exec Command="dotnet build "$(RepoRoot)/tests/IntegrationTests/Nemera.Presentation.Api.IntegrationTests/Nemera.Presentation.Api.IntegrationTests.csproj" -c $(Configuration) --no-restore -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="VerifyBundledPlugins" DependsOnTargets="Build">
|
||||||
|
<Exec Command="dotnet test "$(Solution)" -c $(Configuration) --no-build --filter "FullyQualifiedName~BundledPluginManifest"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Ensures a fresh publish output exists unless the caller explicitly reuses the output of the preceding publish step. -->
|
||||||
|
<Target Name="EnsurePublishedBundledPlugins">
|
||||||
|
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="Publish" Condition="'$(ReusePublishedBundledPlugins)' != 'true' And '$(_PublishedBundledPlugins)' != 'true'" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Verifies the manifest embedded in the published API assembly against the plugin binaries that were actually published. -->
|
||||||
|
<Target Name="VerifyPublishedBundledPlugins" DependsOnTargets="EnsurePublishedBundledPlugins">
|
||||||
|
<Error Condition="!Exists('$(ApiPublishDirectory)/Nemera.Presentation.Api.dll')" Text="The published API assembly is missing from '$(ApiPublishDirectory)'." />
|
||||||
|
<Error Condition="!Exists('$(ApiPublishDirectory)/plugins')" Text="The published bundled plugins are missing from '$(ApiPublishDirectory)/plugins'." />
|
||||||
|
<Exec Command="dotnet test "$(Solution)" -c $(Configuration) --no-build --filter "FullyQualifiedName~PublishedBundledPluginManifest"" EnvironmentVariables="NEMERA_API_PUBLISH_DIRECTORY=$(ApiPublishDirectory)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Official release configuration must be validated before any build or test work starts. -->
|
||||||
|
<Target Name="ValidateOfficialRelease">
|
||||||
|
<Error Condition="'$(OfficialReleaseBuild)' != 'true'" Text="The Publish target is reserved for official release builds. Pass -p:OfficialReleaseBuild=true." />
|
||||||
|
<Error Condition="'$(Configuration)' != 'Release'" Text="Official releases must be published in the Release configuration." />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="Publish" DependsOnTargets="ValidateOfficialRelease;VerifyBundledPlugins">
|
||||||
|
<RemoveDir Directories="$(ApiPublishDirectory)" Condition="Exists('$(ApiPublishDirectory)')" />
|
||||||
|
<RemoveDir Directories="$(WebPublishDirectory)" Condition="Exists('$(WebPublishDirectory)')" />
|
||||||
|
<Error Condition="!Exists('$(BundledPluginsCurrentManifest)')" Text="The current bundled plugin manifest '$(BundledPluginsCurrentManifest)' is missing. Build the official plugins before publishing." />
|
||||||
|
<MakeDir Directories="$(ApiPublishDirectory)/plugins" />
|
||||||
|
<MSBuild Projects="@(BundledPluginProject)" Targets="Build" Properties="Configuration=$(Configuration);NemeraPluginsOutputDirectory=$(ApiPublishDirectory)/plugins/" />
|
||||||
|
<ItemGroup>
|
||||||
|
<_PublishedBundledPluginAssembly Include="$(ApiPublishDirectory)/plugins/Nemera.Plugins.*.dll" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Error Condition="'@(_PublishedBundledPluginAssembly)' == ''" Text="No bundled plugin binaries were deployed to '$(ApiPublishDirectory)/plugins'." />
|
||||||
|
<GetFileHash Files="@(_PublishedBundledPluginAssembly)" Algorithm="SHA256">
|
||||||
|
<Output TaskParameter="Items" ItemName="_PublishedBundledPluginHash" />
|
||||||
|
</GetFileHash>
|
||||||
|
<WriteLinesToFile File="$(BundledPluginsCurrentManifest)" Lines="@(_PublishedBundledPluginHash->'%(Filename)%(Extension)|%(FileHash)')" Overwrite="true" WriteOnlyWhenDifferent="true" />
|
||||||
|
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" -c $(Configuration) -o "$(ApiPublishDirectory)" -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)" -p:BundledPluginsPredeployed=true" />
|
||||||
|
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" -c $(Configuration) -o "$(WebPublishDirectory)"" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<_PublishedBundledPlugins>true</_PublishedBundledPlugins>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Official images must be Release builds, so they cannot bypass the release configuration or the manifest checks. -->
|
||||||
|
<Target Name="ValidateDockerRelease" Condition="'$(_OfficialReleaseBuild)' == 'true'">
|
||||||
|
<Error Condition="'$(Configuration)' != 'Release'" Text="Official Docker images must be built in the Release configuration." />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Official images ship the verified publish output. Local images build from source so docker compose keeps working without a prior publish. -->
|
||||||
|
<Target Name="Docker" DependsOnTargets="$(_DockerDependsOn)">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_ImageVersion Condition="'$(Version)' != ''">$(Version)</_ImageVersion>
|
||||||
|
<_ImageVersion Condition="'$(Version)' == ''">latest</_ImageVersion>
|
||||||
|
<_DockerApiDockerfile Condition="'$(_OfficialReleaseBuild)' == 'true'">$(RepoRoot)/src/Nemera.Presentation.Api/Dockerfile.release</_DockerApiDockerfile>
|
||||||
|
<_DockerApiDockerfile Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)/src/Nemera.Presentation.Api/Dockerfile</_DockerApiDockerfile>
|
||||||
|
<_DockerApiContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(ApiPublishDirectory)</_DockerApiContext>
|
||||||
|
<_DockerApiContext Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)</_DockerApiContext>
|
||||||
|
<_DockerWebDockerfile Condition="'$(_OfficialReleaseBuild)' == 'true'">$(RepoRoot)/src/Nemera.Presentation.Web/Dockerfile.release</_DockerWebDockerfile>
|
||||||
|
<_DockerWebDockerfile Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)/src/Nemera.Presentation.Web/Dockerfile</_DockerWebDockerfile>
|
||||||
|
<_DockerWebContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(WebPublishDirectory)</_DockerWebContext>
|
||||||
|
<_DockerWebContext Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)</_DockerWebContext>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Exec Command="docker build -t nemera-api:$(_ImageVersion) -f "$(_DockerApiDockerfile)" "$(_DockerApiContext)"" />
|
||||||
|
<Exec Command="docker build -t nemera-web:$(_ImageVersion) -f "$(_DockerWebDockerfile)" "$(_DockerWebContext)"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Recording is only allowed from a clean GitHub Actions checkout whose commit is the current origin/master. -->
|
||||||
|
<Target Name="ValidateBundledPluginsRecording">
|
||||||
|
<Error Condition="'$(AllowBundledPluginsRecording)' != 'true'" Text="Recording bundled plugin hashes is reserved for the release workflow. Pass -p:AllowBundledPluginsRecording=true only from CI." />
|
||||||
|
<Error Condition="'$(GITHUB_ACTIONS)' != 'true'" Text="Recording bundled plugin hashes is only allowed in GitHub Actions." />
|
||||||
|
<PropertyGroup>
|
||||||
|
<_ReleaseBranchIsValid>false</_ReleaseBranchIsValid>
|
||||||
|
<_ReleaseBranchIsValid Condition="'$(ReleaseBranch)' != '' And $(ReleaseBranch.StartsWith('release/'))">true</_ReleaseBranchIsValid>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="'$(_ReleaseBranchIsValid)' != 'true'" Text="Recording bundled plugin hashes requires a release/x.y.z branch." />
|
||||||
|
<Exec Command="git status --porcelain" WorkingDirectory="$(RepoRoot)" ConsoleToMSBuild="true">
|
||||||
|
<Output TaskParameter="ConsoleOutput" ItemName="_BundledPluginsGitStatus" />
|
||||||
|
</Exec>
|
||||||
|
<Error Condition="'@(_BundledPluginsGitStatus)' != ''" Text="Recording bundled plugin hashes requires a clean worktree. Commit or stash the changes first." />
|
||||||
|
<Exec Command="git rev-parse HEAD" WorkingDirectory="$(RepoRoot)" ConsoleToMSBuild="true">
|
||||||
|
<Output TaskParameter="ConsoleOutput" ItemName="_BundledPluginsHead" />
|
||||||
|
</Exec>
|
||||||
|
<Exec Command="git rev-parse origin/master" WorkingDirectory="$(RepoRoot)" ConsoleToMSBuild="true">
|
||||||
|
<Output TaskParameter="ConsoleOutput" ItemName="_BundledPluginsMasterHead" />
|
||||||
|
</Exec>
|
||||||
|
<Error Condition="'@(_BundledPluginsHead)' != '@(_BundledPluginsMasterHead)'" Text="Recording bundled plugin hashes requires the release branch to point at origin/master. Merge the previous trust-list pull request and recreate the release branch from master." />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="RecordBundledPlugins" DependsOnTargets="ValidateBundledPluginsRecording;Publish;VerifyPublishedBundledPlugins;RecordBundledPluginsFromPublish" />
|
||||||
|
|
||||||
|
<!-- VerifyPublishedBundledPlugins has already proved that the published plugin set exactly matches the embedded current manifest. -->
|
||||||
|
<Target Name="RecordBundledPluginsFromPublish" DependsOnTargets="ValidateOfficialRelease;ValidateBundledPluginsRecording;VerifyPublishedBundledPlugins">
|
||||||
|
<ItemGroup>
|
||||||
|
<_BundledPluginPublishedAssembly Include="$(ApiPublishDirectory)/plugins/Nemera.Plugins.*.dll" />
|
||||||
|
</ItemGroup>
|
||||||
|
<GetFileHash Files="@(_BundledPluginPublishedAssembly)" Algorithm="SHA256">
|
||||||
|
<Output TaskParameter="Items" ItemName="_RecordedBundledPluginHash" />
|
||||||
|
</GetFileHash>
|
||||||
|
<Error Condition="'@(_RecordedBundledPluginHash)' == ''" Text="No bundled plugin binaries were found in '$(ApiPublishDirectory)/plugins'." />
|
||||||
|
<Error Condition="!Exists('$(BundledPluginsManifest)')" Text="The bundled plugin trust manifest '$(BundledPluginsManifest)' is missing." />
|
||||||
|
<ReadLinesFromFile File="$(BundledPluginsManifest)">
|
||||||
|
<Output TaskParameter="Lines" ItemName="_ExistingBundledPluginManifestLine" />
|
||||||
|
</ReadLinesFromFile>
|
||||||
|
<ItemGroup>
|
||||||
|
<_NewBundledPluginManifestLine Include="@(_RecordedBundledPluginHash->'%(Filename)%(Extension)|%(FileHash)')" />
|
||||||
|
<_CombinedBundledPluginManifestLine Include="@(_ExistingBundledPluginManifestLine);@(_NewBundledPluginManifestLine)" />
|
||||||
|
</ItemGroup>
|
||||||
|
<!-- Rewrite the manifest as a deduplicated merge so a repeated run cannot append the same hash twice. -->
|
||||||
|
<RemoveDuplicates Inputs="@(_CombinedBundledPluginManifestLine)">
|
||||||
|
<Output TaskParameter="Filtered" ItemName="_DeduplicatedBundledPluginManifestLine" />
|
||||||
|
</RemoveDuplicates>
|
||||||
|
<WriteLinesToFile File="$(BundledPluginsManifest)" Lines="@(_DeduplicatedBundledPluginManifestLine)" Overwrite="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="CI" DependsOnTargets="Test">
|
||||||
|
<Message Text="CI build complete." Importance="high" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
@@ -657,3 +657,6 @@ public void Add_WhenCalledWithVariousInputs_ShouldReturnExpectedSum(int a, int b
|
|||||||
|
|
||||||
### Security Testing
|
### Security Testing
|
||||||
- Include tests that verify security measures (e.g., authentication, authorization)
|
- Include tests that verify security measures (e.g., authentication, authorization)
|
||||||
|
|
||||||
|
## Releasing
|
||||||
|
Releases are cut only by the repository owner. The required GitHub environment, release branch ruleset, secrets, credential rotation and troubleshooting steps are documented in [Releasing](./technical/RELEASING.md).
|
||||||
@@ -86,6 +86,8 @@ Use a release package or installer when one is available, or, with the .NET 10 S
|
|||||||
dotnet build Nemera.slnx
|
dotnet build Nemera.slnx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The official release artifacts include the PDF plugin's native libraries for Linux x64 and ARM64 (including Alpine x64), macOS Intel and Apple Silicon, and Windows x64 and ARM64. The single release download works on those platforms; the plugin loads the native libraries that match the host at runtime.
|
||||||
|
|
||||||
Run the API and the web client from the installed release package or from the published build. In development, their addresses come from each project's `launchSettings.json` (`http://localhost:5214` and `http://localhost:5012`). When you run a published build directly on a host, set the addresses yourself, either with `ASPNETCORE_URLS` or with `ASPNETCORE_HTTP_PORTS`:
|
Run the API and the web client from the installed release package or from the published build. In development, their addresses come from each project's `launchSettings.json` (`http://localhost:5214` and `http://localhost:5012`). When you run a published build directly on a host, set the addresses yourself, either with `ASPNETCORE_URLS` or with `ASPNETCORE_HTTP_PORTS`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ The `Needs web` column is worth pausing on: the providers marked `yes` reach out
|
|||||||
|
|
||||||
## Installing a plugin
|
## Installing a plugin
|
||||||
|
|
||||||
Plugins are managed from the administration area, on the Plugins page, which only administrators can open. To install one, upload either a single `.dll` assembly or a `.zip` archive that holds the assembly together with any dependencies it needs.
|
Plugins are managed from the administration area, on the Plugins page, which only administrators can open. To install one, upload either a single `.dll` assembly or a `.zip` archive that holds the assembly together with any managed dependency assemblies it needs. Only `.dll` entries are installed from the archive; dependency manifests, native `.so` and `.dylib` libraries, and the original directory structure are not.
|
||||||
|
|
||||||
The uploaded files are placed in the plugin storage directory, `plugins` by default, and are picked up at the **next startup of the API**. In other words, after installing a plugin, restart the API server for it to take effect. Installing is a supervised operation: the archive is unpacked into a flat set of assemblies inside the plugin directory, and any directory component in the upload is stripped, so a crafted archive cannot write outside that directory.
|
The uploaded files are placed in the plugin storage directory, `plugins` by default, and are picked up at the **next startup of the API**. In other words, after installing a plugin, restart the API server for it to take effect. Installing is a supervised operation: the archive is unpacked into a flat set of `.dll` files inside the plugin directory, and any directory component in the upload is stripped, so a crafted archive cannot write outside that directory.
|
||||||
|
|
||||||
Once installed and restarted, the plugin appears on the Plugins page with its name, author, version and description.
|
Once installed and restarted, the plugin appears on the Plugins page with its name, author, version and description.
|
||||||
|
|
||||||
@@ -59,6 +59,12 @@ Each plugin is listed with one of two states:
|
|||||||
|
|
||||||
Nemera reconciles the list at every startup. A plugin that is no longer present in the storage directory is forgotten, together with the per library settings that referenced it.
|
Nemera reconciles the list at every startup. A plugin that is no longer present in the storage directory is forgotten, together with the per library settings that referenced it.
|
||||||
|
|
||||||
|
Every official release of Nemera embeds the SHA-256 checksum of each bundled plugin's main assembly, plus an append-only list of checksums from earlier official releases. A plugin whose main assembly matches an entry is marked **Official**. The checksum covers only that main assembly; the libraries and native files shipped next to it are not checksummed. The list keeps older bundled versions recognized, so shipping a new version does not make an older one unofficial. A checksum can be revoked through the project's deny list; a revoked binary is no longer marked Official, but it still loads.
|
||||||
|
|
||||||
|
The **Official** mark is meaningful only when Nemera itself came from an official release published by the project. If you built Nemera yourself or are running a modified build, that build does not generate the current release's trust entries, so a plugin you rebuild locally is not marked Official unless it matches a binary from an earlier official release. Nemera does not call home to check plugin checksums against a server-side list, because that would conflict with the project's no outbound calls policy. The release channel is the trust anchor instead.
|
||||||
|
|
||||||
|
The **Official** mark is informational. It never prevents a plugin from loading, and plugins always work whether they are marked or not.
|
||||||
|
|
||||||
## Uninstalling a plugin
|
## Uninstalling a plugin
|
||||||
|
|
||||||
There is no uninstall button. To remove a plugin, delete its assembly (and any files that came with it) from the plugin storage directory and restart the API. The plugin then disappears from the list, and the settings that enabled it for your libraries are cleaned up.
|
There is no uninstall button. To remove a plugin, delete its assembly (and any files that came with it) from the plugin storage directory and restart the API. The plugin then disappears from the list, and the settings that enabled it for your libraries are cleaned up.
|
||||||
@@ -81,7 +87,7 @@ The shipped plugins use these settings for practical things, such as the base ad
|
|||||||
|
|
||||||
## Writing your own plugin
|
## Writing your own plugin
|
||||||
|
|
||||||
Anyone can write a plugin, and it is the intended way to teach Nemera about a new source or a new format. A plugin is a .NET assembly targeting the same framework as the server, referencing the `Nemera.Plugins.Contracts` project. To be a plugin it implements `IPlugin`, which describes it and lists its settings, and `IPluginServiceRegistrator`, which wires its services up. To contribute a capability it also implements one or more of `IMetadataProvider`, `IArtworkProvider` and `IBookReader`. Package the built assembly, and any dependencies, into a ZIP and install it like any other plugin.
|
Anyone can write a plugin, and it is the intended way to teach Nemera about a new source or a new format. A plugin is a .NET assembly targeting the same framework as the server, referencing the `Nemera.Plugins.Contracts` project. To be a plugin it implements `IPlugin`, which describes it and lists its settings, and `IPluginServiceRegistrator`, which wires its services up. To contribute a capability it also implements one or more of `IMetadataProvider`, `IArtworkProvider` and `IBookReader`. Package the built assembly, and any managed dependency assemblies, into a ZIP and install it like any other plugin. Only `.dll` files are installed from an archive, so the upload flow does not support plugins that need native `.so` or `.dylib` libraries.
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,188 @@
|
|||||||
|
# Releasing
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
|
||||||
|
- [Overview](#overview)
|
||||||
|
- [Required GitHub settings](#required-github-settings)
|
||||||
|
- [Release branch ruleset](#release-branch-ruleset)
|
||||||
|
- [Release environment](#release-environment)
|
||||||
|
- [Secrets](#secrets)
|
||||||
|
- [Workflows](#workflows)
|
||||||
|
- [Cutting a release](#cutting-a-release)
|
||||||
|
- [Revoking a bundled plugin hash](#revoking-a-bundled-plugin-hash)
|
||||||
|
- [Rotating credentials](#rotating-credentials)
|
||||||
|
- [Troubleshooting](#troubleshooting)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Releases are cut only by the repository owner. There is one official build, and it runs on the release branch.
|
||||||
|
|
||||||
|
1. The owner creates a `release/x.y.z` branch from `master`.
|
||||||
|
2. The `Publish Release` workflow builds and publishes the official artifacts with `OfficialReleaseBuild=true`.
|
||||||
|
3. The same workflow verifies the published API assembly against the published plugin binaries, records the release's plugin hashes in the append-only trust list, builds the release images from the verified publish output, and opens a pull request to `master`.
|
||||||
|
4. The owner downloads the official artifacts and creates the GitHub release and tag.
|
||||||
|
5. The owner merges the trust-list pull request. The current release already embeds its own official plugin manifest, so this pull request keeps the release's plugin binaries Official in future releases.
|
||||||
|
|
||||||
|
The full test suite runs on normal pull requests to `master`. The release build does not rerun the full suite. It runs the manifest verification tests for the official build, publishes, verifies the published API assembly against the published plugin binaries, records the hashes and builds the release images from the verified publish output.
|
||||||
|
|
||||||
|
The repository pins the .NET SDK in `global.json`. The workflows install that exact SDK, and the Docker build stage uses the matching `10.0.100` SDK image, so root-level and container builds use the same toolchain.
|
||||||
|
|
||||||
|
The `release-api` artifact is a single framework-dependent publish built on `ubuntu-latest`. The bundled plugin deployment keeps the PDF plugin's native libraries for the supported runtime identifiers: `win-x64`, `win-arm64`, `linux-x64`, `linux-arm64`, `linux-musl-x64`, `osx-x64` and `osx-arm64`. The macOS packages also keep their shared SkiaSharp library in the `osx` fallback folder, which the build retains automatically even though no device reports that identifier. The list is defined by `BundledPluginRuntimeIdentifiers` in `plugins/Directory.Build.props`, and the PDF plugin validates its required native libraries for every identifier in it, accepting a library from either the identifier's own folder or its OS family fallback. The plugin resolves the matching native library at runtime from its dependency manifest. The release Docker images copy that same publish output.
|
||||||
|
|
||||||
|
The presentation host does not compile against the concrete plugin projects, and it does not own the bundled plugin catalog. The plugin projects are part of the solution and copy their outputs to the API plugin folder. `build.proj` owns the release catalog: it builds and hashes the plugin binaries, writes the current manifest, passes that manifest to the API publish, and copies the binaries into the published plugin folder. Adding or removing a bundled plugin changes the release catalog and the solution, not the host project.
|
||||||
|
|
||||||
|
## Required GitHub settings
|
||||||
|
|
||||||
|
### Release branch ruleset
|
||||||
|
|
||||||
|
Create a repository ruleset under **Settings > Rules > Rulesets > New branch ruleset**:
|
||||||
|
|
||||||
|
- Target branches: `refs/heads/release/*`.
|
||||||
|
- Enable **Restrict creations**, **Restrict updates**, **Restrict deletions**, and **Block force pushes**.
|
||||||
|
- Bypass list: add only the owner's user account. Do not add the repository admin role if more than one administrator exists.
|
||||||
|
|
||||||
|
This prevents write collaborators from creating or pushing release branches. The ruleset enforces who can create the branch. The owner can create it from the GitHub Branches page or by pushing it.
|
||||||
|
|
||||||
|
The `Publish Release` workflow runs only when a branch matching `release/x.y.z` is created, and only when the actor is the repository owner.
|
||||||
|
|
||||||
|
### Release environment
|
||||||
|
|
||||||
|
Create an environment under **Settings > Environments > New environment** named `release`:
|
||||||
|
|
||||||
|
- Required reviewers: the owner.
|
||||||
|
- Deployment branches: allow `master` and `release/*`. A `create` event runs on the branch that was created, so the `publish` job runs on the release branch; the `record-manifest` job checks out `master` in that same release-branch run.
|
||||||
|
- Environment secrets:
|
||||||
|
- `SIXLABORS_LICENSE_KEY`
|
||||||
|
- `RELEASE_PR_TOKEN`
|
||||||
|
|
||||||
|
The `publish` job uses the license secret and has a read-only token. The `record-manifest` job uses the pull request token and does not have the license secret. The environment approval is the gate for both jobs.
|
||||||
|
|
||||||
|
### Secrets
|
||||||
|
|
||||||
|
#### SIXLABORS_LICENSE_KEY
|
||||||
|
|
||||||
|
This is the Six Labors license key content.
|
||||||
|
|
||||||
|
- The value to be put in the secret is the content of the license file, or the value already stored in the existing repository secret used by `Run All Tests`.
|
||||||
|
- `Run All Tests` uses the repository secret `SIXLABORS_LICENSE_KEY`.
|
||||||
|
- `Publish Release` uses the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
|
||||||
|
- `Publish Release` also exposes the secret as the `SixLaborsLicenseKey` MSBuild environment property, so every project that references ImageSharp validates the license, not only `Nemera.Domain`.
|
||||||
|
|
||||||
|
If the key is missing or expired, the build fails with a message such as `No Six Labors license found` or an expired license error.
|
||||||
|
|
||||||
|
#### RELEASE_PR_TOKEN
|
||||||
|
|
||||||
|
This is a fine-grained GitHub personal access token owned by the repository owner.
|
||||||
|
|
||||||
|
Create it under **Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token**:
|
||||||
|
|
||||||
|
- Resource owner: the owner's account.
|
||||||
|
- Repository access: only `BinaryAlley/Nemera`.
|
||||||
|
- Permissions:
|
||||||
|
- `Contents: Read and write`
|
||||||
|
- `Pull requests: Read and write`
|
||||||
|
- `Metadata: Read-only` is added automatically.
|
||||||
|
- Expiration: set an explicit date, for example 90 days, and add a calendar reminder.
|
||||||
|
|
||||||
|
Copy the generated `github_pat_...` value immediately. GitHub shows it only once. Store it as the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
|
||||||
|
|
||||||
|
Why a personal access token is needed: pull requests created with the workflow `GITHUB_TOKEN` do not trigger `pull_request` workflows. The trust-list pull request must run `Run All Tests` and the branch validators, so the `record-manifest` job pushes and creates the pull request with this token.
|
||||||
|
|
||||||
|
The token is used only by the `record-manifest` job. It is not available to the build job, and the build job's token is read-only. The `record-manifest` checkout uses the token as its git token, so the persisted git credential is the PAT and both `git push` and `gh pr create` authenticate with it.
|
||||||
|
|
||||||
|
## Workflows
|
||||||
|
|
||||||
|
- `Publish Release` runs when the owner creates a `release/x.y.z` branch. It has two jobs:
|
||||||
|
- `publish`: builds and publishes the official artifacts with `OfficialReleaseBuild=true`, runs the manifest verification tests, verifies the published API assembly against the published plugin binaries, records the released plugin hashes, builds the release images from the verified publish output, and uploads the `release-api`, `release-web` and `bundled-plugins-manifest` artifacts. It has the license secret and a read-only token.
|
||||||
|
- `record-manifest`: downloads the manifest artifact, appends only the release entries that are missing from master's current trust list, and opens the `other/record-release-x.y.z` pull request to `master` with the `RELEASE_PR_TOKEN`. It does not have the license secret.
|
||||||
|
- `Run All Tests` runs on pull requests to `master` and uses the repository `SIXLABORS_LICENSE_KEY` secret.
|
||||||
|
- `Branch Push Naming Convention Check` and `Pull Request Source Branch Validation Check` allow `feature/`, `bugfix/`, `hotfix/`, `documentation/`, `refactor/`, `other/`, and `release/x.y.z`.
|
||||||
|
|
||||||
|
The release branch is built from `master` after the normal pull request checks have passed. The release build does not rerun the full test suite. It runs the manifest verification tests, because that is the only part of the build that changes when the official plugin manifest and the official release marker are embedded. It then verifies the published API assembly against the published plugin binaries before recording hashes or building images. The trust-list pull request runs the full suite before it can be merged.
|
||||||
|
|
||||||
|
Recording is CI-only. The publish job checks that the worktree is clean and that `HEAD` matches `origin/master` before it appends to the trust list. A local `RecordBundledPlugins` run is rejected by the guard.
|
||||||
|
|
||||||
|
The trust list `build/BundledPlugins.manifest` is append-only. Never remove existing entries. The record job uses master's current file as the base and appends only the entries that are missing from it, skipping duplicates, so the record pull request diff contains additions only. Use the release workflow, which calls `RecordBundledPlugins`, instead of editing the file by hand. The deny list `build/BundledPlugins.deny.manifest` is the revocation path: add an entry to stop trusting a hash, and remove the entry to restore trust.
|
||||||
|
|
||||||
|
## Cutting a release
|
||||||
|
|
||||||
|
1. Ensure that everything you want in the release is on `master`, that the previous release's trust-list pull request is merged, and that the normal pull request checks have passed.
|
||||||
|
2. Verify that `SIXLABORS_LICENSE_KEY` and `RELEASE_PR_TOKEN` are present and current in the `release` environment, and that the repository `SIXLABORS_LICENSE_KEY` secret is current.
|
||||||
|
3. Create the `release/x.y.z` branch from the current `master` as the owner. The publish job requires the branch to point at the current `origin/master`. The check is exact: if anything merges to `master` before the job runs, the job fails and the branch must be recreated from the new `master`.
|
||||||
|
4. Approve the `release` environment for the `publish` and `record-manifest` jobs.
|
||||||
|
5. Wait for `Publish Release` to publish and verify the official artifacts, record the trust list and build the release images.
|
||||||
|
6. Download the `release-api` and `release-web` artifacts.
|
||||||
|
7. Create the GitHub release and tag manually from those artifacts. The workflow does not create the release.
|
||||||
|
8. Wait for `Run All Tests` and both branch validators on the `other/record-release-1.2.3` pull request. Review the trust-list diff and merge it.
|
||||||
|
9. The workflow builds the release images from the verified publish output to validate the image definitions, but it does not upload them. Build the images you ship from the downloaded artifacts, so they contain exactly the plugin binaries whose hashes were recorded:
|
||||||
|
```bash
|
||||||
|
docker build -t nemera-api:1.2.3 -f src/Nemera.Presentation.Api/Dockerfile.release <release-api-directory>
|
||||||
|
docker build -t nemera-web:1.2.3 -f src/Nemera.Presentation.Web/Dockerfile.release <release-web-directory>
|
||||||
|
```
|
||||||
|
To publish, verify and build in one local step instead, run:
|
||||||
|
```bash
|
||||||
|
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
|
||||||
|
```
|
||||||
|
That target publishes from source, verifies the publish output and builds the images from it. Those images are not the exact released artifacts unless the build is byte-identical, so prefer the downloaded artifacts for the images you ship.
|
||||||
|
|
||||||
|
The local equivalent of the official build is verification only. Recording is CI-only. The release workflow checks that the checkout is clean and that `HEAD` matches `origin/master` exactly before it appends to the trust list.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dotnet msbuild build/build.proj -t:VerifyPublishedBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true
|
||||||
|
```
|
||||||
|
|
||||||
|
For a local Release build, set `SixLaborsLicenseKey` to the content of `src/Nemera.Domain/sixlabors.lic` first. The file alone is only discovered by `Nemera.Domain`, and projects that reference ImageSharp through it fail license validation otherwise.
|
||||||
|
|
||||||
|
## Revoking a bundled plugin hash
|
||||||
|
|
||||||
|
The main trust list is append-only, so revoke a bad hash instead of removing it:
|
||||||
|
|
||||||
|
1. Add a `<assembly file name>|<SHA-256>` line to `build/BundledPlugins.deny.manifest`.
|
||||||
|
2. Merge the change to `master`.
|
||||||
|
3. The next build embeds the deny list. The reader removes the hash from both the historical and the current trust lists, so a plugin with that hash is no longer marked Official. It still loads.
|
||||||
|
|
||||||
|
The deny list is intentionally not append-only. Remove the line to restore trust if the revocation was a mistake.
|
||||||
|
|
||||||
|
## Rotating credentials
|
||||||
|
|
||||||
|
### Six Labors license
|
||||||
|
|
||||||
|
When the license is renewed or replaced:
|
||||||
|
|
||||||
|
1. Put the new value in the repository secret `SIXLABORS_LICENSE_KEY` used by `Run All Tests`.
|
||||||
|
2. Put the same value in the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
|
||||||
|
3. Re-run the failed workflow.
|
||||||
|
|
||||||
|
The local `src/Nemera.Domain/sixlabors.lic` file is only a local copy. Update it for local Release builds, but never commit it.
|
||||||
|
|
||||||
|
### RELEASE_PR_TOKEN
|
||||||
|
|
||||||
|
When the token expires, is revoked or is compromised:
|
||||||
|
|
||||||
|
1. Generate a new fine-grained token with the same repository access and permissions.
|
||||||
|
2. Replace the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
|
||||||
|
3. Re-create the release branch or re-run the failed `Publish Release` workflow, depending on where it failed.
|
||||||
|
4. Revoke the old token.
|
||||||
|
|
||||||
|
If the token is compromised, also review recent branches, pull requests and workflow runs. The token has only `Contents` and `Pull requests` write access to this repository.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
| Symptom | Cause | Fix |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `Publish Release` does not run | The created ref is not a `release/x.y.z` branch, or the actor is not the repository owner. | Create the branch as the owner using the three-part version. |
|
||||||
|
| The workflow waits for approval | The `release` environment has required reviewers. | Approve the `publish` and `record-manifest` jobs as the owner. |
|
||||||
|
| `No Six Labors license found` | The secret is missing or empty. | Check the repository secret and the `release` environment secret. |
|
||||||
|
| Six Labors license expired | The license key is no longer valid. | Renew it, update both secrets and re-run. |
|
||||||
|
| `git push` or `gh pr create` fails with 401 or 403 | `RELEASE_PR_TOKEN` is missing, expired or lacks `Contents` or `Pull requests` write, or the `record-manifest` checkout does not use it as the git token. | Generate a new token if needed, update the environment secret, and ensure the `record-manifest` checkout passes it as `token`. |
|
||||||
|
| The trust-list pull request has no CI | It was created with `GITHUB_TOKEN` instead of the PAT. | Verify that the `record-manifest` job uses `RELEASE_PR_TOKEN` and that the secret is current. |
|
||||||
|
| A release branch is rejected by the ruleset | The branch was not created by the owner. | Create it as the owner. The bypass list must contain only the owner's account. |
|
||||||
|
| The branch validator rejects a release branch | The branch is not `release/x.y.z`. | Use three numeric parts, for example `release/1.2.3`. |
|
||||||
|
| The branch validator rejects the trust-list pull request | The branch prefix is not allowed. | The workflow uses `other/record-release-x.y.z`, which is allowed. |
|
||||||
|
| `Official` is false in a release | The build did not use `OfficialReleaseBuild=true`, or the plugin binary does not match the trust manifest. | Use the `Publish Release` workflow, or pass `-p:OfficialReleaseBuild=true` with `Configuration=Release`. |
|
||||||
|
| `RecordBundledPlugins` fails | Recording is attempted outside GitHub Actions, from a dirty worktree, from a commit that is not the current `origin/master`, or without `Configuration=Release` and `OfficialReleaseBuild=true`. | Use the `Publish Release` workflow. Commit or stash changes, merge the previous trust-list pull request, and recreate the release branch from `master`, if the guard reports a tree or history problem. |
|
||||||
|
| `RecordBundledPlugins` fails because `master` moved | The release branch no longer matches the current `origin/master`. | Recreate the `release/x.y.z` branch from the new `master` and approve the new run. |
|
||||||
|
| The record-list pull request removes trust-list lines | The merge step was skipped, or master's current manifest was replaced with an older artifact. | The record job only appends missing entries and fails if the staged diff removes a line. Rerun the workflow. |
|
||||||
|
| A known good plugin is not Official | A deny-list entry matches its hash. | Remove the matching line from `build/BundledPlugins.deny.manifest`. |
|
||||||
|
| `VerifyPublishedBundledPlugins` fails | The manifest embedded in the published API assembly does not match the published plugin binaries. | Re-run the release build from the same commit. Do not mix artifacts from different builds. |
|
||||||
|
| The release image build fails with an official configuration error | `Docker` was called with `OfficialReleaseBuild=true` and a configuration other than `Release`. | Pass `-p:Configuration=Release`. |
|
||||||
@@ -66,6 +66,8 @@ GET api/v1/plugins
|
|||||||
200 Ok
|
200 Ok
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`isOfficial` is true when the plugin's main assembly matches a checksum from the append-only list of previous official releases, after the checksums in the deny list are removed. The checksum covers only the plugin's main assembly; the libraries and native files shipped next to it are not checksummed. An official release build also embeds and trusts the checksums of its own bundled plugins; a non-official build does not trust its own plugin binaries. A plugin that does not match, or whose checksum is denied, still loads and runs. The flag is informational only and never affects loading.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -76,6 +78,7 @@ GET api/v1/plugins
|
|||||||
"description": "Retrieves artist, album and track metadata from MusicBrainz.",
|
"description": "Retrieves artist, album and track metadata from MusicBrainz.",
|
||||||
"loadStatus": "Loaded",
|
"loadStatus": "Loaded",
|
||||||
"loadError": null,
|
"loadError": null,
|
||||||
|
"isOfficial": true,
|
||||||
"settings": {
|
"settings": {
|
||||||
"BaseUrl": "https://musicbrainz.org/ws/2/",
|
"BaseUrl": "https://musicbrainz.org/ws/2/",
|
||||||
"DoesAllowPrivateBaseUrl": "false",
|
"DoesAllowPrivateBaseUrl": "false",
|
||||||
|
|||||||
File renamed without changes.
@@ -1,6 +1,11 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
|
||||||
|
|
||||||
<!-- Shared warning and documentation policy for every plugin project under plugins. -->
|
<!-- Shared warning and documentation policy for every plugin project under plugins. -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<BaseOutputPath>$(RepoRoot)bin/plugins/</BaseOutputPath>
|
||||||
|
<!-- The real runtime identifiers the release artifact supports. Every bundled plugin with native dependencies must provide its libraries for each of them. The OS family fallback folders, such as osx, are kept automatically. -->
|
||||||
|
<BundledPluginRuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;linux-musl-x64;osx-x64;osx-arm64</BundledPluginRuntimeIdentifiers>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<Project>
|
||||||
|
<!-- The release orchestrator passes the plugin deployment destination. The default is used by solution builds and plugin tests. -->
|
||||||
|
<Target Name="SetPluginsDestination" BeforeTargets="CopyToPluginsFolder">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_PluginsDestination Condition="'$(NemeraPluginsOutputDirectory)' != ''">$(NemeraPluginsOutputDirectory)</_PluginsDestination>
|
||||||
|
<_PluginsDestination Condition="'$(NemeraPluginsOutputDirectory)' == ''">$(RepoRoot)bin/api/$(Configuration)/$(TargetFramework)/plugins/</_PluginsDestination>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Deploys the dependency manifest next to the plugin, so the host native resolver can use it. The PDF plugin prunes the native runtime folders to the supported list after the copy. -->
|
||||||
|
<Target Name="PreparePluginsCopy" BeforeTargets="CopyToPluginsFolder" DependsOnTargets="SetPluginsDestination">
|
||||||
|
<ItemGroup>
|
||||||
|
<_PluginsReferenceCopyLocalPath Include="@(ReferenceCopyLocalPaths)" />
|
||||||
|
</ItemGroup>
|
||||||
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
|
<Copy SourceFiles="$(TargetDir)$(TargetName).deps.json" DestinationFolder="$(_PluginsDestination)" Condition="Exists('$(TargetDir)$(TargetName).deps.json')" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -12,8 +11,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -13,9 +12,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -12,8 +11,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -13,9 +12,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -13,9 +12,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -13,9 +12,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -12,8 +11,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\plugins\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -12,21 +11,71 @@
|
|||||||
<Compile Include="..\..\src\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
<Compile Include="..\..\src\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
<!-- The supported runtimes come from the shared bundled plugin property. Each runtime also uses an OS family fallback folder, where the native dependency packages keep the libraries shared by every architecture of that operating system. -->
|
||||||
<MakeDir Directories="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Target Name="DefinePdfRuntimeLibraries">
|
||||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
|
||||||
<Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
|
||||||
<!-- The native libraries of the dependencies ship for every platform and architecture under a runtimes\<rid>\native
|
|
||||||
subdirectory of the plugin output; only the ones of the runtime the host runs on are deployed, flattened into the plugins
|
|
||||||
directory, so that a wrong-architecture native library (for example the x86 pdfium next to a 64-bit host) is never copied. -->
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<_CurrentRidNatives Include="$(OutDir)runtimes\$(NETCoreSdkRuntimeIdentifier)\native\*" />
|
<_SupportedPdfRuntime Include="$(BundledPluginRuntimeIdentifiers)" />
|
||||||
|
<_WindowsPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('win-'))">
|
||||||
|
<PdfFamily>win</PdfFamily>
|
||||||
|
</_WindowsPdfRuntime>
|
||||||
|
<_LinuxPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('linux-'))">
|
||||||
|
<PdfFamily>linux</PdfFamily>
|
||||||
|
</_LinuxPdfRuntime>
|
||||||
|
<_MacOsPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('osx-'))">
|
||||||
|
<PdfFamily>osx</PdfFamily>
|
||||||
|
</_MacOsPdfRuntime>
|
||||||
|
<_UnknownPdfRuntime Include="@(_SupportedPdfRuntime)" />
|
||||||
|
<_UnknownPdfRuntime Remove="@(_WindowsPdfRuntime);@(_LinuxPdfRuntime);@(_MacOsPdfRuntime)" />
|
||||||
|
<_PdfFamilyRuntime Include="win" Condition="'@(_WindowsPdfRuntime)' != ''" />
|
||||||
|
<_PdfFamilyRuntime Include="linux" Condition="'@(_LinuxPdfRuntime)' != ''" />
|
||||||
|
<_PdfFamilyRuntime Include="linux-musl" Condition="'@(_LinuxPdfRuntime)' != ''" />
|
||||||
|
<_PdfFamilyRuntime Include="osx" Condition="'@(_MacOsPdfRuntime)' != ''" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- The native libraries are what make the PDF reader work at runtime, so a build that produced none is a build that would deploy
|
</Target>
|
||||||
a silently broken plugin; failing here makes a missing RuntimeIdentifier visible at build time instead of as a runtime
|
|
||||||
DllNotFoundException. -->
|
<Target Name="CopyToPluginsFolder" AfterTargets="Build">
|
||||||
<Error Condition="'@(_CurrentRidNatives)' == ''" Text="No native libraries were produced under '$(OutDir)runtimes\$(NETCoreSdkRuntimeIdentifier)\native'. Build the Nemera.Plugins.Pdf project with an explicit runtime identifier (for example: dotnet build -r win-x64) so the PDF reader ships its native rendering libraries." />
|
<MakeDir Directories="$(_PluginsDestination)" />
|
||||||
<Copy SourceFiles="@(_CurrentRidNatives)" DestinationFolder="$(SolutionDir)..\bin\api\$(Configuration)\$(TargetFramework)\plugins\" />
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(_PluginsDestination)" />
|
||||||
|
<Copy SourceFiles="@(_PluginsReferenceCopyLocalPath)" DestinationFolder="$(_PluginsDestination)%(_PluginsReferenceCopyLocalPath.DestinationSubDirectory)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Keeps the native runtime folders of every supported runtime and of its OS family fallback, and removes the flat native copies so the dependency manifest selects the right library for the host. The plugins folder is shared with the other bundled plugins, so only folders that contain the PDF native libraries are pruned. -->
|
||||||
|
<Target Name="PrunePdfNativeRuntimes" AfterTargets="Build" DependsOnTargets="DefinePdfRuntimeLibraries;SetPluginsDestination;CopyToPluginsFolder">
|
||||||
|
<ItemGroup>
|
||||||
|
<_CopiedRuntimeDirectory Include="$([System.IO.Directory]::GetDirectories('$(_PluginsDestination)runtimes'))" />
|
||||||
|
<_CopiedPdfRuntimeDirectory Include="@(_CopiedRuntimeDirectory)" Condition="Exists('%(Identity)/native/pdfium.dll') Or Exists('%(Identity)/native/libpdfium.so') Or Exists('%(Identity)/native/libpdfium.dylib') Or Exists('%(Identity)/native/libSkiaSharp.dll') Or Exists('%(Identity)/native/libSkiaSharp.so') Or Exists('%(Identity)/native/libSkiaSharp.dylib')" />
|
||||||
|
<_CopiedPdfRuntimeDirectory Remove="@(_SupportedPdfRuntime)" MatchOnMetadata="Filename" />
|
||||||
|
<_CopiedPdfRuntimeDirectory Remove="@(_PdfFamilyRuntime)" MatchOnMetadata="Filename" />
|
||||||
|
<_RootPdfNativeFile Include="$(_PluginsDestination)pdfium.dll;$(_PluginsDestination)libpdfium.so;$(_PluginsDestination)libpdfium.dylib;$(_PluginsDestination)libSkiaSharp.dll;$(_PluginsDestination)libSkiaSharp.so;$(_PluginsDestination)libSkiaSharp.dylib" />
|
||||||
|
</ItemGroup>
|
||||||
|
<RemoveDir Directories="@(_CopiedPdfRuntimeDirectory)" />
|
||||||
|
<Delete Files="@(_RootPdfNativeFile)" TreatErrorsAsWarnings="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- The PDF plugin needs both native libraries for every supported runtime. A library satisfies the requirement when it is in the runtime's own folder or in its OS family fallback folder, which is how the macOS packages split SkiaSharp from pdfium. Deriving the list from the shared property makes adding a runtime without the matching package libraries fail the build. -->
|
||||||
|
<Target Name="ValidatePdfNativeLibraries" AfterTargets="Build" DependsOnTargets="PrunePdfNativeRuntimes">
|
||||||
|
<Error Condition="'@(_UnknownPdfRuntime)' != ''" Text="The bundled plugin runtime identifiers must be real runtime identifiers starting with win-, linux- or osx-, and must not list OS family fallback folders: @(_UnknownPdfRuntime)" />
|
||||||
|
<ItemGroup>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_WindowsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/pdfium.dll') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/pdfium.dll')">
|
||||||
|
<PdfNativeLibrary>pdfium.dll</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_WindowsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.dll') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.dll')">
|
||||||
|
<PdfNativeLibrary>libSkiaSharp.dll</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_LinuxPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libpdfium.so') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libpdfium.so')">
|
||||||
|
<PdfNativeLibrary>libpdfium.so</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_LinuxPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.so') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.so')">
|
||||||
|
<PdfNativeLibrary>libSkiaSharp.so</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_MacOsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libpdfium.dylib') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libpdfium.dylib')">
|
||||||
|
<PdfNativeLibrary>libpdfium.dylib</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
<_MissingPdfNativeLibrary Include="@(_MacOsPdfRuntime)" Condition="!Exists('$(_PluginsDestination)runtimes/%(Identity)/native/libSkiaSharp.dylib') And !Exists('$(_PluginsDestination)runtimes/%(PdfFamily)/native/libSkiaSharp.dylib')">
|
||||||
|
<PdfNativeLibrary>libSkiaSharp.dylib</PdfNativeLibrary>
|
||||||
|
</_MissingPdfNativeLibrary>
|
||||||
|
</ItemGroup>
|
||||||
|
<Error Condition="'@(_MissingPdfNativeLibrary)' != ''" Text="The PDF plugin is missing required native libraries (runtime: library): @(_MissingPdfNativeLibrary->'%(Identity): %(PdfNativeLibrary)')" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<Project>
|
<Project>
|
||||||
|
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
|
||||||
|
|
||||||
<!-- Shared warning and documentation policy for every production project under src. -->
|
<!-- Shared warning and documentation policy for every production project under src. -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<BaseOutputPath>$(RepoRoot)bin/api/</BaseOutputPath>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
||||||
|
|||||||
@@ -23,4 +23,11 @@ public interface IPluginManager
|
|||||||
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||||
/// <returns>The plugin, or <see langword="null"/> when no plugin with the provided Id was loaded.</returns>
|
/// <returns>The plugin, or <see langword="null"/> when no plugin with the provided Id was loaded.</returns>
|
||||||
IPlugin? GetPlugin(Guid pluginId);
|
IPlugin? GetPlugin(Guid pluginId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the loaded plugin identified by <paramref name="pluginId"/> matches a trusted bundled plugin binary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||||
|
/// <returns><see langword="true"/> when the plugin is official, <see langword="false"/> otherwise.</returns>
|
||||||
|
bool IsOfficial(Guid pluginId);
|
||||||
}
|
}
|
||||||
@@ -16,9 +16,11 @@ public static class PluginEntityMapping
|
|||||||
/// Converts <paramref name="pluginEntity"/> to <see cref="PluginResponse"/>.
|
/// Converts <paramref name="pluginEntity"/> to <see cref="PluginResponse"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pluginEntity">The repository entity to be converted.</param>
|
/// <param name="pluginEntity">The repository entity to be converted.</param>
|
||||||
|
/// <param name="isOfficial">Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||||
/// <returns>The converted response.</returns>
|
/// <returns>The converted response.</returns>
|
||||||
public static PluginResponse ToResponse(this PluginEntity pluginEntity)
|
public static PluginResponse ToResponse(this PluginEntity pluginEntity, bool isOfficial)
|
||||||
{
|
{
|
||||||
|
// Official status is supplied by the caller because it is derived from the running plugin manager, not from the persisted entity.
|
||||||
return new PluginResponse(
|
return new PluginResponse(
|
||||||
pluginEntity.Id,
|
pluginEntity.Id,
|
||||||
pluginEntity.Name,
|
pluginEntity.Name,
|
||||||
@@ -27,7 +29,8 @@ public static class PluginEntityMapping
|
|||||||
pluginEntity.Description,
|
pluginEntity.Description,
|
||||||
pluginEntity.LoadStatus,
|
pluginEntity.LoadStatus,
|
||||||
pluginEntity.LoadError,
|
pluginEntity.LoadError,
|
||||||
pluginEntity.ToSettings()
|
pluginEntity.ToSettings(),
|
||||||
|
isOfficial
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Nemera.Domain.Common.Primitives;
|
|
||||||
using Nemera.Application.Common.CQRS;
|
using Nemera.Application.Common.CQRS;
|
||||||
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
||||||
using Nemera.Application.Common.DataAccess.Repositories.Plugins;
|
using Nemera.Application.Common.DataAccess.Repositories.Plugins;
|
||||||
using Nemera.Application.Common.DataAccess.UoW;
|
using Nemera.Application.Common.DataAccess.UoW;
|
||||||
using Nemera.Application.Common.DTO.Filtering;
|
using Nemera.Application.Common.DTO.Filtering;
|
||||||
using Nemera.Application.Common.DTO.Pagination;
|
using Nemera.Application.Common.DTO.Pagination;
|
||||||
|
using Nemera.Application.Common.Infrastructure.Plugins;
|
||||||
using Nemera.Application.Common.Mapping.Plugins;
|
using Nemera.Application.Common.Mapping.Plugins;
|
||||||
using Nemera.Contracts.Responses.Plugins;
|
using Nemera.Contracts.Responses.Plugins;
|
||||||
|
using Nemera.Domain.Common.Primitives;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -22,14 +23,17 @@ namespace Nemera.Application.Core.Plugins.Queries.GetPlugins;
|
|||||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IReadOnlyList<PluginResponse>>>
|
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IReadOnlyList<PluginResponse>>>
|
||||||
{
|
{
|
||||||
private readonly IUnitOfWork _unitOfWork;
|
private readonly IUnitOfWork _unitOfWork;
|
||||||
|
private readonly IPluginManager _pluginManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="GetPluginsQueryHandler"/> class.
|
/// Initializes a new instance of the <see cref="GetPluginsQueryHandler"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||||
public GetPluginsQueryHandler(IUnitOfWork unitOfWork)
|
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
||||||
|
public GetPluginsQueryHandler(IUnitOfWork unitOfWork, IPluginManager pluginManager)
|
||||||
{
|
{
|
||||||
_unitOfWork = unitOfWork;
|
_unitOfWork = unitOfWork;
|
||||||
|
_pluginManager = pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,6 +47,7 @@ public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IRea
|
|||||||
public async Task<Result<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
public async Task<Result<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
Result<PaginatedResultDto<PluginEntity>> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
return getPluginsResult.Match(plugins => Result.From<IReadOnlyList<PluginResponse>>([.. plugins.Data.Select(plugin => plugin.ToResponse())]), errors => errors);
|
// Official status comes from the loaded plugin binaries, not from the persisted entity, so it is resolved for each response.
|
||||||
|
return getPluginsResult.Match(plugins => Result.From<IReadOnlyList<PluginResponse>>([.. plugins.Data.Select(plugin => plugin.ToResponse(_pluginManager.IsOfficial(plugin.Id)))]), errors => errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ namespace Nemera.Contracts.Responses.Plugins;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a detected plugin.
|
/// Represents a detected plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// IsOfficial is computed from the loaded plugin binaries when the response is built. It is not stored with the plugin entity, because replacing a plugin binary must change the badge without a database migration.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="Id">The unique identifier of the plugin.</param>
|
/// <param name="Id">The unique identifier of the plugin.</param>
|
||||||
/// <param name="Name">The display name of the plugin.</param>
|
/// <param name="Name">The display name of the plugin.</param>
|
||||||
/// <param name="Author">The author of the plugin.</param>
|
/// <param name="Author">The author of the plugin.</param>
|
||||||
@@ -18,6 +21,7 @@ namespace Nemera.Contracts.Responses.Plugins;
|
|||||||
/// <param name="LoadStatus">The load status of the plugin.</param>
|
/// <param name="LoadStatus">The load status of the plugin.</param>
|
||||||
/// <param name="LoadError">The error message when the plugin failed to load, if applicable.</param>
|
/// <param name="LoadError">The error message when the plugin failed to load, if applicable.</param>
|
||||||
/// <param name="Settings">The settings of the plugin.</param>
|
/// <param name="Settings">The settings of the plugin.</param>
|
||||||
|
/// <param name="IsOfficial">Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||||
[DebuggerDisplay("Name: {Name}")]
|
[DebuggerDisplay("Name: {Name}")]
|
||||||
public sealed record PluginResponse(
|
public sealed record PluginResponse(
|
||||||
Guid Id,
|
Guid Id,
|
||||||
@@ -27,5 +31,6 @@ public sealed record PluginResponse(
|
|||||||
string Description,
|
string Description,
|
||||||
PluginLoadStatus LoadStatus,
|
PluginLoadStatus LoadStatus,
|
||||||
string? LoadError,
|
string? LoadError,
|
||||||
IReadOnlyDictionary<string, string>? Settings
|
IReadOnlyDictionary<string, string>? Settings,
|
||||||
|
bool IsOfficial
|
||||||
);
|
);
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
+16
-9
@@ -1,4 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Nemera.Application.Common.DomainEvents;
|
using Nemera.Application.Common.DomainEvents;
|
||||||
using Nemera.Application.Common.Infrastructure.Authentication;
|
using Nemera.Application.Common.Infrastructure.Authentication;
|
||||||
using Nemera.Application.Common.Infrastructure.Authorization;
|
using Nemera.Application.Common.Infrastructure.Authorization;
|
||||||
@@ -8,8 +11,8 @@ using Nemera.Application.Common.Infrastructure.Authorization.Policies.Over18;
|
|||||||
using Nemera.Application.Common.Infrastructure.Models.DTO.Configuration;
|
using Nemera.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||||
using Nemera.Application.Common.Infrastructure.Plugins;
|
using Nemera.Application.Common.Infrastructure.Plugins;
|
||||||
using Nemera.Application.Common.Infrastructure.Reading;
|
using Nemera.Application.Common.Infrastructure.Reading;
|
||||||
using Nemera.Application.Common.Infrastructure.Security;
|
|
||||||
using Nemera.Application.Common.Infrastructure.Scheduling;
|
using Nemera.Application.Common.Infrastructure.Scheduling;
|
||||||
|
using Nemera.Application.Common.Infrastructure.Security;
|
||||||
using Nemera.Application.Common.Infrastructure.Themes;
|
using Nemera.Application.Common.Infrastructure.Themes;
|
||||||
using Nemera.Application.Common.Infrastructure.Time;
|
using Nemera.Application.Common.Infrastructure.Time;
|
||||||
using Nemera.Application.Common.Infrastructure.Validation;
|
using Nemera.Application.Common.Infrastructure.Validation;
|
||||||
@@ -34,14 +37,14 @@ using Nemera.Infrastructure.Core.Authorization.Policies.Common.Factory;
|
|||||||
using Nemera.Infrastructure.Core.Authorization.Policies.ConsumptionActivity;
|
using Nemera.Infrastructure.Core.Authorization.Policies.ConsumptionActivity;
|
||||||
using Nemera.Infrastructure.Core.Authorization.Policies.LibraryOwnership;
|
using Nemera.Infrastructure.Core.Authorization.Policies.LibraryOwnership;
|
||||||
using Nemera.Infrastructure.Core.Authorization.Policies.Over18;
|
using Nemera.Infrastructure.Core.Authorization.Policies.Over18;
|
||||||
|
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||||
|
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Cancellation;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Cancellation;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Audio.Music;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Audio.Music;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Common;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Common;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.WrittenContent.Books;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.WrittenContent.Books;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Progress;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
using Nemera.Infrastructure.Core.MediaLibrary.Management.Scanning.Queue;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
|
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
|
||||||
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
using Nemera.Infrastructure.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||||
using Nemera.Infrastructure.Core.Plugins;
|
using Nemera.Infrastructure.Core.Plugins;
|
||||||
@@ -52,9 +55,6 @@ using Nemera.Infrastructure.Core.Security;
|
|||||||
using Nemera.Infrastructure.Core.Themes;
|
using Nemera.Infrastructure.Core.Themes;
|
||||||
using Nemera.Infrastructure.Core.Time;
|
using Nemera.Infrastructure.Core.Time;
|
||||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -77,8 +77,9 @@ public static class InfrastructureLayerServices
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="services">The service collection to add the services to.</param>
|
/// <param name="services">The service collection to add the services to.</param>
|
||||||
/// <param name="configuration">The configuration used to read the application configuration.</param>
|
/// <param name="configuration">The configuration used to read the application configuration.</param>
|
||||||
|
/// <param name="bundledPluginChecksums">The trusted checksums of the bundled plugin assemblies, keyed by assembly file name.</param>
|
||||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||||
public static IServiceCollection AddInfrastructureLayerServices(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddInfrastructureLayerServices(this IServiceCollection services, IConfiguration configuration, IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums)
|
||||||
{
|
{
|
||||||
// Scan the current assembly for validators and add them to the DI container.
|
// Scan the current assembly for validators and add them to the DI container.
|
||||||
IEnumerable<Type> concreteTypes = Assembly.GetExecutingAssembly()
|
IEnumerable<Type> concreteTypes = Assembly.GetExecutingAssembly()
|
||||||
@@ -190,10 +191,15 @@ public static class InfrastructureLayerServices
|
|||||||
services.AddSingleton<IBookReadingService, BookReadingService>();
|
services.AddSingleton<IBookReadingService, BookReadingService>();
|
||||||
|
|
||||||
// Plugins: load the plugin assemblies from the plugins directory, register their services and provide the plugin manager.
|
// Plugins: load the plugin assemblies from the plugins directory, register their services and provide the plugin manager.
|
||||||
|
// The trust list only labels plugins as Official. It never gates loading, so a plugin with an unknown or missing hash still works.
|
||||||
string pluginsDirectorySetting = configuration.GetSection(PluginsSettingsDto.SECTION_NAME)["Directory"] ?? "plugins";
|
string pluginsDirectorySetting = configuration.GetSection(PluginsSettingsDto.SECTION_NAME)["Directory"] ?? "plugins";
|
||||||
string pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsDirectorySetting);
|
string pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsDirectorySetting);
|
||||||
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
|
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services, bundledPluginChecksums);
|
||||||
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins, pluginLoadResult.LoadContexts));
|
IReadOnlySet<Guid> officialPluginIds = pluginLoadResult.LoadedPlugins
|
||||||
|
.Where(plugin => plugin.IsOfficial)
|
||||||
|
.Select(plugin => plugin.PluginId)
|
||||||
|
.ToHashSet();
|
||||||
|
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins, pluginLoadResult.LoadContexts, officialPluginIds));
|
||||||
services.AddScoped<IPluginSettingsStore, PluginSettingsStore>();
|
services.AddScoped<IPluginSettingsStore, PluginSettingsStore>();
|
||||||
services.AddScoped<IPluginInstaller, PluginInstaller>();
|
services.AddScoped<IPluginInstaller, PluginInstaller>();
|
||||||
services.AddScoped<IMediaLibraryProviderConfigurationStore, MediaLibraryProviderConfigurationStore>();
|
services.AddScoped<IMediaLibraryProviderConfigurationStore, MediaLibraryProviderConfigurationStore>();
|
||||||
@@ -201,6 +207,7 @@ public static class InfrastructureLayerServices
|
|||||||
serviceProvider.GetRequiredService<IServiceScopeFactory>(),
|
serviceProvider.GetRequiredService<IServiceScopeFactory>(),
|
||||||
serviceProvider.GetRequiredService<IPluginManager>(),
|
serviceProvider.GetRequiredService<IPluginManager>(),
|
||||||
pluginLoadResult.Errors,
|
pluginLoadResult.Errors,
|
||||||
|
pluginLoadResult.Warnings,
|
||||||
serviceProvider.GetRequiredService<ILogger<PluginDetectionSyncJob>>()));
|
serviceProvider.GetRequiredService<ILogger<PluginDetectionSyncJob>>()));
|
||||||
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<PluginDetectionSyncJob>());
|
services.AddHostedService(serviceProvider => serviceProvider.GetRequiredService<PluginDetectionSyncJob>());
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data transfer object for the trust metadata of a loaded plugin.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The Official flag is computed at load time from the plugin binary's SHA-256 hash against the embedded trust list. It is not persisted, because a plugin binary can be replaced and because each release ships a different trust list.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="PluginId">The unique identifier of the plugin.</param>
|
||||||
|
/// <param name="AssemblyFileName">The file name of the plugin assembly.</param>
|
||||||
|
/// <param name="IsOfficial">Whether the plugin assembly matches a trusted bundled plugin binary.</param>
|
||||||
|
[DebuggerDisplay("AssemblyFileName: {AssemblyFileName}, IsOfficial: {IsOfficial}")]
|
||||||
|
internal sealed record LoadedPluginMetadataDto(
|
||||||
|
Guid PluginId,
|
||||||
|
string AssemblyFileName,
|
||||||
|
bool IsOfficial
|
||||||
|
);
|
||||||
@@ -16,8 +16,12 @@ namespace Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
|||||||
/// when a lazily resolved dependency is first used.
|
/// when a lazily resolved dependency is first used.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="Errors">The errors that occurred while loading the plugins.</param>
|
/// <param name="Errors">The errors that occurred while loading the plugins.</param>
|
||||||
|
/// <param name="LoadedPlugins">The trust metadata of the successfully loaded plugins.</param>
|
||||||
|
/// <param name="Warnings">The warnings that occurred while loading the plugins, such as a trust status that could not be verified or a dependency manifest that could not be read.</param>
|
||||||
internal sealed record PluginLoadResultDto(
|
internal sealed record PluginLoadResultDto(
|
||||||
IReadOnlyList<IPlugin> Plugins,
|
IReadOnlyList<IPlugin> Plugins,
|
||||||
IReadOnlyList<PluginLoadContext> LoadContexts,
|
IReadOnlyList<PluginLoadContext> LoadContexts,
|
||||||
IReadOnlyList<PluginLoadErrorDto> Errors
|
IReadOnlyList<PluginLoadErrorDto> Errors,
|
||||||
|
IReadOnlyList<LoadedPluginMetadataDto> LoadedPlugins,
|
||||||
|
IReadOnlyList<string> Warnings
|
||||||
);
|
);
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Nemera.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
using Nemera.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||||
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
using Nemera.Application.Common.DataAccess.Entities.Plugins;
|
||||||
using Nemera.Application.Common.DataAccess.UoW;
|
using Nemera.Application.Common.DataAccess.UoW;
|
||||||
@@ -9,9 +12,6 @@ using Nemera.Domain.Common.Primitives;
|
|||||||
using Nemera.Domain.SharedKernel.Common.Enums.Plugins;
|
using Nemera.Domain.SharedKernel.Common.Enums.Plugins;
|
||||||
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -31,6 +31,7 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
|||||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
private readonly IPluginManager _pluginManager;
|
private readonly IPluginManager _pluginManager;
|
||||||
private readonly IReadOnlyList<PluginLoadErrorDto> _loadErrors;
|
private readonly IReadOnlyList<PluginLoadErrorDto> _loadErrors;
|
||||||
|
private readonly IReadOnlyList<string> _warnings;
|
||||||
private readonly ILogger<PluginDetectionSyncJob> _logger;
|
private readonly ILogger<PluginDetectionSyncJob> _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,12 +40,14 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
|||||||
/// <param name="serviceScopeFactory">Injected factory for creating scopes in which services are requested.</param>
|
/// <param name="serviceScopeFactory">Injected factory for creating scopes in which services are requested.</param>
|
||||||
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
/// <param name="pluginManager">Injected manager of the plugins loaded by the host application.</param>
|
||||||
/// <param name="loadErrors">The errors that occurred while loading the plugins.</param>
|
/// <param name="loadErrors">The errors that occurred while loading the plugins.</param>
|
||||||
|
/// <param name="warnings">The warnings that occurred while loading the plugins.</param>
|
||||||
/// <param name="logger">Injected logger used for logging.</param>
|
/// <param name="logger">Injected logger used for logging.</param>
|
||||||
public PluginDetectionSyncJob(IServiceScopeFactory serviceScopeFactory, IPluginManager pluginManager, IReadOnlyList<PluginLoadErrorDto> loadErrors, ILogger<PluginDetectionSyncJob> logger)
|
public PluginDetectionSyncJob(IServiceScopeFactory serviceScopeFactory, IPluginManager pluginManager, IReadOnlyList<PluginLoadErrorDto> loadErrors, IReadOnlyList<string> warnings, ILogger<PluginDetectionSyncJob> logger)
|
||||||
{
|
{
|
||||||
_serviceScopeFactory = serviceScopeFactory;
|
_serviceScopeFactory = serviceScopeFactory;
|
||||||
_pluginManager = pluginManager;
|
_pluginManager = pluginManager;
|
||||||
_loadErrors = loadErrors;
|
_loadErrors = loadErrors;
|
||||||
|
_warnings = warnings;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +62,11 @@ internal sealed class PluginDetectionSyncJob : BackgroundService
|
|||||||
if (_logger.IsEnabled(LogLevel.Warning))
|
if (_logger.IsEnabled(LogLevel.Warning))
|
||||||
_logger.LogWarning("Plugin load failure: {LoadError}", loadError.ErrorMessage);
|
_logger.LogWarning("Plugin load failure: {LoadError}", loadError.ErrorMessage);
|
||||||
|
|
||||||
|
// Warnings are informational and never stop the host. They cover trust verification and dependency resolution problems.
|
||||||
|
foreach (string warning in _warnings)
|
||||||
|
if (_logger.IsEnabled(LogLevel.Warning))
|
||||||
|
_logger.LogWarning("Plugin warning: {Warning}", warning);
|
||||||
|
|
||||||
await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope();
|
await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope();
|
||||||
IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetRequiredService<IUnitOfWork>();
|
IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetRequiredService<IUnitOfWork>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,51 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Nemera.Infrastructure.Core.Plugins;
|
namespace Nemera.Infrastructure.Core.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Assembly load context of a single plugin, resolving the shared host assemblies from the default context and the plugin local dependencies from the plugin directory.
|
/// Assembly load context of a single plugin, resolving the shared host assemblies from the default context, and the plugin local dependencies and native libraries from its dependency manifest.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class PluginLoadContext : AssemblyLoadContext
|
internal sealed class PluginLoadContext : AssemblyLoadContext
|
||||||
{
|
{
|
||||||
private readonly string _pluginDirectory;
|
private readonly string _pluginDirectory;
|
||||||
|
private readonly AssemblyDependencyResolver? _dependencyResolver;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the plugin assembly has no dependency manifest next to it.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDependencyManifestMissing { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the error that occurred while reading the dependency manifest, or <see langword="null"/> when no error occurred.
|
||||||
|
/// </summary>
|
||||||
|
public string? DependencyManifestError { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginLoadContext"/> class.
|
/// Initializes a new instance of the <see cref="PluginLoadContext"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pluginDirectory">The directory where the plugin assemblies and their dependencies are located.</param>
|
/// <param name="pluginAssemblyPath">The path of the plugin assembly whose dependencies and native libraries are resolved from its adjacent dependency manifest.</param>
|
||||||
/// <param name="name">The name of the load context.</param>
|
/// <param name="name">The name of the load context.</param>
|
||||||
public PluginLoadContext(string pluginDirectory, string name) : base(name, isCollectible: true)
|
public PluginLoadContext(string pluginAssemblyPath, string name) : base(name, isCollectible: true)
|
||||||
{
|
{
|
||||||
_pluginDirectory = pluginDirectory;
|
_pluginDirectory = Path.GetDirectoryName(pluginAssemblyPath) ?? throw new ArgumentException("The plugin assembly path has no directory.", nameof(pluginAssemblyPath));
|
||||||
|
IsDependencyManifestMissing = !File.Exists(Path.ChangeExtension(pluginAssemblyPath, ".deps.json"));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dependencyResolver = new AssemblyDependencyResolver(pluginAssemblyPath);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
// The plugin can still load its managed dependencies through the directory fallback, but the native libraries under the shared runtimes folder cannot be resolved without a readable dependency manifest,
|
||||||
|
// so the error is recorded and the loader reports it for the plugin that it belongs to.
|
||||||
|
_dependencyResolver = null;
|
||||||
|
DependencyManifestError = exception.Message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,4 +74,19 @@ internal sealed class PluginLoadContext : AssemblyLoadContext
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the native library whose name is specified, using the plugin's dependency manifest to select the library of the current runtime.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unmanagedDllName">The name of the native library to load.</param>
|
||||||
|
/// <returns>The handle of the loaded native library.</returns>
|
||||||
|
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
||||||
|
{
|
||||||
|
// The dependency resolver selects the native library for the current RID from the plugin's deps.json. When it has no match,
|
||||||
|
// fall back to the default resolution so system libraries still load.
|
||||||
|
string? nativeLibraryPath = _dependencyResolver?.ResolveUnmanagedDllToPath(unmanagedDllName);
|
||||||
|
return nativeLibraryPath is null
|
||||||
|
? base.LoadUnmanagedDll(unmanagedDllName)
|
||||||
|
: NativeLibrary.Load(nativeLibraryPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Security.Cryptography;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Nemera.Infrastructure.Core.Plugins;
|
namespace Nemera.Infrastructure.Core.Plugins;
|
||||||
@@ -21,20 +22,23 @@ internal static class PluginLoader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pluginsDirectory">The directory where the plugin assemblies are located.</param>
|
/// <param name="pluginsDirectory">The directory where the plugin assemblies are located.</param>
|
||||||
/// <param name="services">The service collection to which the plugin services are added.</param>
|
/// <param name="services">The service collection to which the plugin services are added.</param>
|
||||||
|
/// <param name="bundledPluginChecksums">The trusted checksums of the bundled plugin assemblies, keyed by assembly file name.</param>
|
||||||
/// <returns>The result of loading the plugins.</returns>
|
/// <returns>The result of loading the plugins.</returns>
|
||||||
public static PluginLoadResultDto LoadPlugins(string pluginsDirectory, IServiceCollection services)
|
public static PluginLoadResultDto LoadPlugins(string pluginsDirectory, IServiceCollection services, IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums)
|
||||||
{
|
{
|
||||||
List<IPlugin> plugins = [];
|
List<IPlugin> plugins = [];
|
||||||
List<PluginLoadContext> loadContexts = [];
|
List<PluginLoadContext> loadContexts = [];
|
||||||
List<PluginLoadErrorDto> errors = [];
|
List<PluginLoadErrorDto> errors = [];
|
||||||
|
List<LoadedPluginMetadataDto> loadedPlugins = [];
|
||||||
|
List<string> warnings = [];
|
||||||
|
|
||||||
if (!Directory.Exists(pluginsDirectory))
|
if (!Directory.Exists(pluginsDirectory))
|
||||||
return new PluginLoadResultDto(plugins, loadContexts, errors);
|
return new PluginLoadResultDto(plugins, loadContexts, errors, loadedPlugins, warnings);
|
||||||
|
|
||||||
foreach (string assemblyPath in Directory.EnumerateFiles(pluginsDirectory, "*.dll"))
|
foreach (string assemblyPath in Directory.EnumerateFiles(pluginsDirectory, "*.dll"))
|
||||||
{
|
{
|
||||||
// A failing plugin must not prevent the other plugins from loading, so each assembly is isolated in its own load context.
|
// A failing plugin must not prevent the other plugins from loading, so each assembly is isolated in its own load context.
|
||||||
PluginLoadContext loadContext = new(pluginsDirectory, Path.GetFileNameWithoutExtension(assemblyPath));
|
PluginLoadContext loadContext = new(assemblyPath, Path.GetFileNameWithoutExtension(assemblyPath));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly assembly = loadContext.LoadFromAssemblyPath(assemblyPath);
|
Assembly assembly = loadContext.LoadFromAssemblyPath(assemblyPath);
|
||||||
@@ -52,9 +56,25 @@ internal static class PluginLoader
|
|||||||
if (plugin is IPluginServiceRegistrator serviceRegistrator)
|
if (plugin is IPluginServiceRegistrator serviceRegistrator)
|
||||||
serviceRegistrator.RegisterServices(services);
|
serviceRegistrator.RegisterServices(services);
|
||||||
plugins.Add(plugin);
|
plugins.Add(plugin);
|
||||||
|
// The trust manifest is a list of known bundled binaries, so a plugin remains Official only while its assembly matches one of them.
|
||||||
|
string assemblyFileName = Path.GetFileName(assemblyPath);
|
||||||
|
(string? checksum, string? checksumError) = GetSha256(assemblyPath);
|
||||||
|
bool isOfficial = checksum is not null
|
||||||
|
&& bundledPluginChecksums.TryGetValue(assemblyFileName, out IReadOnlySet<string>? trustedChecksums)
|
||||||
|
&& trustedChecksums.Contains(checksum);
|
||||||
|
// A checksum failure must not prevent the plugin from loading. It only means the Official badge cannot be verified.
|
||||||
|
if (checksum is null)
|
||||||
|
warnings.Add($"The SHA-256 checksum of plugin assembly '{assemblyFileName}' could not be computed, so its Official status cannot be verified: {checksumError}");
|
||||||
|
loadedPlugins.Add(new LoadedPluginMetadataDto(plugin.Id, assemblyFileName, isOfficial));
|
||||||
// A collectible load context is only kept alive by a direct reference to the context object itself, so the context of a loaded plugin is held for the lifetime
|
// A collectible load context is only kept alive by a direct reference to the context object itself, so the context of a loaded plugin is held for the lifetime
|
||||||
// of the host, keeping the plugin assemblies (and any lazily resolved dependency, like a book reader library) from being unloaded by the garbage collector.
|
// of the host, keeping the plugin assemblies (and any lazily resolved dependency, like a book reader library) from being unloaded by the garbage collector.
|
||||||
loadContexts.Add(loadContext);
|
loadContexts.Add(loadContext);
|
||||||
|
// Uploaded plugins normally have no dependency manifest because the installer stores only assemblies. Only a bundled
|
||||||
|
// (Official) plugin is expected to have one, so a missing manifest is a warning only for that case.
|
||||||
|
if (loadContext.DependencyManifestError is not null)
|
||||||
|
warnings.Add($"The dependency manifest of plugin assembly '{assemblyFileName}' could not be read, so its native libraries cannot be resolved from the plugin folder: {loadContext.DependencyManifestError}");
|
||||||
|
else if (loadContext.IsDependencyManifestMissing && isOfficial)
|
||||||
|
warnings.Add($"The bundled plugin assembly '{assemblyFileName}' has no dependency manifest next to it, so its native libraries cannot be resolved from the plugin folder.");
|
||||||
break; // Only one plugin descriptor per assembly.
|
break; // Only one plugin descriptor per assembly.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +95,29 @@ internal static class PluginLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PluginLoadResultDto(plugins, loadContexts, errors);
|
return new PluginLoadResultDto(plugins, loadContexts, errors, loadedPlugins, warnings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the SHA-256 checksum of the file at <paramref name="path"/>, in the uppercase hexadecimal form the bundled plugin trust manifest uses.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path of the file to hash.</param>
|
||||||
|
/// <returns>The checksum and a <see langword="null"/> error message, or a <see langword="null"/> checksum and the error message when the file cannot be read.</returns>
|
||||||
|
private static (string? Checksum, string? ErrorMessage) GetSha256(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
return (Convert.ToHexString(SHA256.HashData(fileStream)), null);
|
||||||
|
}
|
||||||
|
catch (IOException exception)
|
||||||
|
{
|
||||||
|
return (null, exception.Message);
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException exception)
|
||||||
|
{
|
||||||
|
return (null, exception.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,12 +130,14 @@ internal static class PluginLoader
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
Span<byte> signature = stackalloc byte[2];
|
{
|
||||||
if (fileStream.Read(signature) < signature.Length)
|
Span<byte> signature = stackalloc byte[2];
|
||||||
return false;
|
if (fileStream.Read(signature) < signature.Length)
|
||||||
// The DOS signature "MZ" is the header every PE image starts with, whether it is a managed assembly or a native library.
|
return false;
|
||||||
return signature[0] == (byte)'M' && signature[1] == (byte)'Z';
|
// The DOS signature "MZ" is the header every PE image starts with, whether it is a managed assembly or a native library.
|
||||||
|
return signature[0] == (byte)'M' && signature[1] == (byte)'Z';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Nemera.Infrastructure.Core.Plugins;
|
|||||||
internal sealed class PluginManager : IPluginManager
|
internal sealed class PluginManager : IPluginManager
|
||||||
{
|
{
|
||||||
private readonly IReadOnlyDictionary<Guid, IPlugin> _pluginsById;
|
private readonly IReadOnlyDictionary<Guid, IPlugin> _pluginsById;
|
||||||
|
private readonly IReadOnlySet<Guid> _officialPluginIds;
|
||||||
// The load contexts of the loaded plugins are held for the lifetime of the host, because a collectible load context is only kept alive by a direct reference to the
|
// The load contexts of the loaded plugins are held for the lifetime of the host, because a collectible load context is only kept alive by a direct reference to the
|
||||||
// context object itself, and the garbage collector would otherwise unload the plugin assemblies mid-request, when a lazily resolved dependency is first used.
|
// context object itself, and the garbage collector would otherwise unload the plugin assemblies mid-request, when a lazily resolved dependency is first used.
|
||||||
private readonly IReadOnlyList<PluginLoadContext> _loadContexts;
|
private readonly IReadOnlyList<PluginLoadContext> _loadContexts;
|
||||||
@@ -23,9 +24,11 @@ internal sealed class PluginManager : IPluginManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plugins">The plugins that were loaded successfully.</param>
|
/// <param name="plugins">The plugins that were loaded successfully.</param>
|
||||||
/// <param name="loadContexts">The load contexts of the loaded plugins, kept referenced for the lifetime of the host.</param>
|
/// <param name="loadContexts">The load contexts of the loaded plugins, kept referenced for the lifetime of the host.</param>
|
||||||
public PluginManager(IEnumerable<IPlugin> plugins, IReadOnlyList<PluginLoadContext> loadContexts)
|
/// <param name="officialPluginIds">The Ids of the loaded plugins whose assemblies match a trusted bundled plugin binary.</param>
|
||||||
|
public PluginManager(IEnumerable<IPlugin> plugins, IReadOnlyList<PluginLoadContext> loadContexts, IReadOnlySet<Guid> officialPluginIds)
|
||||||
{
|
{
|
||||||
_pluginsById = plugins.ToDictionary(plugin => plugin.Id);
|
_pluginsById = plugins.ToDictionary(plugin => plugin.Id);
|
||||||
|
_officialPluginIds = officialPluginIds;
|
||||||
_loadContexts = loadContexts;
|
_loadContexts = loadContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +50,14 @@ internal sealed class PluginManager : IPluginManager
|
|||||||
{
|
{
|
||||||
return _pluginsById.GetValueOrDefault(pluginId);
|
return _pluginsById.GetValueOrDefault(pluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the loaded plugin identified by <paramref name="pluginId"/> matches a trusted bundled plugin binary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pluginId">The unique identifier of the plugin.</param>
|
||||||
|
/// <returns><see langword="true"/> when the plugin is official, <see langword="false"/> otherwise.</returns>
|
||||||
|
public bool IsOfficial(Guid pluginId)
|
||||||
|
{
|
||||||
|
return _officialPluginIds.Contains(pluginId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -31,6 +31,7 @@ public class GetPluginsEndpointSummary : Summary<GetPluginsEndpoint, EmptyReques
|
|||||||
ResponseParam<PluginResponse>(r => r.LoadStatus, "The load status of the plugin.");
|
ResponseParam<PluginResponse>(r => r.LoadStatus, "The load status of the plugin.");
|
||||||
ResponseParam<PluginResponse>(r => r.LoadError, "The error message when the plugin failed to load, if applicable.");
|
ResponseParam<PluginResponse>(r => r.LoadError, "The error message when the plugin failed to load, if applicable.");
|
||||||
ResponseParam<PluginResponse>(r => r.Settings, "The settings of the plugin.");
|
ResponseParam<PluginResponse>(r => r.Settings, "The settings of the plugin.");
|
||||||
|
ResponseParam<PluginResponse>(r => r.IsOfficial, "Whether the plugin matches a trusted bundled plugin binary.");
|
||||||
|
|
||||||
Response(200, "The list of detected plugins is returned.",
|
Response(200, "The list of detected plugins is returned.",
|
||||||
example: new PluginResponse[] {
|
example: new PluginResponse[] {
|
||||||
@@ -46,7 +47,8 @@ public class GetPluginsEndpointSummary : Summary<GetPluginsEndpoint, EmptyReques
|
|||||||
{
|
{
|
||||||
{ "preferredLanguage", "en" },
|
{ "preferredLanguage", "en" },
|
||||||
{ "selectionStrategy", "first" }
|
{ "selectionStrategy", "first" }
|
||||||
}
|
},
|
||||||
|
IsOfficial: true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Nemera.Presentation.Api.Core.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the trust manifests of the bundled plugin binaries embedded in the API assembly.
|
||||||
|
/// </summary>
|
||||||
|
internal static class BundledPluginManifestReader
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The resource name of the append-only trust list of previously released bundled plugin binaries.
|
||||||
|
/// </summary>
|
||||||
|
private const string HISTORICAL_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.historical.manifest";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The resource name of the trust list generated for the current build's bundled plugin binaries.
|
||||||
|
/// </summary>
|
||||||
|
private const string CURRENT_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.current.manifest";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The resource name of the list of bundled plugin checksums that are no longer trusted.
|
||||||
|
/// </summary>
|
||||||
|
private const string DENY_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.deny.manifest";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the trusted SHA-256 checksums of the bundled plugin binaries from the embedded trust manifests.
|
||||||
|
/// The current build's manifest is read only for an official release build, so a local build cannot certify its own plugins.
|
||||||
|
/// Denied checksums are removed from the historical and current trust lists.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A dictionary that maps each bundled plugin assembly file name to the checksums it is allowed to have.</returns>
|
||||||
|
public static IReadOnlyDictionary<string, IReadOnlySet<string>> ReadExpectedChecksums()
|
||||||
|
{
|
||||||
|
// The historical list is always embedded, because it carries the hashes of earlier releases and those binaries must stay trusted after an upgrade.
|
||||||
|
using (Stream historicalManifestStream = GetManifestResourceStream(HISTORICAL_MANIFEST_RESOURCE_NAME))
|
||||||
|
{
|
||||||
|
// The deny list is always embedded too, so revoking a hash does not depend on the release being rebuilt.
|
||||||
|
using (Stream denyManifestStream = GetManifestResourceStream(DENY_MANIFEST_RESOURCE_NAME))
|
||||||
|
{
|
||||||
|
// A normal build cannot certify its own plugins. Only an official release build embeds the current manifest,
|
||||||
|
// so a developer cannot make a locally built plugin appear Official just by building the project.
|
||||||
|
if (!IsOfficialReleaseBuild())
|
||||||
|
return ReadExpectedChecksums(historicalManifestStream, null, denyManifestStream);
|
||||||
|
using (Stream currentManifestStream = GetManifestResourceStream(CURRENT_MANIFEST_RESOURCE_NAME))
|
||||||
|
return ReadExpectedChecksums(historicalManifestStream, currentManifestStream, denyManifestStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the trusted SHA-256 checksums of the bundled plugin binaries from the provided trust manifest streams.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="historicalManifestStream">The stream that contains the append-only trust list of previously released bundled plugin binaries.</param>
|
||||||
|
/// <param name="currentManifestStream">The stream that contains the trust list generated for the current build's bundled plugin binaries, or <see langword="null"/> when the build is not an official release build.</param>
|
||||||
|
/// <param name="denyManifestStream">The stream that contains the checksums that are no longer trusted, or <see langword="null"/> when no deny list is available.</param>
|
||||||
|
/// <returns>A dictionary that maps each bundled plugin assembly file name to the checksums it is allowed to have.</returns>
|
||||||
|
internal static IReadOnlyDictionary<string, IReadOnlySet<string>> ReadExpectedChecksums(Stream historicalManifestStream, Stream? currentManifestStream = null, Stream? denyManifestStream = null)
|
||||||
|
{
|
||||||
|
// Assembly file names are compared case-insensitively because the plugins directory is case-insensitive on Windows.
|
||||||
|
Dictionary<string, HashSet<string>> checksumsByAssemblyFileName = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
// The historical list comes first so the current release can add hashes without replacing the earlier ones.
|
||||||
|
ReadManifest(historicalManifestStream, HISTORICAL_MANIFEST_RESOURCE_NAME, checksumsByAssemblyFileName);
|
||||||
|
if (currentManifestStream is not null)
|
||||||
|
ReadManifest(currentManifestStream, CURRENT_MANIFEST_RESOURCE_NAME, checksumsByAssemblyFileName);
|
||||||
|
// Revocation is applied last so a denied hash wins over every trust list, including the current release's own entries.
|
||||||
|
if (denyManifestStream is not null)
|
||||||
|
RemoveDeniedChecksums(denyManifestStream, checksumsByAssemblyFileName);
|
||||||
|
// The loader only reads the trust list, so the result exposes the sets as read-only even though they were built as mutable sets.
|
||||||
|
Dictionary<string, IReadOnlySet<string>> expectedChecksums = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
foreach (KeyValuePair<string, HashSet<string>> checksums in checksumsByAssemblyFileName)
|
||||||
|
expectedChecksums[checksums.Key] = checksums.Value;
|
||||||
|
return expectedChecksums;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the checksums of the deny list from the accumulated trust list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="denyManifestStream">The stream that contains the checksums that are no longer trusted.</param>
|
||||||
|
/// <param name="checksumsByAssemblyFileName">The dictionary that accumulates the trust list entries.</param>
|
||||||
|
private static void RemoveDeniedChecksums(Stream denyManifestStream, Dictionary<string, HashSet<string>> checksumsByAssemblyFileName)
|
||||||
|
{
|
||||||
|
// The deny list is parsed on its own first, so an entry for an unknown or retired assembly can be ignored without failing the whole manifest.
|
||||||
|
Dictionary<string, HashSet<string>> deniedChecksumsByAssemblyFileName = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
ReadManifest(denyManifestStream, DENY_MANIFEST_RESOURCE_NAME, deniedChecksumsByAssemblyFileName);
|
||||||
|
foreach (KeyValuePair<string, HashSet<string>> deniedChecksums in deniedChecksumsByAssemblyFileName)
|
||||||
|
{
|
||||||
|
// A deny entry for an assembly that is not trusted anywhere is harmless.
|
||||||
|
if (!checksumsByAssemblyFileName.TryGetValue(deniedChecksums.Key, out HashSet<string>? assemblyChecksums))
|
||||||
|
continue;
|
||||||
|
assemblyChecksums.ExceptWith(deniedChecksums.Value);
|
||||||
|
// An assembly with no trusted hashes left is removed, so the result never carries an empty trust set.
|
||||||
|
if (assemblyChecksums.Count == 0)
|
||||||
|
checksumsByAssemblyFileName.Remove(deniedChecksums.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the API assembly was produced by an official release build.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the assembly carries the official release marker, <see langword="false"/> otherwise.</returns>
|
||||||
|
private static bool IsOfficialReleaseBuild()
|
||||||
|
{
|
||||||
|
// The official build injects this marker from the OFFICIAL_RELEASE_BUILD compilation symbol. build.proj defines the symbol only for the
|
||||||
|
// official release flow, so a normal build has no marker and does not embed a current manifest of its own binaries.
|
||||||
|
return typeof(BundledPluginManifestReader).Assembly
|
||||||
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
|
.Any(attribute => attribute.Key == "OfficialReleaseBuild" && attribute.Value == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens an embedded trust manifest resource.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resourceName">The name of the embedded manifest resource.</param>
|
||||||
|
/// <returns>The stream that contains the manifest.</returns>
|
||||||
|
private static Stream GetManifestResourceStream(string resourceName)
|
||||||
|
{
|
||||||
|
// The historical and deny manifests are required for every build. A missing resource means the packaging step is broken,
|
||||||
|
// and failing fast is safer than starting with an empty trust list that marks every bundled plugin as not Official.
|
||||||
|
return typeof(BundledPluginManifestReader).Assembly.GetManifestResourceStream(resourceName)
|
||||||
|
?? throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' is missing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads one trust manifest and adds its entries to <paramref name="checksumsByAssemblyFileName"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="manifestStream">The stream that contains the manifest.</param>
|
||||||
|
/// <param name="resourceName">The name of the manifest resource, used in error messages.</param>
|
||||||
|
/// <param name="checksumsByAssemblyFileName">The dictionary that accumulates the trust list entries.</param>
|
||||||
|
private static void ReadManifest(Stream manifestStream, string resourceName, Dictionary<string, HashSet<string>> checksumsByAssemblyFileName)
|
||||||
|
{
|
||||||
|
// Each entry is "assembly-file-name|sha256". Blank lines and lines starting with # are ignored, so the checked-in list can carry release notes.
|
||||||
|
using (StreamReader reader = new(manifestStream))
|
||||||
|
{
|
||||||
|
int lineNumber = 0;
|
||||||
|
string? line;
|
||||||
|
while ((line = reader.ReadLine()) is not null)
|
||||||
|
{
|
||||||
|
lineNumber++;
|
||||||
|
string trimmedLine = line.Trim();
|
||||||
|
if (trimmedLine.Length == 0 || trimmedLine.StartsWith('#'))
|
||||||
|
continue;
|
||||||
|
// A malformed entry is a build error rather than a skipped line, because silently ignoring it could hide a plugin that the release intended to trust.
|
||||||
|
string[] parts = trimmedLine.Split('|');
|
||||||
|
if (parts.Length != 2)
|
||||||
|
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid entry at line {lineNumber}.");
|
||||||
|
string assemblyFileName = parts[0].Trim();
|
||||||
|
string checksum = parts[1].Trim();
|
||||||
|
// A SHA-256 checksum is 64 hexadecimal characters. The length check gives a clearer error than the conversion below.
|
||||||
|
if (assemblyFileName.Length == 0 || checksum.Length != 64)
|
||||||
|
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid entry at line {lineNumber}.");
|
||||||
|
int checksumLength;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
checksumLength = Convert.FromHexString(checksum).Length;
|
||||||
|
}
|
||||||
|
catch (FormatException exception)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid checksum at line {lineNumber}.", exception);
|
||||||
|
}
|
||||||
|
// The byte count is checked as well, so a future change to the length check cannot let a non-SHA-256 value through.
|
||||||
|
if (checksumLength != 32)
|
||||||
|
throw new InvalidOperationException($"The bundled plugin manifest resource '{resourceName}' contains an invalid checksum at line {lineNumber}.");
|
||||||
|
// The historical and current manifests can list the same hash. The set makes that duplicate harmless.
|
||||||
|
if (!checksumsByAssemblyFileName.TryGetValue(assemblyFileName, out HashSet<string>? assemblyChecksums))
|
||||||
|
{
|
||||||
|
assemblyChecksums = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
checksumsByAssemblyFileName[assemblyFileName] = assemblyChecksums;
|
||||||
|
}
|
||||||
|
assemblyChecksums.Add(checksum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// The official release marker tells the trust manifest reader and the manifest tests that this is an official release build.
|
||||||
|
// The OFFICIAL_RELEASE_BUILD symbol is defined by build/build.proj only for the official release build, so a normal local build cannot produce it.
|
||||||
|
#if OFFICIAL_RELEASE_BUILD
|
||||||
|
[assembly: System.Reflection.AssemblyMetadata("OfficialReleaseBuild", "true")]
|
||||||
|
#endif
|
||||||
@@ -14,34 +14,33 @@ WORKDIR /app
|
|||||||
EXPOSE 5214
|
EXPOSE 5214
|
||||||
|
|
||||||
# ==== Stage 1: Build stage
|
# ==== Stage 1: Build stage
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:10.0.100 AS build
|
||||||
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
||||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
COPY ["Directory.Build.props", "."]
|
||||||
COPY ["Nemera.Presentation.Api/Nemera.Presentation.Api.csproj", "Nemera.Presentation.Api/"]
|
COPY ["Directory.Packages.props", "."]
|
||||||
COPY ["Nemera.Application/Nemera.Application.csproj", "Nemera.Application/"]
|
COPY ["global.json", "."]
|
||||||
COPY ["Nemera.Contracts/Nemera.Contracts.csproj", "Nemera.Contracts/"]
|
COPY ["src/AssemblyInfo_Shared.cs", "src/"]
|
||||||
COPY ["Nemera.Domain/Nemera.Domain.csproj", "Nemera.Domain/"]
|
COPY ["src/Directory.Build.props", "src/"]
|
||||||
COPY ["Nemera.Domain.SharedKernel/Nemera.Domain.SharedKernel.csproj", "Nemera.Domain.SharedKernel/"]
|
COPY ["src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj", "src/Nemera.Presentation.Api/"]
|
||||||
COPY ["Nemera.Infrastructure/Nemera.Infrastructure.csproj", "Nemera.Infrastructure/"]
|
COPY ["src/Nemera.Application/Nemera.Application.csproj", "src/Nemera.Application/"]
|
||||||
COPY ["Nemera.DataAccess/Nemera.DataAccess.csproj", "Nemera.DataAccess/"]
|
COPY ["src/Nemera.Contracts/Nemera.Contracts.csproj", "src/Nemera.Contracts/"]
|
||||||
COPY ["Nemera.Plugins.Contracts/Nemera.Plugins.Contracts.csproj", "Nemera.Plugins.Contracts/"]
|
COPY ["src/Nemera.Domain/Nemera.Domain.csproj", "src/Nemera.Domain/"]
|
||||||
|
COPY ["src/Nemera.Domain.SharedKernel/Nemera.Domain.SharedKernel.csproj", "src/Nemera.Domain.SharedKernel/"]
|
||||||
|
COPY ["src/Nemera.Infrastructure/Nemera.Infrastructure.csproj", "src/Nemera.Infrastructure/"]
|
||||||
|
COPY ["src/Nemera.DataAccess/Nemera.DataAccess.csproj", "src/Nemera.DataAccess/"]
|
||||||
|
COPY ["src/Nemera.Plugins.Contracts/Nemera.Plugins.Contracts.csproj", "src/Nemera.Plugins.Contracts/"]
|
||||||
|
|
||||||
RUN dotnet restore "./Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" /p:BaseOutputPath=/app/publish/
|
RUN dotnet restore "./src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" /p:BaseOutputPath=/app/publish/
|
||||||
|
|
||||||
# Build the project.
|
# Build the project.
|
||||||
COPY ["Nemera.Presentation.Api/", "Nemera.Presentation.Api/"]
|
COPY ["src/", "src/"]
|
||||||
COPY ["Nemera.Application/", "Nemera.Application/"]
|
COPY ["build/", "build/"]
|
||||||
COPY ["Nemera.Contracts/", "Nemera.Contracts/"]
|
WORKDIR /src/src/Nemera.Presentation.Api
|
||||||
COPY ["Nemera.Domain/", "Nemera.Domain/"]
|
|
||||||
COPY ["Nemera.Infrastructure/", "Nemera.Infrastructure/"]
|
|
||||||
COPY ["Nemera.DataAccess/", "Nemera.DataAccess/"]
|
|
||||||
COPY . .
|
|
||||||
WORKDIR /src/Nemera.Presentation.Api
|
|
||||||
|
|
||||||
RUN dotnet build "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
RUN dotnet build "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
||||||
|
|
||||||
@@ -50,7 +49,10 @@ FROM build AS publish
|
|||||||
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
|
||||||
RUN dotnet publish "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:BaseOutputPath=/app/publish/
|
RUN dotnet publish "./Nemera.Presentation.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:BaseOutputPath=/app/publish/ -p:BundledPluginsPredeployed=true
|
||||||
|
# Build the bundled plugins into the publish folder, so the image contains the same plugin binaries as the verified release artifact.
|
||||||
|
COPY ["plugins/", "/src/plugins/"]
|
||||||
|
RUN dotnet msbuild "/src/build/build.proj" -t:BuildBundledPlugins -p:Configuration=$BUILD_CONFIGURATION -p:NemeraPluginsOutputDirectory=/app/publish/plugins/
|
||||||
|
|
||||||
# ==== Stage 3: Run stage
|
# ==== Stage 3: Run stage
|
||||||
#FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
|
#FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
|
||||||
@@ -58,7 +60,8 @@ FROM base AS final
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=publish /app/publish .
|
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||||
|
COPY --from=publish --chown=app:app /app/publish .
|
||||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||||
ENV ASPNETCORE_HTTP_PORTS=5214
|
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||||
@@ -66,4 +69,4 @@ EXPOSE 5214
|
|||||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||||
|
|
||||||
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
||||||
# docker build --no-cache -t nemera-api -f Nemera.Presentation.Api/Dockerfile .
|
# docker build --no-cache -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile .
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# This image ships the published release artifacts, so the recorded plugin hashes and the image contents are the same files.
|
||||||
|
# Build it with the published API directory as the context:
|
||||||
|
# docker build -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile.release bin/api/publish
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||||
|
|
||||||
|
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||||
|
# FFmpeg is used by the API server to remux or transcode audio the browser cannot play directly.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends curl ffmpeg \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& mkdir -p /app /logs && chown -R app:app /app /logs
|
||||||
|
|
||||||
|
USER app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||||
|
COPY --chown=app:app . .
|
||||||
|
|
||||||
|
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||||
|
EXPOSE 5214
|
||||||
|
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<UserSecretsId>37d55c87-4374-4971-82e9-012fcaad1853</UserSecretsId>
|
<UserSecretsId>37d55c87-4374-4971-82e9-012fcaad1853</UserSecretsId>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
@@ -11,6 +10,9 @@
|
|||||||
<DockerfileTag>nemera-api</DockerfileTag>
|
<DockerfileTag>nemera-api</DockerfileTag>
|
||||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(OfficialReleaseBuild)' == 'true'">
|
||||||
|
<DefineConstants>$(DefineConstants);OFFICIAL_RELEASE_BUILD</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -69,4 +71,31 @@
|
|||||||
<ProjectReference Include="..\Nemera.Infrastructure\Nemera.Infrastructure.csproj" />
|
<ProjectReference Include="..\Nemera.Infrastructure\Nemera.Infrastructure.csproj" />
|
||||||
<ProjectReference Include="..\Nemera.DataAccess\Nemera.DataAccess.csproj" />
|
<ProjectReference Include="..\Nemera.DataAccess\Nemera.DataAccess.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(BundledPluginsCurrentManifest)' != ''">
|
||||||
|
<!-- A relative current manifest path is resolved against the repository root, not the API project directory. -->
|
||||||
|
<_BundledPluginsCurrentManifestPath Condition="$([System.IO.Path]::IsPathRooted('$(BundledPluginsCurrentManifest)'))">$(BundledPluginsCurrentManifest)</_BundledPluginsCurrentManifestPath>
|
||||||
|
<_BundledPluginsCurrentManifestPath Condition="!$([System.IO.Path]::IsPathRooted('$(BundledPluginsCurrentManifest)'))">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\$(BundledPluginsCurrentManifest)'))</_BundledPluginsCurrentManifestPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- The API embeds the trust manifests, but it does not reference or catalog the plugin projects. The release orchestrator generates and passes the current manifest. -->
|
||||||
|
<EmbeddedResource Include="..\..\build\BundledPlugins.manifest" LogicalName="Nemera.Presentation.Api.BundledPlugins.historical.manifest" Link="Core\Plugins\BundledPlugins.historical.manifest" />
|
||||||
|
<EmbeddedResource Include="..\..\build\BundledPlugins.deny.manifest" LogicalName="Nemera.Presentation.Api.BundledPlugins.deny.manifest" Link="Core\Plugins\BundledPlugins.deny.manifest" />
|
||||||
|
<EmbeddedResource Include="$(_BundledPluginsCurrentManifestPath)" LogicalName="Nemera.Presentation.Api.BundledPlugins.current.manifest" Link="Core\Plugins\BundledPlugins.current.manifest" Condition="'$(_BundledPluginsCurrentManifestPath)' != ''" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Official release builds receive the current manifest from build.proj. The API does not know the bundled plugin catalog. -->
|
||||||
|
<Target Name="ValidateBundledPluginsCurrentManifest" BeforeTargets="AssignTargetPaths" Condition="'$(OfficialReleaseBuild)' == 'true'">
|
||||||
|
<Error Condition="'$(_BundledPluginsCurrentManifestPath)' == ''" Text="Official release builds require the current bundled plugin manifest. Build the API through build.proj so the plugin binaries are hashed first." />
|
||||||
|
<Error Condition="'$(_BundledPluginsCurrentManifestPath)' != '' And !Exists('$(_BundledPluginsCurrentManifestPath)')" Text="The current bundled plugin manifest '$(_BundledPluginsCurrentManifestPath)' does not exist. Build the API through build.proj so the plugin binaries are hashed first." />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- Publishing uses the plugins folder already populated by the build, unless the orchestrator has already deployed the plugins. -->
|
||||||
|
<Target Name="CopyBundledPluginsToPublish" AfterTargets="Publish" Condition="'$(BundledPluginsPredeployed)' != 'true'">
|
||||||
|
<ItemGroup>
|
||||||
|
<_BundledPluginPublishFile Include="$(TargetDir)plugins/**/*" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Copy SourceFiles="@(_BundledPluginPublishFile)" DestinationFolder="$(PublishDir)plugins/%(RecursiveDir)" SkipUnchangedFiles="true" />
|
||||||
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,5 +1,16 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Nemera.Application.Common.DependencyInjection;
|
using Nemera.Application.Common.DependencyInjection;
|
||||||
using Nemera.DataAccess.Common.DependencyInjection;
|
using Nemera.DataAccess.Common.DependencyInjection;
|
||||||
using Nemera.DataAccess.Core.UoW;
|
using Nemera.DataAccess.Core.UoW;
|
||||||
@@ -13,20 +24,11 @@ using Nemera.Infrastructure.Core.Scheduling.Notifications;
|
|||||||
using Nemera.Presentation.Api.Common.DependencyInjection;
|
using Nemera.Presentation.Api.Common.DependencyInjection;
|
||||||
using Nemera.Presentation.Api.Common.Middlewares;
|
using Nemera.Presentation.Api.Common.Middlewares;
|
||||||
using Nemera.Presentation.Api.Common.Utilities;
|
using Nemera.Presentation.Api.Common.Utilities;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Nemera.Presentation.Api.Core.Plugins;
|
||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
||||||
using Microsoft.Extensions.FileProviders;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Scalar.AspNetCore;
|
using Scalar.AspNetCore;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -55,7 +57,9 @@ public class Program
|
|||||||
builder.Services.AddPresentationApiLayerServices(builder.Configuration);
|
builder.Services.AddPresentationApiLayerServices(builder.Configuration);
|
||||||
builder.Services.AddPresentationApiTelemetryServices(builder.Configuration, builder.Environment);
|
builder.Services.AddPresentationApiTelemetryServices(builder.Configuration, builder.Environment);
|
||||||
builder.Services.AddApplicationLayerServices();
|
builder.Services.AddApplicationLayerServices();
|
||||||
builder.Services.AddInfrastructureLayerServices(builder.Configuration);
|
// The trust list only labels plugins as Official. It is read once at startup and never prevents a plugin from loading.
|
||||||
|
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums = BundledPluginManifestReader.ReadExpectedChecksums();
|
||||||
|
builder.Services.AddInfrastructureLayerServices(builder.Configuration, bundledPluginChecksums);
|
||||||
builder.Services.AddDataAccessLayerServices();
|
builder.Services.AddDataAccessLayerServices();
|
||||||
builder.Services.AddDomainLayerServices();
|
builder.Services.AddDomainLayerServices();
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,5 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: Guid("D910C582-3905-4DD3-8BCA-0CB30852704E")]
|
[assembly: Guid("D910C582-3905-4DD3-8BCA-0CB30852704E")]
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Nemera.Presentation.Api.UnitTests")]
|
[assembly: InternalsVisibleTo("Nemera.Presentation.Api.UnitTests")]
|
||||||
|
[assembly: InternalsVisibleTo("Nemera.Presentation.Api.IntegrationTests")]
|
||||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||||
@@ -52,4 +52,9 @@ public class PluginDto
|
|||||||
/// Gets or sets the settings of the plugin.
|
/// Gets or sets the settings of the plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, string>? Settings { get; set; }
|
public Dictionary<string, string>? Settings { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether the plugin matches a trusted bundled plugin binary.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsOfficial { get; set; }
|
||||||
}
|
}
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>فشل الرفع</value>
|
<value>فشل الرفع</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>رسمي</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Upload fehlgeschlagen</value>
|
<value>Upload fehlgeschlagen</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Offiziell</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Upload failed</value>
|
<value>Upload failed</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Official</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Error al subir</value>
|
<value>Error al subir</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Oficial</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Échec du téléversement</value>
|
<value>Échec du téléversement</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Officiel</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Caricamento non riuscito</value>
|
<value>Caricamento non riuscito</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Ufficiale</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>アップロードに失敗しました</value>
|
<value>アップロードに失敗しました</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>公式</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Upload failed</value>
|
<value>Upload failed</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Official</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Încărcarea a eșuat</value>
|
<value>Încărcarea a eșuat</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Oficial</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>Не вдалося завантажити</value>
|
<value>Не вдалося завантажити</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>Офіційний</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -165,4 +165,7 @@
|
|||||||
<data name="UploadFailed" xml:space="preserve">
|
<data name="UploadFailed" xml:space="preserve">
|
||||||
<value>上传失败</value>
|
<value>上传失败</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Official" xml:space="preserve">
|
||||||
|
<value>官方</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -50,7 +50,14 @@
|
|||||||
@foreach (PluginDto plugin in Model)
|
@foreach (PluginDto plugin in Model)
|
||||||
{
|
{
|
||||||
<tr data-plugin-id="@plugin.Id">
|
<tr data-plugin-id="@plugin.Id">
|
||||||
<td>@plugin.Name</td>
|
<td>
|
||||||
|
@plugin.Name
|
||||||
|
@* Only a loaded plugin can carry the Official badge; a failed plugin has no trusted binary to describe. *@
|
||||||
|
@if (plugin.LoadStatus == PluginLoadStatus.Loaded && plugin.IsOfficial)
|
||||||
|
{
|
||||||
|
<span class="plugin-official-badge">@_localizer["Official"]</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
<td>@plugin.Author</td>
|
<td>@plugin.Author</td>
|
||||||
<td>@plugin.Version</td>
|
<td>@plugin.Version</td>
|
||||||
<td>@plugin.Description</td>
|
<td>@plugin.Description</td>
|
||||||
|
|||||||
@@ -11,22 +11,25 @@ EXPOSE 5012
|
|||||||
|
|
||||||
|
|
||||||
# ==== Stage 1: Build stage
|
# ==== Stage 1: Build stage
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:10.0.100 AS build
|
||||||
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
# Restore NuGet packages (keeping this section separate from the rest of the project files allows Docker to cache the restored packages).
|
||||||
COPY ["AssemblyInfo_Shared.cs", "."]
|
COPY ["Directory.Build.props", "."]
|
||||||
COPY ["Nemera.Presentation.Web/Nemera.Presentation.Web.csproj", "Nemera.Presentation.Web/"]
|
COPY ["Directory.Packages.props", "."]
|
||||||
|
COPY ["global.json", "."]
|
||||||
|
COPY ["src/AssemblyInfo_Shared.cs", "src/"]
|
||||||
|
COPY ["src/Directory.Build.props", "src/"]
|
||||||
|
COPY ["src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj", "src/Nemera.Presentation.Web/"]
|
||||||
|
|
||||||
RUN dotnet restore "./Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" /p:BaseOutputPath=/app/publish/
|
RUN dotnet restore "./src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" /p:BaseOutputPath=/app/publish/
|
||||||
|
|
||||||
# Build the project.
|
# Build the project.
|
||||||
COPY ["Nemera.Presentation.Web/", "Nemera.Presentation.Web/"]
|
COPY ["src/", "src/"]
|
||||||
COPY . .
|
WORKDIR /src/src/Nemera.Presentation.Web
|
||||||
WORKDIR /src/Nemera.Presentation.Web
|
|
||||||
|
|
||||||
RUN dotnet build "./Nemera.Presentation.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
RUN dotnet build "./Nemera.Presentation.Web.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BaseOutputPath=/app/publish/
|
||||||
|
|
||||||
@@ -43,7 +46,7 @@ FROM base AS final
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=publish /app/publish .
|
COPY --from=publish --chown=app:app /app/publish .
|
||||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||||
@@ -51,4 +54,4 @@ EXPOSE 5012
|
|||||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||||
|
|
||||||
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
# To build this Docker image, run the following command from the root of the project (location of the .slnx solution file):
|
||||||
# docker build --no-cache -t nemera-web -f Nemera.Presentation.Web/Dockerfile .
|
# docker build --no-cache -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile .
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# This image ships the published release artifacts, so the image contents are the same files the release workflow exported.
|
||||||
|
# Build it with the published Web directory as the context:
|
||||||
|
# docker build -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile.release bin/web/publish
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||||
|
|
||||||
|
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends curl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& mkdir /logs && chown -R app:app /logs
|
||||||
|
|
||||||
|
USER app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --chown=app:app . .
|
||||||
|
|
||||||
|
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||||
|
EXPOSE 5012
|
||||||
|
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\web\</BaseOutputPath>
|
<BaseOutputPath>$(RepoRoot)bin/web/</BaseOutputPath>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<WarningsNotAsErrors>$(WarningsNotAsErrors);EXTEXP0018</WarningsNotAsErrors>
|
<WarningsNotAsErrors>$(WarningsNotAsErrors);EXTEXP0018</WarningsNotAsErrors>
|
||||||
<UserSecretsId>10a94da9-18ed-4c70-a9da-b461e08958c4</UserSecretsId>
|
<UserSecretsId>10a94da9-18ed-4c70-a9da-b461e08958c4</UserSecretsId>
|
||||||
|
|||||||
@@ -2516,3 +2516,17 @@ html.audio-player-initializing .audio-player-container {
|
|||||||
animation: none;
|
animation: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Informational badge for a loaded bundled plugin whose binary matches the release trust list. */
|
||||||
|
.plugin-official-badge {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 0.4rem;
|
||||||
|
padding: 0 0.35rem;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
border-radius: 2px;
|
||||||
|
font-size: 0.7em;
|
||||||
|
line-height: 1.4;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
+13
-1
@@ -31,7 +31,9 @@
|
|||||||
<Folder Name="/docs/manual/using-nemera/">
|
<Folder Name="/docs/manual/using-nemera/">
|
||||||
<File Path="../docs/manual/using-nemera/index.md" />
|
<File Path="../docs/manual/using-nemera/index.md" />
|
||||||
</Folder>
|
</Folder>
|
||||||
<Folder Name="/docs/technical/" />
|
<Folder Name="/docs/technical/">
|
||||||
|
<File Path="../docs/technical/RELEASING.md" />
|
||||||
|
</Folder>
|
||||||
<Folder Name="/docs/technical/api/" />
|
<Folder Name="/docs/technical/api/" />
|
||||||
<Folder Name="/docs/technical/api/admin/" />
|
<Folder Name="/docs/technical/api/admin/" />
|
||||||
<Folder Name="/docs/technical/api/admin/authorization/">
|
<Folder Name="/docs/technical/api/admin/authorization/">
|
||||||
@@ -359,6 +361,16 @@
|
|||||||
<Project Path="../plugins/Nemera.Plugins.OpenLibrary/Nemera.Plugins.OpenLibrary.csproj" />
|
<Project Path="../plugins/Nemera.Plugins.OpenLibrary/Nemera.Plugins.OpenLibrary.csproj" />
|
||||||
<Project Path="../plugins/Nemera.Plugins.Pdf/Nemera.Plugins.Pdf.csproj" />
|
<Project Path="../plugins/Nemera.Plugins.Pdf/Nemera.Plugins.Pdf.csproj" />
|
||||||
</Folder>
|
</Folder>
|
||||||
|
<Folder Name="/build/">
|
||||||
|
<File Path="../Directory.Build.props" />
|
||||||
|
<File Path="../global.json" />
|
||||||
|
<File Path="../build/build.proj" />
|
||||||
|
<File Path="../build/BundledPlugins.props" />
|
||||||
|
<File Path="../build/BundledPlugins.manifest" />
|
||||||
|
<File Path="../build/BundledPlugins.deny.manifest" />
|
||||||
|
<File Path="../src/Nemera.Presentation.Api/Dockerfile.release" />
|
||||||
|
<File Path="../src/Nemera.Presentation.Web/Dockerfile.release" />
|
||||||
|
</Folder>
|
||||||
<Folder Name="/Solution Items/">
|
<Folder Name="/Solution Items/">
|
||||||
<File Path="../.editorconfig" />
|
<File Path="../.editorconfig" />
|
||||||
</Folder>
|
</Folder>
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
<DockerPublishLocally>False</DockerPublishLocally>
|
<DockerPublishLocally>False</DockerPublishLocally>
|
||||||
<ProjectGuid>d4c61542-fc91-47fa-b1d2-11cc99617454</ProjectGuid>
|
<ProjectGuid>d4c61542-fc91-47fa-b1d2-11cc99617454</ProjectGuid>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- Keep the compose project's empty build output under the repository bin directory. -->
|
||||||
|
<OutputPath>$(RepoRoot)bin/docker-compose/$(Configuration)/</OutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="docker-compose.override.yml">
|
<None Include="docker-compose.override.yml">
|
||||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||||
@@ -14,6 +18,6 @@
|
|||||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||||
</None>
|
</None>
|
||||||
<None Include="docker-compose.yml" />
|
<None Include="docker-compose.yml" />
|
||||||
<None Include=".dockerignore" />
|
<None Include="..\.dockerignore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -2,8 +2,8 @@ services:
|
|||||||
nemera-api:
|
nemera-api:
|
||||||
container_name: nemera-api
|
container_name: nemera-api
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ..
|
||||||
dockerfile: Nemera.Presentation.Api/Dockerfile
|
dockerfile: src/Nemera.Presentation.Api/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- ASPNETCORE_ENVIRONMENT=Development
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
- ASPNETCORE_HTTP_PORTS=5214
|
- ASPNETCORE_HTTP_PORTS=5214
|
||||||
@@ -18,8 +18,8 @@ services:
|
|||||||
nemera-web:
|
nemera-web:
|
||||||
container_name: nemera-web
|
container_name: nemera-web
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ..
|
||||||
dockerfile: Nemera.Presentation.Web/Dockerfile
|
dockerfile: src/Nemera.Presentation.Web/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- ASPNETCORE_ENVIRONMENT=Development
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
- ASPNETCORE_HTTP_PORTS=5012
|
- ASPNETCORE_HTTP_PORTS=5012
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ services:
|
|||||||
container_name: nemera-api
|
container_name: nemera-api
|
||||||
image: ${DOCKER_REGISTRY-}nemera-api
|
image: ${DOCKER_REGISTRY-}nemera-api
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ..
|
||||||
dockerfile: Nemera.Presentation.Api/Dockerfile
|
dockerfile: src/Nemera.Presentation.Api/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- LOG_PATH=/logs
|
- LOG_PATH=/logs
|
||||||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||||
@@ -26,8 +26,8 @@ services:
|
|||||||
container_name: nemera-web
|
container_name: nemera-web
|
||||||
image: ${DOCKER_REGISTRY-}nemera-web
|
image: ${DOCKER_REGISTRY-}nemera-web
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ..
|
||||||
dockerfile: Nemera.Presentation.Web/Dockerfile
|
dockerfile: src/Nemera.Presentation.Web/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- LOG_PATH=/logs
|
- LOG_PATH=/logs
|
||||||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
+5
-2
@@ -29,6 +29,7 @@ public class PluginResponseFixture
|
|||||||
/// <param name="loadStatus">Optional. The load status of the plugin.</param>
|
/// <param name="loadStatus">Optional. The load status of the plugin.</param>
|
||||||
/// <param name="loadError">Optional. The error message when the plugin failed to load.</param>
|
/// <param name="loadError">Optional. The error message when the plugin failed to load.</param>
|
||||||
/// <param name="settings">Optional. The settings of the plugin.</param>
|
/// <param name="settings">Optional. The settings of the plugin.</param>
|
||||||
|
/// <param name="isOfficial">Optional. Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||||
/// <returns>The created <see cref="PluginResponse"/>.</returns>
|
/// <returns>The created <see cref="PluginResponse"/>.</returns>
|
||||||
public PluginResponse Create(
|
public PluginResponse Create(
|
||||||
Guid? id = null,
|
Guid? id = null,
|
||||||
@@ -38,7 +39,8 @@ public class PluginResponseFixture
|
|||||||
string? description = null,
|
string? description = null,
|
||||||
PluginLoadStatus? loadStatus = null,
|
PluginLoadStatus? loadStatus = null,
|
||||||
string? loadError = null,
|
string? loadError = null,
|
||||||
IReadOnlyDictionary<string, string>? settings = null)
|
IReadOnlyDictionary<string, string>? settings = null,
|
||||||
|
bool isOfficial = false)
|
||||||
{
|
{
|
||||||
return new PluginResponse(
|
return new PluginResponse(
|
||||||
id ?? Guid.NewGuid(),
|
id ?? Guid.NewGuid(),
|
||||||
@@ -51,7 +53,8 @@ public class PluginResponseFixture
|
|||||||
settings ?? new Dictionary<string, string>
|
settings ?? new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
||||||
}
|
},
|
||||||
|
isOfficial
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
@@ -18,7 +17,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\plugins\Nemera.Plugins.Pdf\Nemera.Plugins.Pdf.csproj" />
|
|
||||||
<ProjectReference Include="..\..\..\src\Nemera.Plugins.Contracts\Nemera.Plugins.Contracts.csproj" />
|
<ProjectReference Include="..\..\..\src\Nemera.Plugins.Contracts\Nemera.Plugins.Contracts.csproj" />
|
||||||
<ProjectReference Include="..\..\Common\Nemera.Contracts.Fixtures\Nemera.Contracts.Fixtures.csproj" />
|
<ProjectReference Include="..\..\Common\Nemera.Contracts.Fixtures\Nemera.Contracts.Fixtures.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Nemera.Presentation.Api.Fixtures.Core.Plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fixture class for computing the SHA-256 checksums of bundled plugin files.
|
||||||
|
/// </summary>
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class BundledPluginFileHashFixture
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the SHA-256 checksum of the file at <paramref name="path"/>, in the uppercase hexadecimal form the trust manifest uses.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path of the file to hash.</param>
|
||||||
|
/// <returns>The uppercase hexadecimal SHA-256 checksum.</returns>
|
||||||
|
public string Create(string path)
|
||||||
|
{
|
||||||
|
// Convert.ToHexString returns uppercase hexadecimal, which is the form the trust manifest uses.
|
||||||
|
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
return Convert.ToHexString(SHA256.HashData(fileStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
+4
-2
@@ -26,8 +26,9 @@ public class PluginDtoFixture
|
|||||||
/// <param name="author">Optional author of the plugin.</param>
|
/// <param name="author">Optional author of the plugin.</param>
|
||||||
/// <param name="version">Optional version of the plugin.</param>
|
/// <param name="version">Optional version of the plugin.</param>
|
||||||
/// <param name="loadStatus">Optional load status of the plugin.</param>
|
/// <param name="loadStatus">Optional load status of the plugin.</param>
|
||||||
|
/// <param name="isOfficial">Optional. Whether the plugin matches a trusted bundled plugin binary.</param>
|
||||||
/// <returns>A configured <see cref="PluginDto"/> instance.</returns>
|
/// <returns>A configured <see cref="PluginDto"/> instance.</returns>
|
||||||
public PluginDto Create(Guid? id = null, string? name = null, string? author = null, string? version = null, PluginLoadStatus? loadStatus = null)
|
public PluginDto Create(Guid? id = null, string? name = null, string? author = null, string? version = null, PluginLoadStatus? loadStatus = null, bool isOfficial = false)
|
||||||
{
|
{
|
||||||
return new PluginDto
|
return new PluginDto
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,8 @@ public class PluginDtoFixture
|
|||||||
Description = _faker.Lorem.Sentence(),
|
Description = _faker.Lorem.Sentence(),
|
||||||
LoadStatus = loadStatus ?? PluginLoadStatus.Loaded,
|
LoadStatus = loadStatus ?? PluginLoadStatus.Loaded,
|
||||||
LoadError = null,
|
LoadError = null,
|
||||||
Settings = null
|
Settings = null,
|
||||||
|
IsOfficial = isOfficial
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\web\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<IsTestProject>false</IsTestProject>
|
<IsTestProject>false</IsTestProject>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<Project>
|
||||||
|
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
|
||||||
|
|
||||||
|
<!-- Test binaries stay under the repository bin directory when a test project is built outside the solution. Each project keeps its own folder so manifests and dependencies do not collide. -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<BaseOutputPath>$(RepoRoot)bin/tests/$(MSBuildProjectName)/</BaseOutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
+3
-3
@@ -19,7 +19,7 @@ public class PluginLoadContextTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
PluginLoadContext sut = new(temporaryPluginDirectory.Path, "test-context");
|
PluginLoadContext sut = new(Path.Combine(temporaryPluginDirectory.Path, "Plugin.dll"), "test-context");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Assembly result = sut.LoadFromAssemblyName(typeof(object).Assembly.GetName());
|
Assembly result = sut.LoadFromAssemblyName(typeof(object).Assembly.GetName());
|
||||||
@@ -35,7 +35,7 @@ public class PluginLoadContextTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
string destinationPath = temporaryPluginDirectory.CopyDll(Path.Combine(AppContext.BaseDirectory, "Nemera.TestPlugin.dll"), "PluginLocalDependency.dll");
|
string destinationPath = temporaryPluginDirectory.CopyDll(Path.Combine(AppContext.BaseDirectory, "Nemera.TestPlugin.dll"), "PluginLocalDependency.dll");
|
||||||
PluginLoadContext sut = new(temporaryPluginDirectory.Path, "test-context");
|
PluginLoadContext sut = new(destinationPath, "test-context");
|
||||||
MethodInfo loadMethod = typeof(PluginLoadContext).GetMethod("Load", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
MethodInfo loadMethod = typeof(PluginLoadContext).GetMethod("Load", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -52,7 +52,7 @@ public class PluginLoadContextTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
PluginLoadContext sut = new(temporaryPluginDirectory.Path, "test-context");
|
PluginLoadContext sut = new(Path.Combine(temporaryPluginDirectory.Path, "Missing.dll"), "test-context");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Action act = () => sut.LoadFromAssemblyName(new AssemblyName($"Definitely.Not.Resolvable.{Guid.NewGuid()}"));
|
Action act = () => sut.LoadFromAssemblyName(new AssemblyName($"Definitely.Not.Resolvable.{Guid.NewGuid()}"));
|
||||||
|
|||||||
+227
-13
@@ -1,12 +1,18 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Nemera.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
|
||||||
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
using Nemera.Infrastructure.Common.Models.DTO.Plugins;
|
||||||
using Nemera.Infrastructure.Core.Plugins;
|
using Nemera.Infrastructure.Core.Plugins;
|
||||||
using Nemera.Plugins.Contracts.Core.Plugins;
|
using Nemera.Plugins.Contracts.Core.Plugins;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Nemera.Plugins.Contracts.Core.Reading;
|
||||||
|
using Nemera.Plugins.Pdf.Fixtures.Core.Pdf;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Security.Cryptography;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
namespace Nemera.Infrastructure.IntegrationTests.Core.Plugins;
|
namespace Nemera.Infrastructure.IntegrationTests.Core.Plugins;
|
||||||
@@ -17,6 +23,46 @@ namespace Nemera.Infrastructure.IntegrationTests.Core.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class PluginLoaderTests
|
public class PluginLoaderTests
|
||||||
{
|
{
|
||||||
|
private static readonly IReadOnlyDictionary<string, IReadOnlySet<string>> s_emptyBundledPluginChecksums = new Dictionary<string, IReadOnlySet<string>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier of the bundled PDF plugin used by the deployed plugin loading test.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Guid s_pdfPluginId = new("c2f9b8f0-5a4b-4e3d-8b2f-7e4a9c1d3e5f");
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task LoadPlugins_WhenLoadingTheBundledPdfPlugin_ShouldRenderAPdfPage()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
string repositoryRoot = FindRepositoryRoot();
|
||||||
|
DirectoryInfo testOutputDirectory = new(AppContext.BaseDirectory);
|
||||||
|
string configuration = testOutputDirectory.Parent?.Name
|
||||||
|
?? throw new InvalidOperationException("The test configuration could not be determined from the test output directory.");
|
||||||
|
string targetFramework = testOutputDirectory.Name;
|
||||||
|
string pluginsDirectory = Path.Combine(repositoryRoot, "bin", "api", configuration, targetFramework, "plugins");
|
||||||
|
Assert.True(Directory.Exists(pluginsDirectory), $"The deployed plugins directory '{pluginsDirectory}' does not exist. Build the solution before running this test so the bundled plugins are deployed.");
|
||||||
|
using TemporaryPluginDirectory temporaryDirectory = new();
|
||||||
|
string pdfPath = Path.Combine(temporaryDirectory.Path, "minimal.pdf");
|
||||||
|
TestPdfFileFactory.CreateMinimalPdf(pdfPath);
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(pluginsDirectory, services, s_emptyBundledPluginChecksums);
|
||||||
|
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||||
|
IBookReader pdfReader = serviceProvider.GetRequiredKeyedService<IBookReader>(s_pdfPluginId);
|
||||||
|
string workingDirectory = Path.Combine(temporaryDirectory.Path, "work");
|
||||||
|
ReadingDocumentDto document = await pdfReader.OpenAsync(pdfPath, workingDirectory, shouldRenderPdfAsImages: false, CancellationToken.None);
|
||||||
|
byte[] pageImage = await pdfReader.GetResourceAsync(pdfPath, workingDirectory, "page:1", CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
Assert.Empty(result.Warnings);
|
||||||
|
Assert.Contains(result.Plugins, plugin => plugin.Id == s_pdfPluginId);
|
||||||
|
Assert.NotEmpty(result.LoadedPlugins);
|
||||||
|
Assert.Single(document.Spine);
|
||||||
|
Assert.NotEmpty(pageImage);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LoadPlugins_WhenDirectoryDoesNotExist_ShouldReturnNoPluginsAndNoErrors()
|
public void LoadPlugins_WhenDirectoryDoesNotExist_ShouldReturnNoPluginsAndNoErrors()
|
||||||
{
|
{
|
||||||
@@ -25,11 +71,12 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(nonExistentDirectory, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(nonExistentDirectory, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
Assert.Empty(result.Errors);
|
Assert.Empty(result.Errors);
|
||||||
|
Assert.Empty(result.LoadedPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -41,7 +88,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -60,7 +107,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -77,7 +124,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -93,14 +140,16 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IPlugin loadedPlugin = Assert.Single(result.Plugins);
|
IPlugin loadedPlugin = Assert.Single(result.Plugins);
|
||||||
Assert.Empty(result.Errors);
|
Assert.Empty(result.Errors);
|
||||||
|
// A plugin that is not Official is expected to come from an uploaded assembly without a dependency manifest, so the loader does not warn.
|
||||||
|
Assert.Empty(result.Warnings);
|
||||||
Assert.Equal(Guid.Parse("7B5A3E5D-9B7F-4A1E-8D9C-2F3A4B5C6D7E"), loadedPlugin.Id);
|
Assert.Equal(Guid.Parse("7B5A3E5D-9B7F-4A1E-8D9C-2F3A4B5C6D7E"), loadedPlugin.Id);
|
||||||
Assert.Equal("Test Plugin", loadedPlugin.Name);
|
Assert.Equal("Test Plugin", loadedPlugin.Name);
|
||||||
Assert.Contains(services, descriptor => descriptor.ImplementationInstance as string == "plugin-services-registered");
|
Assert.Contains(services, descriptor => (descriptor.ImplementationInstance as string) == "plugin-services-registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -112,7 +161,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Single(result.Plugins);
|
Assert.Single(result.Plugins);
|
||||||
@@ -121,6 +170,130 @@ public class PluginLoaderTests
|
|||||||
Assert.Single(result.LoadContexts);
|
Assert.Single(result.LoadContexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenPluginDependencyManifestIsInvalid_ShouldLoadPluginAndRecordWarning()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
temporaryPluginDirectory.CopyDll(GetTestPluginAssemblyPath());
|
||||||
|
temporaryPluginDirectory.CreateFile("Nemera.TestPlugin.deps.json", "{ this is not a valid dependency manifest");
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result.Plugins);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
string warning = Assert.Single(result.Warnings);
|
||||||
|
Assert.Contains("Nemera.TestPlugin.dll", warning);
|
||||||
|
Assert.Contains("dependency manifest", warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenOfficialPluginHasNoDependencyManifest_ShouldLoadPluginAndRecordWarning()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
string assemblyPath = GetTestPluginAssemblyPath();
|
||||||
|
temporaryPluginDirectory.CopyDll(assemblyPath);
|
||||||
|
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums =
|
||||||
|
CreateBundledPluginChecksums("Nemera.TestPlugin.dll", ComputeChecksum(assemblyPath));
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, bundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result.Plugins);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
string warning = Assert.Single(result.Warnings);
|
||||||
|
Assert.Contains("Nemera.TestPlugin.dll", warning);
|
||||||
|
Assert.Contains("no dependency manifest", warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenBundledPluginChecksumMatches_ShouldLoadPluginAndMarkItOfficial()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
string assemblyPath = GetTestPluginAssemblyPath();
|
||||||
|
temporaryPluginDirectory.CopyDll(assemblyPath);
|
||||||
|
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums =
|
||||||
|
CreateBundledPluginChecksums("Nemera.TestPlugin.dll", ComputeChecksum(assemblyPath));
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, bundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
IPlugin loadedPlugin = Assert.Single(result.Plugins);
|
||||||
|
Assert.Equal(Guid.Parse("7B5A3E5D-9B7F-4A1E-8D9C-2F3A4B5C6D7E"), loadedPlugin.Id);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
LoadedPluginMetadataDto metadata = Assert.Single(result.LoadedPlugins);
|
||||||
|
Assert.Equal("Nemera.TestPlugin.dll", metadata.AssemblyFileName);
|
||||||
|
Assert.True(metadata.IsOfficial);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenBundledPluginChecksumDoesNotMatch_ShouldLoadPluginWithoutMarkingItOfficial()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
temporaryPluginDirectory.CopyDll(GetTestPluginAssemblyPath());
|
||||||
|
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums =
|
||||||
|
CreateBundledPluginChecksums("Nemera.TestPlugin.dll", new string('0', 64));
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, bundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result.Plugins);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
LoadedPluginMetadataDto metadata = Assert.Single(result.LoadedPlugins);
|
||||||
|
Assert.False(metadata.IsOfficial);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenPluginIsNotInTheBundledManifest_ShouldLoadPluginWithoutMarkingItOfficial()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
temporaryPluginDirectory.CopyDll(GetTestPluginAssemblyPath());
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result.Plugins);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
LoadedPluginMetadataDto metadata = Assert.Single(result.LoadedPlugins);
|
||||||
|
Assert.False(metadata.IsOfficial);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LoadPlugins_WhenBundledManifestListsMultipleChecksums_ShouldMarkTheMatchingOneOfficial()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using TemporaryPluginDirectory temporaryPluginDirectory = new();
|
||||||
|
string assemblyPath = GetTestPluginAssemblyPath();
|
||||||
|
temporaryPluginDirectory.CopyDll(assemblyPath);
|
||||||
|
IReadOnlyDictionary<string, IReadOnlySet<string>> bundledPluginChecksums =
|
||||||
|
CreateBundledPluginChecksums("Nemera.TestPlugin.dll", new string('0', 64), ComputeChecksum(assemblyPath));
|
||||||
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, bundledPluginChecksums);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result.Plugins);
|
||||||
|
Assert.Empty(result.Errors);
|
||||||
|
LoadedPluginMetadataDto metadata = Assert.Single(result.LoadedPlugins);
|
||||||
|
Assert.True(metadata.IsOfficial);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LoadPlugins_WhenDirectoryContainsManagedDependencyAssemblyAlongsideAPlugin_ShouldSkipTheDependencyAndLoadOnlyThePlugin()
|
public void LoadPlugins_WhenDirectoryContainsManagedDependencyAssemblyAlongsideAPlugin_ShouldSkipTheDependencyAndLoadOnlyThePlugin()
|
||||||
{
|
{
|
||||||
@@ -134,7 +307,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
IPlugin loadedPlugin = Assert.Single(result.Plugins);
|
IPlugin loadedPlugin = Assert.Single(result.Plugins);
|
||||||
@@ -154,7 +327,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -173,7 +346,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -192,7 +365,7 @@ public class PluginLoaderTests
|
|||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services);
|
PluginLoadResultDto result = PluginLoader.LoadPlugins(temporaryPluginDirectory.Path, services, s_emptyBundledPluginChecksums);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(result.Plugins);
|
Assert.Empty(result.Plugins);
|
||||||
@@ -224,6 +397,47 @@ public class PluginLoaderTests
|
|||||||
return Path.Combine(AppContext.BaseDirectory, "Microsoft.AspNetCore.SignalR.Core.dll");
|
return Path.Combine(AppContext.BaseDirectory, "Microsoft.AspNetCore.SignalR.Core.dll");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a bundled plugin trust list containing one assembly with the provided checksums.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assemblyFileName">The file name of the bundled plugin assembly.</param>
|
||||||
|
/// <param name="checksums">The checksums the assembly is allowed to have.</param>
|
||||||
|
/// <returns>The bundled plugin trust list.</returns>
|
||||||
|
private static IReadOnlyDictionary<string, IReadOnlySet<string>> CreateBundledPluginChecksums(string assemblyFileName, params string[] checksums)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, IReadOnlySet<string>>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
[assemblyFileName] = new HashSet<string>(checksums, StringComparer.OrdinalIgnoreCase)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the SHA-256 checksum of the file at <paramref name="path"/>, in the hexadecimal form the bundled plugin trust manifest uses.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path of the file to hash.</param>
|
||||||
|
/// <returns>The uppercase hexadecimal SHA-256 checksum.</returns>
|
||||||
|
private static string ComputeChecksum(string path)
|
||||||
|
{
|
||||||
|
using (FileStream fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
return Convert.ToHexString(SHA256.HashData(fileStream));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Locates the repository root from the test output directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The absolute path of the repository root.</returns>
|
||||||
|
private static string FindRepositoryRoot()
|
||||||
|
{
|
||||||
|
DirectoryInfo? directory = new(AppContext.BaseDirectory);
|
||||||
|
while (directory is not null)
|
||||||
|
{
|
||||||
|
if (File.Exists(Path.Combine(directory.FullName, "src", "Nemera.slnx")))
|
||||||
|
return directory.FullName;
|
||||||
|
directory = directory.Parent;
|
||||||
|
}
|
||||||
|
throw new InvalidOperationException("The repository root could not be located from the test output directory.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test helper managing a temporary plugins directory, deleted when the test finishes.
|
/// Test helper managing a temporary plugins directory, deleted when the test finishes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
+1
@@ -44,6 +44,7 @@
|
|||||||
<ProjectReference Include="..\..\Common\Nemera.Application.Fixtures\Nemera.Application.Fixtures.csproj" />
|
<ProjectReference Include="..\..\Common\Nemera.Application.Fixtures\Nemera.Application.Fixtures.csproj" />
|
||||||
<ProjectReference Include="..\..\Common\Nemera.Contracts.Fixtures\Nemera.Contracts.Fixtures.csproj" />
|
<ProjectReference Include="..\..\Common\Nemera.Contracts.Fixtures\Nemera.Contracts.Fixtures.csproj" />
|
||||||
<ProjectReference Include="..\..\Common\Nemera.Infrastructure.Fixtures\Nemera.Infrastructure.Fixtures.csproj" />
|
<ProjectReference Include="..\..\Common\Nemera.Infrastructure.Fixtures\Nemera.Infrastructure.Fixtures.csproj" />
|
||||||
|
<ProjectReference Include="..\..\Common\Nemera.Plugins.Pdf.Fixtures\Nemera.Plugins.Pdf.Fixtures.csproj" />
|
||||||
<ProjectReference Include="..\..\Common\Nemera.TestPlugin\Nemera.TestPlugin.csproj" />
|
<ProjectReference Include="..\..\Common\Nemera.TestPlugin\Nemera.TestPlugin.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user