From c192cf05adfa20409f22a437cabc02afac7bfdfa Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 27 Feb 2024 12:01:35 +0100 Subject: [PATCH] Update GeosquareService and AmazonCustomS3Config classes --- .../Publication/GeosquareService.cs | 2 +- .../Resources/AmazonCustomS3Config.cs | 2 +- .../Resources/IS3ClientFactory.cs | 1 + .../Resources/S3ClientFactory.cs | 2 +- src/Stars.Services/Resources/S3Options.cs | 28 +++++++++++++++++++ src/Stars.Services/Router/GenericCatalog.cs | 2 +- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs b/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs index 53ad8bb7..a97b7c77 100644 --- a/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs +++ b/src/Stars.Data/ThirdParty/Publication/GeosquareService.cs @@ -81,7 +81,7 @@ public async Task PublishAsync(IPublicationModel publicationM return state; } - private HttpClient CreateClient(string catalogId) + public HttpClient CreateClient(string catalogId) { HttpClient client = httpClientFactory.CreateClient(catalogId); if (client.BaseAddress == null) diff --git a/src/Stars.Services/Resources/AmazonCustomS3Config.cs b/src/Stars.Services/Resources/AmazonCustomS3Config.cs index afe2acad..2f3c9743 100644 --- a/src/Stars.Services/Resources/AmazonCustomS3Config.cs +++ b/src/Stars.Services/Resources/AmazonCustomS3Config.cs @@ -3,7 +3,7 @@ namespace Terradue.Stars.Services.Resources { - internal class AmazonCustomS3Config : AmazonS3Config + public class AmazonCustomS3Config : AmazonS3Config { private string _region; private string _serviceURL; diff --git a/src/Stars.Services/Resources/IS3ClientFactory.cs b/src/Stars.Services/Resources/IS3ClientFactory.cs index 3c3d71ca..ebf1b4ff 100644 --- a/src/Stars.Services/Resources/IS3ClientFactory.cs +++ b/src/Stars.Services/Resources/IS3ClientFactory.cs @@ -11,6 +11,7 @@ public interface IS3ClientFactory { IAmazonS3 CreateS3Client(S3Url s3Url); IAmazonS3 CreateS3Client(IAsset asset); + IAmazonS3 CreateS3Client(S3Configuration s3Config); Task CreateS3ClientAsync(S3Url url, IIdentityProvider identityProvider, string policy = null); AWSCredentials GetConfiguredCredentials(S3Url s3Url, IIdentityProvider identityProvider = null); IAmazonS3 CreateS3Client(string name); diff --git a/src/Stars.Services/Resources/S3ClientFactory.cs b/src/Stars.Services/Resources/S3ClientFactory.cs index d1b740ed..fca7e860 100644 --- a/src/Stars.Services/Resources/S3ClientFactory.cs +++ b/src/Stars.Services/Resources/S3ClientFactory.cs @@ -297,7 +297,7 @@ public S3Configuration GetAmazonS3Config(S3Url s3Url) /// /// /// - private static AmazonCustomS3Config CreateS3Configuration(AWSOptions options) + public static AmazonCustomS3Config CreateS3Configuration(AWSOptions options) { AmazonCustomS3Config config = new AmazonCustomS3Config(); diff --git a/src/Stars.Services/Resources/S3Options.cs b/src/Stars.Services/Resources/S3Options.cs index 654d6057..a41da2ea 100644 --- a/src/Stars.Services/Resources/S3Options.cs +++ b/src/Stars.Services/Resources/S3Options.cs @@ -76,6 +76,34 @@ public S3Configuration(S3Configuration s3Configuration) this.UseWebIdentity = s3Configuration == null ? false : s3Configuration.UseWebIdentity; } + /// + /// Create a new S3Configuration from original AmazonS3Config and AWSCredentials + /// This is useful when you want to create a new S3Configuration from an existing AmazonS3Config and AWSCredentials + /// and leverage the modification to access a custom S3 service by using IS3ClientFactory + /// + /// + /// + /// + public static S3Configuration Create(AmazonS3Config amazonS3Config, AWSCredentials awsCredentials) + { + return new S3Configuration + { + AmazonS3Config = amazonS3Config, + AWSCredentials = awsCredentials, + UrlPattern = $".*", // match all + Region = amazonS3Config?.RegionEndpoint?.SystemName, + ServiceURL = amazonS3Config?.ServiceURL, + AccessKey = awsCredentials?.GetCredentials()?.AccessKey, + SecretKey = awsCredentials?.GetCredentials()?.SecretKey, + SessionToken = awsCredentials?.GetCredentials()?.Token, + AuthenticationRegion = amazonS3Config?.AuthenticationRegion, + UseHttp = amazonS3Config?.UseHttp ?? false, + ForcePathStyle = amazonS3Config?.ForcePathStyle ?? false, + TryAdaptRegion = true, + UseWebIdentity = false + }; + } + public string UrlPattern { get; set; } public string ServiceURL { get; set; } public string AccessKey { get; set; } diff --git a/src/Stars.Services/Router/GenericCatalog.cs b/src/Stars.Services/Router/GenericCatalog.cs index c085dfe5..f115e1a7 100644 --- a/src/Stars.Services/Router/GenericCatalog.cs +++ b/src/Stars.Services/Router/GenericCatalog.cs @@ -22,7 +22,7 @@ public GenericCatalog(IEnumerable routes, string id) public string Title => id; - public ContentType ContentType => new ContentType("application/catalog"); + public ContentType ContentType => new ContentType("application/atom+xml"); public Uri Uri => new Uri("stars://catalog");