using Amazon.Runtime; using Amazon.S3; using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.S3Utils.Data; public record S3RegionCredentials : S3Credentials { public required String Region { get; init; } private AmazonS3Client? _Client; internal AmazonS3Client Client => _Client ??= new AmazonS3Client ( credentials: new BasicAWSCredentials(Key, Secret), clientConfig: new() { ServiceURL = Region.EnsureStartsWith("https://"), ForcePathStyle = true, } ); public new static S3RegionCredentials? FromS3Cfg() => FromFile(S3CfgFile); public new static S3RegionCredentials? FromFile(String file) { // [default] // host_base = sos-ch-dk-2.exo.io // host_bucket = %(bucket)s.sos-ch-dk-2.exo.io // access_key = xxxxxxxxxxxxxxx // secret_key = xxxxxxxxxxxxxxx // use_https = True try { var cfg = ParseFile(file); return new S3RegionCredentials { Key = cfg["access_key"], Secret = cfg["secret_key"], Region = cfg["host_base"], }; } catch { return null; } } }