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.
- Loading branch information
1 parent
9c9ddc2
commit 4bda675
Showing
34 changed files
with
1,226 additions
and
12 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
72 changes: 72 additions & 0 deletions
72
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Instances/AddInstance.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,72 @@ | ||
// 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.Instances.Commands; | ||
using FluentValidation; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.Instances; | ||
|
||
public class AddInstance : IFeature | ||
{ | ||
public void MapEndpoints(IEndpointRouteBuilder endpoints) | ||
{ | ||
AdminApiAdminConsoleEndpointBuilder.MapPost(endpoints, "/instances", Execute) | ||
.WithRouteOptions(b => b.WithResponseCode(201)) | ||
.BuildForVersions(); | ||
} | ||
|
||
public async Task<IResult> Execute(Validator validator, IAddInstanceCommand addInstanceCommand, AddInstanceRequest request) | ||
{ | ||
await validator.GuardAsync(request); | ||
var addedInstanceResult = await addInstanceCommand.Execute(request); | ||
|
||
return Results.Created($"/instances/{addedInstanceResult.DocId}", addedInstanceResult); | ||
} | ||
|
||
public class AddInstanceRequest : IAddInstanceModel | ||
{ | ||
[Required] | ||
public int InstanceId { get; set; } | ||
[Required] | ||
public int EdOrgId { get; set; } | ||
[Required] | ||
public int TenantId { get; set; } | ||
[Required] | ||
public string Document { get; set; } | ||
} | ||
|
||
public class Validator : AbstractValidator<AddInstanceRequest> | ||
{ | ||
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; | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Instances/InstanceModel.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,26 @@ | ||
// 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 Newtonsoft.Json; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.OdsInstances; | ||
|
||
public class InstanceModel | ||
{ | ||
[JsonProperty("DocId")] | ||
public int DocId { get; set; } | ||
|
||
[JsonProperty("InstanceId")] | ||
public int? InstanceId { get; set; } | ||
|
||
[JsonProperty("TenantId")] | ||
public int? TenantId { get; set; } | ||
|
||
[JsonProperty("EdOrgId")] | ||
public int? EdOrgId { get; set; } | ||
|
||
[JsonProperty("Document")] | ||
public string? Document { get; set; } | ||
} |
37 changes: 37 additions & 0 deletions
37
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Instances/ReadInstances.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,37 @@ | ||
// 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 AutoMapper; | ||
using EdFi.Ods.AdminApi.AdminConsole.Features.OdsInstances; | ||
using EdFi.Ods.AdminApi.AdminConsole.Infrastructure.Services.Instances.Queries; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.UserProfiles; | ||
|
||
public class ReadInstances : IFeature | ||
{ | ||
public void MapEndpoints(IEndpointRouteBuilder endpoints) | ||
{ | ||
AdminApiAdminConsoleEndpointBuilder.MapGet(endpoints, "/instances", GetInstances) | ||
.BuildForVersions(); | ||
|
||
AdminApiAdminConsoleEndpointBuilder.MapGet(endpoints, "/instances/{id}", GetInstance) | ||
.WithRouteOptions(b => b.WithResponse<InstanceModel>(200)) | ||
.BuildForVersions(); | ||
} | ||
|
||
internal async Task<IResult> GetInstances([FromServices] IGetInstancesQuery getInstancesQuery) | ||
{ | ||
var instances = await getInstancesQuery.Execute(); | ||
return Results.Ok(instances); | ||
} | ||
internal async Task<IResult> GetInstance([FromServices] IGetInstanceQuery getInstanceQuery, int docId) | ||
{ | ||
var instance = await getInstanceQuery.Execute(docId); | ||
return Results.Ok(instance); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Application/EdFi.Ods.AdminApi.AdminConsole/Helpers/Encryption.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,35 @@ | ||
// 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 Rijndael256; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Helpers; | ||
public class Encryption : RijndaelEtM | ||
{ | ||
/// <summary> | ||
/// Encrypts plaintext using the Encrypt-then-MAC (EtM) mode via the Rijndael cipher in | ||
/// CBC mode with a password derived HMAC SHA-512 salt. A random 128-bit Initialization | ||
/// Vector is generated for the cipher. | ||
/// </summary> | ||
/// <param name="plainText">The plainText to encrypt.</param> | ||
/// <param name="encryptionKey">The encryptionKey to encrypt the plainText with.</param> | ||
/// <returns>The Base64 encoded EtM ciphertext.</returns> | ||
public static string Encrypt(string plainText, string encryptionKey) | ||
{ | ||
return Encrypt(plainText, encryptionKey, KeySize.Aes256); | ||
} | ||
|
||
/// <summary> | ||
/// Decrypts EtM ciphertext using the Rijndael cipher in CBC mode with a password derived | ||
/// HMAC SHA-512 salt. | ||
/// </summary> | ||
/// <param name="ciphertText">The Base64 encoded EtM ciphertext to decrypt.</param> | ||
/// <param name="encryptionKey">The encryptionKey to decrypt the EtM ciphertext with.</param> | ||
/// <returns>The plaintext.</returns> | ||
public static string Decrypt(string ciphertText, string encryptionKey) | ||
{ | ||
return Decrypt(ciphertText, encryptionKey, KeySize.Aes256); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Application/EdFi.Ods.AdminApi.AdminConsole/Helpers/IEncryptionKeyResolver.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,11 @@ | ||
// 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. | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Helpers; | ||
|
||
public interface IEncryptionKeyResolver | ||
{ | ||
string GetEncryptionKey(); | ||
} |
11 changes: 11 additions & 0 deletions
11
Application/EdFi.Ods.AdminApi.AdminConsole/Helpers/IEncryptionKeySettings.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,11 @@ | ||
// 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. | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Helpers; | ||
|
||
public interface IEncryptionKeySettings | ||
{ | ||
public string EncryptionKey { get; set; } | ||
} |
21 changes: 21 additions & 0 deletions
21
Application/EdFi.Ods.AdminApi.AdminConsole/Helpers/OptionsEncryptionKeyResolver.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,21 @@ | ||
// 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. | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Helpers; | ||
|
||
public class OptionsEncryptionKeyResolver : IEncryptionKeyResolver | ||
{ | ||
private readonly string _encryptionKey; | ||
|
||
public OptionsEncryptionKeyResolver(IEncryptionKeySettings encryptionKeySettings) | ||
{ | ||
_encryptionKey = encryptionKeySettings.EncryptionKey; | ||
} | ||
|
||
public string GetEncryptionKey() | ||
{ | ||
return _encryptionKey; | ||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
...pi.AdminConsole/Infrastructure/DataAccess/Artifacts/MsSql/20241030014056_InitialCreate.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
88 changes: 88 additions & 0 deletions
88
...nsole/Infrastructure/DataAccess/Artifacts/MsSql/20241030141215_InstanceTables.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.