Example #1
0
 public S3StreamingCarrier(ILogger <S3StreamingCarrier> logger, Amazon.Extensions.NETCore.Setup.AWSOptions options, S3BucketsOptions s3BucketsConfiguration = null)
 {
     this.logger  = logger;
     this.options = options;
     this.s3BucketsConfiguration = s3BucketsConfiguration;
     Priority = 75;
 }
Example #2
0
        /// <summary>
        /// Performs all of the global settings that have been specified in AWSOptions.
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="options"></param>
        private static void PerformGlobalConfig(ILogger logger, AWSOptions options)
        {
            if (options?.Logging != null)
            {
                if (options.Logging.LogTo.HasValue && AWSConfigs.LoggingConfig.LogTo != options.Logging.LogTo.Value)
                {
                    AWSConfigs.LoggingConfig.LogTo = options.Logging.LogTo.Value;
                    logger?.LogDebug($"Configuring SDK LogTo: {AWSConfigs.LoggingConfig.LogTo}");
                }

                if (options.Logging.LogResponses.HasValue && AWSConfigs.LoggingConfig.LogResponses != options.Logging.LogResponses.Value)
                {
                    AWSConfigs.LoggingConfig.LogResponses = options.Logging.LogResponses.Value;
                    logger?.LogDebug($"Configuring SDK LogResponses: {AWSConfigs.LoggingConfig.LogResponses}");
                }

                if (options.Logging.LogMetrics.HasValue && AWSConfigs.LoggingConfig.LogMetrics != options.Logging.LogMetrics.Value)
                {
                    AWSConfigs.LoggingConfig.LogMetrics = options.Logging.LogMetrics.Value;
                    logger?.LogDebug($"Configuring SDK LogMetrics: {AWSConfigs.LoggingConfig.LogMetrics}");
                }

                if (options.Logging.LogResponsesSizeLimit.HasValue && AWSConfigs.LoggingConfig.LogResponsesSizeLimit != options.Logging.LogResponsesSizeLimit.Value)
                {
                    AWSConfigs.LoggingConfig.LogResponsesSizeLimit = options.Logging.LogResponsesSizeLimit.Value;
                    logger?.LogDebug($"Configuring SDK LogResponsesSizeLimit: {AWSConfigs.LoggingConfig.LogResponsesSizeLimit}");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Creates the AWS service client that implements the service client interface. The AWSOptions object
        /// will be searched for in the IServiceProvider.
        /// </summary>
        /// <param name="provider">The dependency injection provider.</param>
        /// <returns>The AWS service client</returns>
        internal static object CreateServiceClient(Type serviceInterfaceType, AWSOptions options)
        {
            var credentials = CreateCredentials(options);
            var config      = CreateConfig(serviceInterfaceType, options);
            var client      = CreateClient(serviceInterfaceType, credentials, config);

            return(client);
        }
Example #4
0
        /// <summary>
        /// Creates the AWSCredentials using either the profile indicated from the AWSOptions object
        /// of the SDK fallback credentials search.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static AWSCredentials CreateCredentials(AWSOptions options)
        {
            if (options != null &&
                !string.IsNullOrEmpty(options.Profile) &&
                StoredProfileAWSCredentials.IsProfileKnown(options.Profile, options.ProfilesLocation))
            {
                return(new StoredProfileAWSCredentials(options.Profile, options.ProfilesLocation));
            }

            return(FallbackCredentialsFactory.GetCredentials());
        }
Example #5
0
        /// <summary>
        /// Creates the ClientConfig object for the service client.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static ClientConfig CreateConfig(Type serviceInterfaceType, AWSOptions options)
        {
            var configTypeName = serviceInterfaceType.Namespace + "." + serviceInterfaceType.Name.Substring(1) + "Config";
            var configType     = serviceInterfaceType.GetTypeInfo().Assembly.GetType(configTypeName);

            var          constructor = configType.GetConstructor(EMPTY_TYPES);
            ClientConfig config      = constructor.Invoke(EMPTY_PARAMETERS) as ClientConfig;

            if (options == null)
            {
                options = new AWSOptions();
            }

            var defaultConfig = options.DefaultClientConfig;

            if (options.IsDefaultClientConfigSet)
            {
                var emptyArray  = new object[0];
                var singleArray = new object[1];

                var clientConfigTypeInfo = typeof(ClientConfig).GetTypeInfo();
                foreach (var property in clientConfigTypeInfo.DeclaredProperties)
                {
                    if (property.GetMethod != null && property.SetMethod != null)
                    {
                        // Skip RegionEndpoint because it is set below and calling the get method on the
                        // property triggers the default region fallback mechanism.
                        if (string.Equals(property.Name, "RegionEndpoint", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        singleArray[0] = property.GetMethod.Invoke(defaultConfig, emptyArray);
                        if (singleArray[0] != null)
                        {
                            property.SetMethod.Invoke(config, singleArray);
                        }
                    }
                }
            }

            // Setting RegionEndpoint only if ServiceURL was not set, because ServiceURL value will be lost otherwise
            if (options.Region != null && string.IsNullOrEmpty(defaultConfig.ServiceURL))
            {
                config.RegionEndpoint = options.Region;
            }

            return(config);
        }
Example #6
0
        /// <summary>
        /// Creates the AWSCredentials using either the profile indicated from the AWSOptions object
        /// of the SDK fallback credentials search.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static AWSCredentials CreateCredentials(AWSOptions options)
        {
            if (options != null)
            {
                if (options.Credentials != null)
                {
                    return(options.Credentials);
                }
                if (!string.IsNullOrEmpty(options.Profile))
                {
                    var            chain = new CredentialProfileStoreChain(options.ProfilesLocation);
                    AWSCredentials result;
                    if (chain.TryGetAWSCredentials(options.Profile, out result))
                    {
                        return(result);
                    }
                }
            }

            return(FallbackCredentialsFactory.GetCredentials());
        }
        /// <summary>
        /// Creates the AWSCredentials using either the profile indicated from the AWSOptions object
        /// of the SDK fallback credentials search.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static AWSCredentials CreateCredentials(ILogger logger, AWSOptions options)
        {
            if (options != null)
            {
                if (options.Credentials != null)
                {
                    logger?.LogInformation("Using AWS credentials specified with the AWSOptions.Credentials property");
                    return(options.Credentials);
                }
                if (!string.IsNullOrEmpty(options.Profile))
                {
                    var            chain = new CredentialProfileStoreChain(options.ProfilesLocation);
                    AWSCredentials result;
                    if (chain.TryGetAWSCredentials(options.Profile, out result))
                    {
                        logger?.LogInformation($"Found AWS credentials for the profile {options.Profile}");
                        return(result);
                    }
                    else
                    {
                        logger?.LogInformation($"Failed to find AWS credentials for the profile {options.Profile}");
                    }
                }
            }

            var credentials = FallbackCredentialsFactory.GetCredentials();

            if (credentials == null)
            {
                logger?.LogError("Last effort to find AWS Credentials with AWS SDK's default credential search failed");
                throw new AmazonClientException("Failed to find AWS Credentials for constructing AWS service client");
            }
            else
            {
                logger?.LogInformation("Found credentials using the AWS SDK's default credential search");
            }

            return(credentials);
        }
Example #8
0
 /// <summary>
 /// Constructs an instance of the ClientFactory
 /// </summary>
 /// <param name="type">The type object for the Amazon service client interface, for example IAmazonS3.</param>
 internal ClientFactory(Type type, AWSOptions awsOptions)
 {
     _serviceInterfaceType = type;
     _awsOptions           = awsOptions;
 }
        /// <summary>
        /// Creates the AWS service client that implements the service client interface. The AWSOptions object
        /// will be searched for in the IServiceProvider.
        /// </summary>
        /// <param name="provider">The dependency injection provider.</param>
        /// <returns>The AWS service client</returns>
        internal static IAmazonService CreateServiceClient(ILogger logger, Type serviceInterfaceType, AWSOptions options)
        {
            var credentials = CreateCredentials(logger, options);
            var config      = CreateConfig(serviceInterfaceType, options);
            var client      = CreateClient(serviceInterfaceType, credentials, config);

            return(client as IAmazonService);
        }
Example #10
0
        /// <summary>
        /// Creates the ClientConfig object for the service client.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static ClientConfig CreateConfig(Type serviceInterfaceType, AWSOptions options)
        {
            var configTypeName = serviceInterfaceType.Namespace + "." + serviceInterfaceType.Name.Substring(1) + "Config";
            var configType     = serviceInterfaceType.GetTypeInfo().Assembly.GetType(configTypeName);

            var          constructor = configType.GetConstructor(EMPTY_TYPES);
            ClientConfig config      = constructor.Invoke(EMPTY_PARAMETERS) as ClientConfig;

            if (options == null)
            {
                options = new AWSOptions();
            }

            if (options.DefaultConfigurationMode.HasValue)
            {
                config.DefaultConfigurationMode = options.DefaultConfigurationMode.Value;
            }

            var defaultConfig = options.DefaultClientConfig;

            if (options.IsDefaultClientConfigSet)
            {
                var emptyArray  = new object[0];
                var singleArray = new object[1];

                var clientConfigTypeInfo = typeof(ClientConfig).GetTypeInfo();
                foreach (var property in clientConfigTypeInfo.DeclaredProperties)
                {
                    if (property.GetMethod != null && property.SetMethod != null)
                    {
                        // Skip RegionEndpoint because it is set below and calling the get method on the
                        // property triggers the default region fallback mechanism.
                        if (string.Equals(property.Name, "RegionEndpoint", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        // DefaultConfigurationMode is skipped from the DefaultClientConfig because it is expected to be set
                        // at the top level of AWSOptions which is done before this loop.
                        if (string.Equals(property.Name, "DefaultConfigurationMode", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        // Skip setting RetryMode if it is set to legacy but the DefaultConfigurationMode is not legacy.
                        // This will allow the retry mode to be configured from the DefaultConfiguration.
                        // This is a workaround to handle the inability to tell if RetryMode was explicitly set.
                        if (string.Equals(property.Name, "RetryMode", StringComparison.Ordinal) &&
                            defaultConfig.RetryMode == RequestRetryMode.Legacy &&
                            config.DefaultConfigurationMode != DefaultConfigurationMode.Legacy)
                        {
                            continue;
                        }

                        singleArray[0] = property.GetMethod.Invoke(defaultConfig, emptyArray);
                        if (singleArray[0] != null)
                        {
                            property.SetMethod.Invoke(config, singleArray);
                        }
                    }
                }
            }

            // Setting RegionEndpoint only if ServiceURL was not set, because ServiceURL value will be lost otherwise
            if (options.Region != null && string.IsNullOrEmpty(defaultConfig.ServiceURL))
            {
                config.RegionEndpoint = options.Region;
            }

            return(config);
        }
 public S3WebRequestCreate(ILogger logger, Amazon.Extensions.NETCore.Setup.AWSOptions options, S3BucketsOptions s3BucketsConfiguration = null)
 {
     this.logger  = logger;
     this.options = options;
     this.s3BucketsConfiguration = s3BucketsConfiguration;
 }