Skip to content

Commit

Permalink
feat(api): add schema validation endpoint
Browse files Browse the repository at this point in the history
add get endpoint for credentials
add swagger
add post endpoint to validate json schemas

Refs: #4 #6 #11
  • Loading branch information
Phil91 committed Mar 5, 2024
1 parent e94a727 commit ab55b55
Show file tree
Hide file tree
Showing 45 changed files with 1,201 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0']
dotnet-version: ['7.0']

steps:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0']
dotnet-version: ['7.0']

steps:
- name: Set up JDK 17
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.tests-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0']
dotnet-version: ['7.0']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository contains the backend code for the SSI Authority & Schema Registr

## How to build and run

Install [the .NET 8.0 SDK](https://www.microsoft.com/net/download).
Install [the .NET 7.0 SDK](https://www.microsoft.com/net/download).

Run the following command from the CLI:

Expand Down
35 changes: 35 additions & 0 deletions docker/Dockerfile-registry-migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###############################################################
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
###############################################################

FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine AS base

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine-amd64 AS publish
WORKDIR /
COPY LICENSE NOTICE.md DEPENDENCIES /
COPY /src/database /src/database
WORKDIR /src/database/SsiAuthoritySchemaRegistry.Migrations
RUN dotnet publish "SsiAuthoritySchemaRegistry.Migrations.csproj" -c Release -o /migrations/publish

FROM base AS final
ENV COMPlus_EnableDiagnostics=0
WORKDIR /migrations
COPY --from=publish /migrations/publish .
RUN chown -R 1000:3000 /migrations
USER 1000:3000
ENTRYPOINT ["dotnet", "Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Migrations.dll"]
37 changes: 37 additions & 0 deletions docker/Dockerfile-registry-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###############################################################
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
###############################################################

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine-amd64 AS publish
WORKDIR /
COPY LICENSE NOTICE.md DEPENDENCIES /
COPY src/ src/
WORKDIR /src/hub/SsiAuthoritySchemaRegistry.Service
RUN dotnet publish "SsiAuthoritySchemaRegistry.Service.csproj" -c Release -o /app/publish

FROM base AS final
ENV COMPlus_EnableDiagnostics=0
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_URLS http://+:8080
EXPOSE 8080
RUN chown -R 1000:3000 /app
USER 1000:3000
ENTRYPOINT ["dotnet", "Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.dll"]
22 changes: 22 additions & 0 deletions docker/notice-registry-migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Notice for Docker image

DockerHub: [https://hub.docker.com/r/tractusx/ssi-authority-schema-registry](https://hub.docker.com/r/tractusx/ssi-authority-schema-registry-migrations)

Eclipse Tractus-X product(s) installed within the image:

__SSI Authority & Schema Registry Migrations__

- GitHub: https://github.com/eclipse-tractusx/ssi-authority-schema-registry
- Project home: https://projects.eclipse.org/projects/automotive.tractusx
- Dockerfile: https://github.com/eclipse-tractusx/ssi-authority-schema-registry/blob/main/docker/Dockerfile-registry-migrations
- Project license: [Apache License, Version 2.0](https://github.com/eclipse-tractusx/ssi-authority-schema-registry/blob/main/LICENSE)

__Used base images__

- Dockerfile: [mcr.microsoft.com/dotnet/runtime:7.0-alpine](https://github.com/dotnet/dotnet-docker/blob/main/src/runtime/7.0/alpine3.19/amd64/Dockerfile)
- GitHub project: [https://github.com/dotnet/dotnet-docker](https://github.com/dotnet/dotnet-docker)
- DockerHub: [https://hub.docker.com/_/microsoft-dotnet-runtime](https://hub.docker.com/_/microsoft-dotnet-runtime)

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
22 changes: 22 additions & 0 deletions docker/notice-registry-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Notice for Docker image

DockerHub: [https://hub.docker.com/r/tractusx/ssi-authority-schema-registry-service](https://hub.docker.com/r/tractusx/ssi-authority-schema-registry-service)

Eclipse Tractus-X product(s) installed within the image:

__SSI Authority & Schema Registry Service__

- GitHub: https://github.com/eclipse-tractusx/ssi-authority-schema-registry
- Project home: https://projects.eclipse.org/projects/automotive.tractusx
- Dockerfile: https://github.com/eclipse-tractusx/ssi-authority-schema-registry/blob/main/docker/Dockerfile-registry-service
- Project license: [Apache License, Version 2.0](https://github.com/eclipse-tractusx/ssi-authority-schema-registry/blob/main/LICENSE)

__Used base images__

- Dockerfile: [mcr.microsoft.com/dotnet/aspnet:7.0-alpine](https://github.com/dotnet/dotnet-docker/blob/main/src/aspnet/7.0/alpine3.19/amd64/Dockerfile)
- GitHub project: [https://github.com/dotnet/dotnet-docker](https://github.com/dotnet/dotnet-docker)
- DockerHub: [https://hub.docker.com/_/microsoft-dotnet-aspnet](https://hub.docker.com/_/microsoft-dotnet-aspnet)

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
- Copyright (c) 2024 Contributors to the Eclipse Foundation
-
- See the NOTICE file(s) distributed with this work for additional
- information regarding copyright ownership.
Expand Down
7 changes: 7 additions & 0 deletions src/SsiAuthoritySchemaRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SsiAuthoritySchemaRegistry.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SsiAuthoritySchemaRegistry.Service", "registry\SsiAuthoritySchemaRegistry.Service\SsiAuthoritySchemaRegistry.Service.csproj", "{1AA22A40-802C-407B-AABF-E250931E4673}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SsiAuthoritySchemaRegistry.DbAccess", "database\SsiAuthoritySchemaRegistry.DbAccess\SsiAuthoritySchemaRegistry.DbAccess.csproj", "{F52F0D32-5BDD-499F-8CA2-A1FE5867B379}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -28,10 +30,15 @@ Global
{1AA22A40-802C-407B-AABF-E250931E4673}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AA22A40-802C-407B-AABF-E250931E4673}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AA22A40-802C-407B-AABF-E250931E4673}.Release|Any CPU.Build.0 = Release|Any CPU
{F52F0D32-5BDD-499F-8CA2-A1FE5867B379}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F52F0D32-5BDD-499F-8CA2-A1FE5867B379}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F52F0D32-5BDD-499F-8CA2-A1FE5867B379}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F52F0D32-5BDD-499F-8CA2-A1FE5867B379}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FA3B20E3-D396-467E-A05C-B16808055B33} = {CD0CFEEC-AE1A-4861-A9DA-1A6985271A2C}
{F68BA7A9-AD67-4E0B-B859-1505671304E9} = {CD0CFEEC-AE1A-4861-A9DA-1A6985271A2C}
{1AA22A40-802C-407B-AABF-E250931E4673} = {F4C71A62-F592-42D1-981E-253B3C5F80D6}
{F52F0D32-5BDD-499F-8CA2-A1FE5867B379} = {CD0CFEEC-AE1A-4861-A9DA-1A6985271A2C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Entities;
using System.Diagnostics.CodeAnalysis;

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.DependencyInjection;

public static class RegistryRepositoriesServiceExtensions
{
[ExcludeFromCodeCoverage]
public static IServiceCollection AddRegistryRepositories(this IServiceCollection services, IConfiguration configuration)
{
services
.AddDbContext<RegistryContext>(o => o
.UseNpgsql(configuration.GetConnectionString("RegistryDb")))
.AddScoped<IRegistryRepositories, RegistryRepositories>()
.AddHealthChecks()
.AddDbContextCheck<RegistryContext>("RegistryContext", tags: new[] { "registrydb" });
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess;

public interface IRegistryRepositories
{
public T GetInstance<T>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using System.Text.Json.Serialization;

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.Models;

public record CredentialData(
[property: JsonPropertyName("credentialName")] string CredentialName,
[property: JsonPropertyName("credential")] string Credential,
[property: JsonPropertyName("authorities")] IEnumerable<string> Authorities
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.Repositories;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Entities;
using System.Collections.Immutable;

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess;

public class RegistryRepositories : IRegistryRepositories
{
private readonly RegistryContext _dbContext;

private static readonly IReadOnlyDictionary<Type, Func<RegistryContext, Object>> Types = new Dictionary<Type, Func<RegistryContext, Object>> {
{ typeof(ICredentialRepository), context => new CredentialRepository(context) }
}.ToImmutableDictionary();

public RegistryRepositories(RegistryContext dbContext)
{
_dbContext = dbContext;
}

public RepositoryType GetInstance<RepositoryType>()
{
object? repository = default;

if (Types.TryGetValue(typeof(RepositoryType), out var createFunc))
{
repository = createFunc(_dbContext);
}

return (RepositoryType)(repository ?? throw new ArgumentException($"unexpected type {typeof(RepositoryType).Name}", nameof(RepositoryType)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Microsoft.EntityFrameworkCore;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.Models;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Entities;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Entities.Enums;

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.Repositories;

public class CredentialRepository : ICredentialRepository
{
private readonly RegistryContext _dbContext;

public CredentialRepository(RegistryContext dbContext)
{
_dbContext = dbContext;
}

public IAsyncEnumerable<CredentialData> GetCredentials(string? bpnl, CredentialTypeId? credentialTypeId) =>
_dbContext.Credentials
.Where(c =>
(bpnl == null || c.Authorities.Select(a => a.Bpn).Contains(bpnl)) &&
(credentialTypeId == null || c.TypeId == credentialTypeId))
.Select(c => new CredentialData(c.Type!.Label, c.Name, c.Authorities.Select(a => a.Bpn)))
.AsAsyncEnumerable();
}
Loading

0 comments on commit ab55b55

Please sign in to comment.