コード例 #1
0
        /// <summary>
        /// Builds the set used to identify a specific endpoint variant
        /// </summary>
        /// <param name="dualStack">Whether to use a dualstack (IPv6 enabled) endpoint</param>
        /// <param name="fips">Whether to use a FIPS-compliant endpoint</param>
        /// <returns>Set used to identify the combined variant in endpoints.json</returns>
        private static HashSet <string> BuildVariantHashSet(GetEndpointForServiceOptions options)
        {
            options = options ?? new GetEndpointForServiceOptions();

            if (!options.DualStack && !options.FIPS)
            {
                return(null);
            }

            var variants = new HashSet <string>();

            if (options.DualStack)
            {
                variants.Add("dualstack");
            }
            if (options.FIPS)
            {
                variants.Add("fips");
            }

            return(variants);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the endpoint for the given service in the current region
        /// </summary>
        /// <param name="serviceName">Name of the service in endpoints.json</param>
        /// <param name="options"> Specify additional requirements on the <see cref="RegionEndpoint.Endpoint"/> to be returned.</param>
        /// <returns>Matching endpoint from endpoints.json, or a computed endpoint if possible</returns>
        public RegionEndpoint.Endpoint GetEndpointForService(string serviceName, GetEndpointForServiceOptions options)
        {
            var variants = BuildVariantHashSet(options);

            return(GetEndpointForService(serviceName, variants));
        }
コード例 #3
0
            /// <summary>
            /// Gets the endpoint for a service in a region.
            /// </summary>
            /// <param name="serviceName">The services system name.</param>
            /// <param name="options"> Specify additional requirements on the <see cref="Amazon.RegionEndpoint.Endpoint"/> to be returned.</param>
            /// <exception cref="System.ArgumentException">Thrown when the request service does not have a valid endpoint in the region.</exception>
            public Amazon.RegionEndpoint.Endpoint GetEndpointForService(string serviceName, GetEndpointForServiceOptions options)
            {
                if (options?.FIPS == true)
                {
                    throw new NotSupportedException($"{typeof(RegionEndpointProviderV2)} does not support FIPS");
                }

                if (!RegionEndpoint.loaded)
                {
                    RegionEndpoint.LoadEndpointDefinitions();
                }

                var rule             = GetEndpointRule(serviceName);
                var endpointTemplate = rule["endpoint"].ToString();

                if (options?.DualStack == true)
                {
                    // We need special handling for S3's s3.amazonaws.com endpoint, which doesn't
                    // support dualstack (need to transform to s3.dualstack.us-east-1.amazonaws.com).
                    // Other endpoints that begin s3-* need to transform to s3.* for dualstack support.
                    // S3's 'external' endpoints do not support dualstack and should not be transformed.
                    if (serviceName.Equals("s3", StringComparison.OrdinalIgnoreCase))
                    {
                        if (endpointTemplate.Equals("s3.amazonaws.com", StringComparison.OrdinalIgnoreCase))
                        {
                            endpointTemplate = "s3.dualstack.us-east-1.amazonaws.com";
                        }
                        else
                        {
                            var isExternalEndpoint = endpointTemplate.StartsWith("s3-external-", StringComparison.OrdinalIgnoreCase);
                            if (!isExternalEndpoint)
                            {
                                // transform fixed s3-<region> to s3.<region> and then onto s3.dualstack.<region>,
                                // bypassing endpoints that do not start with the expected tags.
                                if (endpointTemplate.StartsWith("s3-", StringComparison.OrdinalIgnoreCase))
                                {
                                    endpointTemplate = "s3." + endpointTemplate.Substring(3);
                                }

                                if (endpointTemplate.StartsWith("s3.", StringComparison.OrdinalIgnoreCase))
                                {
                                    endpointTemplate = endpointTemplate.Replace("s3.", "s3.dualstack.");
                                }
                            }
                        }
                    }
                    else
                    {
                        endpointTemplate = endpointTemplate.Replace("{region}", "dualstack.{region}");
                    }
                }

                var hostName = endpointTemplate.Replace("{region}", this.SystemName).Replace("{service}", serviceName);

                string signatureVersion = null;

                if (rule["signature-version"] != null)
                {
                    signatureVersion = rule["signature-version"].ToString();
                }

                string authRegion;

                if (rule["auth-region"] != null)
                {
                    authRegion = rule["auth-region"].ToString();
                }
                else
                {
                    authRegion = Amazon.Util.AWSSDKUtils.DetermineRegion(hostName);
                }

                if (string.Equals(authRegion, this.SystemName, StringComparison.OrdinalIgnoreCase))
                {
                    authRegion = null;
                }

                // v2 doesn't support the 'deprecated' property
                var deprecated = false;

                return(new Amazon.RegionEndpoint.Endpoint(hostName, authRegion, signatureVersion, deprecated));
            }