-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add schema validation endpoint
add get endpoint for credentials add swagger add post endpoint to validate json schemas Refs: #4 #6 #11
- Loading branch information
Showing
45 changed files
with
1,201 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...oritySchemaRegistry.DbAccess/DependencyInjection/RegistryRepositoriesServiceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/database/SsiAuthoritySchemaRegistry.DbAccess/IRegistryRepositories.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/database/SsiAuthoritySchemaRegistry.DbAccess/Models/CredentialData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
50 changes: 50 additions & 0 deletions
50
src/database/SsiAuthoritySchemaRegistry.DbAccess/RegistryRepositories.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/database/SsiAuthoritySchemaRegistry.DbAccess/Repositories/CredentialRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.