code.dwrz.net

Go monorepo.
Log | Files | Refs

endpoints.go (12141B)


      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 STS 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:          "sts.{region}.api.aws",
    110 				Protocols:         []string{"https"},
    111 				SignatureVersions: []string{"v4"},
    112 			},
    113 			{
    114 				Variant: endpoints.FIPSVariant,
    115 			}: {
    116 				Hostname:          "sts-fips.{region}.amazonaws.com",
    117 				Protocols:         []string{"https"},
    118 				SignatureVersions: []string{"v4"},
    119 			},
    120 			{
    121 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    122 			}: {
    123 				Hostname:          "sts-fips.{region}.api.aws",
    124 				Protocols:         []string{"https"},
    125 				SignatureVersions: []string{"v4"},
    126 			},
    127 			{
    128 				Variant: 0,
    129 			}: {
    130 				Hostname:          "sts.{region}.amazonaws.com",
    131 				Protocols:         []string{"https"},
    132 				SignatureVersions: []string{"v4"},
    133 			},
    134 		},
    135 		RegionRegex:    partitionRegexp.Aws,
    136 		IsRegionalized: true,
    137 		Endpoints: endpoints.Endpoints{
    138 			endpoints.EndpointKey{
    139 				Region: "af-south-1",
    140 			}: endpoints.Endpoint{},
    141 			endpoints.EndpointKey{
    142 				Region: "ap-east-1",
    143 			}: endpoints.Endpoint{},
    144 			endpoints.EndpointKey{
    145 				Region: "ap-northeast-1",
    146 			}: endpoints.Endpoint{},
    147 			endpoints.EndpointKey{
    148 				Region: "ap-northeast-2",
    149 			}: endpoints.Endpoint{},
    150 			endpoints.EndpointKey{
    151 				Region: "ap-northeast-3",
    152 			}: endpoints.Endpoint{},
    153 			endpoints.EndpointKey{
    154 				Region: "ap-south-1",
    155 			}: endpoints.Endpoint{},
    156 			endpoints.EndpointKey{
    157 				Region: "ap-southeast-1",
    158 			}: endpoints.Endpoint{},
    159 			endpoints.EndpointKey{
    160 				Region: "ap-southeast-2",
    161 			}: endpoints.Endpoint{},
    162 			endpoints.EndpointKey{
    163 				Region: "ap-southeast-3",
    164 			}: endpoints.Endpoint{},
    165 			endpoints.EndpointKey{
    166 				Region: "aws-global",
    167 			}: endpoints.Endpoint{
    168 				Hostname: "sts.amazonaws.com",
    169 				CredentialScope: endpoints.CredentialScope{
    170 					Region: "us-east-1",
    171 				},
    172 			},
    173 			endpoints.EndpointKey{
    174 				Region: "ca-central-1",
    175 			}: endpoints.Endpoint{},
    176 			endpoints.EndpointKey{
    177 				Region: "eu-central-1",
    178 			}: endpoints.Endpoint{},
    179 			endpoints.EndpointKey{
    180 				Region: "eu-north-1",
    181 			}: endpoints.Endpoint{},
    182 			endpoints.EndpointKey{
    183 				Region: "eu-south-1",
    184 			}: endpoints.Endpoint{},
    185 			endpoints.EndpointKey{
    186 				Region: "eu-west-1",
    187 			}: endpoints.Endpoint{},
    188 			endpoints.EndpointKey{
    189 				Region: "eu-west-2",
    190 			}: endpoints.Endpoint{},
    191 			endpoints.EndpointKey{
    192 				Region: "eu-west-3",
    193 			}: endpoints.Endpoint{},
    194 			endpoints.EndpointKey{
    195 				Region: "me-central-1",
    196 			}: endpoints.Endpoint{},
    197 			endpoints.EndpointKey{
    198 				Region: "me-south-1",
    199 			}: endpoints.Endpoint{},
    200 			endpoints.EndpointKey{
    201 				Region: "sa-east-1",
    202 			}: endpoints.Endpoint{},
    203 			endpoints.EndpointKey{
    204 				Region: "us-east-1",
    205 			}: endpoints.Endpoint{},
    206 			endpoints.EndpointKey{
    207 				Region:  "us-east-1",
    208 				Variant: endpoints.FIPSVariant,
    209 			}: {
    210 				Hostname: "sts-fips.us-east-1.amazonaws.com",
    211 			},
    212 			endpoints.EndpointKey{
    213 				Region: "us-east-1-fips",
    214 			}: endpoints.Endpoint{
    215 				Hostname: "sts-fips.us-east-1.amazonaws.com",
    216 				CredentialScope: endpoints.CredentialScope{
    217 					Region: "us-east-1",
    218 				},
    219 				Deprecated: aws.TrueTernary,
    220 			},
    221 			endpoints.EndpointKey{
    222 				Region: "us-east-2",
    223 			}: endpoints.Endpoint{},
    224 			endpoints.EndpointKey{
    225 				Region:  "us-east-2",
    226 				Variant: endpoints.FIPSVariant,
    227 			}: {
    228 				Hostname: "sts-fips.us-east-2.amazonaws.com",
    229 			},
    230 			endpoints.EndpointKey{
    231 				Region: "us-east-2-fips",
    232 			}: endpoints.Endpoint{
    233 				Hostname: "sts-fips.us-east-2.amazonaws.com",
    234 				CredentialScope: endpoints.CredentialScope{
    235 					Region: "us-east-2",
    236 				},
    237 				Deprecated: aws.TrueTernary,
    238 			},
    239 			endpoints.EndpointKey{
    240 				Region: "us-west-1",
    241 			}: endpoints.Endpoint{},
    242 			endpoints.EndpointKey{
    243 				Region:  "us-west-1",
    244 				Variant: endpoints.FIPSVariant,
    245 			}: {
    246 				Hostname: "sts-fips.us-west-1.amazonaws.com",
    247 			},
    248 			endpoints.EndpointKey{
    249 				Region: "us-west-1-fips",
    250 			}: endpoints.Endpoint{
    251 				Hostname: "sts-fips.us-west-1.amazonaws.com",
    252 				CredentialScope: endpoints.CredentialScope{
    253 					Region: "us-west-1",
    254 				},
    255 				Deprecated: aws.TrueTernary,
    256 			},
    257 			endpoints.EndpointKey{
    258 				Region: "us-west-2",
    259 			}: endpoints.Endpoint{},
    260 			endpoints.EndpointKey{
    261 				Region:  "us-west-2",
    262 				Variant: endpoints.FIPSVariant,
    263 			}: {
    264 				Hostname: "sts-fips.us-west-2.amazonaws.com",
    265 			},
    266 			endpoints.EndpointKey{
    267 				Region: "us-west-2-fips",
    268 			}: endpoints.Endpoint{
    269 				Hostname: "sts-fips.us-west-2.amazonaws.com",
    270 				CredentialScope: endpoints.CredentialScope{
    271 					Region: "us-west-2",
    272 				},
    273 				Deprecated: aws.TrueTernary,
    274 			},
    275 		},
    276 	},
    277 	{
    278 		ID: "aws-cn",
    279 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    280 			{
    281 				Variant: endpoints.DualStackVariant,
    282 			}: {
    283 				Hostname:          "sts.{region}.api.amazonwebservices.com.cn",
    284 				Protocols:         []string{"https"},
    285 				SignatureVersions: []string{"v4"},
    286 			},
    287 			{
    288 				Variant: endpoints.FIPSVariant,
    289 			}: {
    290 				Hostname:          "sts-fips.{region}.amazonaws.com.cn",
    291 				Protocols:         []string{"https"},
    292 				SignatureVersions: []string{"v4"},
    293 			},
    294 			{
    295 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    296 			}: {
    297 				Hostname:          "sts-fips.{region}.api.amazonwebservices.com.cn",
    298 				Protocols:         []string{"https"},
    299 				SignatureVersions: []string{"v4"},
    300 			},
    301 			{
    302 				Variant: 0,
    303 			}: {
    304 				Hostname:          "sts.{region}.amazonaws.com.cn",
    305 				Protocols:         []string{"https"},
    306 				SignatureVersions: []string{"v4"},
    307 			},
    308 		},
    309 		RegionRegex:    partitionRegexp.AwsCn,
    310 		IsRegionalized: true,
    311 		Endpoints: endpoints.Endpoints{
    312 			endpoints.EndpointKey{
    313 				Region: "cn-north-1",
    314 			}: endpoints.Endpoint{},
    315 			endpoints.EndpointKey{
    316 				Region: "cn-northwest-1",
    317 			}: endpoints.Endpoint{},
    318 		},
    319 	},
    320 	{
    321 		ID: "aws-iso",
    322 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    323 			{
    324 				Variant: endpoints.FIPSVariant,
    325 			}: {
    326 				Hostname:          "sts-fips.{region}.c2s.ic.gov",
    327 				Protocols:         []string{"https"},
    328 				SignatureVersions: []string{"v4"},
    329 			},
    330 			{
    331 				Variant: 0,
    332 			}: {
    333 				Hostname:          "sts.{region}.c2s.ic.gov",
    334 				Protocols:         []string{"https"},
    335 				SignatureVersions: []string{"v4"},
    336 			},
    337 		},
    338 		RegionRegex:    partitionRegexp.AwsIso,
    339 		IsRegionalized: true,
    340 		Endpoints: endpoints.Endpoints{
    341 			endpoints.EndpointKey{
    342 				Region: "us-iso-east-1",
    343 			}: endpoints.Endpoint{},
    344 			endpoints.EndpointKey{
    345 				Region: "us-iso-west-1",
    346 			}: endpoints.Endpoint{},
    347 		},
    348 	},
    349 	{
    350 		ID: "aws-iso-b",
    351 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    352 			{
    353 				Variant: endpoints.FIPSVariant,
    354 			}: {
    355 				Hostname:          "sts-fips.{region}.sc2s.sgov.gov",
    356 				Protocols:         []string{"https"},
    357 				SignatureVersions: []string{"v4"},
    358 			},
    359 			{
    360 				Variant: 0,
    361 			}: {
    362 				Hostname:          "sts.{region}.sc2s.sgov.gov",
    363 				Protocols:         []string{"https"},
    364 				SignatureVersions: []string{"v4"},
    365 			},
    366 		},
    367 		RegionRegex:    partitionRegexp.AwsIsoB,
    368 		IsRegionalized: true,
    369 		Endpoints: endpoints.Endpoints{
    370 			endpoints.EndpointKey{
    371 				Region: "us-isob-east-1",
    372 			}: endpoints.Endpoint{},
    373 		},
    374 	},
    375 	{
    376 		ID: "aws-us-gov",
    377 		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
    378 			{
    379 				Variant: endpoints.DualStackVariant,
    380 			}: {
    381 				Hostname:          "sts.{region}.api.aws",
    382 				Protocols:         []string{"https"},
    383 				SignatureVersions: []string{"v4"},
    384 			},
    385 			{
    386 				Variant: endpoints.FIPSVariant,
    387 			}: {
    388 				Hostname:          "sts.{region}.amazonaws.com",
    389 				Protocols:         []string{"https"},
    390 				SignatureVersions: []string{"v4"},
    391 			},
    392 			{
    393 				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
    394 			}: {
    395 				Hostname:          "sts-fips.{region}.api.aws",
    396 				Protocols:         []string{"https"},
    397 				SignatureVersions: []string{"v4"},
    398 			},
    399 			{
    400 				Variant: 0,
    401 			}: {
    402 				Hostname:          "sts.{region}.amazonaws.com",
    403 				Protocols:         []string{"https"},
    404 				SignatureVersions: []string{"v4"},
    405 			},
    406 		},
    407 		RegionRegex:    partitionRegexp.AwsUsGov,
    408 		IsRegionalized: true,
    409 		Endpoints: endpoints.Endpoints{
    410 			endpoints.EndpointKey{
    411 				Region: "us-gov-east-1",
    412 			}: endpoints.Endpoint{},
    413 			endpoints.EndpointKey{
    414 				Region:  "us-gov-east-1",
    415 				Variant: endpoints.FIPSVariant,
    416 			}: {
    417 				Hostname: "sts.us-gov-east-1.amazonaws.com",
    418 			},
    419 			endpoints.EndpointKey{
    420 				Region: "us-gov-east-1-fips",
    421 			}: endpoints.Endpoint{
    422 				Hostname: "sts.us-gov-east-1.amazonaws.com",
    423 				CredentialScope: endpoints.CredentialScope{
    424 					Region: "us-gov-east-1",
    425 				},
    426 				Deprecated: aws.TrueTernary,
    427 			},
    428 			endpoints.EndpointKey{
    429 				Region: "us-gov-west-1",
    430 			}: endpoints.Endpoint{},
    431 			endpoints.EndpointKey{
    432 				Region:  "us-gov-west-1",
    433 				Variant: endpoints.FIPSVariant,
    434 			}: {
    435 				Hostname: "sts.us-gov-west-1.amazonaws.com",
    436 			},
    437 			endpoints.EndpointKey{
    438 				Region: "us-gov-west-1-fips",
    439 			}: endpoints.Endpoint{
    440 				Hostname: "sts.us-gov-west-1.amazonaws.com",
    441 				CredentialScope: endpoints.CredentialScope{
    442 					Region: "us-gov-west-1",
    443 				},
    444 				Deprecated: aws.TrueTernary,
    445 			},
    446 		},
    447 	},
    448 }