forked from Ed-Fi-Alliance-OSS/AdminAPI-1.x
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/adminapi23-rc.0' into ADMINAPI-1090
- Loading branch information
Showing
73 changed files
with
2,006 additions
and
275 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Licensed to the Ed-Fi Alliance under one or more agreements. | ||
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
# See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
name: On Pull Request - Dockerfile - Admin Console | ||
|
||
on: | ||
push: | ||
branches: | ||
- adminapi23-rc.* | ||
pull_request: | ||
branches: | ||
- adminapi23-rc.* | ||
workflow_dispatch: | ||
|
||
env: | ||
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} | ||
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
IMAGE_NAME: ${{ vars.IMAGE_NAME }} | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
docker-analysis: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
security-events: write | ||
pull-requests: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
dockerfile: | ||
[ | ||
{ name: "development", path: "Docker/dev.pgsql.Dockerfile", type: "local" } | ||
] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Set IMAGE_TAG | ||
id: set-image-tag | ||
run: | | ||
if [ "${{ github.event_name }}" == "pull_request" ]; then | ||
echo "IMAGE_TAG=${{ github.base_ref }}" >> $GITHUB_ENV | ||
else | ||
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV | ||
fi | ||
- name: Copy application folder to docker context | ||
if: ${{ matrix.dockerfile.type == 'local' }} | ||
run: | | ||
mkdir Docker/Application | ||
cp -r ./Application/EdFi.Ods.AdminApi ./Docker/Application | ||
cp -r ./Application/EdFi.Ods.AdminApi.AdminConsole ./Docker/Application | ||
cp ./Application/NuGet.Config ./Docker/Application | ||
- uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0 | ||
name: Run Linter on ${{ matrix.dockerfile.name }} Dockerfile | ||
with: | ||
dockerfile: ${{ matrix.dockerfile.path }} | ||
failure-threshold: error | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | ||
with: | ||
username: ${{ env.DOCKER_USERNAME }} | ||
password: ${{ env.DOCKER_HUB_TOKEN }} | ||
|
||
- name: Build | ||
run: | | ||
path=${{matrix.dockerfile.path}} | ||
folder=${path%/*} | ||
cd $folder | ||
dockerfile=$(echo ${{matrix.dockerfile.path}} | awk -F"/" '{print $NF}') | ||
docker build -f $dockerfile -t ${{ matrix.dockerfile.name }} --build-arg="VERSION=${{ env.IMAGE_TAG }}" . | ||
- name: Analyze | ||
uses: docker/scout-action@67eb1afe777307506aaecb9acd9a0e0389cb99ae # v1.5.0 | ||
with: | ||
command: cves | ||
image: local://${{ matrix.dockerfile.name }} | ||
sarif-file: sarif-${{ matrix.dockerfile.name }}.output.json | ||
summary: true | ||
|
||
- name: Push Image on Docker Hub | ||
run: | | ||
docker image tag ${{ matrix.dockerfile.name }} ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | ||
docker push ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | ||
- name: Upload SARIF result | ||
id: upload-sarif | ||
if: ${{ github.event_name != 'pull_request_target' }} | ||
uses: github/codeql-action/upload-sarif@cf7e9f23492505046de9a37830c3711dd0f25bb3 #codeql-bundle-v2.16.2 | ||
with: | ||
sarif_file: sarif-${{ matrix.dockerfile.name }}.output.json |
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
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
71 changes: 71 additions & 0 deletions
71
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Steps/AddStep.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,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using EdFi.Ods.AdminApi.AdminConsole.Infrastructure.Services.Steps.Commands; | ||
using FluentValidation; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.Steps; | ||
|
||
public class AddStep: IFeature | ||
{ | ||
public void MapEndpoints(IEndpointRouteBuilder endpoints) | ||
{ | ||
AdminApiAdminConsoleEndpointBuilder.MapPost(endpoints, "/steps", Execute) | ||
.WithRouteOptions(b => b.WithResponseCode(201)) | ||
.BuildForVersions(); | ||
} | ||
|
||
public async Task<IResult> Execute(Validator validator, IAddStepCommand addStepCommand, AddStepRequest request) | ||
{ | ||
await validator.GuardAsync(request); | ||
var addedStepResult = await addStepCommand.Execute(request); | ||
|
||
return Results.Created($"/steps/{addedStepResult.TenantId}/{addedStepResult.DocId}", addedStepResult); | ||
} | ||
|
||
public class AddStepRequest : IAddStepModel | ||
{ | ||
[Required] | ||
public int InstanceId { get; set; } | ||
public int? EdOrgId { get; set; } | ||
[Required] | ||
public int TenantId { get; set; } | ||
[Required] | ||
public string Document { get; set; } | ||
} | ||
|
||
public class Validator : AbstractValidator<AddStepRequest> | ||
{ | ||
public Validator() | ||
{ | ||
RuleFor(m => m.InstanceId) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.EdOrgId) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.Document) | ||
.NotNull() | ||
.NotEmpty() | ||
.Must(BeValidDocument).WithMessage("Document must be a valid JSON."); | ||
} | ||
|
||
private bool BeValidDocument(string document) | ||
{ | ||
try | ||
{ | ||
Newtonsoft.Json.Linq.JToken.Parse(document); | ||
return true; | ||
} | ||
catch (Newtonsoft.Json.JsonReaderException) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.