1// Code generated by smithy-go-codegen DO NOT EDIT.
  2
  3package endpoints
  4
  5import (
  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
 13type 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
 38func (o Options) GetResolvedRegion() string {
 39	return o.ResolvedRegion
 40}
 41
 42func (o Options) GetDisableHTTPS() bool {
 43	return o.DisableHTTPS
 44}
 45
 46func (o Options) GetUseDualStackEndpoint() aws.DualStackEndpointState {
 47	return o.UseDualStackEndpoint
 48}
 49
 50func (o Options) GetUseFIPSEndpoint() aws.FIPSEndpointState {
 51	return o.UseFIPSEndpoint
 52}
 53
 54func 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
 66type Resolver struct {
 67	partitions endpoints.Partitions
 68}
 69
 70// ResolveEndpoint resolves the service endpoint for the given region and options
 71func (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
 81func New() *Resolver {
 82	return &Resolver{
 83		partitions: defaultPartitions,
 84	}
 85}
 86
 87var partitionRegexp = struct {
 88	Aws      *regexp.Regexp
 89	AwsCn    *regexp.Regexp
 90	AwsIso   *regexp.Regexp
 91	AwsIsoB  *regexp.Regexp
 92	AwsIsoE  *regexp.Regexp
 93	AwsIsoF  *regexp.Regexp
 94	AwsUsGov *regexp.Regexp
 95}{
 96
 97	Aws:      regexp.MustCompile("^(us|eu|ap|sa|ca|me|af|il)\\-\\w+\\-\\d+$"),
 98	AwsCn:    regexp.MustCompile("^cn\\-\\w+\\-\\d+$"),
 99	AwsIso:   regexp.MustCompile("^us\\-iso\\-\\w+\\-\\d+$"),
100	AwsIsoB:  regexp.MustCompile("^us\\-isob\\-\\w+\\-\\d+$"),
101	AwsIsoE:  regexp.MustCompile("^eu\\-isoe\\-\\w+\\-\\d+$"),
102	AwsIsoF:  regexp.MustCompile("^us\\-isof\\-\\w+\\-\\d+$"),
103	AwsUsGov: regexp.MustCompile("^us\\-gov\\-\\w+\\-\\d+$"),
104}
105
106var defaultPartitions = endpoints.Partitions{
107	{
108		ID: "aws",
109		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
110			{
111				Variant: endpoints.DualStackVariant,
112			}: {
113				Hostname:          "oidc.{region}.api.aws",
114				Protocols:         []string{"https"},
115				SignatureVersions: []string{"v4"},
116			},
117			{
118				Variant: endpoints.FIPSVariant,
119			}: {
120				Hostname:          "oidc-fips.{region}.amazonaws.com",
121				Protocols:         []string{"https"},
122				SignatureVersions: []string{"v4"},
123			},
124			{
125				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
126			}: {
127				Hostname:          "oidc-fips.{region}.api.aws",
128				Protocols:         []string{"https"},
129				SignatureVersions: []string{"v4"},
130			},
131			{
132				Variant: 0,
133			}: {
134				Hostname:          "oidc.{region}.amazonaws.com",
135				Protocols:         []string{"https"},
136				SignatureVersions: []string{"v4"},
137			},
138		},
139		RegionRegex:    partitionRegexp.Aws,
140		IsRegionalized: true,
141		Endpoints: endpoints.Endpoints{
142			endpoints.EndpointKey{
143				Region: "af-south-1",
144			}: endpoints.Endpoint{
145				Hostname: "oidc.af-south-1.amazonaws.com",
146				CredentialScope: endpoints.CredentialScope{
147					Region: "af-south-1",
148				},
149			},
150			endpoints.EndpointKey{
151				Region: "ap-east-1",
152			}: endpoints.Endpoint{
153				Hostname: "oidc.ap-east-1.amazonaws.com",
154				CredentialScope: endpoints.CredentialScope{
155					Region: "ap-east-1",
156				},
157			},
158			endpoints.EndpointKey{
159				Region: "ap-northeast-1",
160			}: endpoints.Endpoint{
161				Hostname: "oidc.ap-northeast-1.amazonaws.com",
162				CredentialScope: endpoints.CredentialScope{
163					Region: "ap-northeast-1",
164				},
165			},
166			endpoints.EndpointKey{
167				Region: "ap-northeast-2",
168			}: endpoints.Endpoint{
169				Hostname: "oidc.ap-northeast-2.amazonaws.com",
170				CredentialScope: endpoints.CredentialScope{
171					Region: "ap-northeast-2",
172				},
173			},
174			endpoints.EndpointKey{
175				Region: "ap-northeast-3",
176			}: endpoints.Endpoint{
177				Hostname: "oidc.ap-northeast-3.amazonaws.com",
178				CredentialScope: endpoints.CredentialScope{
179					Region: "ap-northeast-3",
180				},
181			},
182			endpoints.EndpointKey{
183				Region: "ap-south-1",
184			}: endpoints.Endpoint{
185				Hostname: "oidc.ap-south-1.amazonaws.com",
186				CredentialScope: endpoints.CredentialScope{
187					Region: "ap-south-1",
188				},
189			},
190			endpoints.EndpointKey{
191				Region: "ap-south-2",
192			}: endpoints.Endpoint{
193				Hostname: "oidc.ap-south-2.amazonaws.com",
194				CredentialScope: endpoints.CredentialScope{
195					Region: "ap-south-2",
196				},
197			},
198			endpoints.EndpointKey{
199				Region: "ap-southeast-1",
200			}: endpoints.Endpoint{
201				Hostname: "oidc.ap-southeast-1.amazonaws.com",
202				CredentialScope: endpoints.CredentialScope{
203					Region: "ap-southeast-1",
204				},
205			},
206			endpoints.EndpointKey{
207				Region: "ap-southeast-2",
208			}: endpoints.Endpoint{
209				Hostname: "oidc.ap-southeast-2.amazonaws.com",
210				CredentialScope: endpoints.CredentialScope{
211					Region: "ap-southeast-2",
212				},
213			},
214			endpoints.EndpointKey{
215				Region: "ap-southeast-3",
216			}: endpoints.Endpoint{
217				Hostname: "oidc.ap-southeast-3.amazonaws.com",
218				CredentialScope: endpoints.CredentialScope{
219					Region: "ap-southeast-3",
220				},
221			},
222			endpoints.EndpointKey{
223				Region: "ap-southeast-4",
224			}: endpoints.Endpoint{
225				Hostname: "oidc.ap-southeast-4.amazonaws.com",
226				CredentialScope: endpoints.CredentialScope{
227					Region: "ap-southeast-4",
228				},
229			},
230			endpoints.EndpointKey{
231				Region: "ca-central-1",
232			}: endpoints.Endpoint{
233				Hostname: "oidc.ca-central-1.amazonaws.com",
234				CredentialScope: endpoints.CredentialScope{
235					Region: "ca-central-1",
236				},
237			},
238			endpoints.EndpointKey{
239				Region: "ca-west-1",
240			}: endpoints.Endpoint{
241				Hostname: "oidc.ca-west-1.amazonaws.com",
242				CredentialScope: endpoints.CredentialScope{
243					Region: "ca-west-1",
244				},
245			},
246			endpoints.EndpointKey{
247				Region: "eu-central-1",
248			}: endpoints.Endpoint{
249				Hostname: "oidc.eu-central-1.amazonaws.com",
250				CredentialScope: endpoints.CredentialScope{
251					Region: "eu-central-1",
252				},
253			},
254			endpoints.EndpointKey{
255				Region: "eu-central-2",
256			}: endpoints.Endpoint{
257				Hostname: "oidc.eu-central-2.amazonaws.com",
258				CredentialScope: endpoints.CredentialScope{
259					Region: "eu-central-2",
260				},
261			},
262			endpoints.EndpointKey{
263				Region: "eu-north-1",
264			}: endpoints.Endpoint{
265				Hostname: "oidc.eu-north-1.amazonaws.com",
266				CredentialScope: endpoints.CredentialScope{
267					Region: "eu-north-1",
268				},
269			},
270			endpoints.EndpointKey{
271				Region: "eu-south-1",
272			}: endpoints.Endpoint{
273				Hostname: "oidc.eu-south-1.amazonaws.com",
274				CredentialScope: endpoints.CredentialScope{
275					Region: "eu-south-1",
276				},
277			},
278			endpoints.EndpointKey{
279				Region: "eu-south-2",
280			}: endpoints.Endpoint{
281				Hostname: "oidc.eu-south-2.amazonaws.com",
282				CredentialScope: endpoints.CredentialScope{
283					Region: "eu-south-2",
284				},
285			},
286			endpoints.EndpointKey{
287				Region: "eu-west-1",
288			}: endpoints.Endpoint{
289				Hostname: "oidc.eu-west-1.amazonaws.com",
290				CredentialScope: endpoints.CredentialScope{
291					Region: "eu-west-1",
292				},
293			},
294			endpoints.EndpointKey{
295				Region: "eu-west-2",
296			}: endpoints.Endpoint{
297				Hostname: "oidc.eu-west-2.amazonaws.com",
298				CredentialScope: endpoints.CredentialScope{
299					Region: "eu-west-2",
300				},
301			},
302			endpoints.EndpointKey{
303				Region: "eu-west-3",
304			}: endpoints.Endpoint{
305				Hostname: "oidc.eu-west-3.amazonaws.com",
306				CredentialScope: endpoints.CredentialScope{
307					Region: "eu-west-3",
308				},
309			},
310			endpoints.EndpointKey{
311				Region: "il-central-1",
312			}: endpoints.Endpoint{
313				Hostname: "oidc.il-central-1.amazonaws.com",
314				CredentialScope: endpoints.CredentialScope{
315					Region: "il-central-1",
316				},
317			},
318			endpoints.EndpointKey{
319				Region: "me-central-1",
320			}: endpoints.Endpoint{
321				Hostname: "oidc.me-central-1.amazonaws.com",
322				CredentialScope: endpoints.CredentialScope{
323					Region: "me-central-1",
324				},
325			},
326			endpoints.EndpointKey{
327				Region: "me-south-1",
328			}: endpoints.Endpoint{
329				Hostname: "oidc.me-south-1.amazonaws.com",
330				CredentialScope: endpoints.CredentialScope{
331					Region: "me-south-1",
332				},
333			},
334			endpoints.EndpointKey{
335				Region: "sa-east-1",
336			}: endpoints.Endpoint{
337				Hostname: "oidc.sa-east-1.amazonaws.com",
338				CredentialScope: endpoints.CredentialScope{
339					Region: "sa-east-1",
340				},
341			},
342			endpoints.EndpointKey{
343				Region: "us-east-1",
344			}: endpoints.Endpoint{
345				Hostname: "oidc.us-east-1.amazonaws.com",
346				CredentialScope: endpoints.CredentialScope{
347					Region: "us-east-1",
348				},
349			},
350			endpoints.EndpointKey{
351				Region: "us-east-2",
352			}: endpoints.Endpoint{
353				Hostname: "oidc.us-east-2.amazonaws.com",
354				CredentialScope: endpoints.CredentialScope{
355					Region: "us-east-2",
356				},
357			},
358			endpoints.EndpointKey{
359				Region: "us-west-1",
360			}: endpoints.Endpoint{
361				Hostname: "oidc.us-west-1.amazonaws.com",
362				CredentialScope: endpoints.CredentialScope{
363					Region: "us-west-1",
364				},
365			},
366			endpoints.EndpointKey{
367				Region: "us-west-2",
368			}: endpoints.Endpoint{
369				Hostname: "oidc.us-west-2.amazonaws.com",
370				CredentialScope: endpoints.CredentialScope{
371					Region: "us-west-2",
372				},
373			},
374		},
375	},
376	{
377		ID: "aws-cn",
378		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
379			{
380				Variant: endpoints.DualStackVariant,
381			}: {
382				Hostname:          "oidc.{region}.api.amazonwebservices.com.cn",
383				Protocols:         []string{"https"},
384				SignatureVersions: []string{"v4"},
385			},
386			{
387				Variant: endpoints.FIPSVariant,
388			}: {
389				Hostname:          "oidc-fips.{region}.amazonaws.com.cn",
390				Protocols:         []string{"https"},
391				SignatureVersions: []string{"v4"},
392			},
393			{
394				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
395			}: {
396				Hostname:          "oidc-fips.{region}.api.amazonwebservices.com.cn",
397				Protocols:         []string{"https"},
398				SignatureVersions: []string{"v4"},
399			},
400			{
401				Variant: 0,
402			}: {
403				Hostname:          "oidc.{region}.amazonaws.com.cn",
404				Protocols:         []string{"https"},
405				SignatureVersions: []string{"v4"},
406			},
407		},
408		RegionRegex:    partitionRegexp.AwsCn,
409		IsRegionalized: true,
410		Endpoints: endpoints.Endpoints{
411			endpoints.EndpointKey{
412				Region: "cn-north-1",
413			}: endpoints.Endpoint{
414				Hostname: "oidc.cn-north-1.amazonaws.com.cn",
415				CredentialScope: endpoints.CredentialScope{
416					Region: "cn-north-1",
417				},
418			},
419			endpoints.EndpointKey{
420				Region: "cn-northwest-1",
421			}: endpoints.Endpoint{
422				Hostname: "oidc.cn-northwest-1.amazonaws.com.cn",
423				CredentialScope: endpoints.CredentialScope{
424					Region: "cn-northwest-1",
425				},
426			},
427		},
428	},
429	{
430		ID: "aws-iso",
431		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
432			{
433				Variant: endpoints.FIPSVariant,
434			}: {
435				Hostname:          "oidc-fips.{region}.c2s.ic.gov",
436				Protocols:         []string{"https"},
437				SignatureVersions: []string{"v4"},
438			},
439			{
440				Variant: 0,
441			}: {
442				Hostname:          "oidc.{region}.c2s.ic.gov",
443				Protocols:         []string{"https"},
444				SignatureVersions: []string{"v4"},
445			},
446		},
447		RegionRegex:    partitionRegexp.AwsIso,
448		IsRegionalized: true,
449	},
450	{
451		ID: "aws-iso-b",
452		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
453			{
454				Variant: endpoints.FIPSVariant,
455			}: {
456				Hostname:          "oidc-fips.{region}.sc2s.sgov.gov",
457				Protocols:         []string{"https"},
458				SignatureVersions: []string{"v4"},
459			},
460			{
461				Variant: 0,
462			}: {
463				Hostname:          "oidc.{region}.sc2s.sgov.gov",
464				Protocols:         []string{"https"},
465				SignatureVersions: []string{"v4"},
466			},
467		},
468		RegionRegex:    partitionRegexp.AwsIsoB,
469		IsRegionalized: true,
470	},
471	{
472		ID: "aws-iso-e",
473		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
474			{
475				Variant: endpoints.FIPSVariant,
476			}: {
477				Hostname:          "oidc-fips.{region}.cloud.adc-e.uk",
478				Protocols:         []string{"https"},
479				SignatureVersions: []string{"v4"},
480			},
481			{
482				Variant: 0,
483			}: {
484				Hostname:          "oidc.{region}.cloud.adc-e.uk",
485				Protocols:         []string{"https"},
486				SignatureVersions: []string{"v4"},
487			},
488		},
489		RegionRegex:    partitionRegexp.AwsIsoE,
490		IsRegionalized: true,
491	},
492	{
493		ID: "aws-iso-f",
494		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
495			{
496				Variant: endpoints.FIPSVariant,
497			}: {
498				Hostname:          "oidc-fips.{region}.csp.hci.ic.gov",
499				Protocols:         []string{"https"},
500				SignatureVersions: []string{"v4"},
501			},
502			{
503				Variant: 0,
504			}: {
505				Hostname:          "oidc.{region}.csp.hci.ic.gov",
506				Protocols:         []string{"https"},
507				SignatureVersions: []string{"v4"},
508			},
509		},
510		RegionRegex:    partitionRegexp.AwsIsoF,
511		IsRegionalized: true,
512	},
513	{
514		ID: "aws-us-gov",
515		Defaults: map[endpoints.DefaultKey]endpoints.Endpoint{
516			{
517				Variant: endpoints.DualStackVariant,
518			}: {
519				Hostname:          "oidc.{region}.api.aws",
520				Protocols:         []string{"https"},
521				SignatureVersions: []string{"v4"},
522			},
523			{
524				Variant: endpoints.FIPSVariant,
525			}: {
526				Hostname:          "oidc-fips.{region}.amazonaws.com",
527				Protocols:         []string{"https"},
528				SignatureVersions: []string{"v4"},
529			},
530			{
531				Variant: endpoints.FIPSVariant | endpoints.DualStackVariant,
532			}: {
533				Hostname:          "oidc-fips.{region}.api.aws",
534				Protocols:         []string{"https"},
535				SignatureVersions: []string{"v4"},
536			},
537			{
538				Variant: 0,
539			}: {
540				Hostname:          "oidc.{region}.amazonaws.com",
541				Protocols:         []string{"https"},
542				SignatureVersions: []string{"v4"},
543			},
544		},
545		RegionRegex:    partitionRegexp.AwsUsGov,
546		IsRegionalized: true,
547		Endpoints: endpoints.Endpoints{
548			endpoints.EndpointKey{
549				Region: "us-gov-east-1",
550			}: endpoints.Endpoint{
551				Hostname: "oidc.us-gov-east-1.amazonaws.com",
552				CredentialScope: endpoints.CredentialScope{
553					Region: "us-gov-east-1",
554				},
555			},
556			endpoints.EndpointKey{
557				Region: "us-gov-west-1",
558			}: endpoints.Endpoint{
559				Hostname: "oidc.us-gov-west-1.amazonaws.com",
560				CredentialScope: endpoints.CredentialScope{
561					Region: "us-gov-west-1",
562				},
563			},
564		},
565	},
566}