1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# frozen_string_literal: true
require 'set'
module Aws
module Partitions
class Region
# @option options [required, String] :name
# @option options [required, String] :description
# @option options [required, String] :partition_name
# @option options [required, Set<String>] :services
# @api private
def initialize(options = {})
@name = options[:name]
@description = options[:description]
@partition_name = options[:partition_name]
@services = options[:services]
end
# @return [String] The name of this region, e.g. "us-east-1".
attr_reader :name
# @return [String] A short description of this region.
attr_reader :description
# @return [String] The partition this region exists in, e.g. "aws",
# "aws-cn", "aws-us-gov".
attr_reader :partition_name
# @return [Set<String>] The list of services available in this region.
# Service names are the module names as used by the AWS SDK
# for Ruby.
attr_reader :services
class << self
# @api private
def build(region_name, region, partition)
Region.new(
name: region_name,
description: region['description'],
partition_name: partition['partition'],
services: region_services(region_name, partition)
)
end
private
def region_services(region_name, partition)
Partitions.service_ids.inject(Set.new) do |services, (svc_name, svc_id)|
if svc = partition['services'][svc_id]
services << svc_name if service_in_region?(svc, region_name)
else
#raise "missing endpoints for #{svc_name} / #{svc_id}"
end
services
end
end
def service_in_region?(svc, region_name)
svc.key?('endpoints') && svc['endpoints'].key?(region_name)
end
end
end
end
end
|