public static IEnumerable <ValidationResult> Validate(this AwsStorageOptions options) { if (String.IsNullOrWhiteSpace(options.BucketName)) { yield return(new ValidationResult(Constants.ValidationMessages.BucketNameIsEmpty)); } if (options.Credentials != null) { if (String.IsNullOrWhiteSpace(options.Credentials.SecretKey)) { yield return(new ValidationResult(Constants.ValidationMessages.SecretKeyIsEmpty)); } if (String.IsNullOrWhiteSpace(options.Credentials.AccessKeyId)) { yield return(new ValidationResult(Constants.ValidationMessages.AccessKeyIdIsEmpty)); } if (String.IsNullOrWhiteSpace(options.Credentials.RegionEndpoint)) { yield return(new ValidationResult(Constants.ValidationMessages.RegionEndpointIsEmpty)); } } }
public AdminController( IAuthorizationService authorizationService, IOptions <AwsStorageOptions> options) { _authorizationService = authorizationService; _options = options.Value; }
public CreateMediaS3BucketEvent(ShellSettings shellSettings, IOptions <AwsStorageOptions> options, IAmazonS3 amazonS3Client, ILogger <CreateMediaS3BucketEvent> logger) { _shellSettings = shellSettings; _logger = logger; _amazonS3Client = amazonS3Client; _options = options.Value; }
public static AwsStorageOptions BindConfiguration(this AwsStorageOptions options, IShellConfiguration shellConfiguration) { var section = shellConfiguration.GetSection("OrchardCore_Media_AmazonS3"); if (section == null) { return(options); } options.BucketName = section.GetValue(nameof(options.BucketName), String.Empty); options.BasePath = section.GetValue(nameof(options.BasePath), String.Empty); options.CreateBucket = section.GetValue(nameof(options.CreateBucket), false); var credentials = section.GetSection("Credentials"); if (credentials.Exists()) { options.Credentials = new AwsStorageCredentials { RegionEndpoint = credentials.GetValue(nameof(options.Credentials.RegionEndpoint), RegionEndpoint.USEast1.SystemName), SecretKey = credentials.GetValue(nameof(options.Credentials.SecretKey), String.Empty), AccessKeyId = credentials.GetValue(nameof(options.Credentials.AccessKeyId), String.Empty), }; } else { // Attempt to load Credentials from Profile. var profileName = section.GetValue("ProfileName", String.Empty); if (!String.IsNullOrEmpty(profileName)) { var chain = new CredentialProfileStoreChain(); if (chain.TryGetProfile(profileName, out var basicProfile)) { var awsCredentials = basicProfile.GetAWSCredentials(chain)?.GetCredentials(); if (awsCredentials != null) { options.Credentials = new AwsStorageCredentials { RegionEndpoint = basicProfile.Region.SystemName ?? RegionEndpoint.USEast1.SystemName, SecretKey = awsCredentials.SecretKey, AccessKeyId = awsCredentials.AccessKey }; } } } } return(options); }
public static IEnumerable <ValidationResult> Validate(this AwsStorageOptions options) { if (String.IsNullOrWhiteSpace(options.BucketName)) { yield return(new ValidationResult(Constants.ValidationMessages.BucketNameIsEmpty)); } if (options.AwsOptions is not null) { if (options.AwsOptions.Region is null) { yield return(new ValidationResult(Constants.ValidationMessages.RegionEndpointIsEmpty)); } } }
public static AwsStorageOptions BindConfiguration(this AwsStorageOptions options, IShellConfiguration shellConfiguration, ILogger logger) { var section = shellConfiguration.GetSection("OrchardCore_Media_AmazonS3"); if (!section.Exists()) { return(options); } options.BucketName = section.GetValue(nameof(options.BucketName), String.Empty); options.BasePath = section.GetValue(nameof(options.BasePath), String.Empty); options.CreateBucket = section.GetValue(nameof(options.CreateBucket), false); try { // Binding AWS Options options.AwsOptions = shellConfiguration.GetAWSOptions("OrchardCore_Media_AmazonS3"); // In case Credentials sections was specified, trying to add BasicAWSCredential to AWSOptions // since by design GetAWSOptions skips Credential section while parsing config. var credentials = section.GetSection("Credentials"); if (credentials.Exists()) { var secretKey = credentials.GetValue(Constants.AwsCredentialParamNames.SecretKey, String.Empty); var accessKey = credentials.GetValue(Constants.AwsCredentialParamNames.AccessKey, String.Empty); if (!String.IsNullOrWhiteSpace(accessKey) || !String.IsNullOrWhiteSpace(secretKey)) { var awsCredentials = new BasicAWSCredentials(accessKey, secretKey); options.AwsOptions.Credentials = awsCredentials; } } return(options); } catch (ConfigurationException ex) { logger.LogCritical(ex, ex.Message); throw; } }