module Aws::Endpoints::Matchers

generic matcher functions for service endpoints @api private

Constants

BRACKET_REGEX

Regex that extracts anything in square brackets

Public Class Methods

attr(value, path) click to toggle source

getAttr(value: Object | Array, path: string) Document

# File lib/aws-sdk-core/endpoints/matchers.rb, line 26
def self.attr(value, path)
  parts = path.split('.')

  val = if (index = parts.first[BRACKET_REGEX, 1])
          # remove brackets and index from part before indexing
          if (base = parts.first.gsub(BRACKET_REGEX, '')) && !base.empty?
            value[base][index.to_i]
          else
            value[index.to_i]
          end
        else
          value[parts.first]
        end

  if parts.size == 1
    val
  else
    attr(val, parts.slice(1..-1).join('.'))
  end
end
aws_parse_arn(value) click to toggle source

aws.parseArn(value: string) Option<ARN>

# File lib/aws-sdk-core/endpoints/matchers.rb, line 101
def self.aws_parse_arn(value)
  arn = Aws::ARNParser.parse(value)
  json = arn.as_json
  # HACK: because of poor naming and also requirement of splitting
  resource = json.delete('resource')
  json['resourceId'] = resource.split(%r{[:\/]}, -1)
  json
rescue Aws::Errors::InvalidARNError
  nil
end
aws_partition(value) click to toggle source

aws.partition(value: string) Option<Partition>

# File lib/aws-sdk-core/endpoints/matchers.rb, line 96
def self.aws_partition(value)
  Aws::Partitions::Metadata.partition(value)
end
aws_virtual_hostable_s3_bucket?(value, allow_sub_domains = false) click to toggle source

aws.isVirtualHostableS3Bucket(value: string, allowSubDomains: bool) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 113
def self.aws_virtual_hostable_s3_bucket?(value, allow_sub_domains = false)
  return false if value.empty?

  if allow_sub_domains
    labels = value.split('.', -1)
    return labels.all? { |l| aws_virtual_hostable_s3_bucket?(l) }
  end

  # must be between 3 and 63 characters long, no uppercase
  value =~ /\A(?!-)[a-z0-9-]{3,63}(?<!-)\z/ &&
    # not an IP address
    value !~ /(\d+\.){3}\d+/
end
boolean_equals?(value1, value2) click to toggle source

booleanEquals(value1: bool, value2: bool) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 65
def self.boolean_equals?(value1, value2)
  value1 == value2
end
not(bool) click to toggle source

not(value: bool) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 21
def self.not(bool)
  !bool
end
parse_url(value) click to toggle source

parseUrl(value: string) Option<URL>

# File lib/aws-sdk-core/endpoints/matchers.rb, line 75
def self.parse_url(value)
  URL.new(value).as_json
rescue ArgumentError, URI::InvalidURIError
  nil
end
set?(value) click to toggle source

isSet(value: Option<T>) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 16
def self.set?(value)
  !value.nil?
end
string_equals?(value1, value2) click to toggle source

stringEquals(value1: string, value2: string) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 60
def self.string_equals?(value1, value2)
  value1 == value2
end
substring(input, start, stop, reverse) click to toggle source
# File lib/aws-sdk-core/endpoints/matchers.rb, line 47
def self.substring(input, start, stop, reverse)
  return nil if start >= stop || input.size < stop

  return nil if input.chars.any? { |c| c.ord > 127 }

  return input[start...stop] unless reverse

  r_start = input.size - stop
  r_stop = input.size - start
  input[r_start...r_stop]
end
uri_encode(value) click to toggle source

uriEncode(value: string) string

# File lib/aws-sdk-core/endpoints/matchers.rb, line 70
def self.uri_encode(value)
  CGI.escape(value.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
end
valid_host_label?(value, allow_sub_domains = false) click to toggle source

isValidHostLabel(value: string, allowSubDomains: bool) bool

# File lib/aws-sdk-core/endpoints/matchers.rb, line 82
def self.valid_host_label?(value, allow_sub_domains = false)
  return false if value.empty?

  if allow_sub_domains
    labels = value.split('.', -1)
    return labels.all? { |l| valid_host_label?(l) }
  end

  !!(value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/)
end