class AWS::Core::Policy::ConditionBlock


s3:max-keys may be any of: 10
aws:CurrentTime may be any of: 2010-10-12 2011-01-02
s3:prefix may be any of: photos/index.html
This would print the following lines:<br><br>end<br>end<br>equality_conditions.values.join(“ ”)
puts(“#{key} may be any of: ” +
equality_conditions.keys.each do |key|<br>conditions.each do |equality_conditions|
one:
You can also perform more sophisticated queries, like this
# => [“2010-10-12”, “2011-01-02”]<br>conditions[“aws:CurrentTime”].values
#operators, and #values – for example:
You can get access to the condition data using #[], #keys,
}
}
“s3:max-keys”: 10
“NumericEquals”: {
},
“aws:CurrentTime”: [“2010-10-12”, “2011-01-02”]
“DateEquals”: {
},
“s3:prefix”: “photos/index.html”
“StringEquals”: {
{
(in JSON):
has. For example, consider the following condition block
condition block to see what operators, keys, and values it
This class also provides a convenient way to query a
to specify keys and operators.
See the add method documentation for more details about how
conditions.add(:like, :s3_prefix, “photos/*”, “photos.html”)
example using the add method, for example:
ConditionBlock lets you specify conditions like the above
{ “StringLike”: { “s3:prefix”: [“photos/*”, “photos.html”] } }
condition blocks look like this:
Represents the condition block of a policy. In JSON,

def [](*args)

Returns:
  • (ConditionBlock) - A new set of conditions filtered by the

Other tags:
    See: #add -
def [](*args)
  filtered = @conditions
  args.each do |filter|
    type = valid_operator?(filter) ? nil : :key
    filtered = filter_conditions(filtered) do |op, key, value|
      (match, type) = match_triple(filter, type, op, key, value)
      match
    end
  end
  self.class.new(filtered)
end

def add(operator, key, *values)

Parameters:
  • values (Mixed) -- The value to compare against.
  • key (Symbol or String) -- The key to compare. Symbol
  • operator (Symbol or String) -- The operator used to
def add(operator, key, *values)
  if operator.kind_of?(Symbol)
    converted_values = values.map { |v| convert_value(v) }
  else
    converted_values = values
  end
  operator = translate_operator(operator, values.first)
  op = (@conditions[operator] ||= {})
  raise "duplicate #{operator} conditions for #{key}" if op[key]
  op[translate_key(key)] = converted_values
end

def base_translate(example, base_operator, *modifiers)

def base_translate(example, base_operator, *modifiers)
  "#{type_notation(example)}#{base_operator}#{modifiers.join}"
end

def convert_value(value)

def convert_value(value)
  case value
  when DateTime, Time
    Time.parse(value.to_s).iso8601
  when Date
    value.strftime("%Y-%m-%d")
  else
    value
  end
end

def filter_conditions(conditions = @conditions)

def filter_conditions(conditions = @conditions)
  conditions.inject({}) do |m, (op, keys)|
    m[op] = keys.inject({}) do |m2, (key, value)|
      m2[key] = value if !block_given? or yield(op, key, value)
      m2
    end
    m.delete(op) if m[op].empty?
    m
  end
end

def initialize(conditions = {})

Other tags:
    Api: - private
def initialize(conditions = {})
  # filter makes a copy
  @conditions = filter_conditions(conditions)
end

def keys

Returns:
  • (Array) - Returns an array of unique keys used in the block.
def keys
  @conditions.values.map do |keys|
    keys.keys if keys
  end.compact.flatten.uniq
end

def match_key(filter, key, value = nil)

def match_key(filter, key, value = nil)
  translate_key(filter) == key
end

def match_operator(filter, op, value)

def match_operator(filter, op, value)
  # dates are the only values that don't come back as native types in JSON
  # but where we use the type as a cue to the operator translation
  value = Date.today if op =~ /^Date/
  translate_operator(filter, value) == op
end

def match_triple(filter, type, op, key, value)

def match_triple(filter, type, op, key, value)
  value = [value].flatten.first
  if type
    target = (type == :operator ? op : key)
    match = send("match_#{type}", filter, target, value)
  else
    if match_operator(filter, op, value)
      match = true
      type = :operator
    elsif match_key(filter, key)
      match = true
      type = :key
    else
      match = false
    end
  end
  [match, type]
end

def operators

Returns:
  • (Array) - Returns an array of operators used in this block.
def operators
  @conditions.keys
end

def strip_modifiers(operator)

def strip_modifiers(operator)
  opts = {}
  MODIFIERS.each do |(regex, mod)|
    ruby_name = Inflection.ruby_name(mod).to_sym
    opts[ruby_name] = ""
    if operator.to_s =~ regex
      opts[ruby_name] = mod
      operator = operator.to_s.sub(regex, '').to_sym
    end
  end
  [operator, opts]
end

def to_h

Other tags:
    Api: - private
def to_h
  @conditions
end

def translate_greater_than(example, opts)

def translate_greater_than(example, opts)
  base_translate(example, "GreaterThan", opts[:equals])
end

def translate_gte(example, opts)

def translate_gte(example, opts)
  translate_greater_than(example, { :equals => "Equals" })
end

def translate_is(example, opts)

def translate_is(example, opts)
  return "Bool" if type_notation(example) == "Bool"
  base_translate(example, "Equals", opts[:ignore_case])
end

def translate_is_arn(example, opts)

def translate_is_arn(example, opts)
  "ArnEquals"
end

def translate_is_arn_like(example, opts)

def translate_is_arn_like(example, opts)
  "ArnLike"
end

def translate_is_ip_address(example, opts)

def translate_is_ip_address(example, opts)
  "IpAddress"
end

def translate_key(key)

def translate_key(key)
  if key.kind_of?(Symbol)
    if key.to_s =~ /^s3_(.*)$/
      s3_name = $1
      if s3_name == "version_id" or
          s3_name == "location_constraint"
        s3_name = Inflection.class_name(s3_name)
      else
        s3_name.tr!('_', '-')
      end
      "s3:#{s3_name}"
    else
      "aws:#{Inflection.class_name(key.to_s)}"
    end
  else
    key
  end
end

def translate_less_than(example, opts)

def translate_less_than(example, opts)
  base_translate(example, "LessThan", opts[:equals])
end

def translate_like(example, opts)

def translate_like(example, opts)
  base_translate(example, "Like")
end

def translate_lte(example, opts)

def translate_lte(example, opts)
  translate_less_than(example, { :equals => "Equals" })
end

def translate_not(example, opts)

def translate_not(example, opts)
  base_translate(example, "NotEquals", opts[:ignore_case])
end

def translate_not_arn(example, opts)

def translate_not_arn(example, opts)
  "ArnNotEquals"
end

def translate_not_arn_like(example, opts)

def translate_not_arn_like(example, opts)
  "ArnNotLike"
end

def translate_not_ip_address(example, opts)

def translate_not_ip_address(example, opts)
  "NotIpAddress"
end

def translate_not_like(example, opts)

def translate_not_like(example, opts)
  base_translate(example, "NotLike")
end

def translate_operator(operator, example_value)

def translate_operator(operator, example_value)
  return operator if operator.kind_of?(String)
  original_operator = operator
  (operator, opts) = strip_modifiers(operator)
  raise ArgumentError.new("unrecognized operator #{original_operator}") unless
    respond_to?("translate_#{operator}", true)
  send("translate_#{operator}", example_value, opts)
end

def type_notation(example)

def type_notation(example)
  case example
  when String
    "String"
  when Numeric
    "Numeric"
  when Time, Date
    "Date"
  when true, false
    "Bool"
  end
end

def valid_operator?(operator)

def valid_operator?(operator)
  translate_operator(operator, "")
  true
rescue ArgumentError => e
  false
end

def values

Returns:
  • (Array) - Returns an array of values used in this condition block.
def values
  @conditions.values.map do |keys|
    keys.values
  end.compact.flatten
end