Skip to content

Commit

Permalink
Feat/usesettingsforproxy (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeeelsdon authored Jul 2, 2024
1 parent d8bc44e commit 69afa07
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 198 deletions.
2 changes: 2 additions & 0 deletions src/BL/Models/ViewModels/MinioSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class MinioSettings

public bool UesProxy { get; set; }
public string ProxyAddresURL { get; set; }

public string ProxyAddresURLForExternalFetch { get; set; }

public string BypassProxy { get; set; }
}
Expand Down
43 changes: 26 additions & 17 deletions src/BL/Services/MinioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,39 +263,48 @@ public async Task<bool> FetchAndStoreObject(string url, string bucketName, strin
{
try
{


var proxy = new System.Net.WebProxy("http://192.168.10.15:8080");
HttpClientHandler handler;
if (!string.IsNullOrWhiteSpace(_minioSettings.ProxyAddresURLForExternalFetch))
{
var proxy = new System.Net.WebProxy(_minioSettings.ProxyAddresURLForExternalFetch);
handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
}
else
{
handler = new HttpClientHandler
{

UseProxy = false
};
}


// Configure the HttpClientHandler to use the proxy
var handler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};


// Create the HttpClient with the handler
using (var httpClient = new HttpClient(handler))
{

Log.Information("{Funtion} Step 1 url {Url}","FetchAndStoreObject", url);

var response = await httpClient.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
Log.Information("{Function} Step 1.5 {Code} {Content}","FetchAndStoreObject", response.StatusCode.ToString(), StreamToString(response.Content.ReadAsStreamAsync().Result));
}


response.EnsureSuccessStatusCode();
Log.Information("{Funtion} Step 2", "FetchAndStoreObject");

var contentBytes = await response.Content.ReadAsByteArrayAsync();

var amazonS3Client = GenerateAmazonS3Client();
Log.Information("{Funtion} Step 3", "FetchAndStoreObject");

using (var transferUtility = new TransferUtility(amazonS3Client))
{
Log.Information("{Funtion} Step 4", "FetchAndStoreObject");

await transferUtility.UploadAsync(new MemoryStream(contentBytes), bucketName, key);
Log.Information("{Funtion} Step 5", "FetchAndStoreObject");

}
}

Expand Down
194 changes: 97 additions & 97 deletions src/DARE-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,98 +151,98 @@
{
OnForbidden = context =>
{
Log.Information("ONFORBIDDEN START");
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}
Log.Information("ONFORBIDDEN END");
//Log.Information("ONFORBIDDEN START");
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}
//Log.Information("ONFORBIDDEN END");
return context.Response.CompleteAsync();
},
OnTokenValidated = context =>
{
Log.Information("ONTOKENVALIDATED START");
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}
Log.Information("ONTOKENVALIDATED END");
// Log the issuer claim from the token
var issuer = context.Principal.FindFirst("iss")?.Value;
Log.Information("Token Issuer: {Issuer}", issuer);
var audience = context.Principal.FindFirst("aud")?.Value;
Log.Information("Token Audience: {Audience}", audience);
//Log.Information("ONTOKENVALIDATED START");
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}
//Log.Information("ONTOKENVALIDATED END");
//// Log the issuer claim from the token
//var issuer = context.Principal.FindFirst("iss")?.Value;
//Log.Information("Token Issuer: {Issuer}", issuer);
//var audience = context.Principal.FindFirst("aud")?.Value;
//Log.Information("Token Audience: {Audience}", audience);
return Task.CompletedTask;
},
OnAuthenticationFailed = context =>
{
Log.Information("ONAUTHFAILED START");
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}
Log.Information("ONAUTHFAILED END");
Log.Error("{Function}: {ex}", "OnAuthFailed", context.Exception.Message);
Log.Error("Auth failed event: {event}", context.Request.Headers);
//Log.Information("ONAUTHFAILED START");
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}
//Log.Information("ONAUTHFAILED END");
//Log.Error("{Function}: {ex}", "OnAuthFailed", context.Exception.Message);
//Log.Error("Auth failed event: {event}", context.Request.Headers);
context.Response.StatusCode = 401;
return context.Response.CompleteAsync();
},
OnMessageReceived = context =>
{
Log.Information("ONMESSAGERECEIVED START");
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}
Log.Information("ONMESSAGERECEVIED END");
//Log.Information("ONMESSAGERECEIVED START");
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}
//Log.Information("ONMESSAGERECEVIED END");
string accessToken = context.Request.Query["access_token"];
PathString path = context.HttpContext.Request.Path;

Expand All @@ -258,24 +258,24 @@
},
OnChallenge = context =>
{
Log.Information("ONCHALLENGE START");
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}
Log.Information("ONCHALLENGE END");
//Log.Information("ONCHALLENGE START");
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}
//Log.Information("ONCHALLENGE END");
return Task.CompletedTask;
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/DARE-API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"AWSRegion": "us-east-1",
"AWSService": "s3",
"AttributeName": "policy",
"AdminConsole": "localhost:9001"
"AdminConsole": "localhost:9001",
"ProxyAddresURLForExternalFetch": ""
},
"Serilog": {
"SeqServerUrl": "http://localhost:5341",
Expand Down
54 changes: 27 additions & 27 deletions src/DARE-FrontEnd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@
OnTokenValidated = context =>
{
// Log the issuer claim from the token
var issuer = context.Principal.FindFirst("iss")?.Value;
Log.Information("Token Issuer: {Issuer}", issuer);
var audience = context.Principal.FindFirst("aud")?.Value;
Log.Information("Token Audience: {Audience}", audience);
//var issuer = context.Principal.FindFirst("iss")?.Value;
//Log.Information("Token Issuer: {Issuer}", issuer);
//var audience = context.Principal.FindFirst("aud")?.Value;
//Log.Information("Token Audience: {Audience}", audience);
return Task.CompletedTask;
},
OnAccessDenied = context =>
Expand Down Expand Up @@ -249,29 +249,29 @@
},
OnRedirectToIdentityProvider = async context =>
{
Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
context.HttpContext.Connection.RemoteIpAddress);
Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
context.HttpContext.Connection.RemotePort);
Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

foreach (var header in context.HttpContext.Request.Headers)
{
Log.Information("Request Header {key} - {value}", header.Key, header.Value);
}

foreach (var header in context.HttpContext.Response.Headers)
{
Log.Information("Response Header {key} - {value}", header.Key, header.Value);
}

if (submissionKeyCloakSettings.UseRedirectURL)
{
context.ProtocolMessage.RedirectUri = submissionKeyCloakSettings.RedirectURL;
}

Log.Information("Redirect Uri {Redirect}", context.ProtocolMessage.RedirectUri);
//Log.Information("HttpContext.Connection.RemoteIpAddress : {RemoteIpAddress}",
// context.HttpContext.Connection.RemoteIpAddress);
//Log.Information("HttpContext.Connection.RemotePort : {RemotePort}",
// context.HttpContext.Connection.RemotePort);
//Log.Information("HttpContext.Request.Scheme : {Scheme}", context.HttpContext.Request.Scheme);
//Log.Information("HttpContext.Request.Host : {Host}", context.HttpContext.Request.Host);

//foreach (var header in context.HttpContext.Request.Headers)
//{
// Log.Information("Request Header {key} - {value}", header.Key, header.Value);
//}

//foreach (var header in context.HttpContext.Response.Headers)
//{
// Log.Information("Response Header {key} - {value}", header.Key, header.Value);
//}

//if (submissionKeyCloakSettings.UseRedirectURL)
//{
// context.ProtocolMessage.RedirectUri = submissionKeyCloakSettings.RedirectURL;
//}

//Log.Information("Redirect Uri {Redirect}", context.ProtocolMessage.RedirectUri);

await Task.FromResult(0);
}
Expand Down
Loading

0 comments on commit 69afa07

Please sign in to comment.