func()

in pkg/aws/ec2/api/wrapper.go [930:960]


func (e *ec2Wrapper) getRegionalStsEndpoint(partitionID, region string) (endpoints.ResolvedEndpoint, error) {
	var partition *endpoints.Partition
	stsServiceID := "sts"
	for _, p := range endpoints.DefaultPartitions() {
		if partitionID == p.ID() {
			partition = &p
			break
		}
	}
	if partition == nil {
		return endpoints.ResolvedEndpoint{}, fmt.Errorf("partition %s not valid", partitionID)
	}

	stsSvc, ok := partition.Services()[stsServiceID]
	if !ok {
		e.log.Info("STS service not found in partition, generating default endpoint.", "Partition:", partitionID)
		// Add the host of the current instances region if the service doesn't already exists in the partition
		// so we don't fail if the service is not present in the go sdk but matches the instances region.
		res, err := partition.EndpointFor(stsServiceID, region, endpoints.STSRegionalEndpointOption, endpoints.ResolveUnknownServiceOption)
		if err != nil {
			return endpoints.ResolvedEndpoint{}, fmt.Errorf("error resolving endpoint for %s in partition %s. err: %v", region, partition.ID(), err)
		}
		return res, nil
	}

	res, err := stsSvc.ResolveEndpoint(region, endpoints.STSRegionalEndpointOption)
	if err != nil {
		return endpoints.ResolvedEndpoint{}, fmt.Errorf("error resolving endpoint for %s in partition %s. err: %v", region, partition.ID(), err)
	}
	return res, nil
}