Module: Aws::Endpoints::Matchers Private

Defined in:
lib/aws-sdk-core/endpoints/matchers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

generic matcher functions for service endpoints

Constant Summary collapse

BRACKET_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Regex that extracts anything in square brackets

/\[(.*?)\]/.freeze

Class Method Summary collapse

Class Method Details

.attr(value, path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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
          value[parts.first.gsub(BRACKET_REGEX, '')][index.to_i]
        else
          value[parts.first]
        end

  if parts.size == 1
    val
  else
    attr(val, parts.slice(1..-1).join('.'))
  end
end

.aws_parse_arn(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



104
105
106
107
108
109
110
111
112
113
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 104

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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



92
93
94
95
96
97
98
99
100
101
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 92

def self.aws_partition(value)
  partition =
    Aws::Partitions.find { |p| p.region?(value) } ||
    Aws::Partitions.find { |p| value.match(p.region_regex) } ||
    Aws::Partitions.find { |p| p.name == 'aws' }

  return nil unless partition

  partition.
end

.aws_virtual_hostable_s3_bucket?(value, allow_sub_domains = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 116

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) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

booleanEquals(value1: bool, value2: bool) bool

Returns:

  • (Boolean)


61
62
63
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 61

def self.boolean_equals?(value1, value2)
  value1 == value2
end

.not(bool) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

not(value: bool) bool



21
22
23
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 21

def self.not(bool)
  !bool
end

.parse_url(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

parseUrl(value: string) Option<URL>



71
72
73
74
75
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 71

def self.parse_url(value)
  URL.new(value).as_json
rescue ArgumentError, URI::InvalidURIError
  nil
end

.set?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

isSet(value: Option<T>) bool

Returns:

  • (Boolean)


16
17
18
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 16

def self.set?(value)
  !value.nil?
end

.string_equals?(value1, value2) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

stringEquals(value1: string, value2: string) bool

Returns:

  • (Boolean)


56
57
58
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 56

def self.string_equals?(value1, value2)
  value1 == value2
end

.substring(input, start, stop, reverse) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 43

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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

uriEncode(value: string) string



66
67
68
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 66

def self.uri_encode(value)
  CGI.escape(value.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
end

.valid_host_label?(value, allow_sub_domains = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

isValidHostLabel(value: string, allowSubDomains: bool) bool

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
# File 'lib/aws-sdk-core/endpoints/matchers.rb', line 78

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