code.dwrz.net

Go monorepo.
Log | Files | Refs

endpoints.go (9401B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package endpoints
      4 
      5 import (
      6 	"github.com/aws/aws-sdk-go-v2/aws"
      7 	endpoints "github.com/aws/aws-sdk-go-v2/internal/endpoints/v2"
      8 	"github.com/aws/smithy-go/logging"
      9 	"regexp"
     10 )
     11 
     12 // Options is the endpoint resolver configuration options
     13 type Options struct {
     14 	// Logger is a logging implementation that log events should be sent to.
     15 	Logger logging.Logger
     16 
     17 	// LogDeprecated indicates that deprecated endpoints should be logged to the
     18 	// provided logger.
     19 	LogDeprecated bool
     20 
     21 	// ResolvedRegion is used to override the region to be resolved, rather then the
     22 	// using the value passed to the ResolveEndpoint method. This value is used by the
     23 	// SDK to translate regions like fips-us-east-1 or us-east-1-fips to an alternative
     24 	// name. You must not set this value directly in your application.
     25 	ResolvedRegion string
     26 
     27 	// DisableHTTPS informs the resolver to return an endpoint that does not use the
     28 	// HTTPS scheme.
     29 	DisableHTTPS bool
     30 
     31 	// UseDualStackEndpoint specifies the resolver must resolve a dual-stack endpoint.
     32 	UseDualStackEndpoint aws.DualStackEndpointState
     33 
     34 	// UseFIPSEndpoint specifies the resolver must resolve a FIPS endpoint.
     35 	UseFIPSEndpoint aws.FIPSEndpointState
     36 }
     37 
     38 func (o Options) GetResolvedRegion() string {
     39 	return o.ResolvedRegion
     40 }
     41 
     42 func (o Options) GetDisableHTTPS() bool {
     43 	return o.DisableHTTPS
     44 }
     45 
     46 func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState {
     47 	return o.UseDualStackEndpoint
     48 }
     49 
     50 func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState {
     51 	return o.UseFIPSEndpoint
     52 }
     53 
     54 func transformToSharedOptions(options Options) endpoints.Options {
     55 	return endpoints.Options{
     56 		Logger:               options.Logger,
     57 		LogDeprecated:        options.LogDeprecated,
     58 		ResolvedRegion:       options.ResolvedRegion,
     59 		DisableHTTPS:         options.DisableHTTPS,
     60 		UseDualStackEndpoint: options.UseDualStackEndpoint,
     61 		UseFIPSEndpoint:      options.UseFIPSEndpoint,
     62 	}
     63 }
     64 
     65 // Resolver Route 53 endpoint resolver
     66 type Resolver struct {
     67 	partitions endpoints.Partitions
     68 }
     69 
     70 // ResolveEndpoint resolves the service endpoint for the given region and options
     71 func (r *Resolver) ResolveEndpoint(region string, options Options) (endpoint aws.Endpoint, err error) {
     72 	if len(region) == 0 {
     73 		return endpoint, &aws.MissingRegionError{}
     74 	}
     75 
     76 	opt := transformToSharedOptions(options)
     77 	return r.partitions.ResolveEndpoint(region, opt)
     78 }
     79 
     80 // New returns a new Resolver
     81 func New() *Resolver {
     82 	return &Resolver{
     83 		partitions: defaultPartitions,
     84 	}
     85 }
     86 
     87 var partitionRegexp = struct {
     88 	Aws      *regexp.Regexp
     89 	AwsCn    *regexp.Regexp
     90 	AwsIso   *regexp.Regexp
     91 	AwsIsoB  *regexp.Regexp
     92 	AwsUsGov *regexp.Regexp
     93 }{
     94 
     95 	Aws:      regexp.MustCompile("^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$"),
     96 	AwsCn:    regexp.MustCompile("^cn\\-\\w+\\-\\d+$"),
     97 	AwsIso:   regexp.MustCompile("^us\\-iso\\-\\w+\\-\\d+$"),
     98 	AwsIsoB:  regexp.MustCompile("^us\\-isob\\-\\w+\\-\\d+$"),
     99 	AwsUsGov: regexp.MustCompile("^us\\-gov\\-\\w+\\-\\d+$"),
    100 }
    101 
    102 var defaultPartitions = endpoints.Partitions{
    103 	{
    104 		ID: "aws",
    105 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    106 			{
    107 				Variant: endpoints.DualStackVariant,
    108 			}: {
    109 				Hostname:          "route53.{region}.api.aws",
    110 				Protocols:         []string{"https"},
    111 				SignatureVersions: []string{"v4"},
    112 			},
    113 			{
    114 				Variant: endpoints.FIPSVariant,
    115 			}: {
    116 				Hostname:          "route53-fips.{region}.amazonaws.com",
    117 				Protocols:         []string{"https"},
    118 				SignatureVersions: []string{"v4"},
    119 			},
    120 			{
    121 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    122 			}: {
    123 				Hostname:          "route53-fips.{region}.api.aws",
    124 				Protocols:         []string{"https"},
    125 				SignatureVersions: []string{"v4"},
    126 			},
    127 			{
    128 				Variant: 0,
    129 			}: {
    130 				Hostname:          "route53.{region}.amazonaws.com",
    131 				Protocols:         []string{"https"},
    132 				SignatureVersions: []string{"v4"},
    133 			},
    134 		},
    135 		RegionRegex:       partitionRegexp.Aws,
    136 		IsRegionalized:    false,
    137 		PartitionEndpoint: "aws-global",
    138 		Endpoints: endpoints.Endpoints{
    139 			endpoints.EndpointKey{
    140 				Region: "aws-global",
    141 			}: endpoints.Endpoint{
    142 				Hostname: "route53.amazonaws.com",
    143 				CredentialScope: endpoints.CredentialScope{
    144 					Region: "us-east-1",
    145 				},
    146 			},
    147 			endpoints.EndpointKey{
    148 				Region:  "aws-global",
    149 				Variant: endpoints.FIPSVariant,
    150 			}: {
    151 				Hostname: "route53-fips.amazonaws.com",
    152 				CredentialScope: endpoints.CredentialScope{
    153 					Region: "us-east-1",
    154 				},
    155 			},
    156 			endpoints.EndpointKey{
    157 				Region: "fips-aws-global",
    158 			}: endpoints.Endpoint{
    159 				Hostname: "route53-fips.amazonaws.com",
    160 				CredentialScope: endpoints.CredentialScope{
    161 					Region: "us-east-1",
    162 				},
    163 				Deprecated: aws.TrueTernary,
    164 			},
    165 		},
    166 	},
    167 	{
    168 		ID: "aws-cn",
    169 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    170 			{
    171 				Variant: endpoints.DualStackVariant,
    172 			}: {
    173 				Hostname:          "route53.{region}.api.amazonwebservices.com.cn",
    174 				Protocols:         []string{"https"},
    175 				SignatureVersions: []string{"v4"},
    176 			},
    177 			{
    178 				Variant: endpoints.FIPSVariant,
    179 			}: {
    180 				Hostname:          "route53-fips.{region}.amazonaws.com.cn",
    181 				Protocols:         []string{"https"},
    182 				SignatureVersions: []string{"v4"},
    183 			},
    184 			{
    185 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    186 			}: {
    187 				Hostname:          "route53-fips.{region}.api.amazonwebservices.com.cn",
    188 				Protocols:         []string{"https"},
    189 				SignatureVersions: []string{"v4"},
    190 			},
    191 			{
    192 				Variant: 0,
    193 			}: {
    194 				Hostname:          "route53.{region}.amazonaws.com.cn",
    195 				Protocols:         []string{"https"},
    196 				SignatureVersions: []string{"v4"},
    197 			},
    198 		},
    199 		RegionRegex:       partitionRegexp.AwsCn,
    200 		IsRegionalized:    false,
    201 		PartitionEndpoint: "aws-cn-global",
    202 		Endpoints: endpoints.Endpoints{
    203 			endpoints.EndpointKey{
    204 				Region: "aws-cn-global",
    205 			}: endpoints.Endpoint{
    206 				Hostname: "route53.amazonaws.com.cn",
    207 				CredentialScope: endpoints.CredentialScope{
    208 					Region: "cn-northwest-1",
    209 				},
    210 			},
    211 		},
    212 	},
    213 	{
    214 		ID: "aws-iso",
    215 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    216 			{
    217 				Variant: endpoints.FIPSVariant,
    218 			}: {
    219 				Hostname:          "route53-fips.{region}.c2s.ic.gov",
    220 				Protocols:         []string{"https"},
    221 				SignatureVersions: []string{"v4"},
    222 			},
    223 			{
    224 				Variant: 0,
    225 			}: {
    226 				Hostname:          "route53.{region}.c2s.ic.gov",
    227 				Protocols:         []string{"https"},
    228 				SignatureVersions: []string{"v4"},
    229 			},
    230 		},
    231 		RegionRegex:       partitionRegexp.AwsIso,
    232 		IsRegionalized:    false,
    233 		PartitionEndpoint: "aws-iso-global",
    234 		Endpoints: endpoints.Endpoints{
    235 			endpoints.EndpointKey{
    236 				Region: "aws-iso-global",
    237 			}: endpoints.Endpoint{
    238 				Hostname: "route53.c2s.ic.gov",
    239 				CredentialScope: endpoints.CredentialScope{
    240 					Region: "us-iso-east-1",
    241 				},
    242 			},
    243 		},
    244 	},
    245 	{
    246 		ID: "aws-iso-b",
    247 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    248 			{
    249 				Variant: endpoints.FIPSVariant,
    250 			}: {
    251 				Hostname:          "route53-fips.{region}.sc2s.sgov.gov",
    252 				Protocols:         []string{"https"},
    253 				SignatureVersions: []string{"v4"},
    254 			},
    255 			{
    256 				Variant: 0,
    257 			}: {
    258 				Hostname:          "route53.{region}.sc2s.sgov.gov",
    259 				Protocols:         []string{"https"},
    260 				SignatureVersions: []string{"v4"},
    261 			},
    262 		},
    263 		RegionRegex:       partitionRegexp.AwsIsoB,
    264 		IsRegionalized:    false,
    265 		PartitionEndpoint: "aws-iso-b-global",
    266 		Endpoints: endpoints.Endpoints{
    267 			endpoints.EndpointKey{
    268 				Region: "aws-iso-b-global",
    269 			}: endpoints.Endpoint{
    270 				Hostname: "route53.sc2s.sgov.gov",
    271 				CredentialScope: endpoints.CredentialScope{
    272 					Region: "us-isob-east-1",
    273 				},
    274 			},
    275 		},
    276 	},
    277 	{
    278 		ID: "aws-us-gov",
    279 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    280 			{
    281 				Variant: endpoints.DualStackVariant,
    282 			}: {
    283 				Hostname:          "route53.{region}.api.aws",
    284 				Protocols:         []string{"https"},
    285 				SignatureVersions: []string{"v4"},
    286 			},
    287 			{
    288 				Variant: endpoints.FIPSVariant,
    289 			}: {
    290 				Hostname:          "route53-fips.{region}.amazonaws.com",
    291 				Protocols:         []string{"https"},
    292 				SignatureVersions: []string{"v4"},
    293 			},
    294 			{
    295 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    296 			}: {
    297 				Hostname:          "route53-fips.{region}.api.aws",
    298 				Protocols:         []string{"https"},
    299 				SignatureVersions: []string{"v4"},
    300 			},
    301 			{
    302 				Variant: 0,
    303 			}: {
    304 				Hostname:          "route53.{region}.amazonaws.com",
    305 				Protocols:         []string{"https"},
    306 				SignatureVersions: []string{"v4"},
    307 			},
    308 		},
    309 		RegionRegex:       partitionRegexp.AwsUsGov,
    310 		IsRegionalized:    false,
    311 		PartitionEndpoint: "aws-us-gov-global",
    312 		Endpoints: endpoints.Endpoints{
    313 			endpoints.EndpointKey{
    314 				Region: "aws-us-gov-global",
    315 			}: endpoints.Endpoint{
    316 				Hostname: "route53.us-gov.amazonaws.com",
    317 				CredentialScope: endpoints.CredentialScope{
    318 					Region: "us-gov-west-1",
    319 				},
    320 			},
    321 			endpoints.EndpointKey{
    322 				Region:  "aws-us-gov-global",
    323 				Variant: endpoints.FIPSVariant,
    324 			}: {
    325 				Hostname: "route53.us-gov.amazonaws.com",
    326 				CredentialScope: endpoints.CredentialScope{
    327 					Region: "us-gov-west-1",
    328 				},
    329 			},
    330 			endpoints.EndpointKey{
    331 				Region: "fips-aws-us-gov-global",
    332 			}: endpoints.Endpoint{
    333 				Hostname: "route53.us-gov.amazonaws.com",
    334 				CredentialScope: endpoints.CredentialScope{
    335 					Region: "us-gov-west-1",
    336 				},
    337 				Deprecated: aws.TrueTernary,
    338 			},
    339 		},
    340 	},
    341 }