Skip to content

Commit

Permalink
Merge branch 'main' into feat/john/Better-submission-wizard-
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Vaughan committed Apr 30, 2024
2 parents 0ba4de7 + 99b5323 commit 18f62ac
Show file tree
Hide file tree
Showing 59 changed files with 2,386 additions and 92 deletions.
Binary file added OPASettings/bundle.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions OPASettings/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
acmecorp:
url: https://host.docker.internal:7157/api/OPA/BundleGet
allow_insecure_tls : true

discovery:
service: acmecorp
resource: /example/discovery.tar.gz
13 changes: 13 additions & 0 deletions OPASettings/discovery.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package play
import rego.v1
import input

default allow := false

allow if {
print("input", input)
allowed_test
}

allowed_test if input.action.operation in ["ExecuteQuery", "AccessCatalog"]
allowed_test if input.context.identity.user == input.action.resource.table.schemaName
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# DARE-Control
# DARE-Control

to connect them together
u = sailegressapi
pass = password123
24 changes: 22 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,30 @@ services:
- 8181:8181
command:
- "run"
- "--server"
- "--server"
- "-c"
- "config.yaml"
networks:
- communicating

volumes:
- ./OPASettings/config.yaml:/config.yaml

# command:
# - "run"
# - "stuff/bundle.tar.gz"

#command:
# - "build"
# - "-b"
# - "--debug"
# - "stuff/"
# - "-o"
# - "stuff/bundle.tar.gz"
networks:
- communicating
volumes:
- ./OPASettings:/stuff:rw

#postgresHasura:
# image: postgres:15
# restart: always
Expand Down
2 changes: 2 additions & 0 deletions src/BL/Models/Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Submission : BaseModel
public StatusType Status { get; set; }
public string? StatusDescription { get; set; }

public string? QueryToken { get; set; }

public string GetTotalDisplayTime()
{
var end = EndTime == DateTime.MinValue ? (DateTime.Now).ToUniversalTime() : EndTime;
Expand Down
1 change: 1 addition & 0 deletions src/BL/Models/ViewModels/OPASettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class OPASettings
public double ExpiryDelayMinutes { get; set; }
public bool UseRealExpiry { get; set; }

public string OPAPolicyUploadURL { get; set; }
}
}

2 changes: 1 addition & 1 deletion src/BL/Services/BaseClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected async Task<HttpResponseMessage> ClientHelperRequestAsync(string endPoi
// Output the string contentsn

}
Log.Information("{Function} Api returned an error for {endPoint} Response {Res} Error content {Content}", "ClientHelperRequestAsync",endPoint , res, content);
Log.Information("{Function} Api returned an error for {endPoint} Response {Res} Error content {Content}", "ClientHelperRequestAsync",endPoint , res, content);
throw new Exception("API Call Failure: " + res.StatusCode + ": " + res.ReasonPhrase + " " + content);
}
Log.Information("{Function} The response {res}", "ClientHelperRequestAsync", res);
Expand Down
14 changes: 8 additions & 6 deletions src/BL/Services/KeycloakTokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public async Task<string> GetTokenForUser(string username, string password, stri
string clientSecret = _clientSecret;

Log.Information($"GetTokenForUser _proxyUrl > {_proxyUrl} UseProxy > {_useProxy}");

// Create an HttpClientHandler with proxy settings
HttpClientHandler handler = new HttpClientHandler
HttpClientHandler handler = new HttpClientHandler();
handler.UseProxy = _useProxy;
if (_useProxy)
{
Proxy = new WebProxy(_proxyUrl), // Replace with your proxy server URL
UseProxy = _useProxy
};
// Create an HttpClientHandler with proxy settings
handler.Proxy = new WebProxy(_proxyUrl); // Replace with your proxy server URL

}


// Create an HttpClient with the handler
return await KeycloakCommon.GetTokenForUserGuts(username, password, requiredRole, handler, keycloakBaseUrl, clientId, clientSecret);
Expand Down
22 changes: 17 additions & 5 deletions src/DARE-API/Controllers/TESController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
using Newtonsoft.Json.Linq;
using System.Net.Http.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
using DARE_API.Services.Contract;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;

namespace DARE_API.Controllers
{
Expand All @@ -33,6 +37,8 @@ namespace DARE_API.Controllers
public class TaskServiceApiController : ControllerBase
{


private readonly IKeyCloakService _IKeyCloakService;
private readonly ApplicationDbContext _DbContext;
private readonly IBus _rabbit;
protected readonly IHttpContextAccessor _httpContextAccessor;
Expand All @@ -46,17 +52,21 @@ public class TaskServiceApiController : ControllerBase
{ TesView.FULL, new JsonSerializerSettings { ContractResolver = FullTesTaskContractResolver.Instance } }
};

private readonly IKeyclockTokenAPIHelper _IKeyclockTokenAPIHelper;

/// <summary>
/// Contruct a <see cref="TaskServiceApiController"/>
/// </summary>
/// <param name="repository">The main <see cref="ApplicationDbContext"/> database repository</param>
/// <param name="rabbit">The main <see cref="IBus"/> easynet q sender</param>
public TaskServiceApiController(ApplicationDbContext repository, IBus rabbit, IHttpContextAccessor httpContextAccessor)
public TaskServiceApiController(ApplicationDbContext repository, IBus rabbit, IHttpContextAccessor httpContextAccessor,
IKeyclockTokenAPIHelper IKeyclockTokenAPIHelper, IKeyCloakService IKeyCloakService)
{
_DbContext = repository;
_rabbit = rabbit;
_httpContextAccessor = httpContextAccessor;

_IKeyclockTokenAPIHelper = IKeyclockTokenAPIHelper;
_IKeyCloakService = IKeyCloakService;
}

/// <summary>
Expand Down Expand Up @@ -299,7 +309,8 @@ public virtual async Task<IActionResult> CreateTaskAsync([FromBody] TesTask tesT
return BadRequest("No valid tres for this project " + project + ".");
}


var Token = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
Token = Token.Replace("Bearer ", "");
var sub = new Submission()
{
DockerInputLocation = tesTask.Executors.First().Image,
Expand All @@ -310,6 +321,7 @@ public virtual async Task<IActionResult> CreateTaskAsync([FromBody] TesTask tesT
SubmittedBy = user,
TesName = tesTask.Name,
SourceCrate = tesTask.Executors.First().Image,
QueryToken = Token
};


Expand Down Expand Up @@ -535,7 +547,7 @@ public virtual async Task<IActionResult> ListTasks([FromQuery] string namePrefix
{
try {
var decodedPageToken =
pageToken is not null ? Encoding.UTF8.GetString(Base64UrlTextEncoder.Decode(pageToken)) : null;
pageToken is not null ? Encoding.UTF8.GetString(Microsoft.AspNetCore.Authentication.Base64UrlTextEncoder.Decode(pageToken)) : null;

if (pageSize < 1 || pageSize > 2047)
{
Expand All @@ -561,7 +573,7 @@ public virtual async Task<IActionResult> ListTasks([FromQuery] string namePrefix


var nextPageToken = finalList.continuation;
var encodedNextPageToken = nextPageToken is not null ? Base64UrlTextEncoder.Encode(Encoding.UTF8.GetBytes(nextPageToken)) : null;
var encodedNextPageToken = nextPageToken is not null ? Microsoft.AspNetCore.Authentication.Base64UrlTextEncoder.Encode(Encoding.UTF8.GetBytes(nextPageToken)) : null;
var response = new TesListTasksResponse { Tasks = tesTasks.ToList(), NextPageToken = encodedNextPageToken };

return TesJsonResult(response, view);
Expand Down
Loading

0 comments on commit 18f62ac

Please sign in to comment.