code.dwrz.net

Go monorepo.
Log | Files | Refs

endpoints.go (11504B)


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