Class: Awful::CloudWatchEvents

Inherits:
Cli show all
Defined in:
lib/awful/cloudwatch_events.rb

Constant Summary collapse

COLORS =
{
  ENABLED:  :green,
  DISABLED: :yellow,
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#dump(name) ⇒ Object



53
54
55
56
57
# File 'lib/awful/cloudwatch_events.rb', line 53

def dump(name)
  events.describe_rule(name: name).tap do |rule|
    puts YAML.dump(stringify_keys(rule.to_hash))
  end
end

#ls(prefix = nil) ⇒ Object



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
# File 'lib/awful/cloudwatch_events.rb', line 26

def ls(prefix = nil)
  next_token = nil
  rules = []
  loop do
    response = events.list_rules(name_prefix: prefix, next_token: next_token)
    rules = rules + response.rules
    next_token = response.next_token
    break if next_token.nil?
  end

  rules.tap do |list|
    if options[:long]
      print_table list.map { |r|
        [
          r.name,
          color(r.state),
          r.schedule_expression,
          r.description,
        ]
      }
    else
      puts list.map(&:name)
    end
  end
end

#targets(name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/awful/cloudwatch_events.rb', line 61

def targets(name)
  next_token = nil
  targets = []
  loop do
    response = events.list_targets_by_rule(rule: name)
    targets = targets + response.targets
    next_token = response.next_token
    break if next_token.nil?
  end
  targets.tap do |list|
    if options[:long]
      print_table list.map { |t| [t.id, t.arn, t.input, t.input_path] }
    else
      puts list.map(&:arn)
    end
  end
end